chenhaozhe
2026-03-27 9d4fdc8ef43bfcafdb4a0f3e0e3d59cef1812b15
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
using System;
using System.Collections.Generic;
using System.Data;
 
namespace DAL
{
    public class ClsGy_SteppedPriceCoefficientBill : DBUtility.ClsXt_BaseBill
    {
        public Model.ClsGy_SteppedPriceCoefficientBillMain omodel = new Model.ClsGy_SteppedPriceCoefficientBillMain();
        public List<Model.ClsGy_SteppedPriceCoefficientBillSub> DetailColl = new List<Model.ClsGy_SteppedPriceCoefficientBillSub>();
 
        public ClsGy_SteppedPriceCoefficientBill()
        {
            base.MvarItemKeySub = "Gy_SteppedPriceCoefficientBillSub";
            base.MvarItemKeySub2 = "";
            base.MvarItemKeySub3 = "";
            base.MvarItemKeySub4 = "";
            base.MvarItemKey = "Gy_SteppedPriceCoefficientBillMain";
            base.MvarReportTitle = "阶梯工价系数单";
            base.BillType = "GYSTPRICECOEFF"; // 需要根据实际的单据类型编码设置
            base.HBillSubType = "GYSTPRICECOEFF";
        }
 
        #region 固定代码
 
        ~ClsGy_SteppedPriceCoefficientBill()
        {
            DetailColl = null;
        }
 
        #endregion
 
        #region 自定义方法
 
        // 修改单据
        public override bool ModifyBill(Int64 lngBillKey, ref string sReturn)
        {
            try
            {
                oCn.BeginTran();
 
                // 更新主表
                oCn.RunProc("Update Gy_SteppedPriceCoefficientBillMain set " +
                    "HBillNo = '" + omodel.HBillNo + "'" +
                    ", HDate = '" + omodel.HDate.ToString("yyyy-MM-dd HH:mm:ss") + "'" +
                    ", HYear = " + omodel.HYear.ToString() +
                    ", HPeriod = " + omodel.HPeriod.ToString() +
                    ", HRemark = '" + omodel.HRemark + "'" +
                    ", HUpDater = '" + DBUtility.ClsPub.CurUserName + "'" +
                    ", HUpDateDate = getdate()" +
                    // 自定义字段
                    ", HProcID = " + omodel.HProcID.ToString() +
                    ", HEmpID = " + omodel.HEmpID.ToString() +
                    ", HDeptID = " + omodel.HDeptID.ToString() +
                    ", HStockOrgID = " + omodel.HStockOrgID.ToString() +
                    " where HInterID = " + lngBillKey.ToString());
 
                // 删除关联
                DeleteRelation(ref sReturn, lngBillKey);
 
                sReturn = "修改单据成功!";
                oCn.Commit();
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                oCn.RollBack();
                throw;
            }
        }
 
