FrmPurOilCardBudget.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using com.hnshituo.pur.vo;
  11. using Core.Mes.Client.Comm.Control;
  12. using Core.Mes.Client.Comm.Server;
  13. using Core.Mes.Client.Comm.Tool;
  14. using CoreFS.CA06;using Pur.Entity;
  15. using Infragistics.Win;
  16. using Infragistics.Win.UltraWinEditors;
  17. using Infragistics.Win.UltraWinGrid;
  18. using CoreFS.SF01;
  19. using Pur.Pop_upWindow;
  20. using Pur.configure;
  21. using Pur.PublicTools;
  22. namespace Pur.require_plan
  23. {
  24. public partial class FrmPurOilCardBudget : FrmPmsBase
  25. {
  26. public FrmPurOilCardBudget()
  27. {
  28. InitializeComponent();
  29. this.IsLoadUserView = true;
  30. }
  31. private void FrmPurOilCardBudget_Load(object sender, EventArgs e)
  32. {
  33. Init();
  34. GridHelper.SetExcludeColumnsActive(ultraGrid2.DisplayLayout.Bands[0], new string[] { });
  35. PublicPur.InitCellEdit(new UltraGrid[] { ultraGrid1 }, new string[] { "CHK","M1", "M2", "M3", "M4", "M5", "M6", "M7", "M8", "M9", "M10", "M11", "M12","REMARK"});
  36. PublicPur.InitCellPositionRight(new UltraGrid[] { ultraGrid1 }, new string[] { "M1", "M2", "M3", "M4", "M5", "M6", "M7", "M8", "M9", "M10", "M11", "M12" });
  37. PublicPur.InitColumnShowLength(new UltraGrid[] { ultraGrid1 }, 0, new string[] { "M1", "M2", "M3", "M4", "M5", "M6", "M7", "M8", "M9", "M10", "M11", "M12" }, 0, false);
  38. PublicPur.SetupSummaryHeade(new String[] { "Count", "Sum", "Sum", "Sum", "Sum", "Sum", "Sum", "Sum", "Sum", "Sum", "Sum", "Sum", "Sum" }, new String[] { "共{0}条", "{0}", "{0}", "{0}", "{0}", "{0}", "{0}", "{0}", "{0}", "{0}", "{0}", "{0}", "{0}" }, new string[] { "CARDDID", "M1", "M2", "M3", "M4", "M5", "M6", "M7", "M8", "M9", "M10", "M11", "M12" }, this.ultraGrid1.DisplayLayout.Bands[0], SummaryDisplayAreas.BottomFixed);
  39. PublicPur.SetupSummaryHeade(new String[] { "Count" }, new String[] { "共{0}条" }, new string[] { "Id" }, this.ultraGrid2.DisplayLayout.Bands[0], SummaryDisplayAreas.BottomFixed);
  40. Qstatus.SelectedIndex = 0;
  41. txt_type1_M.SelectedIndex = 0;
  42. ck_is_all.Checked = false;
  43. }
  44. string errMsg = "";
  45. public List<CoreAppDepartment> _dtOrg = new List<CoreAppDepartment>();
  46. DataTable dt1;//部门信息
  47. #region toolbar工具栏
  48. /// <summary>
  49. /// toolbar
  50. /// </summary>
  51. /// <param name="sender"></param>
  52. /// <param name="ToolbarKey"></param>
  53. public override void ToolBar_Click(object sender, string ToolbarKey)
  54. {
  55. switch (ToolbarKey)
  56. {
  57. case "Query":
  58. Query();
  59. break;
  60. case "Save":
  61. DoSave();
  62. break;
  63. //case "Delete":
  64. // DeleteOrResume(true);
  65. // break;
  66. //case "Resume":
  67. // DeleteOrResume(false);
  68. // break;
  69. case "Refresh":
  70. doQuery_d("");
  71. break;
  72. case "Close":
  73. this.Close();
  74. break;
  75. case "Copy":
  76. CopyData();
  77. break;
  78. case "UltraGridToExcel":
  79. UltraGridToExcel();
  80. break;
  81. }
  82. }
  83. private void UltraGridToExcel()
  84. {
  85. try
  86. {
  87. this.Cursor = Cursors.Default;
  88. if (ultraGrid1.Rows.Count <= 0)
  89. {
  90. MessageUtil.ShowTips("无可导出的充值标准!");
  91. return;
  92. }
  93. ArrayList alUltraGrid = new ArrayList();
  94. alUltraGrid.Add(ultraGrid1);
  95. ArrayList alSheeft = new ArrayList();
  96. alSheeft.Add("充值标准");
  97. GridHelper.ulGridToExcel(alUltraGrid, alSheeft, "充值标准明细");
  98. }
  99. catch (Exception e)
  100. {
  101. MessageUtil.ShowTips("导出失败" + e.Message);
  102. }
  103. finally
  104. {
  105. this.Cursor = Cursors.Default;
  106. }
  107. }
  108. #endregion
  109. #region toolbar事件
  110. /// <summary>
  111. /// 查询
  112. /// </summary>
  113. /// <param name="Tips"></param>
  114. private void Query()
  115. {
  116. try
  117. {
  118. this.Cursor = Cursors.WaitCursor;
  119. cardM.Clear();
  120. dataSet1.Clear();
  121. OilCardM cardM1 = new OilCardM();
  122. cardM1.OilCardMId = txt_Card_No_M.Text.Trim();
  123. cardM1.UserOrgName = txt_org_name.Text.Trim();
  124. if (txt_type1_M.SelectedIndex != -1)
  125. {
  126. cardM1.Type = txt_type1_M.Value.ToString().Trim();
  127. }
  128. cardM1.DeleteUserid = txt_cardMD_no.Text.Trim();
  129. cardM1.UpdateUserid = txt_User_name1.Text.Trim();
  130. DataTable dt = this.execute<DataTable>("com.hnshituo.pur.requireplan.service.OilCardMService", "find_CardM", new object[] { cardM1 });
  131. if (dt != null)
  132. {
  133. GridHelper.CopyDataToDatatable(ref dt, ref dataTable2, true);
  134. GridHelper.RefreshAndAutoSize(ultraGrid2);
  135. }
  136. }
  137. catch (Exception ex)
  138. {
  139. MessageUtil.ShowError("加载数据失败;" + ex);
  140. }
  141. finally
  142. {
  143. this.Cursor = Cursors.Default;
  144. }
  145. }
  146. ///// <summary>
  147. ///// 作废和恢复
  148. ///// </summary>
  149. ///// <param name="tips"></param>
  150. //private void DeleteOrResume(bool tips)
  151. //{
  152. // ultraGrid1.UpdateData();
  153. // ArrayList list = new ArrayList();
  154. // //作废
  155. // if(tips==true)
  156. // {
  157. // foreach (UltraGridRow row in ultraGrid1.Rows)
  158. // {
  159. // if (Convert.ToBoolean(row.Cells["CHK"].Value))
  160. // {
  161. // OilBudget res = new OilBudget();
  162. // String strId=row.Cells["ID"].Value.ToString().Trim();
  163. // String strValidFlag = "0";
  164. // res.Id = strId;
  165. // res.Validflag = strValidFlag;
  166. // res.DeleteName = UserInfo.GetUserName();
  167. // res.DeleteTime = new DateTime();
  168. // res.DeleteUserid = UserInfo.GetUserID();
  169. // if (!String.IsNullOrEmpty(strId))
  170. // {
  171. // list.Add(res);
  172. // }
  173. // }
  174. // }
  175. // if (list.Count <=0)
  176. // {
  177. // MessageUtil.ShowWarning("请选择需要操作的记录! PS:主键为空的油卡表示未维护该用户年度每月充值标准");
  178. // return;
  179. // }
  180. // if (MessageBox.Show("是否确认作废数据?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  181. // return;
  182. // CoreResult re = this.execute<CoreResult>("com.hnshituo.pur.requireplan.service.OilBudgetService", "doDeleteOrResume", new object[] { list, 0, 0 });
  183. // if (re.Resultcode == 0)
  184. // {
  185. // MessageUtil.ShowTips("操作成功!");
  186. // Query();
  187. // OilBudget strbdg = (OilBudget)list[0];
  188. // string stroldId = strbdg.Id;
  189. // ConfigureClassCommon.doActiveSelRow(ultraGrid2, "ID", stroldId);
  190. // }
  191. // else
  192. // {
  193. // MessageUtil.ShowTips("操作失败:" + re.Resultmsg);
  194. // }
  195. // }
  196. // //恢复
  197. // if(tips==false)
  198. // {
  199. // foreach (UltraGridRow row in ultraGrid1.Rows)
  200. // {
  201. // if (Convert.ToBoolean(row.Cells["CHK"].Value))
  202. // {
  203. // OilBudget res = new OilBudget();
  204. // String strId = row.Cells["ID"].Value.ToString().Trim();
  205. // String strValidFlag = "1";
  206. // res.Id = strId;
  207. // res.Validflag = strValidFlag;
  208. // res.UpdateName = UserInfo.GetUserName();
  209. // res.UpdateTime = new DateTime();
  210. // res.UpdateUserid = UserInfo.GetUserID();
  211. // if (!String.IsNullOrEmpty(strId))
  212. // {
  213. // list.Add(res);
  214. // }
  215. // }
  216. // }
  217. // if (list.Count <= 0)
  218. // {
  219. // MessageUtil.ShowWarning("请选择需要操作的记录! PS:主键为空的油卡表示未维护该用户年度月充值标准)");
  220. // return;
  221. // }
  222. // if (MessageBox.Show("是否确认恢复数据?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  223. // return;
  224. // CoreResult re = this.execute<CoreResult>("com.hnshituo.pur.requireplan.service.OilBudgetService", "doDeleteOrResume", new object[] { list, 0, 0 });
  225. // if (re.Resultcode == 0)
  226. // {
  227. // MessageUtil.ShowTips("操作成功!");
  228. // Query();
  229. // OilBudget strbdg = (OilBudget)list[0];
  230. // string stroldId = strbdg.Id;
  231. // ConfigureClassCommon.doActiveSelRow(ultraGrid2, "ID", stroldId);
  232. // }
  233. // else
  234. // {
  235. // MessageUtil.ShowTips("操作失败:" + re.Resultmsg);
  236. // }
  237. // }
  238. //}
  239. /// <summary>
  240. /// 保存
  241. /// </summary>
  242. private void DoSave()
  243. {
  244. try
  245. {
  246. ultraGrid1.UpdateData();
  247. int i = 0;
  248. ArrayList list = new ArrayList();
  249. foreach (UltraGridRow row in ultraGrid1.Rows)
  250. {
  251. if (Convert.ToBoolean(row.Cells["CHK"].Value))
  252. {
  253. i++;
  254. OilBudget res = new OilBudget();
  255. String strDId = row.Cells["DID"].Value.ToString().Trim();
  256. String strId = row.Cells["ID"].Value.ToString().Trim();
  257. String strYEAR = Qyear.Text.Trim();
  258. String strM1 = row.Cells["M1"].Value.ToString().Trim() == "" ? "0" : row.Cells["M1"].Value.ToString().Trim();
  259. String strM2 = row.Cells["M2"].Value.ToString().Trim() == "" ? "0" : row.Cells["M2"].Value.ToString().Trim();
  260. String strM3 = row.Cells["M3"].Value.ToString().Trim() == "" ? "0" : row.Cells["M3"].Value.ToString().Trim();
  261. String strM4 = row.Cells["M4"].Value.ToString().Trim() == "" ? "0" : row.Cells["M4"].Value.ToString().Trim();
  262. String strM5 = row.Cells["M5"].Value.ToString().Trim() == "" ? "0" : row.Cells["M5"].Value.ToString().Trim();
  263. String strM6 = row.Cells["M6"].Value.ToString().Trim() == "" ? "0" : row.Cells["M6"].Value.ToString().Trim();
  264. String strM7 = row.Cells["M7"].Value.ToString().Trim() == "" ? "0" : row.Cells["M7"].Value.ToString().Trim();
  265. String strM8 = row.Cells["M8"].Value.ToString().Trim() == "" ? "0" : row.Cells["M8"].Value.ToString().Trim();
  266. String strM9 = row.Cells["M9"].Value.ToString().Trim() == "" ? "0" : row.Cells["M9"].Value.ToString().Trim();
  267. String strM10 = row.Cells["M10"].Value.ToString().Trim() == "" ? "0" : row.Cells["M10"].Value.ToString().Trim();
  268. String strM11 = row.Cells["M11"].Value.ToString().Trim() == "" ? "0" : row.Cells["M11"].Value.ToString().Trim();
  269. String strM12 = row.Cells["M12"].Value.ToString().Trim() == "" ? "0" : row.Cells["M12"].Value.ToString().Trim();
  270. String strREMARK = row.Cells["REMARK"].Value.ToString().Trim();
  271. String strVALIDFLAG = row.Cells["VALIDFLAG"].Value.ToString().Trim();
  272. res.Did = strDId;
  273. res.Id = strId;
  274. res.Year = strYEAR;
  275. res.M1 = Convert.ToDouble(strM1);
  276. res.M2 = Convert.ToDouble(strM2);
  277. res.M3 = Convert.ToDouble(strM3);
  278. res.M4 = Convert.ToDouble(strM4);
  279. res.M5 = Convert.ToDouble(strM5);
  280. res.M6 = Convert.ToDouble(strM6);
  281. res.M7 = Convert.ToDouble(strM7);
  282. res.M8 = Convert.ToDouble(strM8);
  283. res.M9 = Convert.ToDouble(strM9);
  284. res.M10 = Convert.ToDouble(strM10);
  285. res.M11 = Convert.ToDouble(strM11);
  286. res.M12 = Convert.ToDouble(strM12);
  287. res.Validflag = strVALIDFLAG;
  288. res.Remark = strREMARK;
  289. if (res == null)
  290. return;
  291. if (!TestData(res))
  292. {
  293. MessageUtil.ShowWarning(errMsg);
  294. return;
  295. }
  296. if (res.Id.Equals(""))
  297. {
  298. res.CreateName = UserInfo.GetUserName();
  299. res.CreateTime = DateTime.Now;
  300. res.CreateUserid = UserInfo.GetUserID();
  301. }
  302. else
  303. {
  304. res.UpdateName = UserInfo.GetUserName();
  305. res.UpdateTime = DateTime.Now;
  306. res.UpdateUserid = UserInfo.GetUserID();
  307. }
  308. list.Add(res);
  309. }
  310. }
  311. if (i == 0)
  312. {
  313. MessageUtil.ShowWarning("请选择需要操作的记录!");
  314. return;
  315. }
  316. if (MessageBox.Show("是否确认保存数据?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  317. return;
  318. CoreResult re = this.execute<CoreResult>("com.hnshituo.pur.requireplan.service.OilBudgetService", "doSave", new object[] { list, 0, 0 });
  319. if (re.Resultcode == 0)
  320. {
  321. MessageUtil.ShowTips("数据保存成功!");
  322. Query();
  323. OilBudget strbdg = (OilBudget)list[0];
  324. string stroldId = strbdg.Id;
  325. ConfigureClassCommon.doActiveSelRow(ultraGrid1, "ID", stroldId);
  326. }
  327. else
  328. {
  329. MessageUtil.ShowTips("保存失败:" + re.Resultmsg);
  330. }
  331. }
  332. catch (Exception ex)
  333. {
  334. MessageUtil.ShowError("保存失败:"+ex);
  335. }
  336. }
  337. /// <summary>
  338. /// 复制旧数据到指定年份
  339. /// </summary>
  340. private void CopyData()//复制旧数据
  341. {
  342. try
  343. {
  344. //不能有重复的部门
  345. //不能有指定年份的数据
  346. ultraGrid1.UpdateData();
  347. int i = 0;
  348. ArrayList list = new ArrayList();
  349. foreach (UltraGridRow row in ultraGrid1.Rows)
  350. {
  351. if (Convert.ToBoolean(row.Cells["CHK"].Value))
  352. {
  353. i++;
  354. OilBudget res = new OilBudget();
  355. String strId = row.Cells["ID"].Value.ToString().Trim();
  356. if (String.IsNullOrEmpty(strId))
  357. {
  358. continue;
  359. }
  360. res.Id = strId;
  361. res.UpdateName = UserInfo.GetUserName();
  362. res.UpdateTime = DateTime.Now;
  363. res.UpdateUserid = UserInfo.GetUserID();
  364. list.Add(res);
  365. }
  366. }
  367. if (i == 0)
  368. {
  369. MessageUtil.ShowWarning("请选择需要操作的记录!");
  370. return;
  371. }
  372. FrmPopCopyBudgetData frm = new FrmPopCopyBudgetData(this.ob, list,"0");
  373. frm.ShowDialog();
  374. //CoreResult re = this.execute<CoreResult>("com.hnshituo.pur.configure.service.ConfigureOrgBudgetService", "doSave", new object[] { list, 0, 0 });
  375. //if (re.Resultcode == 0)
  376. //{
  377. // MessageUtil.ShowTips("数据保存成功!");
  378. // Query(true);
  379. // ConfigureOrgBudget strbdg = (ConfigureOrgBudget)list[0];
  380. // string stroldId = strbdg.Id;
  381. // ConfigureClassCommon.doActiveSelRow(ultraGrid1, "ID", stroldId);
  382. //}
  383. //else
  384. //{
  385. // MessageUtil.ShowTips("保存失败:" + re.Resultmsg);
  386. //}
  387. }
  388. catch (Exception ex)
  389. {
  390. MessageUtil.ShowError("保存失败:" + ex);
  391. }
  392. }
  393. /// <summary>
  394. /// 按月复制
  395. /// </summary>
  396. private void CopyDataMouth()
  397. {
  398. MessageUtil.ShowTips("权限未开放");
  399. return;
  400. //获取计算哪个月的充值金额
  401. frmPop_selectDate frm = new frmPop_selectDate(this.ob,"1");
  402. frm.ShowDialog();
  403. if (frm.tips == "1")
  404. {
  405. DateTime date = frm.date;
  406. if (date == null)
  407. {
  408. MessageUtil.ShowTips("选择的月份为空");
  409. }
  410. OilBudget res = new OilBudget();
  411. res.DeleteTime = date;
  412. res.CreateName = UserInfo.GetUserName();
  413. res.CreateTime = DateTime.Now;
  414. res.CreateUserid = UserInfo.GetUserID();
  415. CoreResult crt = this.execute<CoreResult>("com.hnshituo.pur.requireplan.service.OilBudgetService", "doCopyByMouth", new object[] { res });
  416. if (crt.Resultcode == 0)
  417. {
  418. MessageUtil.ShowTips("操作成功!");
  419. }
  420. else
  421. {
  422. MessageUtil.ShowTips("操作成功:" + crt.Resultmsg);
  423. doQuery_d("");
  424. }
  425. }
  426. }
  427. #endregion
  428. #region 界面初始化
  429. /// <summary>
  430. /// 初始化控件数据
  431. /// </summary>
  432. private void Init()
  433. {
  434. //绑定年份数据
  435. DataTable dt1 = new DataTable();
  436. dt1.Columns.Add("YEAR", Type.GetType("System.Int32"));
  437. for (int i = DateTime.Now.AddYears(-3).Year; i <= DateTime.Now.AddYears(3).Year; i++)
  438. dt1.Rows.Add(new object[] { i });
  439. Qyear.DataSource = dt1;
  440. Qyear.ValueMember = "YEAR";
  441. Qyear.DisplayMember = "YEAR";
  442. Qyear.Value = DateTime.Now.Year.ToString();
  443. //设置界面不可编辑列
  444. SetColumnsActive(ultraGrid1.DisplayLayout.Bands[0], new string[] {"MID","DID", "VALIDFLAG", "CREATENAME", "CREATETIME", "CREATEUSERID" });
  445. Qstatus.SelectedIndex = 0;
  446. }
  447. #endregion
  448. #region 公共函数
  449. /// <summary>
  450. /// 校验保存填写数据是否满足要求
  451. /// </summary>
  452. /// <param name="res"></param>
  453. /// <returns></returns>
  454. private bool TestData(OilBudget res)
  455. {
  456. try
  457. {
  458. if (res.Validflag.ToString() != "" && res.Validflag.ToString() != "有效" && res.Validflag.ToString() != "未维护")
  459. {
  460. errMsg = "无效数据无法保存!";
  461. return false;
  462. }
  463. if (res.Did.ToString() == "")
  464. {
  465. errMsg = "副卡编号为空!";
  466. return false;
  467. }
  468. if (res.Year.ToString() == "")
  469. {
  470. errMsg = "请选择年份!";
  471. return false;
  472. }
  473. if (!IsNum(res.M1.ToString()))
  474. {
  475. errMsg = "1月充值标准请输入数字!";
  476. return false;
  477. }
  478. if(isrightRange(res.M1.ToString())==false)
  479. {
  480. errMsg = "1月" + errMsg;
  481. return false;
  482. }
  483. if (!IsNum(res.M2.ToString()))
  484. {
  485. errMsg = "2月充值标准请输入数字!";
  486. return false;
  487. }
  488. if (isrightRange(res.M2.ToString()) == false)
  489. {
  490. errMsg = "2月" + errMsg;
  491. return false;
  492. }
  493. if (!IsNum(res.M3.ToString()))
  494. {
  495. errMsg = "3月充值标准请输入数字!";
  496. return false;
  497. }
  498. if (isrightRange(res.M3.ToString()) == false)
  499. {
  500. errMsg = "3月" + errMsg;
  501. return false;
  502. }
  503. if (!IsNum(res.M4.ToString()))
  504. {
  505. errMsg = "4月充值标准请输入数字!";
  506. return false;
  507. }
  508. if (isrightRange(res.M4.ToString()) == false)
  509. {
  510. errMsg = "4月" + errMsg;
  511. return false;
  512. }
  513. if (!IsNum(res.M5.ToString()))
  514. {
  515. errMsg = "5月充值标准请输入数字!";
  516. return false;
  517. }
  518. if (isrightRange(res.M5.ToString()) == false)
  519. {
  520. errMsg = "5月" + errMsg;
  521. return false;
  522. }
  523. if (!IsNum(res.M6.ToString()))
  524. {
  525. errMsg = "6月充值标准请输入数字!";
  526. return false;
  527. }
  528. if (isrightRange(res.M6.ToString()) == false)
  529. {
  530. errMsg = "6月" + errMsg;
  531. return false;
  532. }
  533. if (!IsNum(res.M7.ToString()))
  534. {
  535. errMsg = "7月充值标准请输入数字!";
  536. return false;
  537. }
  538. if (isrightRange(res.M7.ToString()) == false)
  539. {
  540. errMsg = "7月" + errMsg;
  541. return false;
  542. }
  543. if (!IsNum(res.M8.ToString()))
  544. {
  545. errMsg = "8月充值标准请输入数字!";
  546. return false;
  547. }
  548. if (isrightRange(res.M8.ToString()) == false)
  549. {
  550. errMsg = "8月" + errMsg;
  551. return false;
  552. }
  553. if (!IsNum(res.M9.ToString()))
  554. {
  555. errMsg = "9月充值标准请输入数字!";
  556. return false;
  557. }
  558. if (isrightRange(res.M9.ToString()) == false)
  559. {
  560. errMsg = "9月" + errMsg;
  561. return false;
  562. }
  563. if (!IsNum(res.M10.ToString()))
  564. {
  565. errMsg = "10月充值标准请输入数字!";
  566. return false;
  567. }
  568. if (isrightRange(res.M10.ToString()) == false)
  569. {
  570. errMsg = "10月" + errMsg;
  571. return false;
  572. }
  573. if (!IsNum(res.M11.ToString()))
  574. {
  575. errMsg = "11月充值标准请输入数字!";
  576. return false;
  577. }
  578. if (isrightRange(res.M11.ToString()) == false)
  579. {
  580. errMsg = "11月" + errMsg;
  581. return false;
  582. }
  583. if (!IsNum(res.M12.ToString()))
  584. {
  585. errMsg = "12月充值标准请输入数字!";
  586. return false;
  587. }
  588. if (isrightRange(res.M12.ToString()) == false)
  589. {
  590. errMsg = "12月" + errMsg;
  591. return false;
  592. }
  593. if (res.Id.ToString() == "") //新增
  594. {
  595. OilBudget bdg = new OilBudget();
  596. bdg.Did = res.Did;
  597. bdg.Year = res.Year;
  598. int count = this.execute<int>("com.hnshituo.pur.requireplan.service.OilBudgetService", "count", new object[] { bdg });
  599. if (count > 0)
  600. {
  601. errMsg = "副卡编号:" + res.Did + ",年份:" + res.Year + " 对应的年度月充值标准信息已经存在!";
  602. return false;
  603. }
  604. }
  605. else //修改
  606. {
  607. OilBudget bdg = new OilBudget();
  608. bdg.Did = res.Did;
  609. bdg.Year = res.Year;
  610. DataTable dt = this.execute<DataTable>("com.hnshituo.pur.requireplan.service.OilBudgetService", "find", new object[] { bdg, 0, 0 });
  611. if (dt != null && dt.Rows.Count > 0)
  612. {
  613. DataRow[] rows = dt.Select("id<>'" + res.Id + "'");
  614. if (rows.Count() >0)
  615. {
  616. errMsg = "副卡编号:" + res.Did + ",年份:" + res.Year + " 对应的年度月充值标准信息已经存在!";
  617. return false;
  618. }
  619. }
  620. }
  621. return true;
  622. }
  623. catch (Exception ex)
  624. {
  625. errMsg = ex + "";
  626. //MessageUtil.ShowError(""+ex);
  627. return false;
  628. }
  629. }
  630. /// <summary>
  631. /// 判断是否为正数数字
  632. /// </summary>
  633. /// <param name="p"></param>
  634. /// <returns></returns>
  635. private bool IsNum(string str)
  636. {
  637. if (str != "")
  638. {
  639. return StringUtil.IsNumber(str);
  640. }
  641. return true;
  642. }
  643. private bool isrightRange(String str)
  644. {
  645. if (Convert.ToDouble(str) >= 200000 || Convert.ToDouble(str) <= -200000)
  646. {
  647. errMsg = "超出每月充值标准最大上限20万!";
  648. return false;
  649. }
  650. return true;
  651. }
  652. /// <summary>
  653. /// 字符串转是否能转换成非负数
  654. /// </summary>
  655. /// <param name="str"></param>
  656. /// <returns></returns>
  657. public static bool Is_Below_zero(string str)
  658. {
  659. try
  660. {
  661. if (str.Equals(""))
  662. {
  663. return true;
  664. }
  665. else
  666. {
  667. if (StringUtil.IsDouble(str) && double.Parse(str) >= 0)
  668. return true;
  669. else
  670. return false;
  671. }
  672. }
  673. catch
  674. {
  675. return false;
  676. }
  677. }
  678. /// <summary>
  679. /// 设置包含在指定列中的列只读
  680. /// </summary>
  681. /// <param name="band"></param>
  682. /// <param name="columnKeys"></param>
  683. public static void SetColumnsActive(UltraGridBand band, params string[] columnKeys)
  684. {
  685. foreach (UltraGridColumn gridColumn in band.Columns)
  686. {
  687. if (columnKeys.Contains(gridColumn.Key) == true)
  688. {
  689. gridColumn.CellActivation = Activation.ActivateOnly;
  690. }
  691. }
  692. }
  693. /// <summary>
  694. /// 初始化Combox数据,加入数据筛选
  695. /// </summary>
  696. /// <param name="cmbx">ComboBox控件</param>
  697. /// <param name="dt">DataTable</param>
  698. /// <param name="filterCondition">RowFilter条件</param>
  699. public static void FillComboxItems(UltraComboEditor cmbx, DataTable dt, string valueCol, string textCol, string filterCondition)
  700. {
  701. if (dt != null && dt.Rows.Count > 0)
  702. {
  703. DataView dvw = dt.DefaultView;
  704. dvw.RowFilter = filterCondition;
  705. ArrayList aryTmp = new ArrayList();
  706. aryTmp.Add(new ValueListItem(" ", " "));
  707. for (int i = 0; i < dvw.Count; i++)
  708. {
  709. aryTmp.Add(new ValueListItem(dvw[i][valueCol].ToString(), dvw[i][textCol].ToString()));
  710. }
  711. cmbx.DataSource = aryTmp;
  712. cmbx.DisplayMember = "DisplayText";
  713. cmbx.ValueMember = "DataValue";
  714. }
  715. }
  716. /// <summary>
  717. /// 查询定额行
  718. /// </summary>
  719. private void doQuery_d(String CardNo)
  720. {
  721. try
  722. {
  723. dataTable1.Clear();
  724. if (ultraGrid2.ActiveRow == null)
  725. {
  726. return;
  727. }
  728. String strMid = ultraGrid2.ActiveRow.GetCellValue("ID").ToString().Trim();
  729. if (String.IsNullOrEmpty(strMid))
  730. {
  731. MessageUtil.ShowTips("主卡编号为空");
  732. return;
  733. }
  734. OilBudget cardD = new OilBudget();
  735. if (!ck_is_all.Checked)
  736. {
  737. cardD.Mid = strMid;
  738. }
  739. cardD.UserName = String.IsNullOrEmpty(QUse_Name.Text.Trim()) ? txt_User_name1.Text.Trim() : QUse_Name.Text.Trim();
  740. cardD.CardDId = String.IsNullOrEmpty(Qcard_d_no.Text.Trim()) ? txt_cardMD_no.Text.Trim() : Qcard_d_no.Text.Trim();
  741. if(Qyear.SelectedIndex==-1)
  742. {
  743. MessageUtil.ShowTips("请选择年份");
  744. return;
  745. }
  746. if (Qyear.Text.Trim().Length < 4)
  747. {
  748. MessageUtil.ShowTips("请选择的年份格式不正确");
  749. return;
  750. }
  751. cardD.Year=Qyear.Text.Trim();
  752. if (Qstatus.SelectedIndex != -1)
  753. {
  754. cardD.Status = Qstatus.Value.ToString().Trim();
  755. }
  756. DataTable dt = this.execute<DataTable>("com.hnshituo.pur.requireplan.service.OilBudgetService", "cardD_Budget", new object[] { cardD });
  757. if (dt != null)
  758. {
  759. GridHelper.CopyDataToDatatable(ref dt, ref dataTable1, true);
  760. GridHelper.RefreshAndAutoSize(ultraGrid1);
  761. if (String.IsNullOrEmpty(CardNo))
  762. {
  763. publicPms.doActiveSelRow(ultraGrid1, "OILCARDID", CardNo);
  764. }
  765. }
  766. }
  767. catch (Exception ex)
  768. {
  769. MessageUtil.ShowError("加载数据失败;" + ex);
  770. }
  771. }
  772. #endregion
  773. #region 界面事件
  774. private void ultraGrid2_AfterRowActivate(object sender, EventArgs e)
  775. {
  776. doQuery_d("");
  777. }
  778. private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e)
  779. {
  780. if (e.Row.Cells["status"].Value.ToString().Equals("暂停"))
  781. {
  782. e.Row.Appearance.ForeColor = Color.Red;
  783. }
  784. else if (e.Row.Cells["status"].Value.ToString().Equals("注销"))
  785. {
  786. e.Row.Appearance.ForeColor = Color.Gray;
  787. }
  788. else
  789. {
  790. e.Row.Appearance.ForeColor = Color.Black;
  791. }
  792. }
  793. private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
  794. {
  795. ultraGrid1.Update();
  796. UltraGridRow ugr = ultraGrid1.ActiveRow;
  797. if (ugr == null)
  798. return;
  799. if (!Convert.ToBoolean(ugr.Cells["CHK"].Value))
  800. {
  801. for (int i = 0; i < ugr.Cells.Count; i++)
  802. {
  803. if (!ugr.Cells[i].Column.Key.Equals("CHK"))
  804. ugr.Cells[i].Activation = Activation.ActivateOnly;
  805. }
  806. }
  807. else
  808. {
  809. for (int i = 0; i < ugr.Cells.Count; i++)
  810. {
  811. ugr.Cells[i].Activation = Activation.AllowEdit;
  812. }
  813. }
  814. }
  815. private void ultraGrid1_AfterRowInsert(object sender, RowEventArgs e)
  816. {
  817. ultraGrid1.Update();
  818. UltraGridRow ugr = ultraGrid1.ActiveRow;
  819. if (!Convert.ToBoolean(ugr.Cells["CHK"].Value))
  820. {
  821. for (int i = 0; i < ugr.Cells.Count; i++)
  822. {
  823. if (!ugr.Cells[i].Column.Key.Equals("CHK"))
  824. ugr.Cells[i].Activation = Activation.ActivateOnly;
  825. }
  826. }
  827. else
  828. {
  829. for (int i = 0; i < ugr.Cells.Count; i++)
  830. {
  831. ugr.Cells[i].Activation = Activation.AllowEdit;
  832. }
  833. }
  834. }
  835. private void ultraGrid1_CellChange(object sender, CellEventArgs e)
  836. {
  837. if (e.Cell.Column.Key.Equals("M1")||e.Cell.Column.Key.Equals("M2")||e.Cell.Column.Key.Equals("M3")||e.Cell.Column.Key.Equals("M4")||e.Cell.Column.Key.Equals("M5")||e.Cell.Column.Key.Equals("M6")||e.Cell.Column.Key.Equals("M7")||e.Cell.Column.Key.Equals("M8")||e.Cell.Column.Key.Equals("M9")||e.Cell.Column.Key.Equals("M10")||e.Cell.Column.Key.Equals("M11")||e.Cell.Column.Key.Equals("M12"))
  838. {
  839. String sreNumOld = e.Cell.Value.ToString();
  840. ultraGrid1.UpdateData();
  841. String sreNumNew = e.Cell.Value.ToString();
  842. if (!Is_Below_zero(sreNumNew))
  843. {
  844. e.Cell.Value = sreNumOld;
  845. }
  846. }
  847. }
  848. #endregion
  849. #region 行按钮
  850. private void btn_refresh_Click(object sender, EventArgs e)
  851. {
  852. doQuery_d("");
  853. }
  854. #endregion
  855. }
  856. }