yangle
2023-05-24 b129762a4bb5ec2cde5edf16bc9cbda57c73587d
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
335
336
337
338
339
340
341
342
343
344
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DBUtility;
 
namespace APSM
{
    public partial class Gy_WorkTimes : Form
    {
        private int HItemIDCol = 0;
        private int HNumberCol = 0;
        private DateTime BDate;
        private DateTime EDate;
        private DateTime XQDate;
        public DBUtility.frm_B_BillQueryCondition_New frmCondition;
        public const string ViewName = "h_v_Gy_WorkTimesList";
        //public string CheckProcName = "h_p_Gy_WorkTimes"; //20141020
        public string ModName = "资源能力";
        public const string BillName = "Gy_WorkTimes";
        public const string ModRightNameEdit = BillName + "_Edit";
        public const string ModRightNameDelete = BillName + "_Delete";
        public DBUtility.ClsPub.Enum_InputMode InputMode;  //录入状态标志(0-非录入状态 1-增加 2-修改)
        public long HItemID;//项目ID 
        public long HSourceID;//资源ID 
        DAL.ClsGy_PlanShifts_Ctl oPs = new DAL.ClsGy_PlanShifts_Ctl();
        DAL.ClsGy_PlanShifts_View oPsHlp = new DAL.ClsGy_PlanShifts_View();
        TreeNode CurNode = new TreeNode(); 
 
        public Gy_WorkTimes()
        {
            InitializeComponent();
        }
        #region 固定代码
        //保存GRID列宽
       
