OTSSourceGrid.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. using OTSIncAReportApp.OTSSampleReportInfo;
  2. using OTSIncAReportApp.SysMgrTools;
  3. using OTSIncAReportGB;
  4. using OTSIncAReportGrids;
  5. using SourceGrid;
  6. using System;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using System.Data;
  10. using System.Diagnostics;
  11. using System.Drawing;
  12. using System.Linq;
  13. using System.Windows.Forms;
  14. namespace OTSIncAReportApp.OTSRstMgrFunction
  15. {
  16. /// <summary>
  17. /// 属性Grid相关操作封装类
  18. /// </summary>
  19. public class OTSSourceGrid
  20. {
  21. #region 变量定义
  22. /// <summary>
  23. /// 主框架窗体
  24. /// </summary>
  25. public frmReportConditionChoose m_frmPropCondition = null;
  26. /// <summary>
  27. /// 当grid被click时,确定点击的行
  28. /// </summary>
  29. public int m_ClickRow = 0;
  30. /// <summary>
  31. /// 当grid被click时,确定点击的列
  32. /// </summary>
  33. public int m_ClickColumn = 0;
  34. /// <summary>
  35. /// 当改变ProperyWindow窗口大小时,窗口响应Resize(object sender, EventArgs e),返回改变后的尺寸,利用改变后的窗口尺寸重回Grid的行宽和列宽
  36. /// </summary>
  37. public int m_PropWindow_X = 0;
  38. /// <summary>
  39. /// 当改变ProperyWindow窗口大小时,窗口响应Resize(object sender, EventArgs e),返回改变后的尺寸,利用改变后的窗口尺寸重回Grid的行宽和列宽
  40. /// </summary>
  41. public int m_PropWindow_Y = 0;
  42. /// <summary>
  43. /// 临时用于计算用的grid行号 总行数
  44. /// </summary>
  45. public static int m_Const_Grid_Row = 42; //总行数
  46. /// <summary>
  47. /// 临时用于计算用的grid行号 总列数
  48. /// </summary>
  49. public static int m_Const_Grid_Column = 3; //总列数
  50. /// <summary>
  51. /// 当选择了Grid的某个row ,修改Row的值,引发的事件
  52. /// </summary>
  53. ChangeGridCellValEvent m_ChangeCellValEvent = null;
  54. /// <summary>
  55. /// 选择COMBOBOX值引发的事件
  56. /// </summary>
  57. ItemValueChange2 m_ValChangeEvent2 = null;
  58. /// <summary>
  59. /// 定义分栏表头样式
  60. /// </summary>
  61. public SourceGrid.Cells.Views.Cell m_Col_HeaderMode = null;
  62. /// <summary>
  63. /// 定义大表头grid表头样式
  64. /// </summary>
  65. SourceGrid.Cells.Views.Cell m_CellTitleModel = null;
  66. /// <summary>
  67. /// 定义分栏标题格样式
  68. /// </summary>
  69. SourceGrid.Cells.Views.Cell m_Col_NameMode = null;
  70. /// <summary>
  71. /// 定义分栏内容格样式
  72. /// </summary>
  73. SourceGrid.Cells.Views.Cell m_Col_ValMode = null;
  74. /// <summary>
  75. /// 只读样式cell设置
  76. /// </summary>
  77. SourceGrid.Cells.Views.Cell M_Col_readonly = null;
  78. /// <summary>
  79. /// 通用参数组的标题名
  80. /// </summary>
  81. public String m_Display_Mode_Name = "parameter";
  82. /// <summary>
  83. /// 通用参数组的GRID行数
  84. /// </summary>
  85. public int m_Display_Mode_Row = 0;
  86. Language lan = new Language();
  87. Hashtable table;
  88. ResultDataMgr m_DataMgr;
  89. #endregion
  90. #region 构造函数及初始化函数
  91. public OTSSourceGrid(frmReportConditionChoose Propwindow)
  92. {
  93. m_DataMgr = Propwindow.m_ReportApp.m_rstDataMgr;
  94. m_frmPropCondition = Propwindow;
  95. m_frmPropCondition.PropGrid.Rows.Clear();
  96. m_frmPropCondition.PropGrid.Redim(m_Const_Grid_Row, m_Const_Grid_Column);
  97. table = lan.GetNameTable("SampleGrid");
  98. string str = table["str1"].ToString();
  99. m_Display_Mode_Name = str;
  100. }
  101. /// <summary>
  102. /// 初始化Grid修改值事件
  103. /// </summary>
  104. void InitChangeValEvent()
  105. {
  106. m_ChangeCellValEvent = new ChangeGridCellValEvent(this);
  107. m_ValChangeEvent2 = new ItemValueChange2(this);
  108. }
  109. #endregion
  110. #region 初始化属性Grid相关方法
  111. /// <summary>
  112. /// 初始化属性Grid相关样式
  113. /// </summary>
  114. public void InitGrid()
  115. {
  116. //初始化Grid修改值事件
  117. InitChangeValEvent();
  118. //定义大表头grid表头样式
  119. {
  120. m_CellTitleModel = new SourceGrid.Cells.Views.Cell();
  121. m_CellTitleModel.BackColor = Color.LightGray;
  122. m_CellTitleModel.ForeColor = Color.Black;
  123. m_CellTitleModel.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleLeft;
  124. }
  125. //定义分栏表头样式
  126. {
  127. m_Col_HeaderMode = new SourceGrid.Cells.Views.Cell();
  128. m_Col_HeaderMode.BackColor = Color.LightGray; //背景色
  129. m_Col_HeaderMode.ForeColor = Color.Black; //字体颜色
  130. m_Col_HeaderMode.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
  131. }
  132. //定义分栏标题格样式
  133. {
  134. m_Col_NameMode = new SourceGrid.Cells.Views.Cell();
  135. m_Col_NameMode.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleLeft;
  136. }
  137. //定义分栏内容格样式
  138. {
  139. m_Col_ValMode = new SourceGrid.Cells.Views.Cell();
  140. m_Col_ValMode.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleLeft;
  141. }
  142. //只读样式cell设置
  143. {
  144. M_Col_readonly = new SourceGrid.Cells.Views.Cell();
  145. M_Col_readonly.ForeColor = Color.Gray;
  146. }
  147. }
  148. /// <summary>
  149. /// 初始化属性Grid相关表头
  150. /// </summary>
  151. public void InitGridTitlet()
  152. {
  153. int firstColumnWidth = 15; //第一列的宽度
  154. int SecondColumnWidth = 150;
  155. //设备各单元格宽度---------------------------------------------
  156. m_frmPropCondition.PropGrid.Columns.SetWidth(0, firstColumnWidth); //设置第一列宽度
  157. m_frmPropCondition.PropGrid.Columns.AutoSizeColumn(2); //固定进度条
  158. //ProperyWindows的窗口宽度包括是第二列和第三列的长度总和
  159. m_frmPropCondition.PropGrid.Columns.SetWidth(1, 150); //第二列宽度
  160. m_frmPropCondition.PropGrid.Columns.SetWidth(2, (m_PropWindow_X - firstColumnWidth - SecondColumnWidth - 18)); //第三列宽度
  161. }
  162. /// <summary>
  163. /// 初始化组的标题栏 iRow:GroupTitle的行号, sGroupName: GroupTitle的名字
  164. /// </summary>
  165. /// <param name="iRow"></param>
  166. /// <param name="sGroupName"></param>
  167. public void InitGroupTitle(int iRow, String sGroupName)
  168. {
  169. if (null == m_frmPropCondition.PropGrid[iRow, 0])
  170. {
  171. m_frmPropCondition.PropGrid[iRow, 0] = new SourceGrid.Cells.Link("-");//第一行,上面用来折叠的"-",一会点击后变成"+"
  172. m_frmPropCondition.PropGrid[iRow, 0].View = m_CellTitleModel; //设置表头的样式
  173. //设置表头"-"按钮,点击后的事件
  174. }
  175. if (null == m_frmPropCondition.PropGrid[iRow, 1])
  176. {
  177. m_frmPropCondition.PropGrid[iRow, 1] = new SourceGrid.Cells.Cell(sGroupName); // 设置GroupTitle的名字
  178. m_frmPropCondition.PropGrid[iRow, 1].View = m_CellTitleModel;
  179. m_frmPropCondition.PropGrid[iRow, 1].ColumnSpan = 2; //设置第二列与第三列合并,表头效果完成。 2:从当前列开始合并2列
  180. }
  181. }
  182. #endregion
  183. #region 属性Grid显示相关方法
  184. public void ShowGeneralGrid(ReportCondition conditionInfo)
  185. {
  186. if (conditionInfo.ConditionItemList.Count() == 0)
  187. return;
  188. int nGridRow = 0;
  189. string str = table["str2"].ToString();
  190. this.InitGroupTitle(nGridRow, str);
  191. nGridRow++;
  192. int Display_Mode_Row = 1;//确定跨行样式的跨行数变量
  193. // 设置样品Grid数据
  194. for (int i = 0; i < conditionInfo.ConditionItemList.Count; i++)
  195. {
  196. Display_Mode_Row++;
  197. //显示样品的属性值
  198. ConditionItem SData = conditionInfo.ConditionItemList[i];
  199. this.SetGridCellVal(nGridRow, SData);
  200. nGridRow++;
  201. }
  202. //控制左边的竖形条框栏的显示
  203. //第二行,第一列,为了效果美化,向下跨行,共跨m_Grid_TotleRow - 1行
  204. if (Display_Mode_Row > 1) //有通用参数组的Grid值显示
  205. {
  206. //获取Grid组Title所在的行号
  207. int iCurRow = Display_Mode_Row;
  208. //第二行的时候,需要定义左边的条框栏
  209. if (m_frmPropCondition.tabIndex == DisplayPicutureType.AnalyzeImg)
  210. {
  211. if (null == m_frmPropCondition.PropGrid[1 + 1, 0])
  212. {
  213. m_frmPropCondition.PropGrid[1, 0] = new SourceGrid.Cells.Cell("");
  214. m_frmPropCondition.PropGrid[1, 0].View = m_Col_HeaderMode;
  215. }
  216. else
  217. {
  218. m_frmPropCondition.PropGrid[iCurRow + 1, 0].Value = "";
  219. }
  220. if (iCurRow == 0)
  221. {
  222. m_frmPropCondition.PropGrid[iCurRow + 1, 0].RowSpan = iCurRow + Display_Mode_Row - 1; //iCurRow + General_Totle_Row-1 : 去掉标题栏计数
  223. }
  224. else
  225. {
  226. m_frmPropCondition.PropGrid[1, 0].RowSpan = Display_Mode_Row - 1; //iCurRow + General_Totle_Row-1 : 去掉标题栏计数
  227. }
  228. }
  229. if (m_frmPropCondition.tabIndex == DisplayPicutureType.AnalyzeDataTable)
  230. {
  231. //第二行的时候,需要定义左边的条框栏
  232. if (null == m_frmPropCondition.PropGrid[1 + 1, 0])
  233. {
  234. m_frmPropCondition.PropGrid[1, 0] = new SourceGrid.Cells.Cell("");
  235. m_frmPropCondition.PropGrid[1, 0].View = m_Col_HeaderMode;
  236. }
  237. else
  238. {
  239. m_frmPropCondition.PropGrid[iCurRow + 1, 0].Value = "";
  240. }
  241. if (iCurRow == 0)
  242. {
  243. m_frmPropCondition.PropGrid[iCurRow + 1, 0].RowSpan = iCurRow + Display_Mode_Row - 1; //iCurRow + General_Totle_Row-1 : 去掉标题栏计数
  244. }
  245. else
  246. {
  247. m_frmPropCondition.PropGrid[1, 0].RowSpan = Display_Mode_Row - 1; //iCurRow + General_Totle_Row-1 : 去掉标题栏计数
  248. }
  249. }
  250. if (m_frmPropCondition.tabIndex == DisplayPicutureType.AnalyzeDataChart)
  251. {
  252. //第二行的时候,需要定义左边的条框栏
  253. if (null == m_frmPropCondition.PropGrid[1, 0])
  254. {
  255. m_frmPropCondition.PropGrid[1, 0] = new SourceGrid.Cells.Cell("");
  256. m_frmPropCondition.PropGrid[1, 0].View = m_Col_HeaderMode;
  257. }
  258. else
  259. {
  260. m_frmPropCondition.PropGrid[iCurRow + 1, 0].Value = "";
  261. }
  262. if (iCurRow == 0)
  263. {
  264. m_frmPropCondition.PropGrid[iCurRow + 1, 0].RowSpan = iCurRow + Display_Mode_Row - 1; //iCurRow + General_Totle_Row-1 : 去掉标题栏计数
  265. }
  266. else
  267. {
  268. m_frmPropCondition.PropGrid[1, 0].RowSpan = Display_Mode_Row - 1; //iCurRow + General_Totle_Row-1 : 去掉标题栏计数
  269. }
  270. }
  271. }
  272. }
  273. /// <summary>
  274. /// 显示Chart图表相关属性Grid
  275. /// </summary>
  276. /// <param name="note"></param>
  277. public void SetPictureType(DisplayPicutureType note)
  278. {
  279. m_frmPropCondition.tabIndex = note;
  280. }
  281. public void SetGridCellVal(int Row, ConditionItem SData)
  282. {
  283. OTS_REPORT_PROP_GRID_ITEMS SampleID = SData.iItemId;
  284. String sCaptionName = SData.sSCaptionName;
  285. object SampleVal = SData.itemDisplayVal;
  286. List<String> comboDownList = SData.comboDownList;
  287. OTS_ITEM_TYPES SampleValType = SData.iItemValType;
  288. bool bReadOnly = SData.bReadOnly;
  289. //每行的第一列显示属性名称
  290. if (null == m_frmPropCondition.PropGrid[Row, 1])
  291. {
  292. m_frmPropCondition.PropGrid[Row, 1] = new SourceGrid.Cells.Cell(sCaptionName);
  293. }
  294. else
  295. {
  296. m_frmPropCondition.PropGrid[Row, 1].Value = sCaptionName;
  297. }
  298. m_frmPropCondition.PropGrid[Row, 1].View = m_Col_NameMode;
  299. //每行的第二列显示属性值
  300. if (null == m_frmPropCondition.PropGrid[Row, 2])
  301. {
  302. switch (SData.iItemValType)
  303. {
  304. case OTS_ITEM_TYPES.COMBO:
  305. try
  306. {
  307. SourceGrid.Cells.Editors.ComboBox m_ComboboxText = null;
  308. List<string> ValList = new List<string>();
  309. string[] arraySample;
  310. if (null == comboDownList)
  311. {
  312. List<string> sSampleVal = new List<string>();
  313. ValList = sSampleVal;
  314. }
  315. else
  316. {
  317. ValList = (List<string>)comboDownList;
  318. }
  319. int iValCount = ValList.Count();
  320. if (iValCount > 0)
  321. {
  322. arraySample = new string[iValCount];
  323. for (int i = 0; i < iValCount; i++)
  324. {
  325. arraySample[i] = ValList[i];
  326. }
  327. }
  328. else
  329. {
  330. arraySample = new string[3] { "", "", "" };
  331. }
  332. m_frmPropCondition.PropGrid[Row, 2] = new SourceGrid.Cells.Cell(SampleVal);
  333. m_ComboboxText = new SourceGrid.Cells.Editors.ComboBox(typeof(string), arraySample, true);
  334. m_frmPropCondition.PropGrid[Row, 2].Editor = m_ComboboxText;
  335. m_ComboboxText.Control.DropDownStyle = ComboBoxStyle.DropDownList; //设置下拉框为不可以编辑的状态
  336. m_frmPropCondition.PropGrid[Row, 2].Value = SampleVal;
  337. m_frmPropCondition.PropGrid[Row, 2].AddController(m_ChangeCellValEvent);
  338. m_frmPropCondition.PropGrid[Row, 2].AddController(m_ValChangeEvent2);
  339. m_ComboboxText.EditableMode = EditableMode.SingleClick;
  340. }
  341. catch (Exception)
  342. {
  343. }
  344. break;
  345. case OTS_ITEM_TYPES.DOUBLE:
  346. var txtbox = new SourceGrid.Cells.Editors.TextBoxNumeric(typeof(double));
  347. m_frmPropCondition.PropGrid[Row, 2] = new SourceGrid.Cells.Cell(SampleVal);
  348. txtbox.EditableMode = EditableMode.SingleClick;
  349. m_frmPropCondition.PropGrid[Row, 2].Editor = txtbox;
  350. m_frmPropCondition.PropGrid[Row, 2].AddController(m_ChangeCellValEvent);
  351. m_frmPropCondition.PropGrid[Row, 2].AddController(m_ValChangeEvent2);
  352. break;
  353. default:
  354. break;
  355. }
  356. if (bReadOnly) //只读模式
  357. {
  358. m_frmPropCondition.PropGrid[Row, 2].Editor = null;
  359. m_frmPropCondition.PropGrid[Row, 2].View = M_Col_readonly;// 设置只读
  360. }
  361. else
  362. {
  363. m_frmPropCondition.PropGrid[Row, 2].View = m_Col_ValMode;
  364. }
  365. //行绑定ID值
  366. m_frmPropCondition.PropGrid.Rows[Row].Tag = SampleID;
  367. //数据位置绑定数据类型
  368. m_frmPropCondition.PropGrid[Row, 2].Tag = SampleValType;
  369. }
  370. else
  371. {
  372. m_frmPropCondition.PropGrid[Row, 2].Value = SampleVal;
  373. }
  374. }
  375. #endregion
  376. }
  377. }