FrmPriceFactor.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. using com.steering.pss.sale.price.entity;
  2. using Core.Mes.Client.Comm.Server;
  3. using Core.Mes.Client.Comm.Tool;
  4. using CoreFS.CA06;
  5. using Infragistics.Win.UltraWinEditors;
  6. using Infragistics.Win.UltraWinGrid;
  7. using System;
  8. using System.Collections;
  9. using System.Collections.Generic;
  10. using System.ComponentModel;
  11. using System.Data;
  12. using System.Drawing;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Windows.Forms;
  16. namespace Core.StlMes.Client.SalePrice.BaseForm
  17. {
  18. public partial class FrmPriceFactor : FrmBase
  19. {
  20. public FrmPriceFactor()
  21. {
  22. InitializeComponent();
  23. }
  24. string isValid = "1";
  25. private void FrmPriceFactor_Load(object sender, EventArgs e)
  26. {
  27. EntityHelper.ShowGridCaption<SlmPriceFactorEntity>(gdFactor.DisplayLayout.Bands[0]);
  28. InitForm();
  29. }
  30. /// <summary>
  31. /// 初始化数据
  32. /// </summary>
  33. private void InitForm()
  34. {
  35. UltraComboEditor uce = new UltraComboEditor();
  36. SalePriceClass.InitComboEditor(uce, "com.steering.pss.sale.price.server.CorePriceFactor.queryTableName", "TABLE_NAME", this.ob, false);
  37. gdFactor.DisplayLayout.Bands[0].Columns["TABLENAME"].EditorComponent = uce;
  38. gdFactor.DisplayLayout.Bands[0].Columns["TABLENAME"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
  39. this.Controls.Add(uce);
  40. uce.Visible = false;
  41. UltraComboEditor uce1 = new UltraComboEditor();
  42. SalePriceClass.InitComboEditorWithParm(uce1, "com.steering.pss.sale.price.server.CorePriceFactor.queryBaseInfo", "BASECODE", "BASENAME", this.ob, true, new object[] { "1228" });
  43. gdFactor.DisplayLayout.Bands[0].Columns["VERTYPE"].EditorComponent = uce1;
  44. gdFactor.DisplayLayout.Bands[0].Columns["VERTYPE"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
  45. this.Controls.Add(uce1);
  46. uce1.Visible = false;
  47. }
  48. public override void ToolBar_Click(object sender, string ToolbarKey)
  49. {
  50. switch (ToolbarKey)
  51. {
  52. case "Query":
  53. QueryData();
  54. break;
  55. case "Save":
  56. SaveFormData();
  57. break;
  58. case "Delete":
  59. DeleteOrResume(true);
  60. break;
  61. case "Resume":
  62. DeleteOrResume(false);
  63. break;
  64. case "Close":
  65. this.Close();
  66. break;
  67. }
  68. }
  69. /// <summary>
  70. /// 初始化行事件
  71. /// </summary>
  72. /// <param name="sender"></param>
  73. /// <param name="e"></param>
  74. private void gdFactor_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
  75. {
  76. if (e.Row != null)
  77. {
  78. string tabName = e.Row.Cells["TABLENAME"].Value.ToString();
  79. UltraComboEditor uce = new UltraComboEditor();
  80. SalePriceClass.InitComboEditorWithParm(uce, "com.steering.pss.sale.price.server.CorePriceFactor.queryColumnName", "COLUMN_NAME", "COLUMN_NAME", this.ob, false, new object[] { tabName });
  81. gdFactor.DisplayLayout.Bands[0].Columns["COLUMNKEY"].EditorComponent = uce;
  82. gdFactor.DisplayLayout.Bands[0].Columns["COLUMNKEY"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
  83. this.Controls.Add(uce);
  84. uce.Visible = false;
  85. if (e.Row.Cells["VALIDFLAG"].Value.ToString() == "无效")
  86. {
  87. e.Row.Appearance.ForeColor = Color.Red;
  88. }
  89. else
  90. {
  91. e.Row.Appearance.ForeColor = Color.Black;
  92. }
  93. }
  94. }
  95. /// <summary>
  96. /// CellChange事件
  97. /// </summary>
  98. /// <param name="sender"></param>
  99. /// <param name="e"></param>
  100. private void gdFactor_CellChange(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e)
  101. {
  102. gdFactor.UpdateData();
  103. if (e.Cell.Column.Key.ToUpper().Equals("COLUMNKEY"))
  104. {
  105. string tabName = e.Cell.Row.Cells["TABLENAME"].Value.ToString();
  106. string colName = e.Cell.Value.ToString();
  107. DataTable dt = ServerHelper.GetData("com.steering.pss.sale.price.server.CorePriceFactor.queryColumnType", new object[] { tabName, colName }, this.ob);
  108. if (dt != null && dt.Rows.Count > 0)
  109. {
  110. string dataType = dt.Rows[0][0].ToString2().ToUpper();
  111. e.Cell.Row.Cells["COLUMNTYPE"].Value = SalePriceClass.GetColumnType(dataType);
  112. }
  113. else
  114. {
  115. e.Cell.Row.Cells["COLUMNTYPE"].Value = "";
  116. }
  117. }
  118. else if (e.Cell.Column.Key.ToUpper().Equals("CHK"))
  119. {
  120. if (Convert.ToBoolean(e.Cell.Value))
  121. {
  122. e.Cell.Row.Cells["FACTORNAME"].Activation = Activation.AllowEdit;
  123. e.Cell.Row.Cells["TABLENAME"].Activation = Activation.AllowEdit;
  124. e.Cell.Row.Cells["COLUMNKEY"].Activation = Activation.AllowEdit;
  125. e.Cell.Row.Cells["VALSQL"].Activation = Activation.AllowEdit;
  126. e.Cell.Row.Cells["VERTYPE"].Activation = Activation.AllowEdit;
  127. }
  128. else
  129. {
  130. e.Cell.Row.Cells["FACTORNAME"].Activation = Activation.ActivateOnly;
  131. e.Cell.Row.Cells["TABLENAME"].Activation = Activation.ActivateOnly;
  132. e.Cell.Row.Cells["COLUMNKEY"].Activation = Activation.ActivateOnly;
  133. e.Cell.Row.Cells["VALSQL"].Activation = Activation.ActivateOnly;
  134. e.Cell.Row.Cells["VERTYPE"].Activation = Activation.ActivateOnly;
  135. }
  136. }
  137. else if (e.Cell.Column.Key.ToUpper().Equals("TABLENAME"))
  138. {
  139. e.Cell.Row.Cells["COLUMNKEY"].Value = "";
  140. }
  141. }
  142. /// <summary>
  143. /// 激活事件
  144. /// </summary>
  145. /// <param name="sender"></param>
  146. /// <param name="e"></param>
  147. private void gdFactor_AfterRowActivate(object sender, EventArgs e)
  148. {
  149. UltraGridRow uRow = gdFactor.ActiveRow;
  150. if (uRow != null)
  151. {
  152. gdFactor.UpdateData();
  153. if (Convert.ToBoolean(uRow.Cells["CHK"].Value))
  154. {
  155. uRow.Cells["FACTORNAME"].Activation = Activation.AllowEdit;
  156. uRow.Cells["TABLENAME"].Activation = Activation.AllowEdit;
  157. uRow.Cells["COLUMNKEY"].Activation = Activation.AllowEdit;
  158. uRow.Cells["VALSQL"].Activation = Activation.AllowEdit;
  159. uRow.Cells["VERTYPE"].Activation = Activation.AllowEdit;
  160. }
  161. else
  162. {
  163. uRow.Cells["FACTORNAME"].Activation = Activation.ActivateOnly;
  164. uRow.Cells["TABLENAME"].Activation = Activation.ActivateOnly;
  165. uRow.Cells["COLUMNKEY"].Activation = Activation.ActivateOnly;
  166. uRow.Cells["VALSQL"].Activation = Activation.ActivateOnly;
  167. uRow.Cells["VERTYPE"].Activation = Activation.ActivateOnly;
  168. }
  169. }
  170. }
  171. /// <summary>
  172. /// 插入一行时
  173. /// </summary>
  174. /// <param name="sender"></param>
  175. /// <param name="e"></param>
  176. private void gdFactor_AfterRowInsert(object sender, RowEventArgs e)
  177. {
  178. string maxId = gdFactor.Rows.AsQueryable().Max(a => a.Cells["FACTORID"].Value.ToString());
  179. if (maxId == "")
  180. {
  181. e.Row.Cells["FACTORID"].Value = "F000001";
  182. }
  183. else
  184. {
  185. string str = "F" + (Convert.ToInt32(maxId.Substring(1, 6)) + 1).ToString().PadLeft(6, '0');
  186. e.Row.Cells["FACTORID"].Value = str;
  187. }
  188. }
  189. /// <summary>
  190. /// 保存界面数据
  191. /// </summary>
  192. private void SaveFormData()
  193. {
  194. gdFactor.UpdateData();
  195. UltraGridRow[] row = gdFactor.Rows.AsQueryable().Where(a => a.Cells["CHK"].Value.ToString().ToUpper() == "TRUE").ToArray();
  196. if (row.Length <= 0)
  197. {
  198. MessageUtil.ShowWarning("请选择需要保存的数据!");
  199. return;
  200. }
  201. ArrayList parm = CheckFormData(row);
  202. if (parm == null || parm.Count <= 0)
  203. {
  204. return;
  205. }
  206. if (MessageUtil.ShowYesNoAndQuestion("是否确认保存数据!") == DialogResult.No) return;
  207. CoreClientParam ccp = new CoreClientParam();
  208. ccp.IfShowErrMsg = false;
  209. ccp.ServerName = "com.steering.pss.sale.price.server.CorePriceFactor";
  210. ccp.MethodName = "saveData";
  211. ccp.ServerParams = new object[] { parm, UserInfo.GetUserName() };
  212. ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  213. if (ccp != null)
  214. {
  215. if (ccp.ReturnCode == -1)
  216. {
  217. MessageUtil.ShowWarning(ccp.ReturnInfo);
  218. return;
  219. }
  220. MessageUtil.ShowTips("数据保存成功!");
  221. QueryData();
  222. }
  223. }
  224. /// <summary>
  225. /// 验证界面数据
  226. /// </summary>
  227. /// <param name="row">界面数据</param>
  228. /// <returns></returns>
  229. private ArrayList CheckFormData(UltraGridRow[] row)
  230. {
  231. ArrayList parm = new ArrayList();
  232. List<string> list = new List<string>();
  233. foreach (var uRow in row)
  234. {
  235. SlmPriceFactorEntity spf = (SlmPriceFactorEntity)uRow.ListObject;
  236. if (spf.Validflag == "无效" && spf.CreateName != "")
  237. {
  238. MessageUtil.ShowWarning("【" + spf.FactorId + "】的因素已经无效,不能修改!");
  239. return null;
  240. }
  241. if (spf.FactorName == "")
  242. {
  243. MessageUtil.ShowWarning("请输入【" + spf.FactorId + "】的因素名称!");
  244. return null;
  245. }
  246. //if (spf.TableName == "")
  247. //{
  248. // MessageUtil.ShowWarning("请选择【" + spf.FactorId + "】的表名!");
  249. // return null;
  250. //}
  251. //if (spf.ColumnKey == "")
  252. //{
  253. // MessageUtil.ShowWarning("请选择【" + spf.FactorId + "】的字段KEY!");
  254. // return null;
  255. //}
  256. if (spf.VerType == "")
  257. {
  258. MessageUtil.ShowWarning("请选择【" + spf.FactorId + "】的版本类型!");
  259. return null;
  260. }
  261. //判断因素名称是否重复
  262. if (spf.Validflag == "") //新增
  263. {
  264. DataTable dt = ServerHelper.GetData("com.steering.pss.sale.price.server.CorePriceFactor.queryFacNameByName", new object[] { spf.FactorName }, this.ob);
  265. if (dt != null && dt.Rows.Count >= 1)
  266. {
  267. MessageUtil.ShowWarning("【" + spf.FactorId + "】您输入的因素名称【" + spf.FactorName + "】已存在!");
  268. return null;
  269. }
  270. }
  271. else
  272. {
  273. DataTable dt = ServerHelper.GetData("com.steering.pss.sale.price.server.CorePriceFactor.queryFacNameById", new object[] { spf.FactorId }, this.ob);
  274. if (dt != null && dt.Rows.Count > 0)
  275. {
  276. if (spf.FactorName != dt.Rows[0][0].ToString())
  277. {
  278. DataTable dt1 = ServerHelper.GetData("com.steering.pss.sale.price.server.CorePriceFactor.queryFacNameByName", new object[] { spf.FactorName }, this.ob);
  279. if (dt1 != null && dt1.Rows.Count >= 1)
  280. {
  281. MessageUtil.ShowWarning("【" + spf.FactorId + "】您输入的因素名称【" + spf.FactorName + "】已存在!");
  282. return null;
  283. }
  284. }
  285. }
  286. }
  287. if (list.Contains(spf.FactorName))
  288. {
  289. MessageUtil.ShowWarning("输入的因素名称重复!");
  290. return null;
  291. }
  292. else
  293. {
  294. list.Add(spf.FactorName);
  295. }
  296. parm.Add(spf);
  297. }
  298. return parm;
  299. }
  300. /// <summary>
  301. /// 查询
  302. /// </summary>
  303. private void QueryData()
  304. {
  305. string facId = "";
  306. string facName = "";
  307. if (labelTextBox1.Checked)
  308. facName = labelTextBox1.Text.Trim();
  309. if (labelTextBox2.Checked)
  310. facId = labelTextBox2.Text.Trim();
  311. List<SlmPriceFactorEntity> list = EntityHelper.GetData<SlmPriceFactorEntity>(
  312. "com.steering.pss.sale.price.server.CorePriceFactor.query", new object[] { facId, facName, isValid }, this.ob);
  313. slmPriceFactorEntityBindingSource.DataSource = list;
  314. }
  315. private void chkValid_CheckedChanged(object sender, EventArgs e)
  316. {
  317. if (chkValid.Checked)
  318. {
  319. isValid = "0";
  320. }
  321. else
  322. {
  323. isValid = "1";
  324. }
  325. }
  326. /// <summary>
  327. /// 删除或恢复
  328. /// </summary>
  329. /// <param name="flag"></param>
  330. private void DeleteOrResume(bool flag)
  331. {
  332. gdFactor.UpdateData();
  333. UltraGridRow[] row = gdFactor.Rows.AsQueryable().Where(a => a.Cells["CHK"].Value.ToString() == "True").ToArray();
  334. if (row.Length <= 0)
  335. {
  336. MessageUtil.ShowWarning("请选择需要" + (flag ? "删除" : "恢复") + "的数据!");
  337. return;
  338. }
  339. ArrayList parm = new ArrayList();
  340. if (flag)
  341. {
  342. foreach (var uRow in row)
  343. {
  344. SlmPriceFactorEntity spf = (SlmPriceFactorEntity)uRow.ListObject;
  345. if (spf.Validflag == "无效")
  346. {
  347. MessageUtil.ShowWarning("您勾选的数据中存在已删除的数据,不必重复删除!");
  348. return;
  349. }
  350. parm.Add(spf.FactorId);
  351. }
  352. }
  353. else
  354. {
  355. foreach (var uRow in row)
  356. {
  357. SlmPriceFactorEntity spf = (SlmPriceFactorEntity)uRow.ListObject;
  358. if (spf.Validflag == "有效")
  359. {
  360. MessageUtil.ShowWarning("您勾选的数据中存在有效的数据,不必进行恢复!");
  361. return;
  362. }
  363. //恢复前判断是否存在相同因素名称的数据
  364. DataTable dt = ServerHelper.GetData("com.steering.pss.sale.price.server.CorePriceFactor.canResume", new object[] { spf.FactorId, spf.FactorName }, this.ob);
  365. if (dt != null && dt.Rows.Count > 0)
  366. {
  367. MessageUtil.ShowWarning("系统已存在名称为【" + spf.FactorName + "】并且有效的因素,不能恢复!");
  368. return;
  369. }
  370. parm.Add(spf.FactorId);
  371. }
  372. }
  373. if (MessageUtil.ShowYesNoAndQuestion("是否" + (flag ? "删除" : "恢复") + "所选的数据!") == DialogResult.No) return;
  374. CoreClientParam ccp = new CoreClientParam();
  375. ccp.ServerName = "com.steering.pss.sale.price.server.CorePriceFactor";
  376. ccp.MethodName = "deleteOrResume";
  377. ccp.ServerParams = new object[] { parm, UserInfo.GetUserName(), flag };
  378. ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  379. if (ccp != null)
  380. {
  381. if (ccp.ReturnCode != -1)
  382. {
  383. MessageUtil.ShowTips("数据" + (flag ? "删除" : "恢复") + "成功!");
  384. QueryData();
  385. }
  386. }
  387. }
  388. }
  389. }