yxj
2025-04-02 bee71e87f2b06265e44c27723d15bff52f1d2dbd
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SQLHelper;
 
namespace DBUtility
{
    public partial class frmHlpBillList : Form
    {
        public frmHlpBillList()
        {
            InitializeComponent();
        }
        public  string ViewName;
        public string tSQL;
        public frmBillQueryCondition_New frmCondition;
        public string sPrimaryCol;
        public Pub_Class.ClsPub.Enum_OKTag OKTag;
        public string sBillName="";
        //³õʼ»¯GRID
        private void initGrid()
        {
            grdMain.Cols = 1;
            grdMain.Rows = 1;
            grdMain.FixedCols = 1;
            grdMain.FixedRows = 1;
            
            //grdMain.ExplorerBar = VSFlex7.ExplorerBarSettings.flexExSortAndMove;
            grdMain.AllowBigSelection = false;
            grdMain.AllowSelection = true;
            grdMain.SelectionMode = VSFlex7.SelModeSettings.flexSelectionByRow;
            grdMain.ScrollTrack = true;
            grdMain.WordWrap = true;
            grdMain.set_ColWidth(-1, 1500);
            grdMain.set_RowHeight(-1, 400);
            grdMain.set_RowHeight(0, 500);
            grdMain.RowHeightMin = 250;
            grdMain.Editable = VSFlex7.EditableSettings.flexEDNone;
            grdMain.AllowUserResizing = VSFlex7.AllowUserResizeSettings.flexResizeBoth;
            grdMain.AllowUserFreezing = VSFlex7.AllowUserFreezeSettings.flexFreezeBoth;
            grdMain.set_FixedAlignment(-1, VSFlex7.AlignmentSettings.flexAlignCenterCenter);
            grdMain.AutoSizeMode = VSFlex7.AutoSizeSettings.flexAutoSizeColWidth;
            grdMain.GridLines = VSFlex7.GridStyleSettings.flexGridFlatVert;
        }
        //ÏÔʾÄÚÈÝ
        private void Display()
        {
            ClsCN SubCn = new ClsCN();
            DataSet DSet ;
            int AddCol = 1;
            grdMain.Rows = grdMain.FixedRows;
            string sSql = "";
            string sWhere =tSQL;
            //¹ýÂËÌõ¼þ
            if (frmCondition.SqlStr.Trim().Length == 0)
                return;
            sSql = frmCondition.SqlStr + sWhere ;
            //
            DSet = SubCn.RunProcReturn(sSql, ViewName);
            //Éú³ÉÊ×ÐбêÌâ
            if (DSet.Tables[0].Rows.Count == 0)
            {
                grdMain.Redraw = VSFlex7.RedrawSettings.flexRDBuffered;
                return;
            }
            //
            grdMain.Redraw = VSFlex7.RedrawSettings.flexRDNone;
            //
            grdMain.Cols = DSet.Tables[0].Columns.Count + grdMain.FixedCols + AddCol;
            grdMain.set_TextMatrix(0, grdMain.FixedCols - 1, "ÐòºÅ");
            grdMain.set_TextMatrix(0, grdMain.FixedCols - 1+AddCol, "Ñ¡Ôñ"); //ÉèÖà×Ô¶¨ÒåÁÐ
            grdMain.set_ColWidth(0, 500);
            for (int i = 0; i <= DSet.Tables[0].Columns.Count - 1; i++)
            {
                grdMain.set_TextMatrix(0, i + grdMain.FixedCols + AddCol, DSet.Tables[0].Columns[i].Caption);
                if (DSet.Tables[0].Columns[i].Caption.ToLower().Substring(0, 1) == "h") //Ê××ÖĸΪhÔòÒþ²Ø
                {
                    grdMain.set_ColHidden(i + grdMain.FixedCols + AddCol, true);
                }
                else
                {
                    grdMain.set_ColHidden(i + grdMain.FixedCols + AddCol, false);
                    grdMain.set_ColWidth(i + grdMain.FixedCols + AddCol, 1000);
                }
            }
 
            //Ìî³äÍø¸ñ
            string s = "";
            grdMain.Rows = DSet.Tables[0].Rows.Count + grdMain.FixedRows;
            for (int i = 0; i <= DSet.Tables[0].Rows.Count - 1; i++)
            {
                grdMain.set_TextMatrix(i + grdMain.FixedRows, 0, (i + grdMain.FixedRows).ToString()); //ÐкÅ
                for (int j = 0; j <= DSet.Tables[0].Columns.Count - 1; j++)
                {
                    s = DSet.Tables[0].Rows[i][j].ToString();
                    grdMain.set_TextMatrix(i + grdMain.FixedRows, j + grdMain.FixedCols + AddCol, s);
                }
            }
            //ºÏ¼Æ
            grdMain.SubtotalPosition = VSFlex7.SubtotalPositionSettings.flexSTBelow;
            for (int i = 0; i <= DSet.Tables[0].Columns.Count - 1; i++)
            {
                if (DSet.Tables[0].Columns[i].DataType.ToString() == "System.Double" ||
                    DSet.Tables[0].Columns[i].DataType.ToString() == "System.Single" ||
                    DSet.Tables[0].Columns[i].DataType.ToString() == "System.Decimal"
                    )
                {
                    //ÈôΪÊýÖµÔò ÓÒ¶ÔÆë²¢ÇҺϼÆ
                    grdMain.set_ColFormat(i + grdMain.FixedCols + AddCol, "###,###,##0.##");
                    grdMain.Subtotal(VSFlex7.SubtotalSettings.flexSTSum, -1, i + grdMain.FixedCols + AddCol, "###,###,##0.00", 15197644, 0, true, "ºÏ¼Æ", 2, false);
                    grdMain.set_ColAlignment(i + grdMain.FixedCols + AddCol, VSFlex7.AlignmentSettings.flexAlignRightCenter);
                }
                else if (DSet.Tables[0].Columns[i].DataType.ToString() == "System.Int16" ||
                        DSet.Tables[0].Columns[i].DataType.ToString() == "System.Int32" ||
                        DSet.Tables[0].Columns[i].DataType.ToString() == "System.Int64")
                {
                    //ÈôΪÊýÖµÔò ÓÒ¶ÔÆë²¢ÇҺϼÆ
                    grdMain.Subtotal(VSFlex7.SubtotalSettings.flexSTSum, -1, i + grdMain.FixedCols + AddCol, 0, 15197644, 0, true, "ºÏ¼Æ", 2, false);
                    grdMain.set_ColAlignment(i + grdMain.FixedCols + AddCol, VSFlex7.AlignmentSettings.flexAlignRightCenter);
                }
                else
                {
                    //·ÇÊýÖµ Ôò×ó¶ÔÆë
                    grdMain.set_ColAlignment(i + grdMain.FixedCols + AddCol, VSFlex7.AlignmentSettings.flexAlignLeftCenter);
                }
            }
            //¹Ì¶¨ÐРÖмä¶ÔÆë
            grdMain.set_FixedAlignment(-1, VSFlex7.AlignmentSettings.flexAlignCenterCenter);
            //¼ÓÔØÁпí
            ClsPub.GetGrid(this.grdMain, this.Name,ClsPub.AppPath);
            //»­Ïß
            GraphLine();
            //
            grdMain.FrozenCols = 2;
            grdMain.Redraw = VSFlex7.RedrawSettings.flexRDBuffered;
        }
 
        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            initGrid();
            Display();
        }
 
