duhe
2023-06-13 bff338f3b532b0bf2a8f3f2d6b662adb9a222f13
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using gregn6Lib;
using SQLHelper;
 
 
namespace CostM
{
    public partial class CB_WIPBalance_QCMX : Form
    {
        public CB_WIPBalance_QCMX()
        {
            InitializeComponent();
        }
 
        const string ViewName = "h_v_CB_WIPBalance_QCMX";
        const string ModCaption = "ÆÚ³õ²ÄÁÏÃ÷ϸ";
        public const string ModName = "1205";
        public const string ModRightName = "CB_WIPBalance_QCMX";
        public const string ModRightNameEdit = ModRightName + "_Edit";
        public const string ModRightNameCheck = ModRightName + "_Check";
        public const string ModRightNameClose = ModRightName + "_Close";
        public const string ModRightNameDelete = ModRightName + "_Delete";
        public const string ModRightNameMoney = ModRightName + "_Money";
        public const string ModRightNameQty = ModRightName + "_Qty";
        public Int32 iTopRow = 0;//»­ºáÏß
        int _ScrollValue = 0;//ˢР»ØÎ»
        public int HYear;
        public int HPeriod;
        public long HMaterID;
 
        public int HQtyCol;
        public int HMoneyCol;
        private void bclk_Click(object sender, EventArgs e)
        {
            //±£´æÁпí
            DBUtility.Xt_BaseBillFun.SaveGrid(grdMain, this.Name);
        }
 
        private void mrlk_Click(object sender, EventArgs e)
        {
            DBUtility.Xt_BaseBillFun.DefaultGridView(grdMain, this.Name);
        }
 
        private void dc_Click(object sender, EventArgs e)
        {
            BLL.ClsPub_BLL.DataToExcel(grdMain);
        }
 
 
        #region  //´òÓ¡ÉèÖÃ
        GridppReport Report;
        private void set_Click(object sender, EventArgs e)
        {
            //Ñ¡Ôñ´òÓ¡Ä£°å
            BLL.Gy_OpenTmp oFrm = new BLL.Gy_OpenTmp();
            oFrm.sBillName = ModName;
            oFrm.sBillModel = ModCaption;
            oFrm.ShowDialog(); 
        }
 
        private void dy_Click(object sender, EventArgs e)
        {
            //Ñ¡Ôñ´òÓ¡Ä£°å
            BLL.Gy_OpenTmp oFrm = new BLL.Gy_OpenTmp();
            oFrm.sBillName = ModName;
            oFrm.sBillModel = ModCaption;
            oFrm.ShowDialog();
            if (oFrm.OKTag == Pub_Class.ClsPub.Enum_OKTag.OKTag_OK)
            {
                //
                Sub_SetReport(oFrm.sOpenTmp);
                Report.Print(true);
            }
        }
 
        private void yl_Click(object sender, EventArgs e)
        {
            //Ñ¡Ôñ´òÓ¡Ä£°å
            BLL.Gy_OpenTmp oFrm = new BLL.Gy_OpenTmp();
            oFrm.sBillName = ModName;
            oFrm.sBillModel = ModCaption;
            oFrm.ShowDialog();
            if (oFrm.OKTag == Pub_Class.ClsPub.Enum_OKTag.OKTag_OK)
            {
                //
                Sub_SetReport(oFrm.sOpenTmp);
                Report.PrintPreview(true);
            }
        }
 
        private void Sub_SetReport(string sOpenTmp)
        {
            //ÅжÏÐÐÊý
            //
            Report = new GridppReport();
            Report.LoadFromFile(DBUtility.ClsPub.AppPath + @"\" + sOpenTmp + ".grf");  //here .
            Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecordByDataTable);
        }
 
        private void ReportFetchRecordByDataTable()
        {
            BLL.Utility.FillRecordToReport(Report, grdMain, grdPrint, 0);
        }
 
        #endregion
 
