using OTSIncAReportApp.DataOperation.Model;
using OTSIncAReportApp.OTSSampleReportInfo;
using OTSIncAReportApp.SysMgrTools;
using OTSIncAReportGB;
using OTSIncAReportGrids;
using SourceGrid;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
namespace OTSIncAReportApp.OTSDataMgrFunction
{
///
/// 属性Grid相关操作封装类
///
public class OTSSourceGrid
{
#region 变量定义
///
/// 主框架窗体
///
public frmReportConditionChoose m_frmPropCondition = null;
///
/// 当grid被click时,确定点击的行
///
public int m_ClickRow = 0;
///
/// 当grid被click时,确定点击的列
///
public int m_ClickColumn = 0;
///
/// 当改变ProperyWindow窗口大小时,窗口响应Resize(object sender, EventArgs e),返回改变后的尺寸,利用改变后的窗口尺寸重回Grid的行宽和列宽
///
public int m_PropWindow_X = 0;
///
/// 当改变ProperyWindow窗口大小时,窗口响应Resize(object sender, EventArgs e),返回改变后的尺寸,利用改变后的窗口尺寸重回Grid的行宽和列宽
///
public int m_PropWindow_Y = 0;
///
/// 临时用于计算用的grid行号 总行数
///
public static int m_Const_Grid_Row = 42; //总行数
///
/// 临时用于计算用的grid行号 总列数
///
public static int m_Const_Grid_Column = 3; //总列数
///
/// 当选择了Grid的某个row ,修改Row的值,引发的事件
///
ChangeGridCellValEvent m_ChangeCellValEvent = null;
///
/// 选择COMBOBOX值引发的事件
///
ItemValueChange2 m_ValChangeEvent2 = null;
///
/// 定义分栏表头样式
///
public SourceGrid.Cells.Views.Cell m_Col_HeaderMode = null;
///
/// 定义大表头grid表头样式
///
SourceGrid.Cells.Views.Cell m_CellTitleModel = null;
///
/// 定义分栏标题格样式
///
SourceGrid.Cells.Views.Cell m_Col_NameMode = null;
///
/// 定义分栏内容格样式
///
SourceGrid.Cells.Views.Cell m_Col_ValMode = null;
///
/// 只读样式cell设置
///
SourceGrid.Cells.Views.Cell M_Col_readonly = null;
///
/// 通用参数组的标题名
///
public String m_Display_Mode_Name = "parameter";
///
/// 通用参数组的GRID行数
///
public int m_Display_Mode_Row = 0;
Language lan = new Language();
Hashtable table;
ResultDataMgr m_DataMgr;
#endregion
#region 构造函数及初始化函数
public OTSSourceGrid(frmReportConditionChoose Propwindow)
{
m_DataMgr = Propwindow.m_ReportApp.m_rstDataMgr;
m_frmPropCondition = Propwindow;
m_frmPropCondition.PropGrid.Rows.Clear();
m_frmPropCondition.PropGrid.Redim(m_Const_Grid_Row, m_Const_Grid_Column);
table = lan.GetNameTable("SampleGrid");
string str = table["str1"].ToString();
m_Display_Mode_Name = str;
}
///
/// 初始化Grid修改值事件
///
void InitChangeValEvent()
{
m_ChangeCellValEvent = new ChangeGridCellValEvent(this);
m_ValChangeEvent2 = new ItemValueChange2(this);
}
#endregion
#region 初始化属性Grid相关方法
///
/// 初始化属性Grid相关样式
///
public void InitGrid()
{
//初始化Grid修改值事件
InitChangeValEvent();
//定义大表头grid表头样式
{
m_CellTitleModel = new SourceGrid.Cells.Views.Cell();
m_CellTitleModel.BackColor = Color.LightGray;
m_CellTitleModel.ForeColor = Color.Black;
m_CellTitleModel.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleLeft;
}
//定义分栏表头样式
{
m_Col_HeaderMode = new SourceGrid.Cells.Views.Cell();
m_Col_HeaderMode.BackColor = Color.LightGray; //背景色
m_Col_HeaderMode.ForeColor = Color.Black; //字体颜色
m_Col_HeaderMode.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
}
//定义分栏标题格样式
{
m_Col_NameMode = new SourceGrid.Cells.Views.Cell();
m_Col_NameMode.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleLeft;
}
//定义分栏内容格样式
{
m_Col_ValMode = new SourceGrid.Cells.Views.Cell();
m_Col_ValMode.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleLeft;
}
//只读样式cell设置
{
M_Col_readonly = new SourceGrid.Cells.Views.Cell();
M_Col_readonly.ForeColor = Color.Gray;
}
}
///
/// 初始化属性Grid相关表头
///
public void InitGridTitlet()
{
int firstColumnWidth = 15; //第一列的宽度
int SecondColumnWidth = 150;
//设备各单元格宽度---------------------------------------------
m_frmPropCondition.PropGrid.Columns.SetWidth(0, firstColumnWidth); //设置第一列宽度
m_frmPropCondition.PropGrid.Columns.AutoSizeColumn(2); //固定进度条
//ProperyWindows的窗口宽度包括是第二列和第三列的长度总和
m_frmPropCondition.PropGrid.Columns.SetWidth(1, 150); //第二列宽度
m_frmPropCondition.PropGrid.Columns.SetWidth(2, (m_PropWindow_X - firstColumnWidth - SecondColumnWidth - 18)); //第三列宽度
}
///
/// 初始化组的标题栏 iRow:GroupTitle的行号, sGroupName: GroupTitle的名字
///
///
///
public void InitGroupTitle(int iRow, String sGroupName)
{
if (null == m_frmPropCondition.PropGrid[iRow, 0])
{
m_frmPropCondition.PropGrid[iRow, 0] = new SourceGrid.Cells.Link("-");//第一行,上面用来折叠的"-",一会点击后变成"+"
m_frmPropCondition.PropGrid[iRow, 0].View = m_CellTitleModel; //设置表头的样式
//设置表头"-"按钮,点击后的事件
}
if (null == m_frmPropCondition.PropGrid[iRow, 1])
{
m_frmPropCondition.PropGrid[iRow, 1] = new SourceGrid.Cells.Cell(sGroupName); // 设置GroupTitle的名字
m_frmPropCondition.PropGrid[iRow, 1].View = m_CellTitleModel;
m_frmPropCondition.PropGrid[iRow, 1].ColumnSpan = 2; //设置第二列与第三列合并,表头效果完成。 2:从当前列开始合并2列
}
}
#endregion
#region 属性Grid显示相关方法
public void ShowGeneralGrid(ReportCondition conditionInfo)
{
if (conditionInfo.ConditionItemList.Count() == 0)
return;
int nGridRow = 0;
string str = table["str2"].ToString();
this.InitGroupTitle(nGridRow, str);
nGridRow++;
int Display_Mode_Row = 1;//确定跨行样式的跨行数变量
// 设置样品Grid数据
for (int i = 0; i < conditionInfo.ConditionItemList.Count; i++)
{
Display_Mode_Row++;
//显示样品的属性值
ConditionItem SData = conditionInfo.ConditionItemList[i];
this.SetGridCellVal(nGridRow, SData);
nGridRow++;
}
//控制左边的竖形条框栏的显示
//第二行,第一列,为了效果美化,向下跨行,共跨m_Grid_TotleRow - 1行
if (Display_Mode_Row > 1) //有通用参数组的Grid值显示
{
//获取Grid组Title所在的行号
int iCurRow = Display_Mode_Row;
//第二行的时候,需要定义左边的条框栏
if (m_frmPropCondition.tabIndex == DisplayPicutureType.AnalyzeImg)
{
if (null == m_frmPropCondition.PropGrid[1 + 1, 0])
{
m_frmPropCondition.PropGrid[1, 0] = new SourceGrid.Cells.Cell("");
m_frmPropCondition.PropGrid[1, 0].View = m_Col_HeaderMode;
}
else
{
m_frmPropCondition.PropGrid[iCurRow + 1, 0].Value = "";
}
if (iCurRow == 0)
{
m_frmPropCondition.PropGrid[iCurRow + 1, 0].RowSpan = iCurRow + Display_Mode_Row - 1; //iCurRow + General_Totle_Row-1 : 去掉标题栏计数
}
else
{
m_frmPropCondition.PropGrid[1, 0].RowSpan = Display_Mode_Row - 1; //iCurRow + General_Totle_Row-1 : 去掉标题栏计数
}
}
if (m_frmPropCondition.tabIndex == DisplayPicutureType.AnalyzeDataTable)
{
//第二行的时候,需要定义左边的条框栏
if (null == m_frmPropCondition.PropGrid[1 + 1, 0])
{
m_frmPropCondition.PropGrid[1, 0] = new SourceGrid.Cells.Cell("");
m_frmPropCondition.PropGrid[1, 0].View = m_Col_HeaderMode;
}
else
{
m_frmPropCondition.PropGrid[iCurRow + 1, 0].Value = "";
}
if (iCurRow == 0)
{
m_frmPropCondition.PropGrid[iCurRow + 1, 0].RowSpan = iCurRow + Display_Mode_Row - 1; //iCurRow + General_Totle_Row-1 : 去掉标题栏计数
}
else
{
m_frmPropCondition.PropGrid[1, 0].RowSpan = Display_Mode_Row - 1; //iCurRow + General_Totle_Row-1 : 去掉标题栏计数
}
}
if (m_frmPropCondition.tabIndex == DisplayPicutureType.AnalyzeDataChart)
{
//第二行的时候,需要定义左边的条框栏
if (null == m_frmPropCondition.PropGrid[1, 0])
{
m_frmPropCondition.PropGrid[1, 0] = new SourceGrid.Cells.Cell("");
m_frmPropCondition.PropGrid[1, 0].View = m_Col_HeaderMode;
}
else
{
m_frmPropCondition.PropGrid[iCurRow + 1, 0].Value = "";
}
if (iCurRow == 0)
{
m_frmPropCondition.PropGrid[iCurRow + 1, 0].RowSpan = iCurRow + Display_Mode_Row - 1; //iCurRow + General_Totle_Row-1 : 去掉标题栏计数
}
else
{
m_frmPropCondition.PropGrid[1, 0].RowSpan = Display_Mode_Row - 1; //iCurRow + General_Totle_Row-1 : 去掉标题栏计数
}
}
}
}
///
/// 显示Chart图表相关属性Grid
///
///
public void SetPictureType(DisplayPicutureType note)
{
m_frmPropCondition.tabIndex = note;
}
public void SetGridCellVal(int Row, ConditionItem SData)
{
OTS_REPORT_PROP_GRID_ITEMS SampleID = SData.iItemId;
String sCaptionName = SData.sSCaptionName;
object SampleVal = SData.itemDisplayVal;
List comboDownList = SData.comboDownList;
OTS_ITEM_TYPES SampleValType = SData.iItemValType;
bool bReadOnly = SData.bReadOnly;
//每行的第一列显示属性名称
if (null == m_frmPropCondition.PropGrid[Row, 1])
{
m_frmPropCondition.PropGrid[Row, 1] = new SourceGrid.Cells.Cell(sCaptionName);
}
else
{
m_frmPropCondition.PropGrid[Row, 1].Value = sCaptionName;
}
m_frmPropCondition.PropGrid[Row, 1].View = m_Col_NameMode;
//每行的第二列显示属性值
if (null == m_frmPropCondition.PropGrid[Row, 2])
{
switch (SData.iItemValType)
{
case OTS_ITEM_TYPES.COMBO:
try
{
SourceGrid.Cells.Editors.ComboBox m_ComboboxText = null;
List ValList = new List();
string[] arraySample;
if (null == comboDownList)
{
List sSampleVal = new List();
ValList = sSampleVal;
}
else
{
ValList = (List)comboDownList;
}
int iValCount = ValList.Count();
if (iValCount > 0)
{
arraySample = new string[iValCount];
for (int i = 0; i < iValCount; i++)
{
arraySample[i] = ValList[i];
}
}
else
{
arraySample = new string[3] { "", "", "" };
}
m_frmPropCondition.PropGrid[Row, 2] = new SourceGrid.Cells.Cell(SampleVal);
m_ComboboxText = new SourceGrid.Cells.Editors.ComboBox(typeof(string), arraySample, true);
m_frmPropCondition.PropGrid[Row, 2].Editor = m_ComboboxText;
m_ComboboxText.Control.DropDownStyle = ComboBoxStyle.DropDownList; //设置下拉框为不可以编辑的状态
m_frmPropCondition.PropGrid[Row, 2].Value = SampleVal;
m_frmPropCondition.PropGrid[Row, 2].AddController(m_ChangeCellValEvent);
m_frmPropCondition.PropGrid[Row, 2].AddController(m_ValChangeEvent2);
m_ComboboxText.EditableMode = EditableMode.SingleClick;
}
catch (Exception)
{
}
break;
case OTS_ITEM_TYPES.DOUBLE:
var txtbox = new SourceGrid.Cells.Editors.TextBoxNumeric(typeof(double));
m_frmPropCondition.PropGrid[Row, 2] = new SourceGrid.Cells.Cell(SampleVal);
txtbox.EditableMode = EditableMode.SingleClick;
m_frmPropCondition.PropGrid[Row, 2].Editor = txtbox;
m_frmPropCondition.PropGrid[Row, 2].AddController(m_ChangeCellValEvent);
m_frmPropCondition.PropGrid[Row, 2].AddController(m_ValChangeEvent2);
break;
default:
break;
}
if (bReadOnly) //只读模式
{
m_frmPropCondition.PropGrid[Row, 2].Editor = null;
m_frmPropCondition.PropGrid[Row, 2].View = M_Col_readonly;// 设置只读
}
else
{
m_frmPropCondition.PropGrid[Row, 2].View = m_Col_ValMode;
}
//行绑定ID值
m_frmPropCondition.PropGrid.Rows[Row].Tag = SampleID;
//数据位置绑定数据类型
m_frmPropCondition.PropGrid[Row, 2].Tag = SampleValType;
}
else
{
m_frmPropCondition.PropGrid[Row, 2].Value = SampleVal;
}
}
#endregion
}
}