FrmPackagesSet.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. using LYFZ.ComponentLibrary;
  2. using System;
  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. namespace LYFZ.Software.MainBusiness.InitialSet
  11. {
  12. public partial class FrmPackagesSet : LYFZ.Software.UI.InitialSet.FrmPackagesSet
  13. {
  14. LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
  15. LYFZ.BLL.BLL_ErpPackages pkbll = new BLL.BLL_ErpPackages();
  16. LYFZ.BLL.BLL_ErpSystemCategory scbll = new BLL.BLL_ErpSystemCategory();
  17. public FrmPackagesSet()
  18. {
  19. this.Load += FrmPackagesSet_Load;
  20. this.Shown += FrmPackagesSet_Shown;
  21. this.listViewData.MouseClick += listViewData_MouseClick;
  22. this.btnClear.Click += btnClear_Click;
  23. this.btnSave.Click += btnSave_Click;
  24. this.btnDelete.Click += btnDelete_Click;
  25. this.txtPak_UnitPrice.KeyPress += txtPak_UnitPrice_KeyPress;
  26. this.CtvSelect.ComboBoxTree_NodeMouseClick += CtvSelect_ComboBoxTree_NodeMouseClick;
  27. this.btnSet.Click += btnSet_Click;
  28. this.btnCloseed.Click += btnCloseed_Click;
  29. }
  30. /// <summary>
  31. /// 套系大类类型
  32. /// </summary>
  33. public int StrPackagesType;
  34. /// <summary>
  35. /// 是否保存
  36. /// </summary>
  37. public bool IsSaveed = false;
  38. /// <summary>
  39. /// 窗体加载事件
  40. /// </summary>
  41. /// <param name="sender"></param>
  42. /// <param name="e"></param>
  43. void FrmPackagesSet_Load(object sender, EventArgs e)
  44. {
  45. string StrColumnName = "";
  46. if (this.StrPackagesType == 1)
  47. {
  48. this.Text = "套系礼包名称设置";
  49. StrColumnName = ",可选几";
  50. }
  51. else
  52. {
  53. this.labelEx1.Visible = false;
  54. this.labelEx5.Visible = false;
  55. this.numOptionalSeveral.Visible = false;
  56. }
  57. this.listViewData.View = View.Details;
  58. this.listViewData.GridLines = true;
  59. ImageList imgList = new ImageList();
  60. imgList.ImageSize = new Size(1, 25);
  61. this.listViewData.SmallImageList = imgList;
  62. string[] StrColumns = (",套系名称,套系价格,状态,套系类别" + StrColumnName).Split(',');
  63. for (int i = 0; i < StrColumns.Length; i++)
  64. {
  65. ColumnHeader ch = new ColumnHeader();
  66. ch.Text = StrColumns[i].Trim();
  67. if (i == 0)
  68. {
  69. ch.Width = 40;
  70. }
  71. else
  72. {
  73. ch.Width = (this.listViewData.Width - 23 - 40) / (StrColumns.Length - 1);
  74. }
  75. switch (StrColumns[i].Trim())
  76. {
  77. case "套系名称":
  78. case "套系类别": ch.TextAlign = HorizontalAlignment.Left; break;
  79. case "套系价格": ch.TextAlign = HorizontalAlignment.Right; break;
  80. case "状态": ch.TextAlign = HorizontalAlignment.Center; break;
  81. default: ch.TextAlign = HorizontalAlignment.Left; break;
  82. }
  83. this.listViewData.Columns.Add(ch);
  84. }
  85. }
  86. /// <summary>
  87. /// 窗体加载事件
  88. /// </summary>
  89. /// <param name="sender"></param>
  90. /// <param name="e"></param>
  91. void FrmPackagesSet_Shown(object sender, EventArgs e)
  92. {
  93. this.PublicFunctionRows();
  94. LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboBoxTreeView_SystemCategory(Enum.GetName(typeof(LYFZ.EnumPublic.EnumPackagesType), StrPackagesType).ToString().Trim(), this.CtvPak_PackagesClass, IsFirstNodeNull: false);
  95. LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboBoxTreeView_SystemCategory(Enum.GetName(typeof(LYFZ.EnumPublic.EnumPackagesType), StrPackagesType).ToString().Trim(), this.CtvSelect, IsFirstNodeNull: true, IsFirstNodeName: "全部");
  96. }
  97. /// <summary>
  98. /// 获取表名
  99. /// </summary>
  100. string GetTableName()
  101. {
  102. return "(select Pak_DividedShop,Pak_PackagesClass,Pak_PackagesID As 套系编号,Pak_Name AS 套系名称,Pak_UnitPrice AS 套系价格,case when Sc_ClassName is null then '' else Sc_ClassName end AS 套系类别," +
  103. "case when Pak_IsDisable = 0 then '显示' else '隐藏' end AS 状态,Pak_OptionalSeveral AS 可选几 from tb_ErpPackages left join tb_ErpSystemCategory on tb_ErpPackages.Pak_PackagesClass=tb_ErpSystemCategory.Sc_ClassCode " +
  104. "Where " + //Pak_DividedShop='" + LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetCompanyInfoID() + "'
  105. " Pak_PackagesMainClass = '" + Enum.GetName(typeof(LYFZ.EnumPublic.EnumPackagesType), StrPackagesType).ToString().Trim() + "') as tb";
  106. }
  107. /// <summary>
  108. /// 绑定数据
  109. /// </summary>
  110. void PublicFunctionRows(string StrWhere = "")
  111. {
  112. DataTable dt = orbll.GetView_Custom(GetTableName(), StrWhere: StrWhere, ShowColumnName: "套系编号,套系名称,套系价格,套系类别,可选几,状态").Tables[0];
  113. this.listViewData.Items.Clear();
  114. for (int i = 0; i < dt.Rows.Count; i++)
  115. {
  116. ListViewItem lvItem = new ListViewItem();
  117. lvItem.Tag = dt.Rows[i]["套系编号"].ToString().Trim();
  118. lvItem.Text = (i + 1).ToString();
  119. ListViewItem.ListViewSubItem ListSubItem = new ListViewItem.ListViewSubItem();
  120. ListSubItem.Name = "套系名称";
  121. ListSubItem.Text = dt.Rows[i]["套系名称"].ToString().Trim();
  122. lvItem.SubItems.Add(ListSubItem);
  123. ListSubItem = new ListViewItem.ListViewSubItem();
  124. ListSubItem.Name = "套系价格";
  125. ListSubItem.Text = dt.Rows[i]["套系价格"].ToString().Trim();
  126. lvItem.SubItems.Add(ListSubItem);
  127. ListSubItem = new ListViewItem.ListViewSubItem();
  128. ListSubItem.Name = "状态";
  129. ListSubItem.Text = dt.Rows[i]["状态"].ToString().Trim();
  130. lvItem.SubItems.Add(ListSubItem);
  131. ListSubItem = new ListViewItem.ListViewSubItem();
  132. ListSubItem.Name = "套系类别";
  133. ListSubItem.Text = dt.Rows[i]["套系类别"].ToString().Trim();
  134. lvItem.SubItems.Add(ListSubItem);
  135. if (this.StrPackagesType == 1)
  136. {
  137. ListSubItem = new ListViewItem.ListViewSubItem();
  138. ListSubItem.Name = "可选几";
  139. ListSubItem.Text = Convert.ToInt32(dt.Rows[i]["可选几"]) == -1 ? "全部" : dt.Rows[i]["可选几"].ToString().Trim();
  140. lvItem.SubItems.Add(ListSubItem);
  141. }
  142. if ((this.listViewData.Items.Count % 2) > 0)
  143. {
  144. lvItem.BackColor = System.Drawing.Color.PapayaWhip;
  145. }
  146. else
  147. {
  148. lvItem.BackColor = System.Drawing.Color.PowderBlue;
  149. }
  150. this.listViewData.Items.Add(lvItem);
  151. }
  152. }
  153. /// <summary>
  154. /// 控件显示单击事件
  155. /// </summary>
  156. /// <param name="sender"></param>
  157. /// <param name="e"></param>
  158. void listViewData_MouseClick(object sender, MouseEventArgs e)
  159. {
  160. try
  161. {
  162. //更新赋值
  163. if (this.listViewData.Items.Count > 0 && this.listViewData.SelectedItems.Count > 0)
  164. {
  165. this.CtvPak_PackagesClass.SetTextAndTag_ValueNull();
  166. string Pak_PackagesID = this.listViewData.SelectedItems[0].Tag.ToString().Trim();// this.dgv.CurrentRow.Cells["套系编号"].Value.ToString();
  167. DataTable dt = pkbll.GetList("Pak_PackagesID='" + Pak_PackagesID + "'").Tables[0];
  168. this.CtvPak_PackagesClass.TagFindText(dt.Rows[0]["Pak_PackagesClass"].ToString());
  169. this.txtPak_Name.Enabled = !orbll.isSeriesNameUse(this.listViewData.SelectedItems[0].SubItems["套系名称"].Text, this.StrPackagesType);
  170. this.txtPak_Name.Text = dt.Rows[0]["Pak_Name"].ToString();
  171. this.txtPak_Name.Tag = dt.Rows[0]["Pak_PackagesID"].ToString();
  172. this.txtPak_UnitPrice.Text = dt.Rows[0]["Pak_UnitPrice"].ToString();
  173. //this.txtPak_IntoTheArchive.Value = Convert.ToDecimal(dt.Rows[0]["Pak_IntoTheArchive"]);
  174. //this.txtPak_IntoTheBook.Value = Convert.ToDecimal(dt.Rows[0]["Pak_IntoTheBook"]);
  175. this.cmbPak_IsDisable.Text = Convert.ToBoolean(dt.Rows[0]["Pak_IsDisable"].ToString()) == true ? "隐藏" : "显示";
  176. if (this.StrPackagesType == 1)
  177. {
  178. this.numOptionalSeveral.Value = Convert.ToInt32(dt.Rows[0]["Pak_OptionalSeveral"]);
  179. }
  180. }
  181. }
  182. catch (Exception ex)
  183. {
  184. MessageBoxCustom.Show(ex.Message);
  185. }
  186. }
  187. /// <summary>
  188. /// 清空填写
  189. /// </summary>
  190. /// <param name="sender"></param>
  191. /// <param name="e"></param>
  192. void btnClear_Click(object sender, EventArgs e)
  193. {
  194. ClearBind();
  195. }
  196. /// <summary>
  197. /// 保存
  198. /// </summary>
  199. /// <param name="sender"></param>
  200. /// <param name="e"></param>
  201. void btnSave_Click(object sender, EventArgs e)
  202. {
  203. #region 判断资料不能为空
  204. if (string.IsNullOrEmpty(CtvPak_PackagesClass.Text))
  205. {
  206. MessageBoxCustom.Show("套系大类不能为空!"); return;
  207. }
  208. if (string.IsNullOrEmpty(txtPak_Name.Text))
  209. {
  210. MessageBoxCustom.Show("套系名称能为空!"); return;
  211. }
  212. if (string.IsNullOrEmpty(txtPak_UnitPrice.Text))
  213. {
  214. MessageBoxCustom.Show("套系价格不能为空!"); return;
  215. }
  216. if (string.IsNullOrEmpty(cmbPak_IsDisable.Text))
  217. {
  218. MessageBoxCustom.Show("状态不能为空!"); return;
  219. }
  220. #endregion
  221. LYFZ.Model.Model_ErpPackages model = null;
  222. DataTable dt = new DataTable();
  223. try
  224. {
  225. if (this.txtPak_Name.Tag == null)
  226. {
  227. #region 增加
  228. dt = pkbll.GetList("Pak_Name='" + txtPak_Name.Text.Trim() + "'").Tables[0];
  229. if (dt.Rows.Count > 0)
  230. {
  231. MessageBoxCustom.Show("套系名称已经存在!"); return;
  232. }
  233. Random action = new Random();
  234. model = new Model.Model_ErpPackages();
  235. model.Pak_PackagesID = "TX" + SDateTime.Now.ToString("yyyyMMddHHmmss") + action.Next(100, 1000);
  236. model.Pak_DividedShop = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetCompanyInfoID();
  237. model.Pak_PackagesMainClass = Enum.GetName(typeof(LYFZ.EnumPublic.EnumPackagesType), this.StrPackagesType).Trim().Trim();
  238. model.Pak_PackagesClass = CtvPak_PackagesClass.Tag.ToString();
  239. model.Pak_Name = txtPak_Name.Text;
  240. model.Pak_UnitPrice = Convert.ToDecimal(txtPak_UnitPrice.Text);
  241. if (this.StrPackagesType == 1)
  242. {
  243. model.Pak_OptionalSeveral = Convert.ToInt32(this.numOptionalSeveral.Value);
  244. }
  245. else
  246. {
  247. model.Pak_OptionalSeveral = 0;
  248. }
  249. if (cmbPak_IsDisable.Text == "显示")
  250. { model.Pak_IsDisable = false; }
  251. else
  252. {
  253. model.Pak_IsDisable = true;
  254. }
  255. model.Pak_Remark = "";
  256. //model.Pak_IntoTheArchive = Convert.ToInt32(txtPak_IntoTheArchive.Value);
  257. //model.Pak_IntoTheBook = Convert.ToInt32(txtPak_IntoTheBook.Value);
  258. model.Pak_CreateDatetime = SDateTime.Now;
  259. model.Pak_PackagesClassName = CtvPak_PackagesClass.Text;
  260. if (!pkbll.Add(model))
  261. {
  262. MessageBoxCustom.Show("保存失败!"); return;
  263. }
  264. #endregion
  265. }
  266. else
  267. {
  268. #region 更新
  269. #region 判断套系名称是否存在
  270. if (!string.IsNullOrEmpty(txtPak_Name.Text))
  271. {
  272. dt = pkbll.GetList("Pak_PackagesID='" + this.txtPak_Name.Tag + "'", "ID desc").Tables[0];
  273. string Pak_Name = dt.Rows[0]["Pak_Name"].ToString().Trim();
  274. if (Pak_Name != txtPak_Name.Text.Trim())
  275. {
  276. dt = pkbll.GetList("Pak_Name='" + txtPak_Name.Text.Trim() + "'").Tables[0];
  277. if (dt.Rows.Count > 0)
  278. {
  279. MessageBoxCustom.Show("套系名称已经存在!"); return;
  280. }
  281. }
  282. }
  283. #endregion
  284. model = pkbll.GetModel("Pak_PackagesID", this.txtPak_Name.Tag.ToString().Trim());
  285. if (model.ID <= 0)
  286. {
  287. MessageBoxCustom.Show("此套系名称不存在或已经被删除!"); return;
  288. }
  289. model.Pak_DividedShop = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetCompanyInfoID();
  290. model.Pak_PackagesClass = CtvPak_PackagesClass.Tag.ToString();
  291. model.Pak_Name = txtPak_Name.Text;
  292. model.Pak_UnitPrice = Convert.ToDecimal(txtPak_UnitPrice.Text);
  293. if (this.StrPackagesType == 1)
  294. {
  295. model.Pak_OptionalSeveral = Convert.ToInt32(this.numOptionalSeveral.Value);
  296. }
  297. if (cmbPak_IsDisable.Text == "显示")
  298. {
  299. model.Pak_IsDisable = false;
  300. }
  301. else
  302. {
  303. model.Pak_IsDisable = true;
  304. }
  305. model.Pak_Remark = "";
  306. //model.Pak_IntoTheArchive = Convert.ToInt32(txtPak_IntoTheArchive.Value);
  307. //model.Pak_IntoTheBook = Convert.ToInt32(txtPak_IntoTheBook.Value);
  308. model.Pak_UpdateDatetime = SDateTime.Now;
  309. model.Pak_PackagesClassName = CtvPak_PackagesClass.Text;
  310. if (!pkbll.Update(model))
  311. {
  312. MessageBoxCustom.Show("保存失败!"); return;
  313. }
  314. #endregion
  315. }
  316. IsSaveed = true;
  317. //清空
  318. ClearBind();
  319. CtvPak_PackagesClass.Text = "";
  320. MessageBoxCustom.Show("保存成功!");
  321. this.GetForNodeCount(this.CtvSelect.GetNodeItem_TextToTag(this.CtvSelect.Text.Trim()));
  322. }
  323. catch (Exception ex)
  324. {
  325. MessageBoxCustom.Show(ex.Message);
  326. }
  327. }
  328. /// <summary>
  329. /// 删除
  330. /// </summary>
  331. /// <param name="sender"></param>
  332. /// <param name="e"></param>
  333. void btnDelete_Click(object sender, EventArgs e)
  334. {
  335. try
  336. {
  337. if (this.listViewData.SelectedItems.Count == 0)
  338. {
  339. MessageBoxCustom.Show("请选中你要删除的数据!"); return;
  340. }
  341. DataTable dt = pkbll.GetList("Pak_PackagesID='" + this.listViewData.SelectedItems[0].Tag.ToString().Trim() + "'", "ID desc").Tables[0];
  342. if (StrPackagesType == 0)
  343. {
  344. DataTable tbl = orbll.GetView_Custom("tb_ErpOrder", StrWhere: "Ord_SeriesName = '" + this.listViewData.SelectedItems[0].SubItems["套系名称"].Text.Trim() + "' or Ord_PhotographyCategory = '" + this.listViewData.SelectedItems[0].SubItems["套系名称"].Text.Trim() + "'", ShowColumnName: "ID").Tables[0];
  345. if (tbl.Rows.Count > 0)
  346. {
  347. MessageBoxCustom.Show("套系已被选中下订单,不能删除套系"); return;
  348. }
  349. }
  350. else if (StrPackagesType == 1)
  351. {
  352. DataTable tbl = orbll.GetView_Custom("tb_ErpOrder", StrWhere: "Ord_PackageName = '" + this.listViewData.SelectedItems[0].SubItems["套系名称"].Text.Trim() + "'", ShowColumnName: "ID").Tables[0];
  353. if (tbl.Rows.Count > 0)
  354. {
  355. MessageBoxCustom.Show("礼包已被选中下订单,不能删除套系"); return;
  356. }
  357. }
  358. int id = Convert.ToInt32(dt.Rows[0]["ID"]);
  359. if (MessageBoxCustom.Show("你确定要删除吗?", "删除提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
  360. {
  361. if (pkbll.Delete(id) == true)
  362. {
  363. MessageBoxCustom.Show("删除成功!");
  364. IsSaveed = true;
  365. //清空
  366. ClearBind();
  367. }
  368. else
  369. {
  370. MessageBoxCustom.Show("删除失败!");
  371. }
  372. }
  373. }
  374. catch (Exception ex)
  375. {
  376. MessageBoxCustom.Show(ex.Message);
  377. }
  378. }
  379. /// <summary>
  380. /// 输入框设置
  381. /// </summary>
  382. /// <param name="sender"></param>
  383. /// <param name="e"></param>
  384. void txtPak_UnitPrice_KeyPress(object sender, KeyPressEventArgs e)
  385. {
  386. //获取或设置一个值,指示是否处理过System.Windows.Forms.Control.KeyPress事件
  387. if (!Char.IsNumber(e.KeyChar) && !Char.IsPunctuation(e.KeyChar) && !Char.IsControl(e.KeyChar))
  388. {
  389. e.Handled = true;
  390. }
  391. else if (Char.IsPunctuation(e.KeyChar))
  392. {
  393. if (e.KeyChar == '.')
  394. {
  395. if (((TextBox)sender).Text.LastIndexOf('.') != -1)
  396. {
  397. e.Handled = true;
  398. }
  399. }
  400. else
  401. {
  402. e.Handled = true;
  403. }
  404. }
  405. }
  406. /// <summary>
  407. /// 查询套系大类
  408. /// </summary>
  409. /// <param name="sender"></param>
  410. /// <param name="e"></param>
  411. void CtvSelect_ComboBoxTree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
  412. {
  413. if (CtvSelect.Text == "全部" || CtvSelect.Tag != null)
  414. {
  415. this.GetForNodeCount(e.Node);
  416. }
  417. }
  418. void GetForNodeCount(TreeNode nodes)
  419. {
  420. StringBuilder str = new StringBuilder();
  421. if (nodes != null)
  422. {
  423. //str.Append(" Pak_DividedShop = '" + LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetCompanyInfoID() + "'");
  424. if (CtvSelect.Text != "全部")
  425. {
  426. string StrContent = "";
  427. foreach (TreeNode node in nodes.Nodes)
  428. {
  429. if (node.Tag != null)
  430. {
  431. StrContent += "'" + node.Tag.ToString().Trim() + "',";
  432. }
  433. }
  434. StrContent += "'" + nodes.Tag.ToString().Trim() + "'";
  435. if (!string.IsNullOrEmpty(StrContent))
  436. {
  437. str.Append(" Pak_PackagesClass in (" + StrContent + ")");//And
  438. }
  439. }
  440. }
  441. this.PublicFunctionRows(str.ToString());
  442. }
  443. /// <summary>
  444. /// 清空
  445. /// </summary>
  446. public void ClearBind()
  447. {
  448. this.txtPak_Name.Text = "";
  449. this.txtPak_Name.Tag = null;
  450. this.txtPak_UnitPrice.Text = "";
  451. this.cmbPak_IsDisable.Text = "显示";
  452. this.txtPak_Name.Enabled = true;
  453. //this.txtPak_IntoTheArchive.Value = 0;
  454. //this.txtPak_IntoTheBook.Value = 0;
  455. }
  456. /// <summary>
  457. /// 关闭
  458. /// </summary>
  459. /// <param name="sender"></param>
  460. /// <param name="e"></param>
  461. void btnCloseed_Click(object sender, EventArgs e)
  462. {
  463. this.Close();
  464. }
  465. /// <summary>
  466. /// 设置套系大类
  467. /// </summary>
  468. /// <param name="sender"></param>
  469. /// <param name="e"></param>
  470. void btnSet_Click(object sender, EventArgs e)
  471. {
  472. LYFZ.Software.MainBusiness.InitialSet.FrmSystemSet frm = new FrmSystemSet();
  473. frm.TypeName = Enum.GetName(typeof(LYFZ.EnumPublic.EnumPackagesType), StrPackagesType).ToString().Trim();
  474. frm.Version = "Version";
  475. if (frm.ShowDialog() == DialogResult.OK)
  476. {
  477. this.FrmPackagesSet_Shown(this, null);
  478. }
  479. }
  480. }
  481. }