frmOrderModel.cs 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using CoreFS.CA03;
  10. using CoreFS.CA04;
  11. using CoreFS.CA06;
  12. using System.Collections;
  13. using Infragistics.Win.UltraWinGrid;
  14. using Core.Mes.Client.Comm.Server;
  15. using Core.Mes.Client.Comm.Control;
  16. using Core.Mes.Client.Comm.Tool;
  17. namespace Core.StlMes.Client.SaleOrder
  18. {
  19. public partial class frmOrderModel : FrmBase
  20. {
  21. public frmOrderModel()
  22. {
  23. InitializeComponent();
  24. }
  25. public frmOrderModel(OpeBase ob)
  26. {
  27. InitializeComponent();
  28. this.ob = ob;
  29. }
  30. private string use_unit;
  31. public string Use_unit
  32. {
  33. get { return use_unit; }
  34. set { use_unit = value; }
  35. }
  36. /// <summary>
  37. /// 范本描述模糊查询
  38. /// </summary>
  39. /// <param name="sender"></param>
  40. /// <param name="e"></param>
  41. private void ultraCheckEditor2_CheckedChanged(object sender, EventArgs e)
  42. {
  43. if (ultraCheckEditor2.Checked)
  44. {
  45. txtNMTitle.Enabled = true;
  46. }
  47. else
  48. {
  49. txtNMTitle.Text = "";
  50. txtNMTitle.Enabled = false;
  51. }
  52. }
  53. /// <summary>
  54. /// 适用单位模糊查询
  55. /// </summary>
  56. /// <param name="sender"></param>
  57. /// <param name="e"></param>
  58. private void ultraCheckEditor1_CheckedChanged(object sender, EventArgs e)
  59. {
  60. if (uceUnit.Checked)
  61. {
  62. cmbSyTitle.Enabled = true;
  63. }
  64. else
  65. {
  66. //cmbSyTitle.Value = "";
  67. cmbSyTitle.Enabled = false;
  68. }
  69. }
  70. private void frmOrderModel_Load(object sender, EventArgs e)
  71. {
  72. string saleRegion = doGetSaleOrg();
  73. //适用单位数据源绑定
  74. BindCmbSy(saleRegion);
  75. if (!"".Equals(Use_unit))
  76. {
  77. uceUnit.Checked = true;
  78. cmbSy.Enabled = false;
  79. cmbSy.Value = Use_unit;
  80. cmbSyTitle.Text = Use_unit;
  81. }
  82. doQuery();
  83. }
  84. /// <summary>
  85. /// 重写基类load事件,屏蔽平台过滤功能。
  86. /// </summary>
  87. /// <param name="e"></param>
  88. protected override void OnLoad(EventArgs e)
  89. {
  90. base.OnLoad(e);
  91. ultraGrid2.DisplayLayout.Bands[0].Override.HeaderClickAction = HeaderClickAction.Select;
  92. }
  93. /// <summary>
  94. /// 手动添加toolbar
  95. /// </summary>
  96. /// <param name="sender"></param>
  97. /// <param name="e"></param>
  98. private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
  99. {
  100. if ("doQuery".Equals(e.Tool.Key))
  101. {
  102. doQueryNew();
  103. }
  104. else if ("doAdd".Equals(e.Tool.Key))
  105. {
  106. doAdd();
  107. }
  108. else if ("doUpdate".Equals(e.Tool.Key))
  109. {
  110. doUpdate();
  111. }
  112. else if ("doDelete".Equals(e.Tool.Key))
  113. {
  114. doDeleteOrRecovery(true);
  115. }
  116. else if ("doRecovery".Equals(e.Tool.Key))
  117. {
  118. doDeleteOrRecovery(false);
  119. }
  120. else if ("doLase".Equals(e.Tool.Key))
  121. {
  122. //上移功能。
  123. doLase();
  124. }
  125. else if ("doNext".Equals(e.Tool.Key))
  126. {
  127. //下移功能
  128. doNext();
  129. }
  130. else if ("doOk".Equals(e.Tool.Key))
  131. {
  132. //确认功能
  133. doOk();
  134. }
  135. else
  136. {
  137. this.Close();
  138. }
  139. }
  140. /// <summary>
  141. /// 委托方法
  142. /// </summary>
  143. /// <param name="ROrdLen"></param>
  144. public delegate void GetOrderModelHander(DataRow row,DataTable dt);
  145. public event GetOrderModelHander GetOrderModel;
  146. /// <summary>
  147. /// 确认功能
  148. /// </summary>
  149. private void doOk()
  150. {
  151. if (ultraGrid1.ActiveRow == null)
  152. {
  153. MessageBox.Show("请选择一条商务条款范本!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  154. return;
  155. }
  156. string orderModelNo = ultraGrid1.ActiveRow.Cells["ORDER_MODEL_NO"].Value.ToString();
  157. //子表Table记录也要返回。
  158. BindOrderModelItem(orderModelNo);
  159. foreach (DataRow row in this.dataTable1.Rows)
  160. {
  161. if (orderModelNo.Equals(row["ORDER_MODEL_NO"].ToString()))
  162. {
  163. if (Convert.ToBoolean(row["CUSTOMER_MODEL_FL"]))
  164. {
  165. row["CUSTOMER_MODEL_FL"] = "1";
  166. }
  167. else
  168. {
  169. row["CUSTOMER_MODEL_FL"] = "0";
  170. }
  171. GetOrderModel(row, dataTable2);
  172. this.Close();
  173. return;
  174. }
  175. }
  176. }
  177. /// <summary>
  178. /// 下移功能
  179. /// </summary>
  180. private void doNext()
  181. {
  182. if (ultraGrid2.ActiveRow == null)
  183. {
  184. MessageBox.Show("请先选择需要范本条目!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  185. return;
  186. }
  187. //获取当前顺序号
  188. string modelIndex = ultraGrid2.ActiveRow.Cells["MODEL_INDEX"].Value.ToString();
  189. string orderModelNo = ultraGrid2.ActiveRow.Cells["ORDER_MODEL_NO"].Value.ToString();
  190. string modelSeqNo = ultraGrid2.ActiveRow.Cells["MODEL_SEQ_NO"].Value.ToString();
  191. //获取最大顺序号。
  192. string IndexMax = (GetIndex(orderModelNo) - 1).ToString();
  193. if (IndexMax.Equals(modelIndex))
  194. {
  195. //最大顺序号,无法下移。
  196. return;
  197. }
  198. ServerHelper.SetData("com.steering.pss.sale.order.CoreOrderModel.doNext", new Object[] { modelIndex, orderModelNo, modelSeqNo }, this.ob);
  199. BindOrderModelItem(orderModelNo);
  200. //聚焦当前操作行
  201. Infragistics.Win.UltraWinGrid.UltraGridRow rowD = null;
  202. for (int i = 0; i < ultraGrid2.Rows.Count; i++)
  203. {
  204. rowD = ultraGrid2.Rows[i];
  205. if (rowD.Cells["ORDER_MODEL_NO"].Value.ToString().Equals(orderModelNo) && rowD.Cells["MODEL_SEQ_NO"].Value.ToString().Equals(modelSeqNo))
  206. {
  207. rowD.Activate();
  208. break;
  209. }
  210. }
  211. }
  212. /// <summary>
  213. /// 上移功能
  214. /// </summary>
  215. private void doLase()
  216. {
  217. if (ultraGrid2.ActiveRow == null)
  218. {
  219. MessageBox.Show("请先选择需要范本条目!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  220. return;
  221. }
  222. //获取当前选中项的顺序号和相关主键。
  223. //ORDER_MODEL_NO,
  224. // MODEL_SEQ_NO,
  225. // MODEL_SEQ,
  226. // MODEL_INDEX,
  227. string modelIndex = ultraGrid2.ActiveRow.Cells["MODEL_INDEX"].Value.ToString();
  228. string orderModelNo = ultraGrid2.ActiveRow.Cells["ORDER_MODEL_NO"].Value.ToString();
  229. string modelSeqNo = ultraGrid2.ActiveRow.Cells["MODEL_SEQ_NO"].Value.ToString();
  230. //如果modelIndex=1,则不执行任何操作。
  231. if ("1".Equals(modelIndex))
  232. {
  233. return;
  234. }
  235. //UPDATE 顺序号=Y WHERE 顺序号=Y-1
  236. //UPDATE 顺序号=Y-1 where 顺序号=当前顺序号所对应的主键id。
  237. //将当前顺序号与相关主键id作为参数,传递到后台执行事物操作。
  238. ServerHelper.SetData("com.steering.pss.sale.order.CoreOrderModel.doLase", new Object[] { modelIndex, orderModelNo, modelSeqNo }, this.ob);
  239. BindOrderModelItem(orderModelNo);
  240. //聚焦当前操作行
  241. Infragistics.Win.UltraWinGrid.UltraGridRow rowD = null;
  242. for (int i = 0; i < ultraGrid2.Rows.Count; i++)
  243. {
  244. rowD = ultraGrid2.Rows[i];
  245. if (rowD.Cells["ORDER_MODEL_NO"].Value.ToString().Equals(orderModelNo) && rowD.Cells["MODEL_SEQ_NO"].Value.ToString().Equals(modelSeqNo))
  246. {
  247. rowD.Activate();
  248. break;
  249. }
  250. }
  251. }
  252. /// <summary>
  253. /// 废除或恢复
  254. /// </summary>
  255. /// <param name="isDelete">true废除 false恢复</param>
  256. private void doDeleteOrRecovery(bool isDelete)
  257. {
  258. //判断是主表还是从表
  259. if ("1".Equals(ultraTabControl1.SelectedTab.Key))
  260. {
  261. if (ultraGrid1.ActiveRow == null)
  262. {
  263. MessageBox.Show("请选择需要" + (isDelete ? "废除" : "恢复") + "的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  264. return;
  265. }
  266. Boolean validflagStr = Convert.ToBoolean(ultraGrid1.ActiveRow.Cells["VALIDFLAG"].Value);
  267. if (isDelete)
  268. {
  269. //无效数据不允许删除。
  270. if (!validflagStr)
  271. {
  272. MessageBox.Show("无效数据不支持废除操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  273. return;
  274. }
  275. }
  276. else
  277. {
  278. //有效数据不允许恢复
  279. if (validflagStr)
  280. {
  281. MessageBox.Show("有效数据不支持恢复操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  282. return;
  283. }
  284. }
  285. ArrayList param = new ArrayList();
  286. string orderModelNo = ultraGrid1.ActiveRow.Cells["ORDER_MODEL_NO"].Value.ToString();
  287. param.Add(orderModelNo);
  288. if (param.Count > 0 && MessageBox.Show("是否确认" + (isDelete ? "废除" : "恢复") + "选中的数据!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  289. {
  290. try
  291. {
  292. int count = ServerHelper.SetData("com.steering.pss.sale.order.CoreOrderModel.deleteLineInfo", new Object[] { param, UserInfo.GetUserName(), isDelete }, this.ob);
  293. if (count > 0)
  294. {
  295. doQuery();
  296. Infragistics.Win.UltraWinGrid.UltraGridRow rowD = null;
  297. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  298. {
  299. rowD = ultraGrid1.Rows[i];
  300. if (rowD.Cells["ORDER_MODEL_NO"].Value.ToString().Equals(orderModelNo))
  301. {
  302. rowD.Activate();
  303. break;
  304. }
  305. }
  306. }
  307. }
  308. catch (Exception ex)
  309. {
  310. MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  311. }
  312. }
  313. }
  314. else
  315. {
  316. //从表删除恢复。
  317. if (ultraGrid2.ActiveRow == null)
  318. {
  319. MessageBox.Show("请选择需要" + (isDelete ? "废除" : "恢复") + "的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  320. return;
  321. }
  322. Boolean validflagStr = Convert.ToBoolean(ultraGrid2.ActiveRow.Cells["VALIDFLAG"].Value);
  323. if (isDelete)
  324. {
  325. //无效数据不允许删除。
  326. if (!validflagStr)
  327. {
  328. MessageBox.Show("无效数据不支持废除操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  329. return;
  330. }
  331. }
  332. else
  333. {
  334. //有效数据不允许恢复
  335. if (validflagStr)
  336. {
  337. MessageBox.Show("有效数据不支持恢复操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  338. return;
  339. }
  340. //恢复,判断主表状态,如果为无效则不允许恢复。
  341. Boolean validflagStrMain = Convert.ToBoolean(ultraGrid1.ActiveRow.Cells["VALIDFLAG"].Value);
  342. if (!validflagStrMain)
  343. {
  344. MessageBox.Show("范本主体无效,范本条目不允许恢复。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  345. return;
  346. }
  347. }
  348. ArrayList param = new ArrayList();
  349. string orderModelNo = ultraGrid2.ActiveRow.Cells["ORDER_MODEL_NO"].Value.ToString();
  350. string xhNo = ultraGrid2.ActiveRow.Cells["MODEL_SEQ_NO"].Value.ToString();
  351. param.Add(orderModelNo);
  352. param.Add(xhNo);
  353. if (param.Count > 0 && MessageBox.Show("是否确认" + (isDelete ? "废除" : "恢复") + "选中的数据!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  354. {
  355. try
  356. {
  357. int count = ServerHelper.SetData("com.steering.pss.sale.order.CoreOrderModel.deleteLineInfo_ITEM", new Object[] { param, UserInfo.GetUserName(), isDelete }, this.ob);
  358. if (count > 0)
  359. {
  360. BindOrderModelItem(orderModelNo);
  361. Infragistics.Win.UltraWinGrid.UltraGridRow rowD = null;
  362. for (int i = 0; i < ultraGrid2.Rows.Count; i++)
  363. {
  364. rowD = ultraGrid2.Rows[i];
  365. if (rowD.Cells["MODEL_SEQ_NO"].Value.ToString().Equals(xhNo))
  366. {
  367. rowD.Activate();
  368. break;
  369. }
  370. }
  371. }
  372. }
  373. catch (Exception ex)
  374. {
  375. MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  376. }
  377. }
  378. }
  379. }
  380. /// <summary>
  381. /// 用于验证修改时,描述是否已存在
  382. /// </summary>
  383. private static string VName = "";
  384. /// <summary>
  385. /// 用于验证从表修改时,描述是否已存在
  386. /// </summary>
  387. private static string VName_Item = "";
  388. /// <summary>
  389. /// 修改功能
  390. /// </summary>
  391. private void doUpdate()
  392. {
  393. //判断主从表。
  394. if ("1".Equals(ultraTabControl1.SelectedTab.Key.ToString()))
  395. {
  396. if (ultraGrid1.ActiveRow == null)
  397. {
  398. MessageBox.Show("请选择需要修改的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  399. return;
  400. }
  401. Boolean validflagStr = Convert.ToBoolean(ultraGrid1.ActiveRow.Cells["VALIDFLAG"].Value);
  402. //无效数据不允许修改
  403. if (!validflagStr)
  404. {
  405. MessageBox.Show("无效数据不支持修改操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  406. return;
  407. }
  408. if (ValidInput())
  409. {
  410. //验证描述不允许重复。
  411. string name = txtNM.Text.Trim();
  412. if (!VName.Equals(name))
  413. {
  414. if (isRepeatName(name))
  415. {
  416. MessageBox.Show("范本描述\"" + name + "\"已存在,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  417. return;
  418. }
  419. }
  420. //确认修改吗?
  421. if (MessageBox.Show("是否确认修改选中的数据!", "提示", MessageBoxButtons.YesNo) == DialogResult.No)
  422. {
  423. return;
  424. }
  425. ArrayList parm = new ArrayList();
  426. string orderModelNo = ultraGrid1.ActiveRow.Cells["ORDER_MODEL_NO"].Value.ToString();
  427. //适用单位编号
  428. parm.Add(cmbSy.Value.ToString());
  429. //适用单位值
  430. parm.Add(cmbSy.Text.Trim());
  431. //范本描述
  432. parm.Add(name);
  433. //是否通用
  434. parm.Add(chkTy.Checked ? "1" : "0");
  435. //是否客户范本
  436. parm.Add(chkFb.Checked ? "1" : "0");
  437. //修改人
  438. parm.Add(this.UserInfo.GetUserName());
  439. //主键id
  440. parm.Add(orderModelNo);
  441. CoreClientParam ccp = new CoreClientParam();
  442. ccp.ServerName = "com.steering.pss.sale.order.CoreOrderModel";
  443. ccp.MethodName = "doUpdate";
  444. ccp.ServerParams = new object[] { parm };
  445. ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  446. if (ccp.ReturnCode == -1) return;
  447. doQuery();
  448. //高亮显示修改的数据
  449. Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
  450. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  451. {
  452. row = ultraGrid1.Rows[i];
  453. if (row.Cells["ORDER_MODEL_NO"].Value.ToString().Equals(orderModelNo))
  454. {
  455. row.Activate();
  456. break;
  457. }
  458. }
  459. MessageBox.Show("修改成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  460. }
  461. }
  462. else
  463. {
  464. //从表修改操作
  465. if (ultraGrid2.ActiveRow == null)
  466. {
  467. MessageBox.Show("请选择需要修改的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  468. return;
  469. }
  470. Boolean validflagStr = Convert.ToBoolean(ultraGrid2.ActiveRow.Cells["VALIDFLAG"].Value);
  471. //无效数据不允许修改
  472. if (!validflagStr)
  473. {
  474. MessageBox.Show("无效数据不支持修改操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  475. return;
  476. }
  477. if (ValidInput_Item())
  478. {
  479. //验证描述不允许重复。
  480. string name = txtXh.Text.Trim();
  481. string no = ultraGrid1.ActiveRow.Cells["ORDER_MODEL_NO"].Value.ToString();
  482. if (!VName_Item.Equals(name))
  483. {
  484. if (isRepeatName_Item(name,no))
  485. {
  486. MessageBox.Show("条目序号\"" + name + "\"已存在,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  487. return;
  488. }
  489. }
  490. //确认修改吗?
  491. if (MessageBox.Show("是否确认修改选中的数据!", "提示", MessageBoxButtons.YesNo) == DialogResult.No)
  492. {
  493. return;
  494. }
  495. ArrayList parm = new ArrayList();
  496. string xhNo = ultraGrid2.ActiveRow.Cells["Model_Seq_No"].Value.ToString();
  497. //条目序号
  498. parm.Add(txtXh.Text.Trim());
  499. //条目内容
  500. parm.Add(txtTmDetails.Text.Trim());
  501. //修改人
  502. parm.Add(this.UserInfo.GetUserName());
  503. //合同范本编号
  504. string orderModelNo = ultraGrid2.ActiveRow.Cells["ORDER_MODEL_NO"].Value.ToString();
  505. parm.Add(orderModelNo);
  506. //主键id
  507. parm.Add(xhNo);
  508. CoreClientParam ccp = new CoreClientParam();
  509. ccp.ServerName = "com.steering.pss.sale.order.CoreOrderModel";
  510. ccp.MethodName = "doUpdate_Item";
  511. ccp.ServerParams = new object[] { parm };
  512. ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  513. if (ccp.ReturnCode == -1) return;
  514. BindOrderModelItem(orderModelNo);
  515. //高亮显示修改的数据
  516. Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
  517. for (int i = 0; i < ultraGrid2.Rows.Count; i++)
  518. {
  519. row = ultraGrid2.Rows[i];
  520. if (row.Cells["Model_Seq_No"].Value.ToString().Equals(xhNo))
  521. {
  522. row.Activate();
  523. break;
  524. }
  525. }
  526. MessageBox.Show("修改成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  527. }
  528. }
  529. }
  530. /// <summary>
  531. /// 查询
  532. /// </summary>
  533. private void doQuery()
  534. {
  535. //ORDER_MODEL_DESC,USE_UNIT
  536. string orderModelDesc = txtNMTitle.Text.Trim();
  537. string userUnit = cmbSyTitle.Value.ToString();
  538. DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderModel.doQuery", new Object[] { orderModelDesc, userUnit }, this.ob);
  539. GridHelper.CopyDataToDatatable(ref dt, ref this.dataTable1, true);
  540. //不同颜色区分是否有效数据
  541. Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
  542. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  543. {
  544. row = ultraGrid1.Rows[i];
  545. if (!row.Cells["VALIDFLAG"].Value.ToString().Equals("1"))
  546. {
  547. row.Cells["VALIDFLAG"].Value = false;
  548. row.Appearance.ForeColor = Color.Red;
  549. }
  550. else
  551. {
  552. row.Cells["VALIDFLAG"].Value = true;
  553. row.Appearance.ForeColor = Color.Black;
  554. }
  555. //是否通用
  556. if (!row.Cells["GENERAL_FL"].Value.ToString().Equals("1"))
  557. {
  558. row.Cells["GENERAL_FL"].Value = false;
  559. }
  560. else
  561. {
  562. row.Cells["GENERAL_FL"].Value = true;
  563. }
  564. //是否合同范本
  565. if (!row.Cells["CUSTOMER_MODEL_FL"].Value.ToString().Equals("1"))
  566. {
  567. row.Cells["CUSTOMER_MODEL_FL"].Value = false;
  568. }
  569. else
  570. {
  571. row.Cells["CUSTOMER_MODEL_FL"].Value = true;
  572. }
  573. //合同范本状态W:待审;S:审核通过;F审核失败
  574. if (row.Cells["ORDER_MODEL_STS"].Value.ToString().Equals("W"))
  575. {
  576. row.Cells["ORDER_MODEL_STS"].Value = "待审";
  577. }
  578. else if (row.Cells["ORDER_MODEL_STS"].Value.ToString().Equals("S"))
  579. {
  580. row.Cells["ORDER_MODEL_STS"].Value = "审核通过";
  581. }
  582. else
  583. {
  584. row.Cells["ORDER_MODEL_STS"].Value = "审核失败";
  585. }
  586. }
  587. //列自适应
  588. GridHelper.RefreshAndAutoSizeExceptRows(ultraGrid1, new UltraGridColumn[] {
  589. });
  590. }
  591. /// <summary>
  592. /// 查询mm
  593. /// </summary>
  594. private void doQueryNew()
  595. {
  596. //ORDER_MODEL_DESC,USE_UNIT
  597. string orderModelDesc = txtNMTitle.Text.Trim();
  598. string userUnit = "";
  599. if (uceUnit.Checked)
  600. {
  601. userUnit = cmbSyTitle.Value.ToString();
  602. }
  603. DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderModel.doQueryNew", new Object[] { orderModelDesc, userUnit }, this.ob);
  604. GridHelper.CopyDataToDatatable(ref dt, ref this.dataTable1, true);
  605. //不同颜色区分是否有效数据
  606. Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
  607. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  608. {
  609. row = ultraGrid1.Rows[i];
  610. if (!row.Cells["VALIDFLAG"].Value.ToString().Equals("1"))
  611. {
  612. row.Cells["VALIDFLAG"].Value = false;
  613. row.Appearance.ForeColor = Color.Red;
  614. }
  615. else
  616. {
  617. row.Cells["VALIDFLAG"].Value = true;
  618. row.Appearance.ForeColor = Color.Black;
  619. }
  620. //是否通用
  621. if (!row.Cells["GENERAL_FL"].Value.ToString().Equals("1"))
  622. {
  623. row.Cells["GENERAL_FL"].Value = false;
  624. }
  625. else
  626. {
  627. row.Cells["GENERAL_FL"].Value = true;
  628. }
  629. //是否合同范本
  630. if (!row.Cells["CUSTOMER_MODEL_FL"].Value.ToString().Equals("1"))
  631. {
  632. row.Cells["CUSTOMER_MODEL_FL"].Value = false;
  633. }
  634. else
  635. {
  636. row.Cells["CUSTOMER_MODEL_FL"].Value = true;
  637. }
  638. //合同范本状态W:待审;S:审核通过;F审核失败
  639. if (row.Cells["ORDER_MODEL_STS"].Value.ToString().Equals("W"))
  640. {
  641. row.Cells["ORDER_MODEL_STS"].Value = "待审";
  642. }
  643. else if (row.Cells["ORDER_MODEL_STS"].Value.ToString().Equals("S"))
  644. {
  645. row.Cells["ORDER_MODEL_STS"].Value = "审核通过";
  646. }
  647. else
  648. {
  649. row.Cells["ORDER_MODEL_STS"].Value = "审核失败";
  650. }
  651. }
  652. //列自适应
  653. GridHelper.RefreshAndAutoSizeExceptRows(ultraGrid1, new UltraGridColumn[] {
  654. });
  655. }
  656. /// <summary>
  657. /// 验证非空字段。
  658. /// </summary>
  659. /// <returns></returns>
  660. private bool ValidInput()
  661. {
  662. if (string.IsNullOrEmpty(txtNM.Text.Trim()))
  663. {
  664. MessageBox.Show("请输入范本描述!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  665. return false;
  666. }
  667. return true;
  668. }
  669. /// <summary>
  670. /// 验证范本条目非空项
  671. /// </summary>
  672. /// <returns></returns>
  673. private bool ValidInput_Item()
  674. {
  675. if (string.IsNullOrEmpty(txtXh.Text.Trim()))
  676. {
  677. MessageBox.Show("请输入条目序号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  678. return false;
  679. }
  680. if (string.IsNullOrEmpty(txtTmDetails.Text.Trim()))
  681. {
  682. MessageBox.Show("请输入条目内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  683. return false;
  684. }
  685. return true;
  686. }
  687. /// <summary>
  688. /// 范本描述是否重复。
  689. /// </summary>
  690. /// <param name="name"></param>
  691. /// <returns></returns>
  692. private bool isRepeatName(string name)
  693. {
  694. DataTable dt = new DataTable();
  695. dt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderModel.isRepeatName", new Object[] { name }, this.ob);
  696. if (dt.Rows.Count > 0)
  697. {
  698. return true;
  699. }
  700. else
  701. {
  702. return false;
  703. }
  704. }
  705. /// <summary>
  706. /// 判断条目序号是否已存在
  707. /// </summary>
  708. /// <param name="name"></param>
  709. /// <returns></returns>
  710. private bool isRepeatName_Item(string name,string modelNo)
  711. {
  712. DataTable dt = new DataTable();
  713. dt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderModel.isRepeatName_Item", new Object[] { name, modelNo }, this.ob);
  714. if (dt.Rows.Count > 0)
  715. {
  716. return true;
  717. }
  718. else
  719. {
  720. return false;
  721. }
  722. }
  723. /// <summary>
  724. /// 获取范本条目顺序号
  725. /// </summary>
  726. /// <returns></returns>
  727. private int GetIndex(string orderModelNo)
  728. {
  729. int index = 1;
  730. DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderModel.GetIndex", new Object[] { orderModelNo }, this.ob);
  731. if (dt.Rows.Count > 0)
  732. {
  733. if (!"".Equals(dt.Rows[0][0].ToString()))
  734. {
  735. index = Convert.ToInt32(dt.Rows[0][0]) + 1;
  736. }
  737. }
  738. return index;
  739. }
  740. /// <summary>
  741. /// 自动生成编号
  742. /// </summary>
  743. /// <returns></returns>
  744. private string GetMaxCode()
  745. {
  746. //获取适用单位编码
  747. string syNo = cmbSy.Value.ToString();
  748. DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderModel.GetMaxCode", new Object[] { syNo }, this.ob);
  749. string maxCode = "";
  750. if (dt.Rows.Count > 0)
  751. {
  752. if (!"".Equals(dt.Rows[0][0].ToString()))
  753. {
  754. maxCode = dt.Rows[0][0].ToString();
  755. //获取最后三位数字。
  756. string maxNumber = (Convert.ToInt32(maxCode.Substring(maxCode.Length - 3)) + 1).ToString();
  757. string codeStr = maxCode.Substring(0, maxCode.Length - 3);
  758. while (maxNumber.Length < 3)
  759. {
  760. maxNumber = "0" + maxNumber;
  761. }
  762. maxCode = codeStr + maxNumber;
  763. }
  764. else
  765. {
  766. maxCode = syNo + "001";
  767. }
  768. }
  769. return maxCode;
  770. }
  771. /// <summary>
  772. /// 条目序号自动生成编号
  773. /// </summary>
  774. /// <returns></returns>
  775. private string GetMaxCode_Item(string orderModelNo)
  776. {
  777. //获取最大序号
  778. DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderModel.GetMaxCode_Item", new Object[] { orderModelNo }, this.ob);
  779. string maxCode = "";
  780. if (dt.Rows.Count > 0)
  781. {
  782. if (!"".Equals(dt.Rows[0][0].ToString()))
  783. {
  784. maxCode = (Convert.ToInt32(dt.Rows[0][0]) + 1).ToString();
  785. while (maxCode.Length < 3)
  786. {
  787. maxCode = "0" + maxCode;
  788. }
  789. }
  790. else
  791. {
  792. maxCode = "001";
  793. }
  794. }
  795. return maxCode;
  796. }
  797. /// <summary>
  798. /// 新增
  799. /// </summary>
  800. private void doAdd()
  801. {
  802. //判断当前编辑区显示的是范本主体,还是范本条目。
  803. if ("1".Equals(ultraTabControl1.SelectedTab.Key))
  804. {
  805. if (ValidInput())
  806. {
  807. try
  808. {
  809. //验证描述不允许重复。
  810. string name = txtNM.Text.Trim();
  811. if (isRepeatName(name))
  812. {
  813. MessageBox.Show("范本描述\"" + name + "\"已存在,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  814. return;
  815. }
  816. ArrayList parm = new ArrayList();
  817. //自动生成编号
  818. string autoCode = GetMaxCode();
  819. if ("".Equals(autoCode))
  820. {
  821. MessageBox.Show("编号超出限制,请与管理员联系。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  822. return;
  823. }
  824. string syNo = autoCode;
  825. parm.Add(syNo);
  826. parm.Add(name);
  827. //适用单位编码
  828. parm.Add(cmbSy.Value.ToString());
  829. //适用单位描述
  830. parm.Add(cmbSy.Text.ToString());
  831. //是否通用
  832. parm.Add(chkTy.Checked ? "1" : "0");
  833. //是否合同范本
  834. parm.Add(chkFb.Checked ? "1" : "0");
  835. //合同范本状态
  836. parm.Add("W");
  837. //有效标识
  838. //创建人
  839. parm.Add(this.UserInfo.GetUserName());
  840. CoreClientParam ccp = new CoreClientParam();
  841. ccp.ServerName = "com.steering.pss.sale.order.CoreOrderModel";
  842. ccp.MethodName = "doAdd";
  843. ccp.ServerParams = new object[] { parm };
  844. ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  845. if (ccp.ReturnCode == -1) return;
  846. doQuery();
  847. //高亮显示新增的数据
  848. Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
  849. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  850. {
  851. row = ultraGrid1.Rows[i];
  852. if (row.Cells["ORDER_MODEL_NO"].Value.ToString().Equals(syNo))
  853. {
  854. row.Activate();
  855. break;
  856. }
  857. }
  858. }
  859. catch (Exception ex)
  860. {
  861. MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  862. }
  863. }
  864. }
  865. else
  866. {
  867. //从表新增
  868. //验证非空项。
  869. if (ultraGrid1.ActiveRow == null)
  870. {
  871. MessageUtil.ShowWarning("请先选择商务条款或者先新增商务条款!");
  872. return;
  873. }
  874. if (ValidInput_Item())
  875. {
  876. try
  877. {
  878. //验证条目序号是否存在
  879. string name = txtXh.Text.Trim();
  880. string no = ultraGrid1.ActiveRow.Cells["ORDER_MODEL_NO"].Value.ToString();
  881. if (isRepeatName_Item(name,no))
  882. {
  883. MessageBox.Show("条目标题\"" + name + "\"已存在,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  884. return;
  885. }
  886. ArrayList parm = new ArrayList();
  887. string orderModelNo = ultraGrid1.ActiveRow.Cells["ORDER_MODEL_NO"].Value.ToString();
  888. //自动生成编号
  889. string autoCode = GetMaxCode_Item(orderModelNo);
  890. if ("".Equals(autoCode))
  891. {
  892. MessageBox.Show("编号超出限制,请与管理员联系。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  893. return;
  894. }
  895. string seqNo = autoCode;
  896. //合同范本编码
  897. parm.Add(orderModelNo);
  898. //条目序号编码
  899. parm.Add(autoCode);
  900. //条目序号值
  901. parm.Add(name);
  902. //条目顺序号
  903. parm.Add(GetIndex(orderModelNo));
  904. //范本条目值
  905. parm.Add(txtTmDetails.Text.Trim());
  906. //有效标识
  907. //创建人
  908. parm.Add(this.UserInfo.GetUserName());
  909. CoreClientParam ccp = new CoreClientParam();
  910. ccp.ServerName = "com.steering.pss.sale.order.CoreOrderModel";
  911. ccp.MethodName = "doAdd_Item";
  912. ccp.ServerParams = new object[] { parm };
  913. ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  914. if (ccp.ReturnCode == -1) return;
  915. BindOrderModelItem(orderModelNo);
  916. //高亮显示新增的数据
  917. Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
  918. for (int i = 0; i < ultraGrid2.Rows.Count; i++)
  919. {
  920. row = ultraGrid2.Rows[i];
  921. if (row.Cells["Model_Seq_No"].Value.ToString().Equals(seqNo))
  922. {
  923. row.Activate();
  924. break;
  925. }
  926. }
  927. }
  928. catch (Exception ex)
  929. {
  930. MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  931. }
  932. }
  933. }
  934. }
  935. /// <summary>
  936. /// 适用单位数据源绑定
  937. /// </summary>
  938. /// <param name="saleRegion"></param>
  939. private void BindCmbSy(string saleRegion)
  940. {
  941. DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderModel.GetSy", new Object[] { saleRegion }, this.ob);
  942. //编辑区域适用单位绑定,不提供空值。
  943. cmbSy.DataSource = dt;
  944. cmbSy.DisplayMember = "CUSTOMER_NM";
  945. cmbSy.ValueMember = "CUSTOMER_NO";
  946. cmbSy.DataBind();
  947. cmbSy.SelectedIndex = 0;
  948. //查询区域适用单位绑定,提供空值。
  949. ComboBoxHelper.FillUltraComboItems(cmbSyTitle, dt);
  950. cmbSyTitle.SelectedIndex = 0;
  951. }
  952. /// <summary>
  953. /// 根据登录账户,判断所属部门。
  954. /// </summary>
  955. private string doGetSaleOrg()
  956. {
  957. // string departmentId = UserInfo.GetDepartment();
  958. string saleRegion = ClsBaseInfo.GetSaleOrg(UserInfo.GetDeptid());
  959. //if ("销售公司".Equals(departmentId))
  960. //{
  961. // saleRegion = "100101";
  962. //}
  963. //else if ("国贸公司".Equals(departmentId))
  964. //{
  965. // saleRegion = "100102";
  966. //}
  967. //else if ("钢贸公司".Equals(departmentId))
  968. //{
  969. // saleRegion = "100103";
  970. //}
  971. //else
  972. //{
  973. // saleRegion = "100101";
  974. //}
  975. return saleRegion;
  976. }
  977. /// <summary>
  978. /// 主表行选中事件,选中主表行,绑定合同条目数据源。
  979. /// </summary>
  980. /// <param name="sender"></param>
  981. /// <param name="e"></param>
  982. private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
  983. {
  984. string orderModelNo = ultraGrid1.ActiveRow.Cells["ORDER_MODEL_NO"].Value.ToString();
  985. BindOrderModelItem(orderModelNo);
  986. //编辑区,Tab页面切换到合同范本主界面,并给编辑区Tab页面赋值。
  987. ultraTabControl1.Tabs[0].Selected = true;
  988. //编辑区控件赋值。
  989. //cmbSy.Value = ultraGrid1.ActiveRow.Cells["USE_UNIT"].Value.ToString();
  990. VName = ultraGrid1.ActiveRow.Cells["ORDER_MODEL_DESC"].Value.ToString();
  991. txtNM.Text = VName;
  992. chkTy.Checked = Convert.ToBoolean(ultraGrid1.ActiveRow.Cells["GENERAL_FL"].Value);
  993. chkFb.Checked = Convert.ToBoolean(ultraGrid1.ActiveRow.Cells["CUSTOMER_MODEL_FL"].Value);
  994. //子表不聚焦,聚焦编辑区会切换到子表编辑区。
  995. ultraGrid2.ActiveRow = null;
  996. txtXh.Text = "";
  997. txtTmDetails.Text = "";
  998. }
  999. /// <summary>
  1000. /// 绑定范本条目数据源
  1001. /// </summary>
  1002. private void BindOrderModelItem(string orderModelNo)
  1003. {
  1004. DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderModel.GetOrderModelItem", new Object[] { orderModelNo }, this.ob);
  1005. GridHelper.CopyDataToDatatable(ref dt, ref this.dataTable2, true);
  1006. //不同颜色区分是否有效数据
  1007. Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
  1008. for (int i = 0; i < ultraGrid2.Rows.Count; i++)
  1009. {
  1010. row = ultraGrid2.Rows[i];
  1011. if (!row.Cells["VALIDFLAG"].Value.ToString().Equals("1"))
  1012. {
  1013. row.Cells["VALIDFLAG"].Value = false;
  1014. row.Appearance.ForeColor = Color.Red;
  1015. }
  1016. else
  1017. {
  1018. row.Cells["VALIDFLAG"].Value = true;
  1019. row.Appearance.ForeColor = Color.Black;
  1020. }
  1021. }
  1022. }
  1023. private void ultraGrid2_AfterRowActivate(object sender, EventArgs e)
  1024. {
  1025. ultraTabControl1.Tabs[1].Selected = true;
  1026. VName_Item = ultraGrid2.ActiveRow.Cells["MODEL_SEQ"].Value.ToString();
  1027. txtXh.Text = VName_Item;
  1028. txtTmDetails.Text = ultraGrid2.ActiveRow.Cells["MODEL_ITM_VAL"].Value.ToString();
  1029. }
  1030. }
  1031. }