YL
2022-02-21 a905b3df0d0c9ae045b51d1299fbb2f2dcbc2e2d
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
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
 
namespace Pub_Control
{
    public  class Clsxt_ICSchemeMain
    {
        public Int64  HInterID;
        public string HName;
        public string HUserCode;
        public string HBillName;
        public string HBillType;
        public bool HStopflag;
        public Int16 HRowHeight;//内容行高
        public Int16 HFixRowHeight;//标题行高
        public Int16 HFontSize;//字体大小
        private string mvarItemKey;
        public  List<Clsxt_ICSchemeSub> DetailColl = new List<Clsxt_ICSchemeSub>();
        public List<Clsxt_ICSchemeMain> MainColl;
        Pub_Class.ClsSqlHelper oCn = new Pub_Class.ClsSqlHelper();
 
        public Clsxt_ICSchemeMain()
        {
            mvarItemKey = "0001";
            mvarReportTitle = "过滤方案";
        }
 
        #region 固定代码
        public string MvarItemKey
        {
            get { return mvarItemKey; }
            set { mvarItemKey = value; }
        }
        private string mvarReportTitle;
 
        public string MvarReportTitle
        {
            get { return mvarReportTitle; }
            set { mvarReportTitle = value; }
        }
 
        ~Clsxt_ICSchemeMain()
        {
            DetailColl = null;
        }
       
