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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using SQLHelper;
 
namespace DBUtility
{
    public  class ClsXt_CheckFlowMain
    {
        public Int64  HInterID;
        public string HName;
        public string HBillTypeID;
        public Int64 HDeptID;
        public bool HStandard;
        public string HRemark;
        private string mvarItemKey;
        public  List<ClsXt_CheckFlowSub> DetailColl = new List<ClsXt_CheckFlowSub>();
        ClsCN oCn = new ClsCN();
 
        public ClsXt_CheckFlowMain()
        {
            mvarItemKey = "8803";
            mvarReportTitle = "审批流单";
        }
 
        #region 固定代码
        public string MvarItemKey
        {
            get { return mvarItemKey; }
            set { mvarItemKey = value; }
        }
        private string mvarReportTitle;
 
        public string MvarReportTitle
        {
            get { return mvarReportTitle; }
            set { mvarReportTitle = value; }
        }
 
        ~ClsXt_CheckFlowMain()
        {
            DetailColl = null;
        }
      
        //删除子表
        public void DeleteBillSub(Int64 lngBillKey)
        {
            oCn.RunProc("Delete From Xt_CheckFlowSub where HInterID=" + lngBillKey.ToString());
        }
        //删除主表
        public void DeleteBillMain(Int64 lngBillKey)
        {
            oCn.RunProc("Delete From Xt_CheckFlowMain where HInterID=" + lngBillKey.ToString());
        }
        //删除单据
        public bool DeleteBill(Int64 lngBillKey, ref string sReturn)
        {
            try
            {
                oCn.BeginTran();
                //删除关联
                DeleteRelation(ref sReturn, lngBillKey);
                //删除明细表
                DeleteBillSub(lngBillKey);
                //删除主表
                DeleteBillMain(lngBillKey);
                sReturn = "删除单据成功!";
                oCn.Commit();
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                oCn.RollBack();
                return false;
            }
        }
        //是否被关联
        public bool isUse(Int64 lngBillKey, ref string sReturn)
        {
            try
            {
                //查询主表
                DataSet Ds ;
                Ds = oCn.RunProcReturn("Select HinterID from Xt_CheckFlowSub Where HInterID=" + lngBillKey.ToString() + " and isnull(HRelationQty,0)<>0 ", "Xt_CheckFlowMain");
                if (Ds.Tables[0].Rows.Count != 0)
                {
                    sReturn = "单据已被关联,不能操作!";
                    return true;
                }
                sReturn = "";
                return false;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                return false;
            }
        }
        //读取下张单据
      
