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
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
 
namespace DAL
{
    /// <summary>
    /// 生产资源
    /// </summary>
    public class ClsGy_Source_View:DBUtility.ClsGy_Base_View
    {
        
        //
        public Model.ClsGy_Source_Model omodel = new Model.ClsGy_Source_Model();
        SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); 
        public ClsGy_Source_View()
        {
            base.MvarReportTitle = "生产资源设置";
            base.MvarItemKey = "Gy_Source";
            base.SQLName = "Select HItemID,HNumber 生产资源代码,HName 生产资源 from Gy_Source where HStopflag=0 Order by HItemID ";
            base.SQLNameByRelation = "Select HItemID,HNumber 生产资源代码,HName 生产资源 from h_v_Sc_GetSource2 ";
            //下拉SQL
            base.SQLNameForDown = " Select top 30 HItemID,HNumber 生产资源代码,HName 生产资源 from Gy_Source ";
            base.SQLOrderForDown = "  Order by HNumber ";
            base.SQLWhereForDown = "  where HStopflag=0  ";
        }
        //
        public void Dispose()
        {
            GC.SuppressFinalize(this);
        }
        //
         
        //返回项目信息
        public override bool GetInfoByID(Int64 sItemID)
        {
            DataSet DS ;
            try
            {
                DS = oCn.RunProcReturn("Select * from " + MvarItemKey + " Where HItemID='" + sItemID + "'", MvarItemKey, ref DBUtility.ClsPub.sExeReturnInfo);
                if (DS.Tables[0].Rows.Count  == 0)
                    return false;
                else
                {
                    return GetInfo(DS);
                }
            }
            catch (Exception e)
            {
                throw (e);
            }
        }
 
 
        //根据代码返回项目信息
        public override bool GetInfoByNumber(string sNumber)
        {
            DataSet DS;
            try
            {
                DS = oCn.RunProcReturn("Select * from " + MvarItemKey + " Where HNumber='" + sNumber + "'", MvarItemKey, ref DBUtility.ClsPub.sExeReturnInfo);
                if (DS.Tables[0].Rows.Count == 0)
                    return false;
                else
                {
                    return GetInfo(DS);
                }
            }
            catch (Exception e)
            {
                throw (e);
            }
        }
        /// <summary>
        /// 得到资源根据物料
        /// </summary>
        /// <returns></returns>
        public bool GetInfoByMater(Int64 HMaterID)
        {
            DataSet DS;
            try
            {
                DS = oCn.RunProcReturn("select top 1 * from h_v_Sc_GetSource where hmaterid=" + HMaterID.ToString() + " ", MvarItemKey, ref DBUtility.ClsPub.sExeReturnInfo);
                if (DS.Tables[0].Rows.Count == 0)
                    return false;
                else
                {
                    return GetInfo(DS);
                }
            }
            catch (Exception e)
            {
                throw (e);
            }
        }
        //返回项目信息
        public override bool GetInfo(DataSet DS)
        {
            try
            {
                omodel = new Model.ClsGy_Source_Model();
                 
                omodel.HItemID = Convert.ToInt64(DS.Tables[0].Rows[0]["HItemID"]);
                omodel.HNumber = DS.Tables[0].Rows[0]["HNumber"].ToString().Trim();
                omodel.HName = DS.Tables[0].Rows[0]["HName"].ToString().Trim();
                omodel.HHelpCode = DS.Tables[0].Rows[0]["HHelpCode"].ToString().Trim();
                omodel.HShortNumber = DS.Tables[0].Rows[0]["HShortNumber"].ToString().Trim();
                omodel.HParentID = Convert.ToInt64(DS.Tables[0].Rows[0]["HParentID"]);
                omodel.HLevel = Convert.ToInt64(DS.Tables[0].Rows[0]["HLevel"]);
                omodel.HEndFlag = (bool)DS.Tables[0].Rows[0]["HEndFlag"];
                omodel.HStopflag = (bool)DS.Tables[0].Rows[0]["HStopflag"];
                omodel.HRemark = DS.Tables[0].Rows[0]["HRemark"].ToString().Trim();
                omodel.HProcID = Convert.ToInt64(DS.Tables[0].Rows[0]["HProcID"]);
                omodel.HRelationID = Convert.ToInt64(DS.Tables[0].Rows[0]["HRelationID"]);
                omodel.HCenterID = Convert.ToInt64(DS.Tables[0].Rows[0]["HCenterID"]);
                omodel.HBarCode = DS.Tables[0].Rows[0]["HBarCodeForBase"].ToString().Trim();
                omodel.HType = DS.Tables[0].Rows[0]["HType"].ToString().Trim();
                omodel.HEquipFileID_K3 = Convert.ToInt64(DS.Tables[0].Rows[0]["HEquipFileID_K3"]);
                //omodel.HGroupK3ID = Convert.ToInt64(DS.Tables[0].Rows[0]["HGroupK3ID"]);
                //omodel.HGroupID = Convert.ToInt64(DS.Tables[0].Rows[0]["HGroupID"]);
                //omodel.HDeptID = Convert.ToInt64(DS.Tables[0].Rows[0]["HDeptID"]);
 
                //omodel.HOverTimes = Convert.ToDouble(DS.Tables[0].Rows[0]["HOverTimes"]);
                //omodel.HWorkTimes = Convert.ToDouble(DS.Tables[0].Rows[0]["HWorkTimes"]);
                //omodel.HMaxWorkTimes = Convert.ToDouble(DS.Tables[0].Rows[0]["HMaxWorkTimes"]);
                //omodel.HMinAdd = Convert.ToDouble(DS.Tables[0].Rows[0]["HMinAdd"]);
                //omodel.HClassCount = Convert.ToInt64(DS.Tables[0].Rows[0]["HClassCount"]);
                return true;
 
            }
            catch (Exception e)
            {
                throw (e);
            }
        }
 
 
        /// <summary>
        /// 得到默认资源根据部门
        /// </summary>
        /// <returns></returns>
        public bool GetInfoByDept(Int64 HDeptID)
        {
            DataSet DS;
            try
            {
                DS = oCn.RunProcReturn("select top 1 s.* from  Gy_Source s inner join Gy_WorkCenter c on s.HCenterID=c.HItemID " +
                       " inner join h_v_K3_Department d on c.HDeptID=d.HItemID Where c.HDeptID="+HDeptID.ToString()+"  "+
                       " Order by newid()", MvarItemKey, ref DBUtility.ClsPub.sExeReturnInfo);
                if (DS==null || DS.Tables[0].Rows.Count == 0)
                {
                    return false;
                }
                else
                {
                    return GetInfo(DS);
                }
            }
            catch (Exception e)
            {
                throw (e);
            }
        }
 
 
 
