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); 
 | 
        } 
 | 
        // 
 | 
    } 
 | 
} 
 |