1
zgq
2021-08-25 0a446ad6c4285abb55f7f456b2273b772a8b6923
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
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Pub_Class;
 
namespace APSM
{
    public class ClsGridSum
    {
        public  AxVSFlex7.AxVSFlexGrid ogrdMain=new AxVSFlex7.AxVSFlexGrid();
        public  AxVSFlex7.AxVSFlexGrid oGridsum=new AxVSFlex7.AxVSFlexGrid();
        private string sTotalCols;
        private string sAllowEdit;
        public Cell OldCell = new Cell();
        public bool Changelock;
        public bool Gdtlock;
        public bool EditStatus;
        public bool DisplayNoCol;
        public Int32 NoCol;
        public string KeyItem;
        public bool NotAllowADDRow;
        public bool NotAllowDELRow;
        public char chr = Convert.ToChar(",");
        
        //获得 合计列
        public void  BuildTotalCols(string[] Cols)
        {
            Int64 i;
            string tStr;
            tStr = "";
            for (i = 0; i < Cols.Length; i++)
            {
                if (i == 0)
                {
                    tStr = Cols[i];
                }
                else
                {
                    tStr = tStr + "," + Cols[i];
                }
            }
            sTotalCols= tStr;
        }
        //获得 可编辑列
        public void  BuildAllowEditCols(string[] Cols)
        {
            Int64 i;
            string tStr;
            tStr = "";
            for (i = 0; i < Cols.Length; i++)
            {
                if (i == 0)
                {
                    tStr = Cols[i];
                }
                else
                {
                    tStr = tStr + "," + Cols[i];
                }
            }
            sAllowEdit= tStr;
        }
        //设置网格属性
        public void SetGridsum( )
        {
            Int32 i;
            oGridsum.Enabled = false;
            oGridsum.Appearance = VSFlex7.AppearanceSettings.flexFlat;
            oGridsum.BorderStyle = VSFlex7.BorderStyleSettings.flexBorderNone;
            oGridsum.ScrollBars = VSFlex7.ScrollBarsSettings.flexScrollBarNone;
            oGridsum.Width  = ogrdMain.Width;
            oGridsum.FixedRows = 0;
            oGridsum.Rows = 1;
            oGridsum.Cols = ogrdMain.Cols;
            oGridsum.LeftCol = ogrdMain.LeftCol;
            oGridsum.set_RowHeight(0, 300);
            oGridsum.Height = 30;
            oGridsum.set_Cell(VSFlex7.CellPropertySettings.flexcpText, 0, 0, 0, oGridsum.Cols - 1, "");
            oGridsum.set_TextMatrix(0, 0, "合计");
            oGridsum.set_ColAlignment(-1, VSFlex7.AlignmentSettings.flexAlignCenterCenter);
            for (i = 0; i < ogrdMain.Cols; i++)
            {
                oGridsum.set_ColHidden(i,ogrdMain.get_ColHidden(i));
                oGridsum.set_ColWidth(i, ogrdMain.get_ColWidth(i));
                oGridsum.set_ColAlignment(i, ogrdMain.get_ColAlignment(i));
                oGridsum.set_ColFormat(i, ogrdMain.get_ColFormat(i));
            }
            oGridsum.set_ColAlignment(0,VSFlex7.AlignmentSettings.flexAlignCenterTop);
            for (i = oGridsum.FixedRows; i < oGridsum.Rows - 1; i++)
            {
                oGridsum.set_RowHeight(i, oGridsum.Height / oGridsum.Rows);
            }
            oGridsum.Width = ogrdMain.Width ;
            RefreshNoCol();
        }
        //合计函数
        public void Total()
        {
            string[] Cols;
            Int32 i, j, ColsTotal;
            if(ClsPub.isStrNull( sTotalCols).ToString().Trim()==""  )
                return;
            Cols = sTotalCols.Split(chr);
            ColsTotal = Cols.Length;
            for (j = 0; j < ColsTotal; j++)
            {
                oGridsum.set_TextMatrix(0, ClsPub.isInt(Cols[j]), "");
            }
            try
            {
                double d = 0;
                for (j = 0; j < ColsTotal; j++)
                {
                    d = 0;
                    for (i = ogrdMain.FixedRows; i < ogrdMain.Rows; i++)
                    {
                        //if (ogrdMain.get_TextMatrix(i, 0) == "*")
                        //{
                        if (ogrdMain.get_RowHidden(i) == false)
                        {
                            d = d + ClsPub.isDoule(ogrdMain.get_TextMatrix(i, ClsPub.isInt(Cols[j])));
                            //oGridsum.set_TextMatrix(0, ClsPub.isInt(Cols[j]), Convert.ToString(oGridsum.get_ValueMatrix(0, ClsPub.isInt(Cols[j])) + ogrdMain.get_ValueMatrix(i, ClsPub.isInt(Cols[j]))) );
                        }
                    }
                    //}
                    oGridsum.set_TextMatrix(0, ClsPub.isInt(Cols[j]), d.ToString());
                }
            }
            catch (Exception  e)
            {
                string s = "";
                s= e.Message;
            }
        }
        //
        public void LeaveCell()
        {
            if (Changelock)
                return;
            OldCell.Col = ogrdMain.Col;
            OldCell.Row = ogrdMain.Row;
        }
        //列是否允许编辑
        public bool FindAllowEditCol(Int64 Col)
        {
            Int64 i;
            string[] s;
            if (sAllowEdit.Trim() == "")
                return false;
            s=sAllowEdit.Split(chr );
            for(i=0;i<=s.Length-1;i++)
            {
                if(Col==ClsPub.isInt(s[i]))
                    return true;
            }
            return false;
        }
        //增行
        public void Sub_AddRow()
        {
            //if (EditStatus == true)
            //{
            //    return;
            //}
            if (ogrdMain.Row < ogrdMain.FixedRows || ogrdMain.Row > ogrdMain.Rows - 1)
            {
                return;
            }
            if (GetNullRows() < 1)
            {
                ogrdMain.AddItem("", ogrdMain.Row);
                if (ogrdMain.Row != ogrdMain.Rows - 1)
                {
                    if (ogrdMain.get_TextMatrix(ogrdMain.Row + 1, 0) == "*")
                    {
                        ogrdMain.set_TextMatrix(ogrdMain.Row, 0, "*");
                    }
                    else
                    {
                        ogrdMain.RemoveItem(ogrdMain.Rows - 1);
                    }
                    DisplayCurRow();
                    DisplayCurCol();
                    RefreshNoCol();
                }
            }
        }
        //删除行
        public void Sub_DelRow()
        {
            int Scqwghz; //原选中行
            int Scqwglz; //原选中列
      
            Scqwghz = ogrdMain.Row;
            Scqwglz = ogrdMain.Col;
            //if (ClsPub.isStrNull(ogrdMain.get_TextMatrix(Scqwghz, 0))!= "")
            //{
            //    if (ogrdMain.get_TextMatrix(ogrdMain.Row, 0) == "*")
            //    {
                    
                    DisplayCurRow();
                    Changelock = true;
                    ogrdMain.Select(ogrdMain.Row, 0);
                    Changelock = false;
                    ogrdMain.set_Cell(VSFlex7.CellPropertySettings.flexcpBackColor, ogrdMain.Row, 0, ogrdMain.Row, ogrdMain.Cols - 1, 123456);
                    if (MessageBox.Show( "确定要删除当前记录?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
                    {
                        ogrdMain.set_Cell(VSFlex7.CellPropertySettings.flexcpBackColor, ogrdMain.Row, 0, ogrdMain.Row, ogrdMain.Cols - 1, 000000);
                        Changelock = true;
                        ogrdMain.Select(Scqwghz, Scqwglz);
                        Changelock = false;
                        return;
                    }
                    ogrdMain.RemoveItem(ogrdMain.Row);
                    if (ogrdMain.Rows < 50 + ogrdMain.FixedRows + 1)
                    {
                        ogrdMain.AddItem("");
                    }
                    Changelock = true;
                    if (ClsPub.isStrNull(ogrdMain.get_TextMatrix(ogrdMain.Row, 0)) != "*" && ClsPub.isStrNull(ogrdMain.get_TextMatrix(ogrdMain.Row - 1, 0)) == "*")
                    {
                        ogrdMain.Select(ogrdMain.Row-1, Scqwglz);
                    }
                    else
                    {
                        ogrdMain.Select(ogrdMain.Row, Scqwglz);
                    }
                    Changelock = false;
                    RefreshNoCol();
            //    }
            //}
            EditStatus = false;
        }
        //获得 NULL 行
        public Int64 GetNullRows()  
        {
            Int32 r, c;
            Int32 lngRows;
            lngRows = 0;
            for (r = ogrdMain.FixedRows; r < ogrdMain.Rows; r++)
            {
                if (ogrdMain.get_TextMatrix(r, 0) == "*")
                {
                    if (DisplayNoCol== true)
                    {
                        for (c = NoCol + 1; c < ogrdMain.Cols; c++)
                        {
                            if (ogrdMain.get_TextMatrix(r, c) != "" || ogrdMain.get_TextMatrix(r, c) != null)
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        for (c =1; c < ogrdMain.Cols; c++)
                        {
                            if (ogrdMain.get_TextMatrix(r, c) != "" || ogrdMain.get_TextMatrix(r, c) != null)
                            {
                                break;
                            }
                        }
                    }
                    if (c == ogrdMain.Cols)
                        lngRows = lngRows + 1;
                }
            }
            return  lngRows;
        }
        //显示当前行
        public void DisplayCurRow()
        {
            Int64 Toprowte;
            if (CountNullRows() < 50)
                ogrdMain.AddItem("");
            Toprowte = 0;
        }
        //计算用户可用行
        public Int64 CountNullRows()
        {
            Int32 r;
            Int32 lngRows;
            lngRows = 0;
            for (r = ogrdMain.FixedRows; r < ogrdMain.Rows; r++)
            {
                if (ogrdMain.get_TextMatrix(r, 0) != "*")
                    lngRows = lngRows + 1;
            }
            return lngRows;
        }
 
        //显示当前列
        public void DisplayCurCol()
        {
            //Int64 Toprowte;
            //Toprowte = 0;
            //while (ogrdMain.CellTop+ogrdMain.get_RowHeight(ogrdMain.Row)+ogrdMain.RowHeightMin>ogrdMain.Size.Height   &&  ogrdMain.TopRow!=Toprowte)
            //{
            //    Toprowte=ogrdMain.TopRow;
            //    ogrdMain.TopRow=ogrdMain.TopRow+1;
            //}
            //Toprowte = 0;
            //while (ogrdMain.CellTop < ogrdMain.FixedRows * ogrdMain.get_RowHeight(0) && ogrdMain.TopRow != Toprowte)
            //{
                
            //    Toprowte = ogrdMain.TopRow;
            //    if (ogrdMain.TopRow > 1)
            //    {
            //        ogrdMain.TopRow = ogrdMain.TopRow -1;
            //    }
            //}
        }
        public void CheckRowData()
        {
            int r;
            if (ogrdMain.Row >= ogrdMain.FixedRows)
            {
                if (ClsPub.isStrNull(ogrdMain.get_TextMatrix(ogrdMain.Row, 0).ToString()) != "*")
                {
                    for ( r = ogrdMain.FixedRows; r < ogrdMain.Rows; r++)
                    {
                        if (ClsPub.isStrNull(ogrdMain.get_TextMatrix(r, 0).ToString()) != "*")
                        {
                            if (NotAllowADDRow)
                            {
                                Changelock = true;
                                ogrdMain.Select(r - 1, ogrdMain.Col);
                                Changelock = false;
                                return;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    //
                    if (r <= ogrdMain.Rows - 1)
                    {
                        Changelock = true;
                        ogrdMain.Select(r , ogrdMain.Col);
                        Changelock = false;
                    }
                    else
                    {
                        Changelock = true;
                        ogrdMain.Select(ogrdMain.Rows - 1, ogrdMain.Col);
                        Changelock = false;
                    }
                }
                DisplayCurRow();
            }
        }
        //刷新行号
        public void RefreshNoCol()
        {
            int  i, m;
            //if (DisplayCurCol==false )
            //{
            //    return;
            //}
            i = 0;
            m = 0;
            for (i = ogrdMain.FixedRows; i < ogrdMain.Rows; i++)
            {
                m = m + 1;
                ogrdMain.set_TextMatrix(i, NoCol, m.ToString().Trim());
            }
            ogrdMain.set_ColAlignment(NoCol, VSFlex7.AlignmentSettings.flexAlignCenterCenter);
        }
        //
    }
}