        //读取首张单据
        public bool GetFirstBill(ref string sReturn)
        {
            try
            {
                //查询主表
                Int64 lMainID = 0;
                DataSet Ds ;
                Ds = oCn.RunProcReturn("Select Top 1 HinterID from Xt_CheckFlowMain Where   HBillType='" + this.MvarItemKey + "' Order By HInterID ", "Xt_CheckFlowMain");
                if (Ds.Tables[0].Rows.Count != 0)
                {
                    lMainID = ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"].ToString());
                    if (lMainID != 0)
                    {
                        if (ShowBill(lMainID, ref sReturn))
                        {
                            sReturn = "查询首张单据成功";
                            return true;
                        }
                    }
                }
                sReturn = "查询首张单据失败";
                return false;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                return false;
            }
        }
        //读取末张单据
        public bool GetLastBill(ref string sReturn)
        {
            try
            {
                //查询主表
                Int64 lMainID = 0;
                DataSet Ds ;
                Ds = oCn.RunProcReturn("Select Top 1 HinterID from Xt_CheckFlowMain Where   HBillType='" + this.MvarItemKey + "' Order By HInterID Desc", "Xt_CheckFlowMain");
                if (Ds.Tables[0].Rows.Count != 0)
                {
                    lMainID = ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"].ToString());
                    if (lMainID != 0)
                    {
                        if (ShowBill(lMainID, ref sReturn))
                        {
                            sReturn = "查询末张单据成功";
                            return true;
                        }
                    }
                }
                sReturn = "查询末张单据失败";
                return false;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                return false;
            }
        }
        //单据号是否重复
        public bool IsExistBillNo(ref string sReturn, string sBillNo, Pub_Class.ClsPub.Enum_BillStatus oBillStatus, Int64 lngBillKey)
        {
            try
            {
                string sSql = "";
                if (oBillStatus == Pub_Class.ClsPub.Enum_BillStatus.BillStatus_AddNew)
                {
                    sSql = "Select HInterID from Xt_CheckFlowMain where hbilltype='" + MvarItemKey + "'and HBillNO ='" + sBillNo + "'";
                }
                else
                {
                    sSql = "Select HInterID from Xt_CheckFlowMain where hbilltype='" + MvarItemKey + "'and HBillNO ='" + sBillNo + "' and HInterID<>" + lngBillKey.ToString();
                }
                DataSet Ds ;
                Ds = oCn.RunProcReturn(sSql, "Xt_CheckFlowMain");
                if (Ds.Tables[0].Rows.Count != 0)
                {
                    sReturn = "单号重复";
                    return true;
                }
                sReturn = "单号未重复";
                return false;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                return false;
            }
        }
        #endregion
        //修改单据
        public bool ModifyBill(Int64 lngBillKey, ref string sReturn)
        {
            try
            {
                //
                oCn.BeginTran();
                //更新主表
                oCn.RunProc("UpDate Xt_CheckFlowMain set  " +
                "HRemark='" + this.HRemark  + "'" +
                ",HName='" + this.HName + "'" +
                ",HDeptID=" + this.HDeptID.ToString() +
                ",HBillTypeID='" + this.HBillTypeID + "'" +
                ",HStandard='" +ClsPub.BoolToString(this.HStandard) + "'" +
                " where HInterID=" + lngBillKey.ToString());
                //删除关联
                DeleteRelation(ref sReturn, lngBillKey);
                //删除子表
                DeleteBillSub(lngBillKey);
                //插入子表
                foreach(ClsXt_CheckFlowSub oSub in DetailColl)
                {
                    oCn.RunProc("Insert into Xt_CheckFlowSub " +
                        " (HInterID,HEntryID,HCheckMan" +
                        ",HFlowNo,HJumpFlag,HMakerSelf,HCheckItemID" +
                        " )values("
                        + lngBillKey.ToString() + "," + oSub.HEntryID.ToString() +",'"+oSub.HCheckMan+"'"+
                        "," + oSub.HFlowNo + "," + Convert.ToString(oSub.HJumpFlag ? 1 : 0) + "," + Convert.ToString(oSub.HMakerSelf ? 1 : 0) + "," + oSub.HCheckItemID + "" + ") ");
                }
                sReturn = "修改单据成功!";
                oCn.Commit();
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                oCn.RollBack();
                return false;
            }
        }
        //新增单据
        public bool AddBill( ref string sReturn)
        {
            try
            {
                //得到mainid
                this.HInterID = ClsPub.CreateBillID(MvarItemKey, ref ClsPub.sExeReturnInfo);
                //若MAINDI重复则重新获取
                oCn.BeginTran();
                //主表
                oCn.RunProc("Insert Into Xt_CheckFlowMain   " +
                "(HBillTypeID,HInterID,HDeptID" + 
                ",HRemark,HStandard,HName" +
                ") " +
                " values('" + this.HBillTypeID.ToString() + "'," + this.HInterID.ToString() + "," + this.HDeptID.ToString() + 
                ",'" + this.HRemark + "'," + Convert.ToString(this.HStandard ? 1 : 0) + ",'" + this.HName.ToString() +
                "') ");
                //插入子表
                foreach (ClsXt_CheckFlowSub oSub in DetailColl)
                {
                    oCn.RunProc("Insert into Xt_CheckFlowSub " +
                        " (HInterID,HEntryID,HCheckMan" +
                        ",HFlowNo,HJumpFlag,HMakerSelf,HCheckItemID" +
                        " )values("
                        + this.HInterID.ToString() + "," + oSub.HEntryID.ToString() + ",'" + oSub.HCheckMan + "'" +
                        "," + oSub.HFlowNo + "," + Convert.ToString(oSub.HJumpFlag ? 1 : 0) + "," + Convert.ToString(oSub.HMakerSelf ? 1 : 0) + "," + oSub.HCheckItemID + "" + ") ");
                }
                sReturn = "新增单据成功!";
                oCn.Commit();
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                oCn.RollBack();
                return false;
            }
        }
        //显示单据
        public bool ShowBill(Int64 lngBillKey, ref string sReturn)
        {
            try
            {
                //查询主表
                DataSet Ds ;
                Ds = oCn.RunProcReturn("Select * from Xt_CheckFlowMain Where HInterID=" + lngBillKey.ToString(), "Xt_CheckFlowMain");
                if(Ds.Tables[0].Rows.Count==0)
                {
                    sReturn = "单据未找到!";
                    return false;
                }
                //赋值
                this.HInterID =ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"].ToString());
                this.HName = Ds.Tables[0].Rows[0]["HName"].ToString().Trim();
                this.HBillTypeID =ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HBillTypeID"].ToString().Trim());
                this.HStandard = ClsPub.isBool(Ds.Tables[0].Rows[0]["HStandard"]);
                this.HRemark = Ds.Tables[0].Rows[0]["HRemark"].ToString().Trim();
                this.HDeptID = ClsPub.isLong(Ds.Tables[0].Rows[0]["HDeptID"].ToString());
                //
                //循环
                DataSet DsSub ;
                DsSub = oCn.RunProcReturn("Select * from Xt_CheckFlowSub Where HInterID=" + lngBillKey.ToString(), "Xt_CheckFlowMain");
                DetailColl.Clear();//清空
                for (int i = 0; i < DsSub.Tables[0].Rows.Count; i++)
                {
                    ClsXt_CheckFlowSub oSub = new ClsXt_CheckFlowSub();
                    oSub.HInterID =ClsPub.isLong( DsSub.Tables[0].Rows[i]["HInterID"].ToString());
                    oSub.HEntryID = ClsPub.isLong(DsSub.Tables[0].Rows[i]["HEntryID"].ToString());
                    oSub.HFlowNo = ClsPub.isInt(DsSub.Tables[0].Rows[i]["HFlowNo"].ToString());
                    oSub.HCheckItemID = ClsPub.isLong(DsSub.Tables[0].Rows[i]["HCheckItemID"].ToString());
                    oSub.HJumpFlag = ClsPub.isBool(DsSub.Tables[0].Rows[i]["HJumpFlag"].ToString());
                    oSub.HMakerSelf = ClsPub.isBool(DsSub.Tables[0].Rows[i]["HMakerSelf"].ToString());
                    oSub.HCheckMan = DsSub.Tables[0].Rows[i]["HCheckMan"].ToString();
 
                    DetailColl.Add(oSub);
                }
                sReturn = "显示单据成功!";
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                return false;
            }
        }
       
        //MAINID是否重复
        public bool IsExistMainID(ref string sReturn, Int64 lngBillKey)
        {
            sReturn = "";
            return false;
        }
        //删除关联
        public void  DeleteRelation(ref string sReturn, Int64 lngBillKey)
        {
            sReturn = "";
            return;
        }
    }
 
}