FrmDressEntry.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  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 System.IO;
  10. using LYFZ.ComponentLibrary;
  11. namespace LYFZ.Software.MainBusiness.Dresses
  12. {
  13. public partial class FrmDressEntry : LYFZ.Software.UI.Dresses.FrmDressEntry
  14. {
  15. private delegate void UpdateControl();
  16. public FrmDressEntry()
  17. {
  18. this.ucPagerEx1.EventPaging += ucPagerEx1_EventPaging;
  19. this.dgv.MouseDoubleClick += dgv_MouseDoubleClick;
  20. }
  21. #region 加载
  22. protected override void FrmDressEntry_Shown(object sender, EventArgs e)
  23. {
  24. try
  25. {
  26. cmbDsfm_IsEnabled.SelectedIndex = 1;
  27. BindDsfm_DressType();
  28. Bind();
  29. #region 权限设置
  30. #region 增加礼服
  31. if (LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.DressEntry, CustomAttributes.OperatingAuthority.Add))
  32. {
  33. btnAdd.Enabled = true;
  34. }
  35. else
  36. {
  37. btnAdd.Enabled = false;
  38. }
  39. #endregion
  40. #region 修改礼服
  41. if (LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.DressEntry, CustomAttributes.OperatingAuthority.Update))
  42. {
  43. btnUpdate.Enabled = true;
  44. }
  45. else
  46. {
  47. btnUpdate.Enabled = false;
  48. }
  49. #endregion
  50. #region 删除礼服
  51. if (LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.DressEntry, CustomAttributes.OperatingAuthority.Delete))
  52. {
  53. btnDelete.Enabled = true;
  54. }
  55. else
  56. {
  57. btnDelete.Enabled = false;
  58. }
  59. #endregion
  60. #region 导出礼服
  61. if (LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.OrdersCustomerCompetence, CustomAttributes.OperatingAuthority.DataExport))
  62. {
  63. btnExport.Enabled = true;
  64. }
  65. else
  66. {
  67. btnExport.Enabled = false;
  68. }
  69. #endregion
  70. #endregion
  71. }
  72. catch (Exception ex)
  73. {
  74. MessageBoxCustom.Show(ex.Message);
  75. }
  76. }
  77. public void Bind()
  78. {
  79. this.ucPagerEx1.PageCurrent = 1;
  80. this.ucPagerEx1.PageSize = 100;
  81. this.ucPagerEx1.Bind();
  82. }
  83. #endregion
  84. #region 增加
  85. protected override void btnAdd_Click(object sender, EventArgs e)
  86. {
  87. try
  88. {
  89. LYFZ.Software.MainBusiness.Dresses.DressEntry.FrmEntry set = new DressEntry.FrmEntry();
  90. set.Type = "Add";
  91. if (set.ShowDialog() == DialogResult.OK)
  92. {
  93. Bind();
  94. }
  95. }
  96. catch (Exception ex)
  97. {
  98. MessageBoxCustom.Show(ex.Message);
  99. }
  100. }
  101. #endregion
  102. #region 修改
  103. protected override void btnUpdate_Click(object sender, EventArgs e)
  104. {
  105. try
  106. {
  107. if (dgv.SelectedRows.Count == 0)
  108. {
  109. MessageBoxCustom.Show("请选择你要修改的礼服!");
  110. return;
  111. }
  112. LYFZ.Software.MainBusiness.Dresses.DressEntry.FrmEntry set = new DressEntry.FrmEntry();
  113. set.Dsfm_DressNumber = dgv.CurrentRow.Cells["Dsfm_DressNumber"].Value.ToString();
  114. set.Type = "Update";
  115. if (set.ShowDialog() == DialogResult.OK)
  116. {
  117. Bind();
  118. }
  119. }
  120. catch (Exception ex)
  121. {
  122. MessageBoxCustom.Show(ex.Message);
  123. }
  124. }
  125. void dgv_MouseDoubleClick(object sender, MouseEventArgs e)
  126. {
  127. try
  128. {
  129. if (e.Location.Y > this.dgv.ColumnHeadersHeight)
  130. {
  131. if (dgv.SelectedRows.Count == 0)
  132. {
  133. MessageBoxCustom.Show("请选择你要修改的礼服!");
  134. return;
  135. }
  136. #region 权限设置
  137. #region 修改礼服
  138. if (LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.DressEntry, CustomAttributes.OperatingAuthority.Update))
  139. {
  140. btnUpdate.Enabled = true;
  141. }
  142. else
  143. {
  144. btnUpdate.Enabled = false;
  145. return;
  146. }
  147. #endregion
  148. #endregion
  149. LYFZ.Software.MainBusiness.Dresses.DressEntry.FrmEntry set = new DressEntry.FrmEntry();
  150. set.Dsfm_DressNumber = dgv.CurrentRow.Cells["Dsfm_DressNumber"].Value.ToString();
  151. set.Type = "Update";
  152. if (set.ShowDialog() == DialogResult.OK)
  153. {
  154. Bind();
  155. }
  156. }
  157. }
  158. catch (Exception ex)
  159. {
  160. MessageBoxCustom.Show(ex.Message);
  161. }
  162. }
  163. protected override void dgv_DoubleClick(object sender, EventArgs e)
  164. {
  165. }
  166. #endregion
  167. #region 删除
  168. protected override void btnDelete_Click(object sender, EventArgs e)
  169. {
  170. try
  171. {
  172. if (this.dgv.SelectedRows.Count == 0)
  173. {
  174. MessageBoxCustom.Show("请选中你要删除的数据!");
  175. return;
  176. }
  177. DataTable dt = new DataTable();
  178. #region 判断是否存在礼服租售洗
  179. string Dsfm_DressNumber = dgv.CurrentRow.Cells["Dsfm_DressNumber"].Value.ToString();
  180. LYFZ.BLL.BLL_ErpDressSaleRentalDetail DressSaleRentalDetailBll = new BLL.BLL_ErpDressSaleRentalDetail();
  181. LYFZ.BLL.BLL_ErpSystemConfigure SystemConfigureBll = new BLL.BLL_ErpSystemConfigure();
  182. DataTable dtmax = DressSaleRentalDetailBll.View_DressSaleRentalDetailDay(" and Dsrd_DressNumber='" + Dsfm_DressNumber + "'").Tables[0];
  183. DataTable dts = SystemConfigureBll.GetList("Sconfig_Code='AlsoClothesDay'").Tables[0];
  184. if (dtmax.Rows.Count > 0)
  185. {
  186. if (!string.IsNullOrEmpty(dtmax.Rows[0]["maxtime"].ToString().Trim()))
  187. {
  188. DateTime Day = Convert.ToDateTime(dtmax.Rows[0]["maxtime"].ToString()).AddDays(Convert.ToDouble(dts.Rows[0]["Sconfig_Value"].ToString()));
  189. if (DateTime.Now <= Day)
  190. {
  191. MessageBoxCustom.Show("此礼服不能删除,已经使用中!");
  192. return;
  193. }
  194. }
  195. }
  196. #endregion
  197. if (MessageBoxCustom.Show("你确定要删除吗?", "删除提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
  198. {
  199. LYFZ.BLL.BLL_ErpDressFrom bll = new BLL.BLL_ErpDressFrom();
  200. int id = Convert.ToInt32(this.dgv.CurrentRow.Cells["ID"].Value);
  201. dt = new DataTable();
  202. dt = bll.View_tb_ErpDressFrom(" and Id=" + id + "").Tables[0];
  203. string Dsfm_PicturePath = dt.Rows[0]["Dsfm_PicturePath"].ToString();
  204. if (!string.IsNullOrEmpty(Dsfm_PicturePath))
  205. {
  206. //删除原图图片
  207. File.Delete((BLL.BLL_ErpDressFrom.GetDressFromPath() + "\\" + dt.Rows[0]["Dsfm_PicturePath"]));
  208. //删除缩略图
  209. char[] paths = Path.GetExtension(Dsfm_PicturePath).ToCharArray();
  210. Dsfm_PicturePath = Dsfm_PicturePath.TrimEnd(paths);
  211. File.Delete(BLL.BLL_ErpDressFrom.GetDressFromPathSmall() + "\\" + Dsfm_PicturePath + "&Small" + Path.GetExtension(dt.Rows[0]["Dsfm_PicturePath"].ToString()));
  212. }
  213. if (bll.Delete(id) == true)
  214. {
  215. MessageBoxCustom.Show("删除成功!");
  216. #region 写入操作日志
  217. string logsContent = "删除礼服名称:" + dgv.CurrentRow.Cells["Dsfm_DressName"].Value.ToString();
  218. LYFZ.BLL.BLL_ErpSystemLogs.WriteSystemLog(LYFZ.EnumPublic.SystemLogsType.删除礼服, logsContent, LYFZ.BLL.BLL_ErpUser.UsersModel.User_EmployeeID, LYFZ.BLL.BLL_ErpUser.UsersModel.User_Name);
  219. //LYFZ.BLL.BLL_ErpSystemLogs systemLogsBll = new BLL.BLL_ErpSystemLogs();
  220. //LYFZ.Model.Model_ErpSystemLogs systemLogsModel = new Model.Model_ErpSystemLogs();
  221. //systemLogsModel.Slogs_Type = "user";
  222. //systemLogsModel.Slogs_Topic = "删除礼服";
  223. //systemLogsModel.Slogs_Content = "删除礼服名称:" + dgv.CurrentRow.Cells["Dsfm_DressName"].Value.ToString();
  224. //systemLogsModel.Slogs_UserName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_Name;
  225. //systemLogsModel.Slogs_IP = "";
  226. //systemLogsModel.Slogs_CreateDatetime = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetServerDateTime();
  227. //systemLogsModel.Slogs_CreateName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
  228. //systemLogsBll.Add(systemLogsModel);
  229. #endregion
  230. Bind();
  231. }
  232. else { MessageBoxCustom.Show("删除失败!"); }
  233. }
  234. }
  235. catch (Exception ex) { MessageBoxCustom.Show(ex.Message); }
  236. }
  237. #endregion
  238. #region 导出
  239. protected override void btnExport_Click(object sender, EventArgs e)
  240. {
  241. try
  242. {
  243. dgv.ExportDataTable();
  244. }
  245. catch (Exception ex)
  246. {
  247. MessageBoxCustom.Show(ex.Message);
  248. }
  249. }
  250. #endregion
  251. #region 查询
  252. protected override void btnSlect_Click(object sender, EventArgs e)
  253. {
  254. try
  255. {
  256. Bind();
  257. }
  258. catch (Exception ex)
  259. {
  260. MessageBoxCustom.Show(ex.Message);
  261. }
  262. }
  263. #endregion
  264. #region 绑定礼服类别
  265. /// <summary>
  266. /// 绑定礼服类别
  267. /// </summary>
  268. public void BindDsfm_DressType()
  269. {
  270. CtvDsfm_DressType.TreeView.Nodes.Clear();
  271. #region 绑定二级礼服类别
  272. LYFZ.BLL.BLL_ErpSystemCategory BLLSystemCategory = new BLL.BLL_ErpSystemCategory();
  273. DataTable tbl = BLLSystemCategory.GetList("Sc_ClassParentID='59'").Tables[0];
  274. if (tbl.Rows.Count > 0)
  275. {
  276. TreeNode root = null;
  277. for (int i = 0; i < tbl.Rows.Count; i++)
  278. {
  279. if (i == 0)
  280. {
  281. root = new TreeNode("全部");
  282. this.CtvDsfm_DressType.TreeView.Nodes.Add(root);
  283. }
  284. root = new TreeNode();
  285. root.Text = tbl.Rows[i]["Sc_ClassName"].ToString();
  286. root.Tag = tbl.Rows[i]["Sc_ClassCode"].ToString();
  287. this.CreateTreeViewShop(root.Nodes, tbl.Rows[i]["ID"].ToString());
  288. this.CtvDsfm_DressType.TreeView.Nodes.Add(root);
  289. }
  290. }
  291. #endregion
  292. }
  293. private void CreateTreeViewShop(TreeNodeCollection nodes, string ClassCode)
  294. {
  295. if (ClassCode != "")
  296. {
  297. LYFZ.BLL.BLL_ErpSystemCategory BLLSystemCategory = new BLL.BLL_ErpSystemCategory();
  298. DataTable tbl = BLLSystemCategory.GetList("Sc_ClassParentID=" + ClassCode + "").Tables[0];
  299. if (tbl.Rows.Count > 0)
  300. {
  301. TreeNode node;
  302. for (int i = 0; i < tbl.Rows.Count; i++)
  303. {
  304. node = new TreeNode();
  305. node.Text = tbl.Rows[i]["Sc_ClassName"].ToString();
  306. node.Tag = tbl.Rows[i]["Sc_ClassCode"].ToString();
  307. nodes.Add(node);
  308. }
  309. }
  310. }
  311. }
  312. #endregion
  313. #region 画分页
  314. /// <summary>
  315. /// 画分页
  316. /// </summary>
  317. /// <param name="e"></param>
  318. /// <returns></returns>
  319. private int ucPagerEx1_EventPaging(UCPager.EventPagingArg e)
  320. {
  321. dgv.Rows.Clear();
  322. LYFZ.BLL.BLL_ErpDressFrom DressFrombll = new BLL.BLL_ErpDressFrom();
  323. DataTable dt = new DataTable();
  324. LYFZ.UCPager.PageData pageData = new LYFZ.UCPager.PageData();
  325. StringBuilder StrWhere = new StringBuilder();
  326. StrWhere.Append("1=1 ");
  327. if (!string.IsNullOrEmpty(CtvDsfm_DressType.Text) && CtvDsfm_DressType.Text != "全部")
  328. {
  329. StrWhere.Append(" and Dsfm_DressType='" + CtvDsfm_DressType.Tag.ToString() + "' ");
  330. }
  331. if (!string.IsNullOrEmpty(txtkeyword.Text))
  332. {
  333. StrWhere.Append(" and (Dsfm_DressNumber like '%" + txtkeyword.Text + "%' or Dsfm_DressName like '%" + txtkeyword.Text + "%')");
  334. }
  335. if (!string.IsNullOrEmpty(cmbDsfm_IsEnabled.Text))
  336. {
  337. if (cmbDsfm_IsEnabled.Text == "上架")
  338. {
  339. StrWhere.Append(" and Dsfm_IsEnabled=1");
  340. }
  341. else { StrWhere.Append(" and Dsfm_IsEnabled=0"); }
  342. }
  343. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
  344. {
  345. pageData.TableName = "View_tb_ErpDressFrom";
  346. pageData.PageIndex = this.ucPagerEx1.PageCurrent;
  347. pageData.PageSize = this.ucPagerEx1.PageSize;
  348. pageData.QueryCondition = StrWhere.ToString();
  349. pageData.QueryFieldName = "ID,Dsfm_DressNumber,Dsfm_DressType,Dsfm_DressName,Dsfm_DressBrand,Dsfm_DressSize,Dsfm_DressQuantity,Dsfm_CostPrice,Dsfm_RentPrice,Dsfm_SalePrice,Dsfm_IsEnabled,Dsfm_PlacedRegion,Dsfm_PicturePath,Dsfm_DressIntroduce,Dsfm_DressDetail,Dsfm_DressRemark,Dsfm_CreateDateTime,Dsfm_CreateName,Dsfm_UpdateDateTime,Dsfm_UpdateName,Dsfm_DressTypeName,Dsfm_PlacedRegionName ";
  350. pageData.OrderStr = "ID desc";
  351. pageData.OrderType = 1;
  352. DataSet da = pageData.QueryDataTable();
  353. dt = da.Tables[0];
  354. if (dt.Rows.Count > 0)
  355. {
  356. this.Invoke(new UpdateControl(delegate()
  357. {
  358. #region 获取礼服表
  359. for (int t = 0; t < dt.Rows.Count; t++)
  360. {
  361. #region
  362. DataGridViewRow dgvr = new DataGridViewRow();
  363. DataGridViewCell cell = null;
  364. cell = new DataGridViewTextBoxCell();
  365. cell.Value = dt.Rows[t]["ID"].ToString().Trim();
  366. dgvr.Cells.Add(cell);
  367. cell = new DataGridViewTextBoxCell();
  368. cell.Value = dt.Rows[t]["Dsfm_DressNumber"].ToString().Trim();
  369. dgvr.Cells.Add(cell);
  370. cell = new DataGridViewTextBoxCell();
  371. cell.Value = dt.Rows[t]["Dsfm_DressTypeName"].ToString().Trim();
  372. dgvr.Cells.Add(cell);
  373. cell = new DataGridViewTextBoxCell();
  374. cell.Value = dt.Rows[t]["Dsfm_PlacedRegionName"].ToString().Trim();
  375. dgvr.Cells.Add(cell);
  376. cell = new DataGridViewTextBoxCell();
  377. cell.Value = dt.Rows[t]["Dsfm_DressName"].ToString().Trim();
  378. dgvr.Cells.Add(cell);
  379. cell = new DataGridViewTextBoxCell();
  380. cell.Value = dt.Rows[t]["Dsfm_DressBrand"].ToString().Trim();
  381. dgvr.Cells.Add(cell);
  382. cell = new DataGridViewTextBoxCell();
  383. cell.Value = dt.Rows[t]["Dsfm_DressSize"].ToString().Trim();
  384. dgvr.Cells.Add(cell);
  385. cell = new DataGridViewTextBoxCell();
  386. cell.Value = dt.Rows[t]["Dsfm_DressQuantity"].ToString().Trim();
  387. dgvr.Cells.Add(cell);
  388. cell = new DataGridViewTextBoxCell();
  389. cell.Value = dt.Rows[t]["Dsfm_CostPrice"].ToString().Trim();
  390. dgvr.Cells.Add(cell);
  391. cell = new DataGridViewTextBoxCell();
  392. cell.Value = dt.Rows[t]["Dsfm_RentPrice"].ToString().Trim();
  393. dgvr.Cells.Add(cell);
  394. cell = new DataGridViewTextBoxCell();
  395. cell.Value = dt.Rows[t]["Dsfm_SalePrice"].ToString().Trim();
  396. dgvr.Cells.Add(cell);
  397. cell = new DataGridViewTextBoxCell();
  398. cell.Value = dt.Rows[t]["Dsfm_IsEnabled"].ToString().Trim() == "0" ? "下架" : "上架";
  399. dgvr.Cells.Add(cell);
  400. cell = new DataGridViewTextBoxCell();
  401. cell.Value = Convert.ToDateTime(dt.Rows[t]["Dsfm_CreateDateTime"].ToString().Trim()).ToString("yyyy-MM-dd");
  402. dgvr.Cells.Add(cell);
  403. cell = new DataGridViewTextBoxCell();
  404. cell.Value = dt.Rows[t]["Dsfm_DressRemark"].ToString().Trim();
  405. dgvr.Cells.Add(cell);
  406. this.dgv.Rows.Add(dgvr);
  407. dgv.ClearSelection();
  408. #endregion
  409. }
  410. #endregion
  411. }));
  412. }
  413. });
  414. try
  415. {
  416. this.ucPagerEx1.TbDataSource = dt;
  417. }
  418. catch { }
  419. return pageData.TotalCount;
  420. }
  421. #endregion
  422. }
  423. }