OTSSourceGrid.cs 17 KB

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