        // 新增单据
        public override bool AddBill(ref string sReturn)
        {
            try
            {
                // 得到mainid
                omodel.HInterID = DBUtility.ClsPub.CreateBillID(BillType, ref DBUtility.ClsPub.sExeReturnInfo);
 
                oCn.BeginTran();
 
                // 插入主表
                oCn.RunProc("Insert Into Gy_SteppedPriceCoefficientBillMain " +
                    "(HBillType, HBillSubType, HInterID, HBillNo, HDate" +
                    ", HYear, HPeriod, HRemark, HMaker, HMakeDate, HCheckFlowID" +
                    ", HProcID, HEmpID, HDeptID, HStockOrgID" +
                    ") values('" +
                    this.BillType + "','" +
                    this.HBillSubType + "'," +
                    omodel.HInterID.ToString() + ",'" +
                    omodel.HBillNo + "','" +
                    omodel.HDate.ToString("yyyy-MM-dd HH:mm:ss") + "'," +
                    omodel.HYear.ToString() + "," +
                    omodel.HPeriod.ToString() + ",'" +
                    omodel.HRemark + "','" +
                    DBUtility.ClsPub.CurUserName + "',getdate()," +
                    omodel.HCheckFlowID.ToString() + "," +
                    omodel.HProcID.ToString() + "," +
                    omodel.HEmpID.ToString() + "," +
                    omodel.HDeptID.ToString() + "," +
                    omodel.HStockOrgID.ToString() +
                    ")");
 
                // 插入子表
                foreach (Model.ClsGy_SteppedPriceCoefficientBillSub oSub in DetailColl)
                {
                    string entryCloseDate = oSub.HEntryCloseDate.HasValue ?
                        oSub.HEntryCloseDate.Value.ToString("yyyy-MM-dd HH:mm:ss") : "NULL";
 
                    oCn.RunProc("Insert into Gy_SteppedPriceCoefficientBillSub " +
                        "(HInterID, HEntryID, HCloseMan, HEntryCloseDate, HCloseType, HRemark" +
                        ", HSourceInterID, HSourceEntryID, HSourceBillNo, HSourceBillType" +
                        ", HRelationQty, HRelationPrice, HSeq, HMinQty, HMaxQty" +
                        ", HPriceCoefficient, HMaxPrice, HStockOrgID" +
                        ") values(" +
                        omodel.HInterID.ToString() + "," +
                        oSub.HEntryID.ToString() + ",'" +
                        oSub.HCloseMan + "'," +
                        (entryCloseDate == "NULL" ? "NULL" : "'" + entryCloseDate + "'") + "," +
                        (oSub.HCloseType ? "1" : "0") + ",'" +
                        oSub.HRemark + "'," +
                        oSub.HSourceInterID.ToString() + "," +
                        oSub.HSourceEntryID.ToString() + ",'" +
                        oSub.HSourceBillNo + "','" +
                        oSub.HSourceBillType + "'," +
                        oSub.HRelationQty.ToString() + "," +
                        oSub.HRelationPrice.ToString() + "," +
                        oSub.HSeq.ToString() + "," +
                        oSub.HMinQty.ToString() + "," +
                        oSub.HMaxQty.ToString() + "," +
                        oSub.HPriceCoefficient.ToString() + "," +
                        oSub.HMaxPrice.ToString() + "," +
                        oSub.HStockOrgID.ToString() +
                        ")");
                }
 
                sReturn = "新增单据成功!";
                oCn.Commit();
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                oCn.RollBack();
                throw;
            }
        }
 