        private void yr_Click(object sender, EventArgs e)
        {
            //ClsCN SubCn = new ClsCN();
            //DataSet DSet;
            ////string sSql = "select * from h_v_CB_WIPBalance_QCMX where Äê=" + cmbHYear.Text + " and ÔÂ=" + cmbHPeriod.Text;
            //string sSql = "exec h_p_CB_WIPBalance_QCMX " + HYear + " ," +HPeriod+","+HMaterID;
 
            //DSet = SubCn.RunProcReturn(sSql, ViewName, ref DBUtility.ClsPub.sExeReturnInfo);
            ////Éú³ÉÊ×ÐбêÌâ
            //if (DSet == null)
            //{
            //    MessageBox.Show("ûÓзµ»ØÈκνá¹û,Çë³¢ÊÔÔٴβéѯ£¡" + DBUtility.ClsPub.sExeReturnInfo);
            //    return;
            //}
            ////ÊͷŶ³½á
            //DBUtility.Xt_BaseBillFun.CancelFrozenCol(grdMain);
            ////ˢкó,»Ø¹öµ½Ô­Î»ÖÃ
            //int selectRows = 0;
            //if (grdMain.CurrentRow != null)
            //{
            //    selectRows = DBUtility.ClsPub.isInt(grdMain.CurrentRow.Index);
            //}
            ////°ó¶¨
            //grdMain.DataSource = DSet.Tables[0].DefaultView;
            ////ˢкó,»Ø¹öµ½Ô­Î»ÖÃ
            //if (grdMain.Rows.Count > _ScrollValue)
            //{
            //    grdMain.FirstDisplayedScrollingRowIndex = _ScrollValue;
            //    //iTopRow = _ScrollValue;
            //}
            //if (grdMain.Rows.Count > 0 && grdMain.Rows.Count > selectRows)
            //{
            //    grdMain.Rows[selectRows].Selected = true;
            //}
            ////ÉèÖúϼÆÁÐ
            ////string sTotalCol = "";
            ////sTotalCol = DBUtility.Gy_BaseFun.GetTotalCols(DSet);
            ////string[] sT;
            ////sT = sTotalCol.Split(Convert.ToChar(","));
            ////oSumGrid.BuildTotalCols(sT);
            ////  
            ////¶³½á
            //int FrCol = DBUtility.ClsPub.isInt(0);
            //string s = "";
            //DBUtility.Xt_BaseBillFun.DisplayGrid(grdMain, this.Name, s, FrCol);
            ////»­Ïß
            //GraphLine();
            ////
            ////Total();
        }
 
        private void GraphLine()
        {
            //int MainIDCol = Fun_GetCol("hmainid");
            //int SubIDCol = Fun_GetCol("hsubid");
            //string s = frmCondition.cmbHComplete.Text;
            //long n = 0;
            //DBUtility.Xt_BaseBillFun.GraphLine(grdMain, MainIDCol, SubIDCol, s, ref n);
            ////ÏÔʾ
            //lbldj.Text = "²éѯ³ö " + n.ToString() + " Õŵ¥¾Ý";
            //lbljl.Text = "¹²ÓР" + grdMain.RowCount.ToString() + " Ìõ¼Ç¼";
 
        }
 
 
        private Int32 Fun_GetCol(string sCol)
        {
            return DBUtility.Xt_BaseBillFun.Fun_GetCol(sCol, grdMain);
        }
 
        private void xz_Click(object sender, EventArgs e)
        {
            //»ñÈ¡±¾ÆÚ³É±¾»á¼ÆÆÚ¼ä
            if (DBUtility.ClsPub.Sub_CBGetCurPeriod() == false)
            {
                MessageBox.Show("»ñÈ¡³É±¾»á¼ÆÆÚ¼äʧ°Ü!");
                return;
            }
            //ÅжÏÊÇ·ñ±¾ÆÚ¼ä
            if (Pub_Class.ClsPub.isInt(cmbHYear.Text) != DBUtility.ClsPub.CBCurYear || Pub_Class.ClsPub.isInt(cmbHPeriod.Text) != DBUtility.ClsPub.CBCurPeriod)
            {
                MessageBox.Show("Ö»Äܱ£´æ±¾ÆÚÊý¾Ý£¡");
                return;
            }
            //
            //´æ´¢¹ý³Ì»ã×ÜÃ÷ϸ½ð¶î ¸üÐÂÆÚ³õ²ÄÁÏ±í  °ë³ÉÆ·½ð¶î Ô­²ÄÁϽð¶î ×ܽð¶î
            ClsCN oCn = new ClsCN();
            oCn.RunProc("exec h_p_CB_WIPBalance_QCMX_Update "+HYear+","+HPeriod+","+HMaterID);
            MessageBox.Show("±£´æÍê±Ï£¡");
        }
 
