wtt
3 天以前 770c739aeadfd1025bd6b64aa6790201b0b1047d
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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using DBUtility;
 
namespace APSM
{
    public partial class Gy_WorkTimes : Form
    {
        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();
        DAL.ClsGy_Source_Ctl oSou = new DAL.ClsGy_Source_Ctl();
        DAL.ClsGy_Source_View oSouHlp = new DAL.ClsGy_Source_View();
        TreeNode CurNode = new TreeNode();
 
        public Gy_WorkTimes()
        {
            InitializeComponent();
        }
        #region 固定代码
        //保存GRID列宽
 
        //窗体加载
        private void Gy_WorkTimes_Load(object sender, EventArgs e)
        {
            cmbYear.Items.Clear();
            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.Items.Add(DateTime.Today.Year + 6);
            cmbYear.Items.Add(DateTime.Today.Year + 7);
            cmbYear.SelectedIndex = 3;
            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()
        {
           //Gy_ICMOSortBillFun.initGridVS_Times(grd, ref BDate, ref EDate, this.Name, ref XQDate, cmbYear);
        }
        //显示列表
        private void Display()
        {
            DateTime Date;
            ////禁用 红色显示  20141020
            //Sub_ShowStopFlag();
            //得到工作中心默认上班时间
            long sID = Convert.ToInt64(CurNode.Name.Substring(1, CurNode.Name.Length - 1));
            Single sWorkTimes = 8;
            //sWorkTimes = oSouHlp.GetInfoByName(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) + "-" + grd.Rows[r].Cells[c].Value.ToString());
                        if (oPsHlp.GetInfoByDate_Line(sID, Date.ToShortDateString()))
                        {
                            grd.Rows[r + 1].Cells[c].Value = DBUtility.ClsPub.isDoule(oPsHlp.omodel.HOverTimes, 0);
                        }
                        else
                        {
                            if (Date.DayOfWeek == DayOfWeek.Sunday)
                            {
                                grd.Rows[r + 1].Cells[c].Value = "0";
                            }
                            else
                            {
                                if (oSouHlp.GetInfoByID(sID))
                                {
                                    //grd.set_TextMatrix(r + 1, c, DBUtility.ClsPub.isDoule(oPsHlp.omodel.HOverTimes, 1));
                                    grd.Rows[r + 1].Cells[c].Value = DBUtility.ClsPub.isDoule(oSouHlp.omodel.HWorkTimes, 0);
                                }
                                else
                                {
                                    //grd.set_TextMatrix(r + 1, c, sWorkTimes.ToString());
                                    grd.Rows[r + 1].Cells[c].Value = 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);
                    grd.Enabled = true;
                    tc.Enabled = true;
                    //tz.Enabled = true;
                    xs.Enabled = true;
                }
                else
                {
                    stTab.SelectedIndex = 1;
                    stTab.TabPages.Remove(this.tabPage1);
                    stTab.TabPages[0].Hide();
                    grd.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,DataGridView grd)
        {
            return 1;
            //return Gy_ICMOSortBillFun.Fun_GetCol_VS(sCol, grd);
        }
        //private void bclk_Click(object sender, EventArgs e)
        //{
        //    //保存列宽
        //        Gy_ICMOSortBillFun.SaveGrid(grd, this.Name, DBUtility.ClsPub.AppPath);
        //}
 
        private void mrlk_Click(object sender, EventArgs e)
        {
            //for (int i = 1; i <= 12; i++)
            //{
            //    grdMain(i).AutoSize(0, grdMain(i).Cols - 1, false, 1);
 
 
            //    //参数解释  开始列 ,结束列,是否以最大列宽为准,最小列宽
            //    Gy_ICMOSortBillFun.SaveGrid(grdMain(i), 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;
            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 cmbYear_SelectedIndexChanged(object sender, EventArgs e)
        {
            initGrid();
        }
        //查询
        private void cx_Click(object sender, EventArgs e)
        {
            frmCondition = new DBUtility.frm_B_BillQueryCondition_New();
            DBUtility.Gy_BaseFun.SetCondition(frmCondition, ViewName, this.Name);
            frmCondition.ShowDialog();
            if (frmCondition.Tag.ToString() == "OK")
            {
                Display();
            }
        } 
        //修改(批量修改)
        private void xg_Click(object sender, EventArgs e)
        {
            Gy_WorkTimesDlg oDlg = new Gy_WorkTimesDlg();
            oDlg.ShowDialog();
            //Display();
        }
 
        //CellBeginEdit事件:在触发该事件时单元格还没有获得焦点,我们可以通过设置事件参数e来决定是否执行对单元格的编辑,如下
        private void grd_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
        //    //执行编辑,这个一般不用写
 
        //    e.Cancel = true;
 
        //    //不执行编辑,这个一般是通过条件判断是否执行编辑,如果条件不成立,即不允许对单元格进行编辑
 
        //    e.Cancel = false;
        }
 
        //CellParsing事件:在该事件中我们可以对输入的文本进行格式化,如将输入的英文字母全部改成大写等等,如下
        private void grd_CellParsing(object sender, DataGridViewCellParsingEventArgs e)
        {
            /*
 
              * 这里必须是通过e.Value来获得重新输入的值
 
               * 如果是通过this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()这种方法获得
 
               * 那么获得值将是原来的值,并不是用户刚刚输入的值
 
               * 这个也正可以对用户输入的数据进行验证,如果不符合则将原来的值再赋给该单元格,不进行修改
 
               * 切记!!!!!
 
               * 在这里必须将e.ParsingApplied属性设置为true,否则刚刚用户输入的值不会更新
 
               * 还是会将原来的值赋给该单元格
 
               * */
 
            e.Value = e.Value.ToString().ToUpper();
 
            e.ParsingApplied = true;
 
            //MessageBox.Show(this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());   
        }
        private void grd_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            DateTime Date = DBUtility.ClsPub.isDate(cmbYear.Text.ToString() + "-" + DBUtility.ClsPub.isInt(e.RowIndex / 2 + 1).ToString() + "-" + grd.Rows[e.RowIndex - 1].Cells[e.ColumnIndex].Value.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(grd.Rows[e.RowIndex].Cells[e.ColumnIndex].Value);
                //
                WriteClass(sWorktimes, sName, Date);
                oPs.AddNew();
                Display();
            }
        }
 
 
 
        //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();
        //}
 
    }
}