yusijie
2024-11-29 89873b7d156f21e7aa71b3f004a11ced2e7a7d4e
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
ÿþusing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Pub_Class;
 
namespace WorkM
{
    public partial class Xs_SendGoodsPlan_CF : Form
    {
        public Xs_SendGoodsPlan_CF()
        {
            InitializeComponent();
        }
        DateTimePicker dtp = new DateTimePicker();  //ُ̑ž[‹OSN*NDateTimePicker§cöN  
        Rectangle _Rectangle;
 
        public string[,] row=new string[60,2];
 
        ClsGridViewSum oSumGrid = new ClsGridViewSum();
        //š[INR 
        //
 
        public const Int16 HTagCol = 0;
        public const Int16 HSnoCol = 1;
        public const Int16 HDateCol = 2;
        public const Int16 HQtyCol = 3;
        //
        public bool isOk;
        public int sHDateCol;
        public int sHQtyCol;
 
        public bool grdStatus=true;
        //RËYSQ<h
        private void initGrid()
        {
            grdMain.ColumnCount = 4;
            DBUtility.Xt_BaseBillFun.initGridFst(grdMain, this.Name);
 
            grdMain.Columns[HSnoCol].HeaderText = "^÷S";
            grdMain.Columns[HDateCol].HeaderText = "åeg";
            grdMain.Columns[HQtyCol].HeaderText = "peϑ";
            //
            grdMain.Controls.Add(dtp);  //Šböeô•§cöN ReQDataGridView 
            dtp.Visible = false;  //HQ N©‹ƒ[>f:y  
            dtp.Format = DateTimePickerFormat.Custom;  //¾‹nåeg<h_:N2010-08-05  
            dtp.TextChanged += new EventHandler(dtp_TextChange); //:Nöeô•§cöN ReQ‹NöNdtp_TextChange  
 
            //<h_S 
            grdMain.Columns[HTagCol].Visible = false;                           //–Ï…R
            //¾‹nïS‘R
            string sAllowCol = HDateCol.ToString() +
                                  "," + HQtyCol.ToString();
            //¾‹nT¡‹R
            string sTotalCol = HQtyCol.ToString();
            //
            DBUtility.Xt_BaseBillFun.initGridLast(sAllowCol, sTotalCol, oSumGrid);
 
        }
        //öeô•§cöN    éböeô•öe 
        private void dtp_TextChange(object sender, EventArgs e)
        {
            grdMain.CurrentCell.Value = dtp.Text.ToString();  //öeô•§cöN    éböeô•öe ÿ1\Šböeô•KÙ~@b(W„vUSCQ<h  
        }
 
 
        //USCQ<h«ˆUSûQ ÿ$R­e/f&T/f>eöeô•§cöN„v£NR
        private void grdMain_CellClick(object sender, DataGridViewCellEventArgs e)
        {
 
            if (e.ColumnIndex == HDateCol)
            {
                _Rectangle = grdMain.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true); //—_0R@b(WUSCQ<hMOnŒT'Y\  
                dtp.Size = new Size(_Rectangle.Width, _Rectangle.Height); //ŠbUSCQ<h'Y\KÙ~öeô•§cöN  
                dtp.Location = new Point(_Rectangle.X, _Rectangle.Y); //ŠbUSCQ<hMOnKÙ~öeô•§cöN  
                dtp.Visible = true;  //ïSåN>f:y§cöN†N  
            }
            else
                dtp.Visible = false;
        }
 
        //S_R„v½[¦^ØSSöe ÿöeô•§cöNHQ–Ï…weg ÿ N6qUSCQ<hØS'Yöeô•§cöNàeÕlߍ@wØS'YæT
        private void grdMain_ColumnWidthChanged(object sender, DataGridViewColumnEventArgs e)
        {
            dtp.Visible = false;
 
            DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
        }
 
        //Ún¨RagÚn¨Röe ÿUSCQ<hMOnÑSuØSS ÿ_N—_–Ï…öeô•§cöN ÿ N6qöeô•§cöNMOn N¨R1\qN†N
        private void grdMain_Scroll(object sender, ScrollEventArgs e)
        {
            dtp.Visible = false;
        }
 
 
        //Q<h‘MR$R­e
        private void grdMain_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            int i = grdMain.CurrentCell.ColumnIndex;
 
            if (i != HDateCol && i != HQtyCol)
            {
                e.Cancel = true;
            }
 