        private void tc_Click(object sender, EventArgs e)
        {
            this.Close();
        }
 
        private void CB_WIPBalance_QCMX_Load(object sender, EventArgs e)
        {
 
            DAL.ClsK3_Material_View oMater = new DAL.ClsK3_Material_View();
            cmbHYear.Items.Clear();
            //»ñÈ¡±¾ÆÚ³É±¾»á¼ÆÆÚ¼ä
            if (DBUtility.ClsPub.Sub_CBGetCurPeriod() == false)
            {
                MessageBox.Show("»ñÈ¡³É±¾»á¼ÆÆÚ¼äʧ°Ü!");
                return;
            }
            cmbHYear.Items.Add(DBUtility.ClsPub.CBCurYear);
            cmbHYear.Items.Add(DBUtility.ClsPub.CBCurYear - 1);
            cmbHYear.Items.Add(DBUtility.ClsPub.CBCurYear - 2);
            cmbHYear.Items.Add(DBUtility.ClsPub.CBCurYear - 3);
            cmbHYear.Items.Add("");
            //cmbHYear.SelectedIndex = 0;
            //cmbHPeriod.Text = DBUtility.ClsPub.CBCurPeriod.ToString();
 
            cmbHYear.Text = HYear.ToString();
            cmbHPeriod.Text = HPeriod.ToString();
            if (oMater.GetInfoByID(HMaterID))
            {
                txtHMaterID.Text = oMater.omodel.HNumber;
                txtHMaterName.Text= oMater.omodel.HName;
 
            }
            else
            {
                txtHMaterID.Text = "";
                txtHMaterName.Text = "";
            }
            initGrid();
            Show();
        }
 
        //³õʼ»¯GRID
        private void initGrid()
        {
            DBUtility.Gy_BaseFun.initGrid(grdMain);
        }
        private void Show()
        {
            ClsCN SubCn = new ClsCN();
            DataSet DSet;
            string sSql = "select * from h_v_CB_WIPBalance_QCMX where Äê=" + HYear + " and ÔÂ=" + HPeriod + " and HProdID=" + HMaterID;
            //string sSql = "exec h_p_CB_WIPBalance_QCMX " + HYear + " ," + HPeriod + "," + HMaterID;
 
            DSet = SubCn.RunProcReturn(sSql, ViewName, ref DBUtility.ClsPub.sExeReturnInfo);
            //Éú³ÉÊ×ÐбêÌâ
            if (DSet == null)
            {
                MessageBox.Show("ûÓзµ»ØÈκνá¹û,Çë³¢ÊÔÔٴβéѯ£¡" + DBUtility.ClsPub.sExeReturnInfo);
                return;
            }
            //ÊͷŶ³½á
            DBUtility.Xt_BaseBillFun.CancelFrozenCol(grdMain);
            //ˢкó,»Ø¹öµ½Ô­Î»ÖÃ
            int selectRows = 0;
            if (grdMain.CurrentRow != null)
            {
                selectRows = DBUtility.ClsPub.isInt(grdMain.CurrentRow.Index);
            }
            //°ó¶¨
            grdMain.DataSource = DSet.Tables[0].DefaultView;
 
            HQtyCol = Fun_GetCol("ÊýÁ¿");
            HMoneyCol = Fun_GetCol("½ð¶î");
            //ˢкó,»Ø¹öµ½Ô­Î»ÖÃ
            if (grdMain.Rows.Count > _ScrollValue)
            {
                grdMain.FirstDisplayedScrollingRowIndex = _ScrollValue;
                //iTopRow = _ScrollValue;
            }
            if (grdMain.Rows.Count > 0 && grdMain.Rows.Count > selectRows)
            {
                grdMain.Rows[selectRows].Selected = true;
            }
            //ÉèÖúϼÆÁÐ
            //string sTotalCol = "";
            //sTotalCol = DBUtility.Gy_BaseFun.GetTotalCols(DSet);
            //string[] sT;
            //sT = sTotalCol.Split(Convert.ToChar(","));
            //oSumGrid.BuildTotalCols(sT);
            //  
            //¶³½á
            int FrCol = DBUtility.ClsPub.isInt(0);
            string s = "";
            DBUtility.Xt_BaseBillFun.DisplayGrid(grdMain, this.Name, s, FrCol);
            //»­Ïß
            GraphLine();
            //
            //Total(); 
            grdMain.ReadOnly = false;
        }
 