        private void tc_Click(object sender, EventArgs e)
        {
            OKTag = Pub_Class.ClsPub.Enum_OKTag.OKTag_Cancel;
            this.Visible = false;
        }
 
        private void sx_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true;
        }
        //ÕÒµ½¶ÔÓ¦ÁÐ
        public Int32 Fun_GetCol(string sCol)
        {
            for (int c = 0; c < grdMain.Cols; c++)
            {
                if (ClsPub.isStrNull(grdMain.get_TextMatrix(0, c)).ToUpper().Trim() == sCol.Trim().ToUpper())
                {
                    return c;
                }
            }
            return 0;
        }
 
        private void frmHlpBillList_Load(object sender, EventArgs e)
        {
            frmCondition = new frmBillQueryCondition_New();
            initGrid();
        }
 
        private void cx_Click(object sender, EventArgs e)
        {
            frmCondition = new frmBillQueryCondition_New();
            frmCondition.Tag = "";
            frmCondition.ViewName = ViewName;
            frmCondition.ModName = this.Name;
            frmCondition.ShowDialog();
            if (frmCondition.Tag.ToString() == "OK")
            {
                Display();
            }
        }
 
        private void bclk_Click(object sender, EventArgs e)
        {
            //±£´æÁпí
            ClsPub.SaveGrid(grdMain, this.Name, ClsPub.AppPath);
        }
 
        private void mrlk_Click(object sender, EventArgs e)
        {
            grdMain.AutoSize(0, grdMain.Cols - 1, false, 1);
            //²ÎÊý½âÊÍ  ¿ªÊ¼ÁР£¬½áÊøÁУ¬ÊÇ·ñÒÔ×î´óÁпíΪ׼£¬×îСÁпí
            ClsPub.SaveGrid(grdMain, this.Name, ClsPub.AppPath);
        }
        //»®Ïß
        private void GraphLine()  //Lock
        {
            //ÕÒµ½Ö÷±íIDºÍ×Ó±íIDµÄ ·¶Î§
            int MainIDCol = Fun_GetCol("hmainid");
            int SubIDCol = Fun_GetCol("hsubid");
            long HMainID = 0;
            //Ñ­»·ËùÓÐÐÐ
            for (int i = grdMain.FixedRows; i < grdMain.Rows - 1; i++)
            {
                if (HMainID == 0)
                {
                    HMainID = ClsPub.isLong(grdMain.get_ValueMatrix(i, MainIDCol).ToString());
                }
                else
                {
                    if (HMainID == ClsPub.isLong(grdMain.get_ValueMatrix(i, MainIDCol).ToString()))
                    {
                        //grdMain.set_Cell(VSFlex7.CellPropertySettings.flexcpText, i, MainIDCol + 1, i, SubIDCol - 1, "");
 
                    }
                    else
                    {
                        HMainID = ClsPub.isLong(grdMain.get_ValueMatrix(i, MainIDCol).ToString());
                        grdMain.Select(i, grdMain.FixedCols, i, grdMain.Cols - 1);
                        grdMain.CellBorder(16755034, 0, 1, 0, 0, 0, 0);
                    }
                }
            }
        }
        //ÊÇ·ñÔÊÐí·µ»Ø
        private bool AllowBack()  //Lock
        {
            string stmp="";
            int PrimaryCol;
            int SelectCol = Fun_GetCol("Ñ¡Ôñ");
            if (sPrimaryCol.Trim() != "")
            {
                PrimaryCol = Fun_GetCol(sPrimaryCol);
                if (PrimaryCol == 0)
                {
                    return true;
                }
                else
                {
                    for (int i = grdMain.FixedRows; i < grdMain.Rows; i++)
                    {
                        if (ClsPub.isStrNull(grdMain.get_TextMatrix(i, SelectCol)) == "*")
                        {
                            if (stmp == "")
                            {
                                stmp = ClsPub.isStrNull(grdMain.get_TextMatrix(i, PrimaryCol));
                            }
                            if(stmp!=ClsPub.isStrNull(grdMain.get_TextMatrix(i, PrimaryCol)))
                                return false;
                        }
                    }
                }
            }
            else
            {
                return true;
            }
            return true;
        }
        //·µ»ØÐÅÏ¢
        private void Sub_DataBack()
        {
            if (!AllowBack())
            {
                MessageBox.Show("²»ÔÊÐíÑ¡Ôñ²»Í¬µÄ" + sPrimaryCol + "£¡", "Ìáʾ");
                return;
            }
            OKTag = Pub_Class.ClsPub.Enum_OKTag.OKTag_OK;
            this.Visible = false;
        }
        //
        private void fh_Click(object sender, EventArgs e)
        {
            Sub_DataBack();
        }
        //Ñ¡ÖÐÐÐ
        private void Sub_SelectRow()
        {
            int SelectCol = Fun_GetCol("Ñ¡Ôñ");
            int BRow, ERow;
            if (grdMain.Row >= grdMain.RowSel)
            {
                BRow = grdMain.RowSel;
                ERow = grdMain.Row;
            }
            else
            {
                ERow = grdMain.RowSel;
                BRow = grdMain.Row;
            }
            for (int i = BRow; i <= ERow; i++)
            {
                grdMain.set_TextMatrix(i, SelectCol, "*");
            }
        }
        //
        private void xz_Click(object sender, EventArgs e)
        {
            Sub_SelectRow();
        }
        //
        private void Sub_ClearRow()
        {
            int SelectCol = Fun_GetCol("Ñ¡Ôñ");
            int BRow, ERow;
            if (grdMain.Row >= grdMain.RowSel)
            {
                BRow = grdMain.RowSel;
                ERow = grdMain.Row;
            }
            else
            {
                ERow = grdMain.RowSel;
                BRow = grdMain.Row;
            }
            for (int i = BRow; i <= ERow; i++)
            {
                grdMain.set_TextMatrix(i, SelectCol, "");
            }
        }
        //
        private void qc_Click(object sender, EventArgs e)
        {
            Sub_ClearRow();
        }
 
        private void timer2_Tick(object sender, EventArgs e)
        {
            timer2.Enabled = false;
            frmCondition = new frmBillQueryCondition_New();
            frmCondition.Tag = "";
            frmCondition.ViewName = ViewName;
            frmCondition.ModName = this.Name;
            frmCondition.ShowDialog();
            if (frmCondition.Tag.ToString() == "OK")
            {
                timer1.Enabled = true;
            }
        }
        //
        private void grdMain_DblClick(object sender, EventArgs e)
        {
            int SelectCol = Fun_GetCol("Ñ¡Ôñ");
            if (grdMain.Row >= grdMain.FixedRows && grdMain.Row <= grdMain.Rows - 2)
            {
                if (ClsPub.isStrNull( grdMain.get_TextMatrix(grdMain.Row, SelectCol)) == "*")
                {
                    grdMain.set_TextMatrix(grdMain.Row, SelectCol, "");
                }
                else
                {
                    grdMain.set_TextMatrix(grdMain.Row, SelectCol,"*") ;
                }
            }
        }
    }
}