            //if (DBUtility.Xt_BaseBillFun.AllowEdit(grdStatus, oSumGrid, i))
            //{
            //    e.Cancel = true;
            //}
        }
 
        //Q<h‘TYt
        private void grdMain_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
            //RowCount(e.RowIndex, 0);  //¡‹—{ Ñ‘˜ US÷N
            //
            if (this.EditingControl != null)      //ʑ>e‹NöN
            {
                EditingControl.KeyDown -= new KeyEventHandler(this.EditingControl_KeyDown);
                this.EditingControl = null;
            }
        }
        DataGridViewTextBoxEditingControl EditingControl;
 
        private void grdMain_CellLeave(object sender, DataGridViewCellEventArgs e)
        {
            //
            if (!grdStatus)
            {
                return;
            }
            DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
            //
            //if (oSumGrid.Changelock)
            //    return;
            //if(oSumGrid.EditStatus)
            //{
            //if (!CheckGridRow(oSumGrid.OldCell.Row))
            //    return;
            //}
        }
 
 
        private void grdMain_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (grdMain.CurrentCell != null)
            {
                if (e.Control is DataGridViewTextBoxEditingControl)
                {
                    this.EditingControl = (DataGridViewTextBoxEditingControl)e.Control;
                    //žX RÔYXbYt 
                    this.EditingControl.KeyDown += new KeyEventHandler(this.EditingControl_KeyDown);
                }
            }
        }
 
        private void EditingControl_KeyDown(object sender, KeyEventArgs e)
        {
            //N¡RYt 
            //Sub_GridKey(e.KeyValue, grdMain.CurrentRow.Index, grdMain.CurrentCell.ColumnIndex, EditingControl);
        }
        private void bc_Click(object sender, EventArgs e)
        {
            //1Y»S&q¹p
            label4.Focus();
            if (!AllowSave())
            {
                return;
            }
            isOk = true;
            sHDateCol = HDateCol;
            sHQtyCol = HQtyCol;
            this.Close();
        }
 
        //ÝOX[MR  Àhåg
        private bool AllowSave()
        {
            double HQty = 0;
            DateTime HMaxDate = DBUtility.ClsPub.isDate(DBUtility.ClsPub.GetServerDate(0)).AddDays(59);
            DateTime HMinDate = DBUtility.ClsPub.isDate(DBUtility.ClsPub.GetServerDate(0));
            for (int i = 0; i < grdMain.Rows.Count; i++)
            {
                if (DBUtility.ClsPub.isStrNull( grdMain.Rows[i].Cells[HDateCol].Value) != "")
                {
                    if (IsDate(grdMain.Rows[i].Cells[HDateCol].Value.ToString()) == false)
                    {
                        MessageBox.Show(",{" + (i + 1) + "Lˆ ÿåeg<h_•ï‹ÿ", "Ðc:y");
                        return false;
                    }
                    if (DBUtility.ClsPub.isDate(grdMain.Rows[i].Cells[HDateCol].Value) > HMaxDate)
                    {
                        MessageBox.Show(",{" + (i + 1) + "Lˆ ÿåeg Ný€'YŽN" + HMaxDate.ToShortDateString() + "ÿ", "Ðc:y");
                        return false;
                    }
                    if (DBUtility.ClsPub.isDate(grdMain.Rows[i].Cells[HDateCol].Value) < HMinDate)
                    {
                        MessageBox.Show(",{" + (i + 1) + "Lˆ ÿåeg Ný€\ŽN" + HMinDate.ToShortDateString() + "ÿ", "Ðc:y");
                        return false;
                    }
                    for (int j = i+1; j < grdMain.Rows.Count; j++)
                    {
                        if (DBUtility.ClsPub.isDate(grdMain.Rows[i].Cells[HDateCol].Value) == DBUtility.ClsPub.isDate(grdMain.Rows[j].Cells[HDateCol].Value))
                        {
                            MessageBox.Show(",{" + (i + 1) + "LˆN,{" + (j + 1) + "Lˆåegøv Tÿ", "Ðc:y");
                            return false;
                        }
                    }
                    HQty = HQty + DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells[HQtyCol].Value);
                }
            }
            if (DBUtility.ClsPub.isDoule(txtHQty.Text) != HQty)
            {
                MessageBox.Show("ÆbRpeϑN¢‹US;`peϑ NNôÿ", "Ðc:y");
                return false;
            }
            return true;
        }
        public bool IsDate(string strDate)
        {
            string sDateType;
            if (strDate.IndexOf("-") != -1)
            {
                sDateType = "yyyy-M-d";
            }
            else if (strDate.IndexOf("/") != -1)
            {
                sDateType = "yyyy/M/d";
            }
            else 
            {
                sDateType = "yyyyMMdd";
            }
          
            try
            {
                //DateTime.Parse(strDate);
                DateTime dt = DateTime.ParseExact(strDate, sDateType, System.Globalization.CultureInfo.InvariantCulture);
                return true;
            }
            catch
            {
                return false;
            }
        }
 
        private void tc_Click(object sender, EventArgs e)
        {
            isOk = false;
            this.Close();
        }
 
        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            //RËYS
            initGrid();
            DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
 
            for (int i = 0; i < 60; i++)
            {
                if (DBUtility.ClsPub.isStrNull(row[i, 0]) != "")
                {
                    string a = DBUtility.ClsPub.isStrNull(row[i, 0]);
                    string b = DBUtility.ClsPub.isStrNull(row[i, 1]);
                    grdMain.Rows[i].Cells[HDateCol].Value = a;
                    grdMain.Rows[i].Cells[HQtyCol].Value = b;
                }
                else
                {
                    break;
                }
            }
        }
 
        private void DelRow_Click(object sender, EventArgs e)
        {
            DBUtility.Xt_BaseBillFun.DelRow(oSumGrid);
        }
 
        private void Xs_SendGoodsPlan_CF_Load(object sender, EventArgs e)
        {
            oSumGrid.NoCol = HSnoCol;
            oSumGrid.ogrdMain = grdMain;
            oSumGrid.oGridsum = grdSum;
        }
 
        private void AddRow_Click(object sender, EventArgs e)
        {
            DBUtility.Xt_BaseBillFun.AddRow(oSumGrid);
        }
    }
}