沈泽
2021-11-01 cb7d88df22d0e2a1aa6987c33c93c3378f1c2837
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
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
 
namespace DAL
{
    public class ClsGy_WorkShift_Ctl : DBUtility.ClsGy_Base_Ctl
    {
        SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
        //原代码 用于 替换子项目
        public Model.ClsGy_WorkShiftMain omodel = new Model.ClsGy_WorkShiftMain();
        public List<Model.ClsGy_WorkShiftSub> DetailColl = new List<Model.ClsGy_WorkShiftSub>();
 
 
 
        //删除子表
        public void DeleteBillSub(Int64 lngBillKey)
        {
            oCn.RunProc("Delete From Gy_WorkShiftSub where HInterID=" + lngBillKey.ToString());
        }
        //删除主表
        public void DeleteBillMain(Int64 lngBillKey)
        {
            oCn.RunProc("Delete From Gy_WorkShift 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 Gy_WorkShiftSub Where HInterID=" + lngBillKey.ToString() + " and isnull(HRelationQty,0)<>0 ", "Gy_WorkShift");
                if (Ds.Tables[0].Rows.Count != 0)
                {
                    sReturn = "单据已被关联,不能操作!";
                    return true;
                }
                sReturn = "";
                return false;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                return false;
            }
        }
        //读取下张单据
      
 
        //修改单据
        public bool ModifyBill(Int64 lngBillKey, ref string sReturn)
        {
            try
            {
                //
                oCn.BeginTran();
                //更新主表
                oCn.RunProc("UpDate Gy_WorkShift set  " +
                "HNumber='" + omodel.HNumber + "'" +
                ",HName='" + omodel.HName + "'" +
                ",HNote='" + omodel.HNote + "'" +
                ",HDeptID=" + omodel.HDeptID.ToString() +
                ",HWorkTimes=" + omodel.HWorkTimes.ToString() +
                ",HStopflag='" + DBUtility.ClsPub.BoolToString(omodel.HStopflag) + "'" +
                ",HRemark='" + omodel.HRemark + "'" +
                " where HInterID=" + lngBillKey.ToString());
                //删除关联
                DeleteRelation(ref sReturn, lngBillKey);
                //删除子表
                DeleteBillSub(lngBillKey);
                //插入子表
                foreach(Model.ClsGy_WorkShiftSub oSub in DetailColl)
                {
                    oCn.RunProc("Insert into Gy_WorkShiftSub " +
                        " (HInterID,HEntryID,HSno" +
                        ",HStartDate,HEndDate,HOverDay" +
                        " )values("
                        + omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + "," + oSub.HSno.ToString() +
                        ",'" + oSub.HStartDate.ToShortTimeString() + "','" + oSub.HEndDate.ToShortTimeString() + "'," + Convert.ToString(oSub.HOverDay ? 1 : 0) + ") ");
                }
                sReturn = "修改单据成功!";
                oCn.Commit();
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                oCn.RollBack();
                return false;
            }
        }
        //新增单据
        public bool AddBill( ref string sReturn)
        {
            try
            {
                //得到mainid
                omodel.HInterID = DBUtility.ClsPub.CreateBillID(MvarItemKey, ref DBUtility.ClsPub.sExeReturnInfo);
                //若MAINDI重复则重新获取
                oCn.BeginTran();
                //主表
                oCn.RunProc("Insert Into Gy_WorkShift   " +
                "(HInterID,HNumber,HName,HNote" +
                ",HDeptID,HWorkTimes,HStopflag,HRemark" +
                ") " +
                " values(" + omodel.HInterID.ToString() + ",'" + omodel.HNumber + "','" + omodel.HName + "','" + omodel.HNote + "'" +
                "," + omodel.HDeptID.ToString() + "," + omodel.HWorkTimes.ToString() + "," + Convert.ToString(omodel.HStopflag ? 1 : 0) + ",'" + omodel.HRemark + "'" +
                ") ");
                //插入子表
                foreach (Model.ClsGy_WorkShiftSub oSub in DetailColl)
                {
                    oCn.RunProc("Insert into Gy_WorkShiftSub " +
                        " (HInterID,HEntryID,HSno" +
                        ",HStartDate,HEndDate,HOverDay" +
                        " )values("
                        + omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + "," + oSub.HSno.ToString() +
                        ",'" + oSub.HStartDate.ToShortTimeString() + "','" + oSub.HEndDate.ToShortTimeString() + "'," + Convert.ToString(oSub.HOverDay ? 1 : 0) + ") ");
                }
                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 Gy_WorkShift Where HInterID=" + lngBillKey.ToString(), "Gy_WorkShift");
                if(Ds.Tables[0].Rows.Count==0)
                {
                    sReturn = "单据未找到!";
                    return false;
                }
                //赋值
                omodel.HInterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"].ToString());
                omodel.HNumber = Ds.Tables[0].Rows[0]["HNumber"].ToString().Trim();
                omodel.HName = Ds.Tables[0].Rows[0]["HName"].ToString().Trim();
                omodel.HNote = Ds.Tables[0].Rows[0]["HNote"].ToString().Trim();
                omodel.HDeptID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HDeptID"].ToString());
 
                omodel.HWorkTimes = DBUtility.ClsPub.isDoule(Ds.Tables[0].Rows[0]["HWorkTimes"]);
                omodel.HStopflag = DBUtility.ClsPub.isBool(Ds.Tables[0].Rows[0]["HStopflag"]);
                omodel.HRemark = Ds.Tables[0].Rows[0]["HRemark"].ToString().Trim();
                //
                //循环
                DataSet DsSub ;
                DsSub = oCn.RunProcReturn("Select * from Gy_WorkShiftSub Where HInterID=" + lngBillKey.ToString(), "Gy_WorkShiftSub");
                DetailColl.Clear();//清空
                for (int i = 0; i < DsSub.Tables[0].Rows.Count; i++)
                {
                    Model.ClsGy_WorkShiftSub oSub = new Model.ClsGy_WorkShiftSub();
                    oSub.HInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HInterID"].ToString());
                    oSub.HEntryID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HEntryID"].ToString());
                    oSub.HSno = DBUtility.ClsPub.isInt(DsSub.Tables[0].Rows[i]["HSno"].ToString());
                    oSub.HStartDate = DBUtility.ClsPub.isDate(DsSub.Tables[0].Rows[i]["HStartDate"].ToString());
                    oSub.HEndDate = DBUtility.ClsPub.isDate(DsSub.Tables[0].Rows[i]["HEndDate"].ToString());
                    oSub.HOverDay = DBUtility.ClsPub.isBool(DsSub.Tables[0].Rows[i]["HOverDay"].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;
        }
 
        //构造函数
        public ClsGy_WorkShift_Ctl()
        {
            MvarItemKey = "3701";
            MvarReportTitle = "班次表";
        }
    }
}