        /// <summary>
        /// 得到资源对应班组
        /// </summary>
        /// <returns></returns>
        public bool GetGroupBySourceID(Int64 HSourceID)
        {
            DataSet DS;
            try
            {
                DS = oCn.RunProcReturn("select * from Gy_Source where HItemID=" + HSourceID.ToString(), MvarItemKey, ref DBUtility.ClsPub.sExeReturnInfo);
                if (DS == null || DS.Tables[0].Rows.Count == 0)
                {
                    return false;
                }
                else
                {
                    return GetInfo(DS);
                }
            }
            catch (Exception e)
            {
                throw (e);
            }
        }
 
        /// <summary>
        /// 得到资源 根据工序
        /// </summary>
        /// <returns></returns>
        public bool GetSourceByProc(Int64 HProcID,List<Model.ClsSourceValues> oValues)
        {
            DataSet DS;
            try
            {
                oValues.Clear();
                DS = oCn.RunProcReturn("select HItemID from Gy_Source where HProcID=" + HProcID.ToString() + " and HStopflag=0 ", MvarItemKey, ref DBUtility.ClsPub.sExeReturnInfo);
                if (DS == null || DS.Tables[0].Rows.Count == 0)
                {
                    return false;
                }
                else
                {
                    for (int i = 0; i < DS.Tables[0].Rows.Count; i++)
                    {
                        Model.ClsSourceValues oSub = new Model.ClsSourceValues();
                        oSub.iSourceID = DBUtility.ClsPub.isLong(DS.Tables[0].Rows[i]["HitemID"]);
                        oValues.Add(oSub);
                    }
                    return true;
                }
            }
            catch (Exception e)
            {
                throw (e);
            }
        }
 
 
    }
}