        // 显示单据
        public override bool ShowBill(Int64 lngBillKey, ref string sReturn)
        {
            try
            {
                // 查询主表
                DataSet Ds;
                Ds = oCn.RunProcReturn("Select * from Gy_SteppedPriceCoefficientBillMain Where HInterID = " + lngBillKey.ToString(), "Gy_SteppedPriceCoefficientBillMain");
 
                if (Ds.Tables[0].Rows.Count == 0)
                {
                    sReturn = "单据未找到!";
                    return false;
                }
 
                // 固定赋值===========================================
                omodel.HYear = (int)DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HYear"]);
                omodel.HPeriod = (int)DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HPeriod"]);
                omodel.HBillType = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HBillType"]);
                omodel.HBillSubType = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HBillSubType"]);
                omodel.HInterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"]);
                omodel.HDate = DBUtility.ClsPub.isDate(Ds.Tables[0].Rows[0]["HDate"]);
                omodel.HBillNo = Ds.Tables[0].Rows[0]["HBillNo"].ToString().Trim();
                omodel.HBillStatus = DBUtility.ClsPub.isInt(Ds.Tables[0].Rows[0]["HBillStatus"]);
                omodel.HCheckItemNowID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HCheckItemNowID"]);
                omodel.HCheckItemNextID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HCheckItemNextID"]);
                omodel.HCheckFlowID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HCheckFlowID"]);
                omodel.HRemark = Ds.Tables[0].Rows[0]["HRemark"].ToString().Trim();
                omodel.HBackDate = GetNullableDateTime(Ds.Tables[0].Rows[0]["HBackDate"]);
                omodel.HBacker = Ds.Tables[0].Rows[0]["HBacker"].ToString().Trim();
                omodel.HCheckDate = GetNullableDateTime(Ds.Tables[0].Rows[0]["HCheckDate"]);
                omodel.HChecker = Ds.Tables[0].Rows[0]["HChecker"].ToString().Trim();
                omodel.HMaker = Ds.Tables[0].Rows[0]["HMaker"].ToString().Trim();
                omodel.HMakeDate = DBUtility.ClsPub.isDate(Ds.Tables[0].Rows[0]["HMakeDate"]);
                omodel.HUpDateDate = GetNullableDateTime(Ds.Tables[0].Rows[0]["HUpDateDate"]);
                omodel.HUpDater = Ds.Tables[0].Rows[0]["HUpDater"].ToString().Trim();
                omodel.HCloseDate = GetNullableDateTime(Ds.Tables[0].Rows[0]["HCloseDate"]);
                omodel.HCloseMan = Ds.Tables[0].Rows[0]["HCloseMan"].ToString().Trim();
                omodel.HCloseType = DBUtility.ClsPub.isBool(Ds.Tables[0].Rows[0]["HCloseType"]);
                omodel.HDeleteDate = GetNullableDateTime(Ds.Tables[0].Rows[0]["HDeleteDate"]);
                omodel.HDeleteMan = Ds.Tables[0].Rows[0]["HDeleteMan"].ToString().Trim();
                //========================================================
 
                // 自定义字段
                omodel.HProcID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HProcID"]);
                omodel.HEmpID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HEmpID"]);
                omodel.HDeptID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HDeptID"]);
                omodel.HStockOrgID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HStockOrgID"]);
 
                // 查询子表
                DataSet DsSub;
                DsSub = oCn.RunProcReturn("Select * from Gy_SteppedPriceCoefficientBillSub Where HInterID = " + lngBillKey.ToString() + " order by HEntryID ", "Gy_SteppedPriceCoefficientBillSub");
 
                DetailColl.Clear(); // 清空
 
                for (int i = 0; i < DsSub.Tables[0].Rows.Count; i++)
                {
                    Model.ClsGy_SteppedPriceCoefficientBillSub oSub = new Model.ClsGy_SteppedPriceCoefficientBillSub();
 
                    // 固定赋值===============================================
                    oSub.HInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HInterID"]);
                    oSub.HEntryID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HEntryID"]);
                    oSub.HSourceInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HSourceInterID"]);
                    oSub.HSourceEntryID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HSourceEntryID"]);
                    oSub.HSourceBillType = DsSub.Tables[0].Rows[i]["HSourceBillType"].ToString().Trim();
                    oSub.HSourceBillNo = DsSub.Tables[0].Rows[i]["HSourceBillNo"].ToString().Trim();
                    oSub.HRelationQty = Convert.ToDecimal(DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HRelationQty"]));
                    oSub.HRelationPrice = Convert.ToDecimal(DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HRelationPrice"]));
                    oSub.HCloseMan = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HCloseMan"]);
                    oSub.HCloseType = DBUtility.ClsPub.isBool(DsSub.Tables[0].Rows[i]["HCloseType"]);
                    oSub.HEntryCloseDate = GetNullableDateTime(DsSub.Tables[0].Rows[i]["HEntryCloseDate"]);
                    oSub.HRemark = DsSub.Tables[0].Rows[i]["HRemark"].ToString().Trim();
                    //===================================================
 
                    // 自定义字段
                    oSub.HSeq = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HSeq"]);
                    oSub.HMinQty = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HMinQty"]);
                    oSub.HMaxQty = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HMaxQty"]);
                    oSub.HPriceCoefficient = Convert.ToDecimal(DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HPriceCoefficient"]));
                    oSub.HMaxPrice = Convert.ToDecimal(DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HMaxPrice"]));
                    oSub.HStockOrgID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HStockOrgID"]);
 
                    DetailColl.Add(oSub);
                }
 
                sReturn = "显示单据成功!";
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                throw;
            }
        }
 
        // 辅助方法:处理可空日期
        private DateTime? GetNullableDateTime(object value)
        {
            if (value == DBNull.Value || value == null)
                return null;
 
            try
            {
                return Convert.ToDateTime(value);
            }
            catch
            {
                return null;
            }
        }
 
        #endregion
 
        #region 其他方法 - 根据需要添加
 
        // 获取工序信息
        public DataSet GetProcessInfo(int procID)
        {
            return oCn.RunProcReturn("select * from Gy_Process where HInterID = " + procID, "Process");
        }
 
        //// 获取员工信息
        //public DataSet GetEmployeeInfo(int empID)
        //{
        //    return oCn.RunProcReturn("select * from t_Emp where FItemID = " + empID, "Employee");
        //}
 
        //// 获取部门信息
        //public DataSet GetDepartmentInfo(int deptID)
        //{
        //    return oCn.RunProcReturn("select * from t_Department where FItemID = " + deptID, "Department");
        //}
 
        //// 获取组织信息
        //public DataSet GetStockOrgInfo(int orgID)
        //{
        //    return oCn.RunProcReturn("select * from t_Stock where FItemID = " + orgID, "StockOrg");
        //}
 
        #endregion
    }
}