        private void grdMain_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            int HYear = DBUtility.ClsPub.isInt( cmbHYear.Text);
            int HPeriod = DBUtility.ClsPub.isInt(cmbHPeriod.Text);
            if (e.ColumnIndex != HQtyCol && e.ColumnIndex != HMoneyCol  || HYear != DBUtility.ClsPub.CBCurYear || HPeriod != DBUtility.ClsPub.CBCurPeriod)
            {
                e.Cancel = true;
            }
        }
 
        private void grdMain_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            Update(e.RowIndex, e.ColumnIndex);
        }
        private void Update(int sRow, int sCol)
        {
            ClsCN oCn = new ClsCN();
            Int64 HItemID = 0;
            HItemID = DBUtility.ClsPub.isLong(grdMain.Rows[sRow].Cells[Fun_GetCol("HItemID")].Value);
            if (HItemID == 0)
                return;
            if (sCol == HQtyCol)
            {
                oCn.RunProc("update CB_WIPMaterBalance_QC set HQty=" + DBUtility.ClsPub.isDoule(grdMain.Rows[sRow].Cells[HQtyCol].Value) + " where HItemID=" + HItemID);
 
            }
            else if (sCol == HMoneyCol)
            {
                oCn.RunProc("update CB_WIPMaterBalance_QC set HMoney=" + DBUtility.ClsPub.isDoule(grdMain.Rows[sRow].Cells[HMoneyCol].Value) + " where HItemID=" + HItemID);
            }
            else
            { }
 
 
        }
 
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            CB_WIPBalance_QCMXAdd  oAdd= new CB_WIPBalance_QCMXAdd();
            oAdd.HYear = HYear;
            oAdd.HPeriod = HPeriod;
            oAdd.HProdID = HMaterID;
            oAdd.ShowDialog();
            Show();
        }
 
        private void sc_Click(object sender, EventArgs e)
        {
            ClsCN oCn = new ClsCN();
            Int64 HItemID = 0;
            HItemID = DBUtility.ClsPub.isLong(grdMain.Rows[grdMain.CurrentRow.Index].Cells[Fun_GetCol("HItemID")].Value);
            if (HItemID == 0)
                return;
 
            //»ñÈ¡±¾ÆÚ³É±¾»á¼ÆÆÚ¼ä
            if (DBUtility.ClsPub.Sub_CBGetCurPeriod() == false)
            {
                MessageBox.Show("»ñÈ¡³É±¾»á¼ÆÆÚ¼äʧ°Ü!");
                return;
            }
            //ÅжÏÊÇ·ñ±¾ÆÚ¼ä
            int sYear = 0;
            int sPeriod = 0;
            sYear = DBUtility.ClsPub.isInt(grdMain.Rows[grdMain.CurrentRow.Index].Cells[Fun_GetCol("Äê")].Value);
            sPeriod = DBUtility.ClsPub.isInt(grdMain.Rows[grdMain.CurrentRow.Index].Cells[Fun_GetCol("ÔÂ")].Value);
 
            if (sYear != DBUtility.ClsPub.CBCurYear || sPeriod != DBUtility.ClsPub.CBCurPeriod)
            {
                MessageBox.Show("Ö»ÄÜɾ³ý±¾ÆÚÊý¾Ý£¡");
                return;
            }
            //
            if (MessageBox.Show("È·¶¨ÒªÉ¾³ýµ±Ç°Ñ¡ÖмǼ£¿", "Ìáʾ", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                oCn.RunProc("delete CB_WIPMaterBalance_QC where HItemID=" + HItemID);
                MessageBox.Show("ɾ³ýÍê±Ï£¡"); 
                Show();
                
            }
        }
    }
}