        //窗体加载
        private void Gy_WorkTimes_Load(object sender, EventArgs e)
        {
            cmbYear.SelectedIndex = 1;
            frmCondition = new DBUtility.frm_B_BillQueryCondition_New();
            LoadTree();
            initGrid();
            RefreshTool();
        }
        //加载子结点
        private void LoadAllNodes(TreeNode sNode)
        {
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
            if (sNode != null)
            {
                try
                {
                    long sName = Convert.ToInt64(sNode.Name.Substring(1, sNode.Name.Length - 1));
                    sNode.Nodes.Clear();
                    string sSQL = "";
                    if (HSourceID == 0)
                    {
                        sSQL = "select hitemid,hnumber,hname from Gy_Source where HParentID='" + sName + "'  order by Hnumber";
                    }
                    else
                    {
                        sSQL = "select hitemid,hnumber,hname from Gy_Source where HItemID=" + HSourceID + "   order by Hnumber";
                    }
                    DataSet Ds = oCn.RunProcReturn(sSQL, "Gy_Source", ref ClsPub.sExeReturnInfo);
                    for (int i = 0; i < Ds.Tables[0].Rows.Count; i++)
                    {
                        TreeNode oNode = sNode.Nodes.Add("T" + Ds.Tables[0].Rows[i]["HItemID"].ToString(), Ds.Tables[0].Rows[i]["HNumber"].ToString() + "-" + Ds.Tables[0].Rows[i]["HName"].ToString(), 0, 1);
                    }
                    sNode.Expand();
                }
                catch (Exception e)
                {
                    MessageBox.Show("加载子项目失败!" + e.Message, "提示");
                }
            }
        }
        //加载树形
        private void LoadTree()
        {
            try
            {
                tv.Nodes.Clear();
                tv.ImageList = imageList1;
                TreeNode sNode = tv.Nodes.Add("T0", "生产资源", 0, 1);
                LoadAllNodes(sNode);
            }
            catch (Exception e)
            {
                MessageBox.Show("加载树型失败!" + e.Message, "提示");
            }
        }
        //树型 单击
        private void tv_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            CurNode = e.Node;
            if (CurNode != null)
            {
                if (CurNode.Nodes.Count == 0 && HSourceID == 0)
                    LoadAllNodes(CurNode);
                Display();
            }
        }
        //初始化GRID
        private void initGrid()
        {
            Sc_ICMOSortBillFun.initGridVS_Times(grdMain, ref BDate, ref EDate, this.Name, ref XQDate, cmbYear);   
        }
        //显示列表
        private void Display()
        {
            DataSet DSet ;
            DateTime Date;
            Int64 sName;
            ////禁用 红色显示  20141020
            //Sub_ShowStopFlag();
            //得到工作中心默认上班时间
            sName = Convert.ToInt64(CurNode.Name.Substring(1, CurNode.Name.Length - 1));
            Single sWorkTimes = 0;
            sWorkTimes = oPsHlp.GetInfoBySource_Line(sName); //根据资源得到工作中心的工时
            //
            for (int r = 0; r <= 22; r = r + 2)
            {
                BDate =DBUtility.ClsPub.isDate(cmbYear.Text.ToString() + "-" + Convert.ToString(r / 2 + 1) + "-01");
                EDate = BDate.AddMonths(1);
                EDate = EDate.AddDays(-1);
 
                TimeSpan t = EDate - BDate;//获取2个时间的相隔天数
                //
                for (int c = 1; c <= DBUtility.ClsPub.isInt(t.Days + 1); c++)
                {
                    if (DBUtility.ClsPub.isStrNull(CurNode.Name) != null && DBUtility.ClsPub.isStrNull(CurNode.Text) != "")
                    {
                        Date = DBUtility.ClsPub.isDate(cmbYear.Text.ToString() + "-" + Convert.ToString(r / 2 + 1) + "-" + grdMain.get_TextMatrix(r, c).ToString());
                        if (oPsHlp.GetInfoByDate_Line(sName, Date.ToShortDateString()))
                        {
                            grdMain.set_TextMatrix(r + 1, c,DBUtility.ClsPub.isDoule(oPsHlp.omodel.HOverTimes, 1));
                        }
                        else
                        {
                            grdMain.set_TextMatrix(r + 1, c, sWorkTimes.ToString());
                        }
                    }
                }
            }
        }
        //退出模块
        private void tc_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        //刷新
        private void xs_Click(object sender, EventArgs e)
        {
            Display();
        }
        //刷新TOOLBAR
        private void RefreshTool()
        {
            if (InputMode == DBUtility.ClsPub.Enum_InputMode.InputMode_View)
            {
                stTab.SelectedIndex = 0; 
                stTab.TabPages.Remove(this.tabPage1);
                stTab.TabPages.Add(this.tabPage1);
                grdMain.Enabled = true;
                tc.Enabled = true;
                tz.Enabled = true;
                xs.Enabled = true; 
            }
            else
            {
                stTab.SelectedIndex = 1;
                stTab.TabPages.Remove(this.tabPage1); 
                stTab.TabPages[0].Hide();
                grdMain.Enabled = false;
                tc.Enabled = true;
                tz.Enabled = false;
                xs.Enabled = false; 
            }
        }
        //取消按钮
        private void cmdCancel_Click(object sender, EventArgs e)
        {
            InputMode = DBUtility.ClsPub.Enum_InputMode.InputMode_View;
            RefreshTool();
        }
        //得到对应列
        private Int32 Fun_GetCol(string sCol)
        {
            return Sc_ICMOSortBillFun.Fun_GetCol_VS(sCol, grdMain);
        }
        private void bclk_Click(object sender, EventArgs e)
        {
            //保存列宽
            Sc_ICMOSortBillFun.SaveGrid(grdMain, this.Name, DBUtility.ClsPub.AppPath);
        }
 
