CraftOrdFdWicCtrl.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Windows.Forms;
  6. using CoreFS.CA06;
  7. using Core.Mes.Client.Comm.Tool;
  8. using Infragistics.Win.UltraWinEditors;
  9. using Core.StlMes.Client.Qcm;
  10. using Core.Mes.Client.Comm.Server;
  11. using Infragistics.Win.UltraWinGrid;
  12. using CoreFS.SA06;
  13. using Core.Mes.Client.Comm.Control;
  14. using Core.Mes.Client.Comm.Format;
  15. using System.Reflection;
  16. namespace Core.StlMes.Client.SaleOrder.Control
  17. {
  18. public partial class CraftOrdFdWicCtrl : UserControl
  19. {
  20. private OpeBase _ob;
  21. UltraComboEditor Wics = new UltraComboEditor();
  22. private string ordLnPk = "";
  23. private string designKey = "";
  24. public CraftOrdFdWicCtrl(System.Windows.Forms.Control container, string ordLnPk, string designKey, OpeBase ob)
  25. {
  26. InitializeComponent();
  27. _ob = ob;
  28. this.ordLnPk = ordLnPk;
  29. this.designKey = designKey;
  30. container.Controls.Add(this);
  31. this.Dock = DockStyle.Fill;
  32. LoadBaseData();
  33. }
  34. private void LoadBaseData()
  35. {
  36. UltraComboEditor ultraComPsc = new UltraComboEditor();
  37. UltraComboEditor ultraComProcess = new UltraComboEditor();
  38. UltraComboEditor ultraComJG = new UltraComboEditor();
  39. UltraComboEditor cmbProBigType = new UltraComboEditor();
  40. this.Controls.Add(ultraComPsc);
  41. this.Controls.Add(ultraComProcess);
  42. this.Controls.Add(ultraComJG);
  43. this.Controls.Add(cmbProBigType);
  44. ultraComPsc.Visible = false;
  45. ultraComProcess.Visible = false;
  46. ultraComJG.Visible = false;
  47. cmbProBigType.Visible = false;
  48. this.Controls.Add(Wics);
  49. Wics.Visible = false;
  50. //绑定数据源 产品规范描述
  51. QcmBaseCommon.InitDropUltraComEditor(ultraComPsc, "com.steering.pss.qcm.ComBaseQuery.getPsc", "PscDesc", _ob, false);
  52. //不可编辑
  53. UltraComboEditor cmbWtr = new UltraComboEditor();
  54. cmbWtr.DropDownListWidth = -1;
  55. this.Controls.Add(cmbWtr);
  56. cmbWtr.Visible = false;
  57. ClsBaseInfo.FillWtrExpress(cmbWtr, _ob, true);
  58. entityGrid1.DisplayLayout.Bands[0].Columns["Formula"].EditorComponent = cmbWtr;
  59. entityGrid1.DisplayLayout.Bands[0].Columns["Formula"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
  60. QcmBaseQuery.NitializeProductBigType(cmbProBigType, false, _ob);
  61. ClsBaseInfo.SetComboItemHeight(cmbProBigType);
  62. ClsBaseInfo.FillComBaseInfo(ultraComboEditor3, "4107", _ob, false);
  63. ((DataTable)ultraComboEditor3.DataSource).DefaultView.Sort = "BASECODE ASC";
  64. }
  65. /// <summary>
  66. /// 查询质量设计水压
  67. /// </summary>
  68. /// <param name="designStdWicEntity"></param>
  69. public void Query()
  70. {
  71. CraftOrdDesignStdWicEntityBindingSource.Clear();
  72. DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CraftOrdFdWic.queryM", new object[]{ ordLnPk }, _ob);
  73. GridHelper.CopyDataToDatatable(dt, dataTable1, true);
  74. }
  75. public void Clear()
  76. {
  77. this.CraftOrdDesignStdWicEntityBindingSource.Clear();
  78. }
  79. public void Save()
  80. {
  81. List<CraftOrdFdWicEntity> parms = new List<CraftOrdFdWicEntity>();
  82. var mRow = ultraGrid1.Rows.Where(a => a.GetValue("Chk") == "True").FirstOrDefault();
  83. var rows = entityGrid1.Rows.Where(a => a.GetValue("Chk") == "True");
  84. if (mRow == null && rows.Count() == 0)
  85. {
  86. MessageUtil.ShowWarning("请选择一条记录!");
  87. return;
  88. }
  89. string mscPline = ultraGrid1.ActiveRow.GetValue("MSC_PLINE");
  90. string processCode = ultraGrid1.ActiveRow.GetValue("PROCESS_CODE");
  91. string wic = ultraGrid1.ActiveRow.GetValue("WIC");
  92. foreach (var row in rows)
  93. {
  94. var parm = EntityHelper.CopyEntity<CraftOrdFdWicEntity>(row.ListObject);
  95. if (parm.PressureY == "" && parm.Pressure == "" && parm.Formula == "")
  96. {
  97. MessageUtil.ShowWarning("请输入试验压力或者试验压力公式");
  98. return;
  99. }
  100. if (parm.OutputStyle == "")
  101. {
  102. MessageUtil.ShowWarning("请选择工艺文件输出方式");
  103. return;
  104. }
  105. string formula = parm.Formula.Replace("f", "1").Replace("YS", "1").Replace("TS", "1").Replace("D", "2").Replace("t", "1");
  106. if (!parm.Formula.Equals("") && formula.CompileFormula() == null)
  107. {
  108. MessageUtil.ShowWarning("公式不合法,请重新输入");
  109. return;
  110. }
  111. if (parm.SaveTime.Equals(""))
  112. {
  113. MessageUtil.ShowWarning("请输入保压时间");
  114. return;
  115. }
  116. if ((parm.Pressure != "" || parm.PressureY != "") && parm.Formula != "")
  117. {
  118. if (parm.GetMaxvalue == null && parm.GetMinvalue == null)
  119. {
  120. MessageUtil.ShowWarning("请选择取大值或取小值");
  121. return;
  122. }
  123. }
  124. parm.CreateName = CoreUserInfo.UserInfo.GetUserName();
  125. parm.UpdateName = CoreUserInfo.UserInfo.GetUserName();
  126. parm.DeleteName = CoreUserInfo.UserInfo.GetUserName();
  127. parm.SpeclFl = "2";
  128. parm.DesginKey = designKey;
  129. parm.OrdLnPk = ordLnPk;
  130. parm.WicMemo = ultraGrid1.ActiveRow.GetValue("WIC_MEMO");
  131. parm.MscPline = ultraGrid1.ActiveRow.GetValue("MSC_PLINE");
  132. parm.ProcessCode = ultraGrid1.ActiveRow.GetValue("PROCESS_CODE");
  133. parm.Wic = ultraGrid1.ActiveRow.GetValue("WIC");
  134. parms.Add(parm);
  135. }
  136. if (MessageUtil.ShowYesNoAndQuestion("是否确认保存?") == DialogResult.No)
  137. {
  138. return;
  139. }
  140. List<string> jsons = new List<string>();
  141. foreach (var craftOrdFdWicEntity in parms)
  142. {
  143. jsons.Add(JSONFormat.Format(craftOrdFdWicEntity));
  144. }
  145. string chkMscPline = mRow == null ? "" : mRow.GetValue("MSC_PLINE");
  146. string chkProcessCode = mRow == null ? "" : mRow.GetValue("PROCESS_CODE");
  147. string chkMemo = mRow == null ? "" : mRow.GetValue("WIC_MEMO");
  148. ServerHelper.SetData("com.steering.pss.sale.order.CraftOrdFdWic.save",
  149. new object[] { jsons, ordLnPk, chkMscPline, chkProcessCode, chkMemo }, _ob);
  150. MessageUtil.ShowTips("保存成功!");
  151. Relocate(mscPline, processCode, wic);
  152. }
  153. public void Delete()
  154. {
  155. List<CraftOrdFdWicEntity> parms = new List<CraftOrdFdWicEntity>();
  156. var mRow = ultraGrid1.Rows.Where(a => a.GetValue("CHK") == "True").FirstOrDefault();
  157. var rows = entityGrid1.Rows.Where(a => a.GetValue("Chk") == "True");
  158. if (mRow == null && rows.Count() == 0)
  159. {
  160. MessageUtil.ShowWarning("请选择一条记录!");
  161. return;
  162. }
  163. string mscPline = ultraGrid1.ActiveRow.GetValue("MSC_PLINE");
  164. string processCode = ultraGrid1.ActiveRow.GetValue("PROCESS_CODE");
  165. string wic = ultraGrid1.ActiveRow.GetValue("WIC");
  166. foreach (var row in rows)
  167. {
  168. var parm = EntityHelper.CopyEntity<CraftOrdFdWicEntity>(row.ListObject);
  169. parm.CreateName = CoreUserInfo.UserInfo.GetUserName();
  170. parm.UpdateName = CoreUserInfo.UserInfo.GetUserName();
  171. parm.DeleteName = CoreUserInfo.UserInfo.GetUserName();
  172. parm.SpeclFl = "2";
  173. parm.DesginKey = designKey;
  174. parms.Add(parm);
  175. }
  176. if (MessageUtil.ShowYesNoAndQuestion("是否确认删除?") == DialogResult.No)
  177. {
  178. return;
  179. }
  180. List<string> jsons = new List<string>();
  181. foreach (var craftOrdDesignStdWicEntity in parms)
  182. {
  183. jsons.Add(JSONFormat.Format(craftOrdDesignStdWicEntity));
  184. }
  185. string parmMscPline = mRow == null ? "" : mRow.GetValue("MSC_PLINE");
  186. string parmProcessCode = mRow == null ? "" : mRow.GetValue("PROCESS_CODE");
  187. ServerHelper.SetData("com.steering.pss.sale.order.CraftOrdFdWic.delete",
  188. new object[] { jsons, ordLnPk, parmMscPline, parmProcessCode }, _ob);
  189. MessageUtil.ShowTips("删除成功!");
  190. Relocate(mscPline, processCode, wic);
  191. }
  192. public void CopyNkStd()
  193. {
  194. var mRow = ultraGrid1.Rows.Where(a => a.GetValue("CHK") == "True").FirstOrDefault();
  195. if (mRow == null)
  196. {
  197. MessageUtil.ShowWarning("请选择一条水压标准索引码!");
  198. return;
  199. }
  200. if (mRow.GetValue("WIC") == "")
  201. {
  202. MessageUtil.ShowWarning("请选择一条水压标准索引码!");
  203. return;
  204. }
  205. if (MessageUtil.ShowYesNoAndQuestion("是否确认复制内控索引码" + mRow.GetValue("WIC") + "?") == DialogResult.No)
  206. {
  207. return;
  208. }
  209. ServerHelper.SetData("com.steering.pss.sale.order.CraftOrdFdWic.copyNkStd", new object[] { designKey, ordLnPk,
  210. mRow.GetValue("MSC_PLINE"), mRow.GetValue("PROCESS_CODE"), mRow.GetValue("WIC") }, _ob);
  211. MessageUtil.ShowTips("复制成功!");
  212. Query();
  213. }
  214. private void GridEdite(UltraGridRow row)
  215. {
  216. if (row.GetValue("Chk") == "True")
  217. {
  218. foreach (UltraGridCell cell in row.Cells)
  219. {
  220. if (cell.Column.CellActivation == Activation.AllowEdit)
  221. {
  222. cell.Activation = Activation.AllowEdit;
  223. }
  224. }
  225. }
  226. else
  227. {
  228. foreach (UltraGridCell cell in row.Cells)
  229. {
  230. if (cell.Column.Key == "Chk") continue;
  231. if (cell.Column.CellActivation == Activation.AllowEdit)
  232. {
  233. cell.Activation = Activation.ActivateOnly;
  234. }
  235. }
  236. }
  237. }
  238. private void entityGrid1_CellChange(object sender, CellEventArgs e)
  239. {
  240. e.Cell.Row.Update();
  241. GridEdite(e.Cell.Row);
  242. if (e.Cell.Column.Key == "PressureY")
  243. {
  244. if (e.Cell.Value.ToString() != "")
  245. {
  246. //英制压力转公制压力系数为0.00689476
  247. e.Cell.Row.Cells["Pressure"].Value = Math.Round(double.Parse(e.Cell.Value.ToString()) * 0.00689476, 2);
  248. }
  249. else
  250. {
  251. e.Cell.Row.Cells["Pressure"].Value = 0;
  252. }
  253. }
  254. else if (e.Cell.Column.Key == "Pressure")
  255. {
  256. if (e.Cell.Value.ToString() != "")
  257. {
  258. if (double.Parse(e.Cell.Value.ToString()) > 6894.76)
  259. {
  260. MessageUtil.ShowWarning("公制压力上限为68900");
  261. e.Cell.Row.Cells["Pressure"].Value = 6894.76;
  262. }
  263. //公制压力转英制压力系数为14.5
  264. e.Cell.Row.Cells["PressureY"].Value = Math.Round(double.Parse(e.Cell.Value.ToString()) / 0.00689476, 2);
  265. }
  266. else
  267. {
  268. e.Cell.Row.Cells["PressureY"].Value = 0;
  269. }
  270. }
  271. }
  272. private void Relocate(string mscPline, string processCode, string pic)
  273. {
  274. Query();
  275. var mRow = ultraGrid1.Rows.Where(a => a.GetValue("MSC_PLINE") == mscPline && a.GetValue("PROCESS_CODE") == processCode &&
  276. a.GetValue("WIC") == pic).FirstOrDefault();
  277. if (mRow != null)
  278. {
  279. mRow.Activate();
  280. }
  281. }
  282. private void entityGrid1_AfterRowInsert(object sender, RowEventArgs e)
  283. {
  284. var mRow = ultraGrid1.ActiveRow;
  285. e.Row.SetValue("mscPline", mRow.GetValue("MSC_PLINE"));
  286. e.Row.SetValue("processCode", mRow.GetValue("PROCESS_CODE"));
  287. e.Row.SetValue("processDesc", mRow.GetValue("PROCESS_DESC"));
  288. e.Row.SetValue("wic", mRow.GetValue("WIC"));
  289. e.Row.Cells["GetMaxvalue"].Value = true;
  290. e.Row.Cells["GetMinvalue"].Value = false;
  291. e.Row.Cells["CraftSource"].Value = "1";
  292. e.Row.Cells["SpeclFl"].Value = "2";
  293. e.Row.Cells["OrdLnPk"].Value = ordLnPk;
  294. }
  295. private void ultraTextEditor1_EditorButtonClick(object sender, EditorButtonEventArgs e)
  296. {
  297. }
  298. private void ultraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e)
  299. {
  300. }
  301. private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
  302. {
  303. var mRow = ultraGrid1.ActiveRow;
  304. string wic = mRow.GetValue("WIC");
  305. string mscPline = mRow.GetValue("MSC_PLINE");
  306. string processCode = mRow.GetValue("PROCESS_CODE");
  307. this.CraftOrdDesignStdWicEntityBindingSource.DataSource = EntityHelper.GetData<CraftOrdFdWicEntity>(
  308. "com.steering.pss.sale.order.CraftOrdFdWic.query",
  309. new object[] { ordLnPk, mscPline, processCode, wic }, _ob);
  310. foreach (var row in entityGrid1.Rows)
  311. {
  312. GridEdite(row);
  313. }
  314. }
  315. private void ultraTextEditor2_EditorButtonClick(object sender, EditorButtonEventArgs e)
  316. {
  317. if (ultraGrid1.ActiveCell.Column.Key == "MSC_PLINE")
  318. {
  319. if (entityGrid1.Rows.Count != 0)
  320. {
  321. MessageUtil.ShowWarning("已维护首日检数据,不能修改!");
  322. }
  323. else
  324. {
  325. UltraGridRow row = ultraGrid1.ActiveRow;
  326. string key = ultraGrid1.ActiveCell.Column.Key;
  327. DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CraftOrdFdWic.getMscPlineProcess",
  328. new object[] { designKey }, _ob);
  329. dt.Columns["MSC_PLINE"].Caption = "制程号";
  330. dt.Columns["WHOLE_BACKLOG"].Caption = "全程途径码";
  331. dt.Columns["WHOLE_BACKLOG_DESC"].Caption = "全程途径描述";
  332. dt.Columns["PROCESS_DESC"].Caption = "工序";
  333. BaseInfoPopup popup = new BaseInfoPopup(dt, "MSC_PLINE", "PROCESS_CODE");
  334. GridHelper.RefreshAndAutoSize(popup.UltraGrid1);
  335. popup.LabelTextBox1.Caption = "制程号";
  336. if (popup.ShowDialog() == DialogResult.OK)
  337. {
  338. row.SetValue("MSC_PLINE", popup.ChoicedRow.GetValue("MSC_PLINE"));
  339. row.SetValue("PROCESS_DESC", popup.ChoicedRow.GetValue("PROCESS_DESC"));
  340. row.SetValue("PROCESS_CODE", popup.ChoicedRow.GetValue("PROCESS_CODE"));
  341. row.SetValue("WIC", popup.ChoicedRow.GetValue("WIC"));
  342. row.Update();
  343. }
  344. }
  345. }
  346. }
  347. private void entityGrid1_BeforeRowInsert(object sender, BeforeRowInsertEventArgs e)
  348. {
  349. if (ultraGrid1.ActiveRow == null || ultraGrid1.ActiveRow.GetValue("WIC") == "")
  350. {
  351. e.Cancel = true;
  352. }
  353. }
  354. private void ultraGrid1_CellChange(object sender, CellEventArgs e)
  355. {
  356. e.Cell.Row.Update();
  357. if (e.Cell.Column.Key == "CHK")
  358. {
  359. UltraGridRow chkRow = e.Cell.Row;
  360. foreach (UltraGridRow row in ultraGrid1.Rows)
  361. {
  362. if (row.Cells["CHK"].Value.ToString() == "True" && row != chkRow)
  363. {
  364. row.Cells["CHK"].Value = "False";
  365. row.Update();
  366. }
  367. }
  368. }
  369. }
  370. private void ultraGrid1_ClickCellButton(object sender, CellEventArgs e)
  371. {
  372. }
  373. /// <summary>
  374. /// 复制
  375. /// </summary>
  376. public void Copy()
  377. {
  378. var chkRows = entityGrid1.Rows.Where(a => a.GetValue("chk") == "True");
  379. if (chkRows.Count() == 0)
  380. {
  381. MessageUtil.ShowWarning("请选择记录后,再进行操作!");
  382. return;
  383. }
  384. ultraGrid1.UpdateData();
  385. DataTable copyTable = CreateTableByEntity((CraftOrdFdWicEntity)chkRows.FirstOrDefault().ListObject);
  386. foreach (UltraGridRow row in entityGrid1.Rows)
  387. {
  388. if (row.GetValue("Chk") != "True") continue;
  389. DataRow dr = copyTable.NewRow();
  390. CopyEntityToRow((CraftOrdFdWicEntity)row.ListObject, dr);
  391. copyTable.Rows.Add(dr);
  392. }
  393. DataTable[] copyTabs = new DataTable[] { copyTable, new DataTable() };
  394. Clipboard.SetData("Wic", copyTabs);
  395. }
  396. /// <summary>
  397. /// 粘贴
  398. /// </summary>
  399. public void Paste()
  400. {
  401. if (ultraGrid1.ActiveRow == null || ultraGrid1.ActiveRow.GetValue("WIC") == "")
  402. {
  403. MessageUtil.ShowWarning("请选择一条成分标准索引码!");
  404. return;
  405. }
  406. DataTable[] copyTabs = (DataTable[])Clipboard.GetData("Wic");
  407. if (copyTabs == null)
  408. {
  409. MessageUtil.ShowWarning("没有数据,请复制后再进行操作!");
  410. return;
  411. }
  412. DataTable copyTab = copyTabs[0];
  413. DataTable copyTab2 = copyTabs[1];
  414. if (copyTab == null || copyTab.Rows.Count == 0)
  415. {
  416. MessageUtil.ShowWarning("没有数据,请复制后再进行操作!");
  417. return;
  418. }
  419. dataTable1.BeginInit();
  420. List<CraftOrdFdWicEntity> data = (List<CraftOrdFdWicEntity>)CraftOrdDesignStdWicEntityBindingSource.DataSource;
  421. CraftOrdFdWicEntity activeFd = null;
  422. foreach (DataRow row in copyTab.Rows)
  423. {
  424. CraftOrdFdWicEntity fd = new CraftOrdFdWicEntity();
  425. fd.Chk = true;
  426. CopyRowToEntity(row, fd);
  427. data.Add(fd);
  428. activeFd = fd;
  429. }
  430. CraftOrdDesignStdWicEntityBindingSource.ResetBindings(false);
  431. //CraftOrdDesignStdCicEntityBindingSource.DataSource = data;
  432. dataTable1.EndInit();
  433. entityGrid1.UpdateData();
  434. if (entityGrid1.Rows.Count > 0)
  435. {
  436. entityGrid1.Rows[entityGrid1.Rows.Count - 1].Activate();
  437. }
  438. }
  439. private string GetLineName(string name)
  440. {
  441. string lineName = "";
  442. for (int i = 0; i < name.Length; i++)
  443. {
  444. if (i == 0)
  445. {
  446. lineName += name[i];
  447. }
  448. else
  449. {
  450. if (name[i] >= 'A' && name[i] <= 'Z')
  451. {
  452. lineName += '_';
  453. lineName += name[i];
  454. }
  455. else
  456. {
  457. lineName += name[i];
  458. }
  459. }
  460. }
  461. return lineName.ToUpper();
  462. }
  463. private string GetName(string lineName)
  464. {
  465. string[] strs = lineName.Split('_');
  466. string name = "";
  467. for (int i = 0; i < strs.Length; i++)
  468. {
  469. name += strs[i].Substring(0, 1).ToUpper() + strs[i].Substring(1).ToLower();
  470. }
  471. return name;
  472. }
  473. private DataTable CreateTableByEntity(CraftOrdFdWicEntity fdEntity)
  474. {
  475. DataTable dt = new DataTable();
  476. PropertyInfo[] srcPropertyInfos = fdEntity.GetType().GetProperties();
  477. foreach (PropertyInfo srcPropertyInfo in srcPropertyInfos)
  478. {
  479. dt.Columns.Add(GetLineName(srcPropertyInfo.Name));
  480. }
  481. return dt;
  482. }
  483. private void CopyEntityToRow(CraftOrdFdWicEntity fdEntity, DataRow desRow)
  484. {
  485. PropertyInfo[] pros = fdEntity.GetType().GetProperties();
  486. foreach (PropertyInfo pro in pros)
  487. {
  488. desRow[GetLineName(pro.Name)] = pro.GetValue(fdEntity, null);
  489. }
  490. }
  491. private void CopyRowToEntity(DataRow row, CraftOrdFdWicEntity fdEntity)
  492. {
  493. PropertyInfo[] pros = fdEntity.GetType().GetProperties();
  494. foreach (DataColumn dc in row.Table.Columns)
  495. {
  496. if (dc.ColumnName == "CREATE_TIME") continue;
  497. PropertyInfo pro = fdEntity.GetType().GetProperty(GetName(dc.ColumnName));
  498. if (pro != null)
  499. {
  500. pro.SetValue(fdEntity, ConvertDataType(pro.PropertyType, row[dc.ColumnName].ToString()), null);
  501. }
  502. }
  503. }
  504. private object ConvertDataType(Type type, object objValue)
  505. {
  506. if (type == typeof(bool))
  507. {
  508. bool result;
  509. if (bool.TryParse(objValue.ToString(), out result))
  510. {
  511. return result;
  512. }
  513. else
  514. {
  515. return false;
  516. }
  517. }
  518. else if (type == typeof(bool?))
  519. {
  520. bool result;
  521. if (bool.TryParse(objValue.ToString(), out result))
  522. {
  523. return result;
  524. }
  525. else
  526. {
  527. return null;
  528. }
  529. }
  530. else if (type == typeof(int?))
  531. {
  532. if (objValue.ToString2() == "")
  533. {
  534. return null;
  535. }
  536. else
  537. {
  538. return int.Parse(objValue.ToString());
  539. }
  540. }
  541. else if (type == typeof(long?))
  542. {
  543. if (objValue.ToString2() == "")
  544. {
  545. return null;
  546. }
  547. else
  548. {
  549. return long.Parse(objValue.ToString());
  550. }
  551. }
  552. else if (type == typeof(short?))
  553. {
  554. if (objValue.ToString2() == "")
  555. {
  556. return null;
  557. }
  558. else
  559. {
  560. return short.Parse(objValue.ToString());
  561. }
  562. }
  563. else if (type == typeof(float?))
  564. {
  565. if (objValue.ToString2() == "")
  566. {
  567. return null;
  568. }
  569. else
  570. {
  571. return float.Parse(objValue.ToString());
  572. }
  573. }
  574. else if (type == typeof(double?))
  575. {
  576. if (objValue.ToString2() == "")
  577. {
  578. return null;
  579. }
  580. else
  581. {
  582. return double.Parse(objValue.ToString());
  583. }
  584. }
  585. else if (type == typeof(decimal?))
  586. {
  587. if (objValue.ToString2() == "")
  588. {
  589. return null;
  590. }
  591. else
  592. {
  593. return decimal.Parse(objValue.ToString());
  594. }
  595. }
  596. else if (type == typeof(DateTime?))
  597. {
  598. if (objValue.ToString2() == "")
  599. {
  600. return null;
  601. }
  602. else
  603. {
  604. return DateTime.Parse(objValue.ToString());
  605. }
  606. }
  607. else
  608. {
  609. return objValue == null ? "" : objValue.ToString();
  610. }
  611. }
  612. private void ultraGrid1_BeforeRowInsert(object sender, BeforeRowInsertEventArgs e)
  613. {
  614. if (ultraGrid1.Rows.Count > 0)
  615. {
  616. e.Cancel = true;
  617. }
  618. }
  619. }
  620. }