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
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
 
namespace DAL
{
    public class ClsGy_ProcPrice_Ctl : DBUtility.ClsGy_Base_Ctl
    {
        SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
        //原代码 用于 替换子项目
        public string HOldNumber;
        public List<Model.ClsGy_ProcPrice_Model> DetailColl = new List<Model.ClsGy_ProcPrice_Model>();
 
 
 
        //反审核
        public bool AbandonCheck(Int64 lngBillKey, ref string sReturn)
        {
            try
            {
                oCn.RunProc(" Update Gy_ProcPrice set HChecker='',HCheckDate=null Where HItemID=" + lngBillKey.ToString());
                sReturn = "";
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                return false;
            }
        }
 
        //审核
        public bool CheckBill(Int64 lngBillKey, ref string sReturn)
        {
 
            try
            {
                oCn.RunProc(" Update Gy_ProcPrice set HStopflag=0,HChecker='" + DBUtility.ClsPub.CurUserName + "',HCheckDate='" + DBUtility.ClsPub.GetServerDate(-1) + "' Where HItemID=" + lngBillKey.ToString());
                //将其他 工价设置为 停用
                oCn.RunProc(" exec h_p_Gy_ProcPriceStopflag   " + lngBillKey.ToString());
                //
                sReturn = "";
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                return false;
            }
        }
 
 
        //新增
        public override bool AddNew()
        {
 
            try
            {
                oCn.BeginTran();
                //插入子表
                foreach (Model.ClsGy_ProcPrice_Model oSub in DetailColl)
                {
                    oCn.RunProc("Insert into Gy_ProcPrice " +
                        " (HMaterID,HProcID,HSourceID" +
                        ",HBeginDate,HEndDate,HCostFlag,HFlowFlag,HPayFlag,HDeptID" +
                        ",HPrice,HStopflag,HRemark,HMaker,HMakeDate)" +
                        " values(" + oSub.HMaterID.ToString() + "," + oSub.HProcID.ToString() + "," + oSub.HSourceID.ToString() +
                        ",'" + oSub.HBeginDate.ToShortDateString() + "','" + oSub.HEndDate.ToShortDateString() + "'," + Convert.ToString(oSub.HCostFlag ? 1 : 0) + "," + Convert.ToString(oSub.HFlowFlag ? 1 : 0) + "," + Convert.ToString(oSub.HPayFlag ? 1 : 0) + "," + oSub.HDeptID.ToString() +
                        "," + oSub.HPrice.ToString() + "," + Convert.ToString(oSub.HStopflag ? 1 : 0) + ",'" + oSub.HRemark + "','" + oSub.HMaker + "','" + oSub.HMakeDate + "') ");
                }
                oCn.Commit();
                return true;
            }
            catch (Exception e)
            {
                oCn.RollBack();
                throw (e);
            }
        }
 
        //修改
        public override bool ModifyByID(Int64 sItemID)
        {
            try
            {
                oCn.BeginTran();
                DeleteByID(sItemID);        //删除记录
                //插入表
                foreach (Model.ClsGy_ProcPrice_Model oSub in DetailColl)
                {
                    oCn.RunProc("Insert into Gy_ProcPrice " +
                         " (HMaterID,HProcID,HSourceID" +
                         ",HBeginDate,HEndDate,HCostFlag,HFlowFlag,HPayFlag,HDeptID" +
                         ",HPrice,HStopflag,HRemark,HMaker,HMakeDate)" +
                         " values(" + oSub.HMaterID.ToString() + "," + oSub.HProcID.ToString() + "," + oSub.HSourceID.ToString() +
                         ",'" + oSub.HBeginDate.ToShortDateString() + "','" + oSub.HEndDate.ToShortDateString() + "'," + Convert.ToString(oSub.HCostFlag ? 1 : 0) + "," + Convert.ToString(oSub.HFlowFlag ? 1 : 0) + "," + Convert.ToString(oSub.HPayFlag ? 1 : 0) + "," + oSub.HDeptID.ToString() +
                         "," + oSub.HPrice.ToString() + "," + Convert.ToString(oSub.HStopflag ? 1 : 0) + ",'" + oSub.HRemark + "','" + oSub.HMaker + "','" + oSub.HMakeDate + "') ");
                }
                oCn.Commit();
                return true;
            }
            catch (Exception e)
            {
                oCn.RollBack();
                throw (e);
            }
        }
 