        private void mrlk_Click(object sender, EventArgs e)
        {
            grdMain.AutoSize(0, grdMain.Cols - 1, false, 1);
            //参数解释  开始列 ,结束列,是否以最大列宽为准,最小列宽
            Sc_ICMOSortBillFun.SaveGrid(grdMain, this.Name, DBUtility.ClsPub.AppPath);
        }
        //选中行是否正常
        private bool AllowRow()
        {
            if (grdMain.Row >= grdMain.FixedRows && grdMain.Row <= grdMain.Rows - 1)
                return true;
            else
                return false;
        }
 
 
        //时间控件
        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            cmbYear.Items.Add(DateTime.Today.Year - 5);
            cmbYear.Items.Add(DateTime.Today.Year - 4);
            cmbYear.Items.Add(DateTime.Today.Year - 3);
            cmbYear.Items.Add(DateTime.Today.Year - 2);
            cmbYear.Items.Add(DateTime.Today.Year - 1);
            cmbYear.Items.Add(DateTime.Today.Year);
            cmbYear.Items.Add(DateTime.Today.Year + 1);
            cmbYear.Items.Add(DateTime.Today.Year + 2);
            cmbYear.Items.Add(DateTime.Today.Year + 3);
            cmbYear.Items.Add(DateTime.Today.Year + 4);
            cmbYear.Items.Add(DateTime.Today.Year + 5);
            cmbYear.SelectedIndex = 5;
            LoadTree();
            initGrid();
        }
 
        #endregion
 
 
        #region 类的读写
        //读取类 到 控件
        private void ShowData(long sItemID)
        {
             //
        }
 
        //写入类 从控件
        private bool WriteClass(double sWorktimes,Int64 sSourceID,DateTime sDate)
        {
            oPs.oModel.HOverTimes = sWorktimes;
            oPs.oModel.HRemark = "";
            oPs.oModel.HShiftsID = 0;
            oPs.oModel.HSourceID= sSourceID;
            oPs.oModel.HDate = sDate;
            return true;
        }
        #endregion
 
 
        #region 界面控件处理
 
        #endregion
 
        ////检测按钮  20141020
        //private void jc_Click(object sender, EventArgs e)
        //{
        //    BLL.ClsPub_BLL.Sub_CheckUseStatus(grdMain, HItemIDCol, CheckProcName);
        //    Display();
        //}
 
 
        ////禁用项目 红色字体 20141020
        //public void Sub_ShowStopFlag()
        //{
        //    BLL.ClsPub_BLL.Sub_ShowStopFlag(grdMain, Fun_GetCol("禁用标记"));
        //}
        private void cmbYear_TextChanged(object sender, EventArgs e)
        {
            initGrid();
        }
 
        private void grdMain_BeforeEdit(object sender, AxVSFlex7._IVSFlexGridEvents_BeforeEditEvent e)
        {
            if (DBUtility.ClsPub.GridToColor(grdMain.get_Cell(VSFlex7.CellPropertySettings.flexcpBackColor, grdMain.Row, grdMain.Col, grdMain.Row, grdMain.Col)) ==DBUtility.ClsPub.Enum_Color.hx_Write)
            {
                //
            }
            else
            {
                e.cancel = true;
            }
        }
 
        private void tz_Click(object sender, EventArgs e)
        {
            Gy_WorkTimesDlg oDlg = new Gy_WorkTimesDlg();
            oDlg.ShowDialog();
            Display();
        }
 
        private void grdMain_AfterEdit(object sender, AxVSFlex7._IVSFlexGridEvents_AfterEditEvent e)
        {
 
            DateTime Date = DBUtility.ClsPub.isDate(cmbYear.Text.ToString() + "-" + DBUtility.ClsPub.isInt(grdMain.Row / 2 + 1).ToString() + "-" + grdMain.get_TextMatrix(grdMain.Row - 1, grdMain.Col).ToString());
            if (DBUtility.ClsPub.isStrNull(CurNode.Name) != null && DBUtility.ClsPub.isStrNull(CurNode.Text) != "")
            {
                Int64 sName = Convert.ToInt64(CurNode.Name.Substring(1, CurNode.Name.Length - 1));
                double sWorktimes =DBUtility.ClsPub.isDoule(grdMain.get_TextMatrix(grdMain.Row, grdMain.Col));
                //
                WriteClass(sWorktimes, sName, Date);
                oPs.AddNew();
                Display();
            }
        }
 
        private void cmdHSource_Click(object sender, EventArgs e)
        {
            DAL.ClsGy_Source_View oSource = new DAL.ClsGy_Source_View();
            oSource.WherePart = txtHSource.Text.Trim();
            if (oSource.RefreshView())
            {
                txtHSource.Text = oSource.oModel.HName;
                txtHSource.Tag = oSource.oModel.HItemID;
                HSourceID = oSource.oModel.HItemID;
            }
            else
            {
                txtHSource.Text = "";
                txtHSource.Tag = "0";
                HSourceID = 0;
            }
            LoadTree();
        }
 
        private void ww_Click(object sender, EventArgs e)
        {
            Gy_WorkTimesWWDlg oDlg = new Gy_WorkTimesWWDlg();
            oDlg.HSourceID = DBUtility.ClsPub.isLong(txtHSource.Tag);
            oDlg.ShowDialog();
            Display();
        }
 
    }
}