        //删除子表
        public void DeleteBillSub(Int64 lngBillKey)
        {
            oCn.RunProc("Delete From xt_ICSchemeSub where HInterID=" + lngBillKey.ToString());
        }
        //删除主表
        public void DeleteBillMain(Int64 lngBillKey)
        {
            oCn.RunProc("Delete From xt_ICSchemeMain 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 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_ICSchemeMain where hbilltype='" + MvarItemKey + "'and HName ='" + sBillNo + "'";
                }
                else
                {
                    sSql = "Select HInterID from xt_ICSchemeMain where hbilltype='" + MvarItemKey + "'and HName ='" + sBillNo + "' and HInterID<>" + lngBillKey.ToString();
                }
                DataSet Ds ;
                Ds = oCn.RunProcReturn(sSql, "xt_ICSchemeMain");
                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();
                //更新主表
                //主表
                DeleteBillMain(lngBillKey);
                oCn.RunProc("Insert Into xt_ICSchemeMain   " +
                "(HBillType,HInterID,HName,HUserCode" +
                ",HBillName,HStopflag" +
                ") " +
                " values('" + this.MvarItemKey + "'," + lngBillKey.ToString() + ",'" + this.HName + "','" + this.HUserCode + "'" +
                ",'" + this.HBillName.ToString() + "',0" +
                ") ");
                //删除关联
                DeleteRelation(ref sReturn, lngBillKey);
                //删除子表
                DeleteBillSub(lngBillKey);
                //插入子表
                foreach(Clsxt_ICSchemeSub oSub in DetailColl)
                {
                    oCn.RunProc("Insert into xt_ICSchemeSub " +
                        " (HInterID,HKey,HValue)" +
                        " values("
                        + this.HInterID.ToString() + ",'" + oSub.HKey.ToString() + "','" + oSub.HValue.ToString() + "') ");
                }
                sReturn = "修改单据成功!";
                oCn.Commit();
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                oCn.RollBack();
                return false;
            }
        }
        //新增单据
        public bool AddBill( ref string sReturn,Int64 sInterID)
        {
            try
            {
                //得到mainid
                this.HInterID = Pub_Class.ClsPub.CreateBillID(MvarItemKey, ref Pub_Class.ClsPub.sExeReturnInfo);
                sInterID = HInterID;
                //若MAINDI重复则重新获取
                oCn.BeginTran();
                //主表
                oCn.RunProc("Insert Into xt_ICSchemeMain   " +
                "(HBillType,HInterID,HName,HUserCode" +
                ",HBillName,HStopflag" +
                ") " +
                " values('" + this.MvarItemKey + "'," + this.HInterID.ToString() + ",'" + this.HName + "','" + this.HUserCode + "'" +
                ",'" + this.HBillName.ToString() + "',0" + 
                ") ");
                //插入子表
                foreach (Clsxt_ICSchemeSub oSub in DetailColl)
                {
                    oCn.RunProc("Insert into xt_ICSchemeSub " +
                        " (HInterID,HKey,HValue)" +
                        " values("
                        + this.HInterID.ToString() + ",'" + oSub.HKey.ToString() + "','" + oSub.HValue.ToString() + "') ");
                }
                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_ICSchemeMain Where HInterID=" + lngBillKey.ToString(), "xt_ICSchemeMain");
                if(Ds.Tables[0].Rows.Count==0)
                {
                    sReturn = "单据未找到!";
                    return false;
                }
                //赋值
                this.HInterID = Pub_Class.ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"].ToString());
                this.HName = Ds.Tables[0].Rows[0]["HName"].ToString().Trim();
                this.HUserCode = Ds.Tables[0].Rows[0]["HUserCode"].ToString().Trim();
                this.HBillType = Ds.Tables[0].Rows[0]["HBillType"].ToString().Trim();
                this.HBillName = Ds.Tables[0].Rows[0]["HBillName"].ToString().Trim();
                this.HStopflag = false;
                //循环
                DataSet DsSub;
                DsSub = oCn.RunProcReturn("Select * from xt_ICSchemeSub Where HInterID=" + this.HInterID, "xt_ICSchemeMain");
                DetailColl.Clear();//清空
                for (int i = 0; i < DsSub.Tables[0].Rows.Count; i++)
                {
                    Clsxt_ICSchemeSub oSub = new Clsxt_ICSchemeSub();
                    oSub.HInterID = Pub_Class.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HInterID"].ToString());
                    oSub.HEntryID = Pub_Class.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HEntryID"].ToString());
                    oSub.HKey = DsSub.Tables[0].Rows[i]["HKey"].ToString().Trim();
                    oSub.HValue = DsSub.Tables[0].Rows[i]["HValue"].ToString().Trim();
                    DetailColl.Add(oSub);
                }
                sReturn = "显示单据成功!";
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                return false;
            }
        }
        //显示默认方案
        public bool ShowDefault(string HBillName)
        {
            try
            {
                //查询主表
                DataSet Ds ;
                Ds = oCn.RunProcReturn("Select * from xt_ICSchemeMain Where HName='默认方案' and HBillName='" + HBillName + "'and HUserCode='" + Pub_Class.ClsPub.CurUserName + "'", "xt_ICSchemeMain");
                if (Ds.Tables[0].Rows.Count == 0)
                {
                    
                    return false;
                }
                //赋值
                this.HInterID = Pub_Class.ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"].ToString());
                this.HName = Ds.Tables[0].Rows[0]["HName"].ToString().Trim();
                this.HUserCode = Ds.Tables[0].Rows[0]["HUserCode"].ToString().Trim();
                this.HBillType = Ds.Tables[0].Rows[0]["HBillType"].ToString().Trim();
                this.HBillName = Ds.Tables[0].Rows[0]["HBillName"].ToString().Trim();
                this.HStopflag = false;
                //循环
                DataSet DsSub ;
                DsSub = oCn.RunProcReturn("Select * from xt_ICSchemeSub Where HInterID=" + this.HInterID, "xt_ICSchemeMain");
                DetailColl.Clear();//清空
                for (int i = 0; i < DsSub.Tables[0].Rows.Count; i++)
                {
                    Clsxt_ICSchemeSub oSub = new Clsxt_ICSchemeSub();
                    oSub.HInterID = Pub_Class.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HInterID"].ToString());
                    oSub.HEntryID = Pub_Class.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HEntryID"].ToString());
                    oSub.HKey = DsSub.Tables[0].Rows[i]["HKey"].ToString().Trim();
                    oSub.HValue = DsSub.Tables[0].Rows[i]["HValue"].ToString().Trim();
                    DetailColl.Add(oSub);
                }
               
                return true;
            }
            catch (Exception e)
            {
               
                return false;
            }
        }
        //MAINID是否重复
        public bool IsExistMainID(ref string sReturn, Int64 lngBillKey)
        {
            sReturn = "";
            return false;
        }
        //删除关联
        public void  DeleteRelation(ref string sReturn, Int64 lngBillKey)
        {
            sReturn = "";
            return;
        }
 
 
        //获取方案列表
        public bool GetBillList(string sViewName,ref string sReturn)
        {
            try
            {
                //查询主表
                DataSet Ds;
                Ds = oCn.RunProcReturn("Select * from xt_ICSchemeMain Where Hname<>'默认方案' and HBillName='" + sViewName + "' and HUserCode='" + Pub_Class.ClsPub.CurUserName + "'", "xt_ICSchemeMain");
                if (Ds.Tables[0].Rows.Count == 0)
                {
                    sReturn = "单据未找到!";
                    return false;
                }
                MainColl = new List<Clsxt_ICSchemeMain>();
                MainColl.Clear();
                //赋值
                for (int i = 0; i < Ds.Tables[0].Rows.Count; i++)
                {
                    Clsxt_ICSchemeMain oMain = new Clsxt_ICSchemeMain();
                    oMain.HInterID = Pub_Class.ClsPub.isLong(Ds.Tables[0].Rows[i]["HInterID"].ToString());
                    oMain.HName = Ds.Tables[0].Rows[i]["HName"].ToString().Trim();
                    oMain.HUserCode = Ds.Tables[0].Rows[i]["HUserCode"].ToString().Trim();
                    oMain.HBillType = Ds.Tables[0].Rows[i]["HBillType"].ToString().Trim();
                    oMain.HBillName = Ds.Tables[0].Rows[i]["HBillName"].ToString().Trim();
                    oMain.HStopflag = false;
                    MainColl.Add(oMain);
                }
                sReturn = "显示单据成功!";
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                return false;
            }
        }
    }
 
}