        //显示单据
        public bool ShowBill(Int64 lngBillKey, ref string sReturn)
        {
            try
            {
                //查询主表
                DataSet DsSub = new DataSet();
                DsSub = oCn.RunProcReturn("Select * from Gy_ProcPrice Where HitemID=" + lngBillKey.ToString(), "Gy_ProcPrice");
                DetailColl.Clear();//清空
                for (int i = 0; i < DsSub.Tables[0].Rows.Count; i++)
                {
                    Model.ClsGy_ProcPrice_Model oSub = new Model.ClsGy_ProcPrice_Model();
                    oSub.HMaterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HMaterID"]);
                    oSub.HProcID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HProcID"]);
                    oSub.HSourceID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HSourceID"]);
                    oSub.HDeptID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HDeptID"]);
                    oSub.HCostFlag = (bool)DsSub.Tables[0].Rows[i]["HCostFlag"];
                    oSub.HFlowFlag = (bool)DsSub.Tables[0].Rows[i]["HFlowFlag"];
                    oSub.HPayFlag = (bool)DsSub.Tables[0].Rows[i]["HPayFlag"];
                    oSub.HBeginDate = DBUtility.ClsPub.isDate(DsSub.Tables[0].Rows[i]["HBeginDate"]);
                    oSub.HEndDate = DBUtility.ClsPub.isDate(DsSub.Tables[0].Rows[i]["HEndDate"]);
                    oSub.HRemark = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HRemark"]);
                    oSub.HPrice = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HPrice"]);
                    oSub.HMaker = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HMaker"]);
                    oSub.HMakeDate = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HMakeDate"]);
                    oSub.HChecker = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HChecker"]);
                    oSub.HCheckDate = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HCheckDate"]);
                    oSub.HSourceID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HSourceID"]);
                    oSub.HFixPrice = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["HFixPrice"]);
                    oSub.HBadPrice = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["HBadPrice"]);
                    oSub.HWasterPrice = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["HWasterPrice"]);
 
                    DetailColl.Add(oSub);
                }
                sReturn = "显示单据成功!";
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                return false;
            }
        }
 
        //批改单据
        public bool BatchModifyBill(Int64 lngBillKey, double sPrice, ref string sReturn)
        {
            try
            {
                oCn.BeginTran();
                oCn.RunProc(" Update Gy_ProcPrice set HPrice=" + sPrice.ToString() + "  Where HItemID=" + lngBillKey.ToString());
                sReturn = "修改单据成功!";
                oCn.Commit();
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                oCn.RollBack();
                return false;
            }
        }
        //根据物料和工序返回工价   //b 单价为ture,定额为false
        public double LoadProcPrice(Int64 sMaterID, Int64 sProcID, Int64 sSourceID, bool b)
        {
            double sPrice = 0;
            try
            {
                //查询主表
                DataSet DsSub = new DataSet();
                DsSub = oCn.RunProcReturn("Select top 1 * from Gy_ProcPrice Where HStopflag=0 and HEndDate>=convert(varchar(10),Getdate(),120)  and HChecker<>''  and HMaterID=" + sMaterID.ToString() + " and HProcID=" + sProcID.ToString() + " and HSourceID=" + sSourceID.ToString(), "Gy_ProcPrice");
                if (DsSub == null)
                {
                    return 0;
                }
                if (b)
                {
                    sPrice = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[0]["HPrice"]);
                }
                else
                {
                    sPrice = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[0]["HFixPrice"]);
                }
                return sPrice;
            }
            catch (Exception e)
            {
                return 0;
            }
        }
 
        //构造函数
        public ClsGy_ProcPrice_Ctl()
        {
            MvarItemKey = "Gy_ProcPrice";
            MvarReportTitle = "工序工价资料";
        }
    }
}