| using System; | 
| using System.Collections.Generic; | 
| using System.Text; | 
| using System.Windows.Forms; | 
| using System.Drawing; | 
|   | 
| namespace Pub_Class | 
| { | 
|     /// <summary> | 
|     /// 单据列表 合计网格 | 
|     /// </summary> | 
|     public class ClsGridListSum | 
|     { | 
|         public DataGridView ogrdMain = new DataGridView(); | 
|         public DataGridView oGridsum = new DataGridView(); | 
|         private string sTotalCols;   | 
|         public bool Changelock;   | 
|         public bool DisplayNoCol;    | 
|         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 SetGridMain(string Name) | 
|         { | 
|             ogrdMain.RowTemplate.Height = 18; | 
|             ogrdMain.RowTemplate.MinimumHeight = 18; | 
|             ogrdMain.ColumnHeadersHeight = 40; | 
|             ogrdMain.RowHeadersVisible = false; | 
|             ogrdMain.ColumnHeadersVisible = true; | 
|             //格式化 | 
|             //表格设置 | 
|             ogrdMain.RowsDefaultCellStyle.SelectionForeColor = Color.White; | 
|             ogrdMain.RowsDefaultCellStyle.SelectionBackColor = Color.DarkCyan; | 
|             ogrdMain.DefaultCellStyle.SelectionBackColor = Color.DarkCyan; | 
|             ogrdMain.DefaultCellStyle.SelectionForeColor = Color.White; | 
|             ogrdMain.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; | 
|             ogrdMain.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; | 
|             ogrdMain.SelectionMode = DataGridViewSelectionMode.FullRowSelect; | 
|             ogrdMain.ReadOnly = true; | 
|             ogrdMain.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing; //允许用户调整列宽 | 
|             ogrdMain.EnableHeadersVisualStyles = false;     //网格标题 样式 | 
|             ogrdMain.AllowUserToAddRows = false;             //是否允许自增--否 | 
|             ogrdMain.AllowUserToDeleteRows = false;          //是否允许删除--否  | 
|             ogrdMain.AllowUserToResizeColumns = true;         //允许调整列宽--是 | 
|             ogrdMain.AllowUserToResizeRows = false;           //允许调整行高--否 | 
|             ogrdMain.AllowUserToOrderColumns = true;         //允许 拖拽列 | 
|             ogrdMain.BackgroundColor = Color.White; | 
|             ogrdMain.GridColor = Color.LightGray;             //网格线颜色 | 
|             ogrdMain.ShowCellToolTips = true; | 
|             ogrdMain.CellBorderStyle = DataGridViewCellBorderStyle.RaisedVertical; | 
|             ogrdMain.ColumnHeadersDefaultCellStyle.BackColor = Color.LightGray; | 
|             // | 
|             ClsPub.GetGridView(ogrdMain, Name, ClsPub.AppPath);//设置列宽 | 
|         } | 
|   | 
|           | 
|         //设置合计网格属性    | 
|         public void SetGridsum( ) | 
|         { | 
|              | 
|             Int32 i; | 
|             oGridsum.Enabled = false; | 
|             oGridsum.Width  = ogrdMain.Width; | 
|             oGridsum.RowHeadersVisible = false; | 
|             oGridsum.ColumnHeadersVisible = false; | 
|             oGridsum.RowCount = 1; | 
|             oGridsum.ColumnCount = ogrdMain.ColumnCount; | 
|             oGridsum.HorizontalScrollingOffset = ogrdMain.HorizontalScrollingOffset;  | 
|   | 
|             oGridsum.Rows[0].Height = 20; | 
|   | 
|             oGridsum.Height = 20; | 
|             //for (i = 1; i < oGridsum.ColumnCount; i++) | 
|             //{ | 
|             //    oGridsum.Rows[0].Cells[i].Value = ""; | 
|             //} | 
|              | 
|             oGridsum.Rows[0].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; | 
|             oGridsum.Rows[0].DefaultCellStyle.BackColor = Color.Khaki; | 
|             for (i = 0; i < ogrdMain.ColumnCount; i++) | 
|             { | 
|   | 
|                 oGridsum.Columns[i].Visible = ogrdMain.Columns[i].Visible; | 
|                 oGridsum.Columns[i].Width = ogrdMain.Columns[i].Width; | 
|                 oGridsum.Rows[0].Cells[i].Value = ""; | 
|             } | 
|             oGridsum.Rows[0].Cells[0].Value = "合计"; | 
|             oGridsum.Width = ogrdMain.Width ; | 
|             RefreshNoCol(); | 
|         } | 
|   | 
|   | 
|         //   | 
|         /// <summary> | 
|         /// 设置合计网格属性(只调列宽不调数据)  | 
|         /// </summary> | 
|         public void SetGridsum_NoData() | 
|         { | 
|   | 
|             Int32 i; | 
|             oGridsum.Enabled = false; | 
|             oGridsum.Width = ogrdMain.Width; | 
|             oGridsum.RowHeadersVisible = false; | 
|             oGridsum.ColumnHeadersVisible = false; | 
|             oGridsum.HorizontalScrollingOffset = ogrdMain.HorizontalScrollingOffset; | 
|   | 
|             oGridsum.Rows[0].Height = 20; | 
|   | 
|             oGridsum.Height = 20; | 
|             oGridsum.Rows[0].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; | 
|             oGridsum.Rows[0].DefaultCellStyle.BackColor = Color.Khaki; | 
|             for (i = 0; i < ogrdMain.ColumnCount; i++) | 
|             { | 
|                 oGridsum.Columns[i].Visible = ogrdMain.Columns[i].Visible; | 
|                 oGridsum.Columns[i].Width = ogrdMain.Columns[i].Width; | 
|             } | 
|             oGridsum.Rows[0].Cells[0].Value = "合计"; | 
|             oGridsum.Width = ogrdMain.Width; | 
|             RefreshNoCol(); | 
|         } | 
|   | 
|   | 
|         //合计函数 | 
|         public void Total() | 
|         { | 
|             string[] Cols; | 
|             Int32 i, j, ColsTotal; | 
|             if(ClsPub.isStrNull(sTotalCols).ToString().Trim()==""  ) | 
|                 return; | 
|             if (ogrdMain.SelectedRows == null) | 
|                 return; | 
|             Cols = sTotalCols.Split(chr); | 
|             ColsTotal = Cols.Length; | 
|             for (j = 0; j < ColsTotal; j++)   //清空 | 
|             { | 
|                 oGridsum.Rows[0].Cells[j].Value = ""; | 
|             } | 
|             try | 
|             { | 
|                 double d = 0; | 
|                 for (j = 0; j < ColsTotal; j++) | 
|                 { | 
|                     d = 0; | 
|                     for (i = 0; i < ogrdMain.SelectedRows.Count; i++) | 
|                     {  | 
|                         //d = d + ClsPub.isDoule(ogrdMain.Rows[i].Cells[ClsPub.isInt(Cols[j])].Value); | 
|                         d = d + ClsPub.isDoule(ogrdMain.SelectedRows[i].Cells[ClsPub.isInt(Cols[j])].Value); | 
|                     } | 
|                     oGridsum.Rows[0].Cells[ClsPub.isInt(Cols[j])].Value=d.ToString(); | 
|                 } | 
|             } | 
|             catch (Exception  e) | 
|             { | 
|                 string s = ""; | 
|                 s= e.Message; | 
|             } | 
|         } | 
|   | 
|         //合计函数 合计全部 | 
|         public void TotalAll() | 
|         { | 
|             string[] Cols; | 
|             Int32 i, j, ColsTotal; | 
|             if (ClsPub.isStrNull(sTotalCols).ToString().Trim() == "") | 
|                 return; | 
|             //if (ogrdMain == null) | 
|             //    return; | 
|             Cols = sTotalCols.Split(chr); | 
|             ColsTotal = Cols.Length; | 
|             for (j = 0; j < ColsTotal; j++)   //清空 | 
|             { | 
|                 oGridsum.Rows[0].Cells[j].Value = ""; | 
|             } | 
|             try | 
|             { | 
|                 double d = 0; | 
|                 for (j = 0; j < ColsTotal; j++) | 
|                 { | 
|                     d = 0; | 
|                     for (i = 0; i < ogrdMain.Rows.Count; i++) | 
|                     { | 
|                         d = d + ClsPub.isDoule(ogrdMain.Rows[i].Cells[ClsPub.isInt(Cols[j])].Value); | 
|                     } | 
|                     oGridsum.Rows[0].Cells[ClsPub.isInt(Cols[j])].Value = d.ToString(); | 
|                 } | 
|             } | 
|             catch (Exception e) | 
|             { | 
|                 string s = ""; | 
|                 s = e.Message; | 
|             } | 
|         } | 
|         // | 
|         //刷新行号 | 
|         public void RefreshNoCol() | 
|         { | 
|             //int  i, m;  | 
|             //i = 0; | 
|             //m = 0; | 
|             //for (i = 0; i < ogrdMain.RowCount; i++) | 
|             //{ | 
|             //    m = m + 1; | 
|             //    ogrdMain.Rows[i].Cells[NoCol].Value = m.ToString().Trim(); | 
|             //} | 
|             //ogrdMain.Columns[NoCol].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; | 
|         } | 
|         // | 
|     } | 
| } |