FrmAlsoBack.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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. namespace LYFZ.Software.MainBusiness.Dresses.DressManagement.Rental
  10. {
  11. public partial class FrmAlsoBack : LYFZ.Software.UI.Dresses.DressManagement.Rental.FrmAlsoBack
  12. {
  13. LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
  14. LYFZ.BLL.BLL_ErpDressSendWashOrder sworbll = new BLL.BLL_ErpDressSendWashOrder();
  15. LYFZ.BLL.BLL_ErpDressSendWashDetail swodbll = new BLL.BLL_ErpDressSendWashDetail();
  16. LYFZ.BLL.BLL_ErpDressSaleRentalDetail rsdbll = new BLL.BLL_ErpDressSaleRentalDetail();
  17. public FrmAlsoBack()
  18. {
  19. this.dgv.CellMouseDown += dgv_CellMouseDown;
  20. this.dgv.DataGridViewConMenu_ItemClicked += dgv_DataGridViewConMenu_ItemClicked;
  21. }
  22. /// <summary>
  23. /// 是否保存
  24. /// </summary>
  25. public bool IsSaveed = false;
  26. /// <summary>
  27. /// 订单号
  28. /// </summary>
  29. public string StrOrderNumber;
  30. /// <summary>
  31. /// 订单类型
  32. /// </summary>
  33. public string OrderType;
  34. /// <summary>
  35. /// 登录者姓名
  36. /// </summary>
  37. string StrUserName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_Name;
  38. /// <summary>
  39. /// 窗体加载事件
  40. /// </summary>
  41. /// <param name="sender"></param>
  42. /// <param name="e"></param>
  43. protected override void FrmAlsoBack_Shown(object sender, EventArgs e)
  44. {
  45. this.dgv.Rows.Clear();
  46. if (!string.IsNullOrEmpty(this.StrOrderNumber))
  47. {
  48. if (this.OrderType == "送洗")
  49. {
  50. #region 获取礼服资料
  51. DataTable dt = orbll.GetView_Custom("tb_ErpDressSendWashDetail Left Join tb_ErpDressFrom on Dsfm_DressNumber = Dswd_DressNumber", StrWhere: "Dswd_Number='" + this.StrOrderNumber + "'", ShowColumnName: "tb_ErpDressSendWashDetail.ID,Dswd_DressNumber,Dsfm_DressCustomNumber,Dswd_DressName,Dswd_BackStatus,Dswd_BackName,Dswd_BackTime").Tables[0];
  52. for (int t = 0; t < dt.Rows.Count; t++)
  53. {
  54. DataGridViewRow dgvr = new DataGridViewRow();
  55. DataGridViewCell cell = null;
  56. cell = new DataGridViewTextBoxCell();
  57. cell.Value = dt.Rows[t]["ID"].ToString().Trim();
  58. dgvr.Cells.Add(cell);
  59. cell = new DataGridViewTextBoxCell();
  60. if (!string.IsNullOrEmpty(dt.Rows[t]["Dsfm_DressCustomNumber"].ToString().Trim()))
  61. { cell.Value = dt.Rows[t]["Dsfm_DressCustomNumber"].ToString().Trim(); }
  62. else
  63. { cell.Value = dt.Rows[t]["Dswd_DressNumber"].ToString().Trim(); }
  64. dgvr.Cells.Add(cell);
  65. cell = new DataGridViewTextBoxCell();
  66. cell.Value = dt.Rows[t]["Dswd_DressName"].ToString().Trim();
  67. dgvr.Cells.Add(cell);
  68. cell = new DataGridViewTextBoxCell();
  69. cell.Value = "1";
  70. dgvr.Cells.Add(cell);
  71. cell = new DataGridViewTextBoxCell();
  72. if (dt.Rows[t]["Dswd_BackStatus"].ToString().Trim() == "1")
  73. { cell.Value = "已还"; }
  74. else if (dt.Rows[t]["Dswd_BackStatus"].ToString().Trim() == "2")
  75. { cell.Value = "报损"; }
  76. else if (dt.Rows[t]["Dswd_BackStatus"].ToString().Trim() == "3")
  77. { cell.Value = "未还"; }
  78. dgvr.Cells.Add(cell);
  79. cell = new DataGridViewTextBoxCell();
  80. DataRow dtRow = LYFZ.DAL.DAL_ErpUser.SimpleUserDataTable.Rows.Find(dt.Rows[t]["Dswd_BackName"].ToString().Trim());
  81. if (dtRow != null)
  82. { cell.Value = dtRow["User_Name"].ToString().Trim(); }
  83. else
  84. { cell.Value = ""; }
  85. dgvr.Cells.Add(cell);
  86. cell = new DataGridViewTextBoxCell();
  87. cell.Value = LYFZ.Command.Command_Validate.DateTimeToString(dt.Rows[t]["Dswd_BackTime"]);
  88. dgvr.Cells.Add(cell);
  89. this.dgv.Rows.Add(dgvr);
  90. }
  91. this.dgv.ClearSelection();
  92. #endregion
  93. }
  94. else
  95. {
  96. #region 获取礼服资料
  97. DataTable dt = orbll.GetView_Custom("tb_ErpDressSaleRentalDetail Left Join tb_ErpDressFrom on Dsfm_DressNumber = Dsrd_DressNumber", StrWhere: "Dsrd_Number='" + this.StrOrderNumber + "'", ShowColumnName: "tb_ErpDressSaleRentalDetail.ID,Dsrd_DressNumber,Dsfm_DressCustomNumber,Dsrd_DressName,Dsrd_BackStatus,Dsrd_BackName,Dsrd_BackTime").Tables[0];
  98. for (int t = 0; t < dt.Rows.Count; t++)
  99. {
  100. DataGridViewRow dgvr = new DataGridViewRow();
  101. DataGridViewCell cell = null;
  102. cell = new DataGridViewTextBoxCell();
  103. cell.Value = dt.Rows[t]["ID"].ToString().Trim();
  104. dgvr.Cells.Add(cell);
  105. cell = new DataGridViewTextBoxCell();
  106. cell.Value = dt.Rows[t]["Dsrd_DressNumber"].ToString().Trim();
  107. dgvr.Cells.Add(cell);
  108. cell = new DataGridViewTextBoxCell();
  109. cell.Value = dt.Rows[t]["Dsrd_DressName"].ToString().Trim();
  110. dgvr.Cells.Add(cell);
  111. cell = new DataGridViewTextBoxCell();
  112. cell.Value = "1";
  113. dgvr.Cells.Add(cell);
  114. cell = new DataGridViewTextBoxCell();
  115. if (dt.Rows[t]["Dsrd_BackStatus"].ToString().Trim() == "1")
  116. { cell.Value = "已还"; }
  117. else if (dt.Rows[t]["Dsrd_BackStatus"].ToString().Trim() == "2")
  118. { cell.Value = "报损"; }
  119. else if (dt.Rows[t]["Dsrd_BackStatus"].ToString().Trim() == "3")
  120. { cell.Value = "未还"; }
  121. dgvr.Cells.Add(cell);
  122. cell = new DataGridViewTextBoxCell();
  123. DataRow dtRow = LYFZ.DAL.DAL_ErpUser.SimpleUserDataTable.Rows.Find(dt.Rows[t]["Dsrd_BackName"].ToString().Trim());
  124. if (dtRow != null)
  125. { cell.Value = dtRow["User_Name"].ToString().Trim(); }
  126. else
  127. { cell.Value = ""; }
  128. dgvr.Cells.Add(cell);
  129. cell = new DataGridViewTextBoxCell();
  130. cell.Value = LYFZ.Command.Command_Validate.DateTimeToString(dt.Rows[t]["Dsrd_BackTime"]);
  131. dgvr.Cells.Add(cell);
  132. this.dgv.Rows.Add(dgvr);
  133. }
  134. this.dgv.ClearSelection();
  135. #endregion
  136. }
  137. }
  138. }
  139. /// <summary>
  140. /// dgv控件里面塞下拉框
  141. /// </summary>
  142. /// <param name="sender"></param>
  143. /// <param name="e"></param>
  144. protected override void cmbFactory_Leave(object sender, EventArgs e)
  145. {
  146. this.dgv.CurrentRow.Cells["Dsrd_BackStatus"].Value = this.cmbFactory.Text.Trim();
  147. if (this.dgv.CurrentRow.Cells["Dsrd_BackStatus"].Value.ToString().Trim() == "未还")
  148. {
  149. this.dgv.CurrentRow.Cells["Dsro_UpdateName"].Value = "";
  150. this.dgv.CurrentRow.Cells["Dsrd_BackTime"].Value = "";
  151. }
  152. else
  153. {
  154. this.dgv.CurrentRow.Cells["Dsro_UpdateName"].Value = this.StrUserName;
  155. this.dgv.CurrentRow.Cells["Dsrd_BackTime"].Value = LYFZ.Command.Command_Validate.DateTimeToString(SDateTime.Now);
  156. }
  157. this.dgv.CurrentRow.Tag = "1";
  158. this.cmbFactory.Visible = false;
  159. }
  160. /// <summary>
  161. /// 双击列表事件
  162. /// </summary>
  163. /// <param name="sender"></param>
  164. /// <param name="e"></param>
  165. protected override void dgv_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
  166. {
  167. if (this.dgv.Rows.Count > 0)
  168. {
  169. if (e.RowIndex >= 0)
  170. {
  171. if (this.dgv.CurrentCell.ColumnIndex == this.dgv.Columns["Dsrd_BackStatus"].Index)
  172. {
  173. DataGridViewCell cell = this.dgv.Rows[e.RowIndex].Cells[e.ColumnIndex];
  174. Rectangle rect = this.dgv.GetCellDisplayRectangle(cell.ColumnIndex, cell.RowIndex, true);
  175. this.cmbFactory.Location = new Point(rect.Location.X + this.dgv.Location.X, rect.Location.Y + this.dgv.Location.Y);
  176. this.cmbFactory.Size = rect.Size;
  177. if (cell.Value != null)
  178. { this.cmbFactory.Text = (string)cell.Value; }
  179. this.cmbFactory.Visible = true;
  180. this.cmbFactory.Focus();
  181. }
  182. }
  183. }
  184. }
  185. /// <summary>
  186. /// 关闭
  187. /// </summary>
  188. /// <param name="sender"></param>
  189. /// <param name="e"></param>
  190. protected override void btnClose_Click(object sender, EventArgs e)
  191. {
  192. this.Close();
  193. }
  194. /// <summary>
  195. /// 保存
  196. /// </summary>
  197. /// <param name="sender"></param>
  198. /// <param name="e"></param>
  199. protected override void btnSave_Click(object sender, EventArgs e)
  200. {
  201. if (this.dgv.Rows.Count > 0)
  202. {
  203. DateTime StrTime = SDateTime.Now;
  204. string StrUserID = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
  205. List<Helper.CommandInfo> clist = new List<Helper.CommandInfo>();
  206. int YHCount = 0;
  207. for (int i = 0; i < this.dgv.Rows.Count; i++)
  208. {
  209. if (this.dgv.Rows[i].Tag != null)
  210. {
  211. string StrBackStatus = "";
  212. switch (this.dgv.Rows[i].Cells["Dsrd_BackStatus"].Value.ToString().Trim())
  213. {
  214. case "已还": StrBackStatus = "1"; YHCount++; break;
  215. case "报损": StrBackStatus = "2"; break;
  216. case "未还": StrBackStatus = "3"; break;
  217. }
  218. if (this.OrderType == "送洗")
  219. {
  220. LYFZ.Model.Model_ErpDressSendWashDetail model = swodbll.GetModel(Convert.ToInt32(this.dgv.Rows[i].Cells["ID"].Value));
  221. model.Dswd_BackStatus = StrBackStatus;
  222. if (StrBackStatus == "3")
  223. {
  224. model.Dswd_BackTime = LYFZ.WinAPI.CustomPublicMethod.GetNullDateTime();
  225. model.Dswd_BackName = "";
  226. }
  227. else
  228. {
  229. model.Dswd_BackTime = StrTime;
  230. model.Dswd_BackName = StrUserID;
  231. }
  232. model.Dswd_UpdateDatetime = StrTime;
  233. model.Dswd_UpdateName = StrUserID;
  234. clist.Add(swodbll.GetUpdateCommandInfo(model));
  235. }
  236. else
  237. {
  238. LYFZ.Model.Model_ErpDressSaleRentalDetail model = rsdbll.GetModel(Convert.ToInt32(this.dgv.Rows[i].Cells["ID"].Value));
  239. model.Dsrd_BackStatus = StrBackStatus;
  240. if (StrBackStatus == "3")
  241. {
  242. model.Dsrd_BackTime = LYFZ.WinAPI.CustomPublicMethod.GetNullDateTime();
  243. model.Dsrd_BackName = "";
  244. }
  245. else
  246. {
  247. model.Dsrd_BackTime = StrTime;
  248. model.Dsrd_BackName = StrUserID;
  249. }
  250. model.Dsrd_UpdateDateTime = StrTime;
  251. model.Dsrd_UpdateName = StrUserID;
  252. clist.Add(rsdbll.GetUpdateCommandInfo(model));
  253. }
  254. }
  255. }
  256. if (clist.Count > 0)
  257. {
  258. if (MessageBoxCustom.Show("你确定要保存吗?", "温馨提示", MessageBoxButtons.YesNo) == DialogResult.No)
  259. { return; }
  260. if (LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist) > 0)
  261. {
  262. this.IsSaveed = true;
  263. System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(delegate()
  264. {
  265. if (this.OrderType != "送洗" && this.dgv.Rows.Count==YHCount)
  266. {
  267. Model.SMSParameters sparameters = new Model.SMSParameters();
  268. sparameters.OrderNumber = this.StrOrderNumber;
  269. new LYFZ.BLL.BLL_SMSTemplates().GenerateEventSMS(EnumPublic.SmsSendEvent.礼服出租还衣后X分钟, sparameters, MainBusiness.CommonLogical.SuccessfulLogin.CurrentCompanyInfoID);
  270. }
  271. }));
  272. t.Start();
  273. MessageBoxCustom.Show("保存成功!");
  274. }
  275. else
  276. { MessageBoxCustom.Show("保存失败!"); }
  277. }
  278. else
  279. { MessageBoxCustom.Show("没做任何修改,不需要保存!"); }
  280. }
  281. }
  282. /// <summary>
  283. /// 右键菜单
  284. /// </summary>
  285. /// <param name="sender"></param>
  286. /// <param name="e"></param>
  287. void dgv_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
  288. {
  289. this.cmbFactory.Visible = false;
  290. if (e.Button == MouseButtons.Right)
  291. {
  292. ToolStripMenuItem item = null;
  293. if (e.ColumnIndex == this.dgv.Columns["Dsrd_BackStatus"].Index)
  294. {
  295. if (LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.StoresTotakePiece, LYFZ.CustomAttributes.OperatingAuthority.OrderSendOut))
  296. {
  297. item = new ToolStripMenuItem();
  298. item.Text = "已还";
  299. item.Tag = "S";
  300. this.dgv.conMenu.Items.Add(item);
  301. item = new ToolStripMenuItem();
  302. item.Text = "未还";
  303. item.Tag = "S";
  304. this.dgv.conMenu.Items.Add(item);
  305. }
  306. }
  307. }
  308. }
  309. /// <summary>
  310. /// 右键菜单选择项事件
  311. /// </summary>
  312. /// <param name="sender"></param>
  313. /// <param name="e"></param>
  314. void dgv_DataGridViewConMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  315. {
  316. ToolStripItem item = e.ClickedItem;
  317. if (item.Tag.ToString().Trim() == "S" && !string.IsNullOrEmpty(item.Text.Trim()))
  318. {
  319. for (int i = 0; i < this.dgv.SelectedRows.Count; i++)
  320. {
  321. this.dgv.SelectedRows[i].Cells["Dsrd_BackStatus"].Value = item.Text.Trim();
  322. if (item.Text.Trim() == "未还")
  323. {
  324. this.dgv.CurrentRow.Cells["Dsro_UpdateName"].Value = "";
  325. this.dgv.CurrentRow.Cells["Dsrd_BackTime"].Value = "";
  326. }
  327. else
  328. {
  329. this.dgv.CurrentRow.Cells["Dsro_UpdateName"].Value = this.StrUserName;
  330. this.dgv.CurrentRow.Cells["Dsrd_BackTime"].Value = LYFZ.Command.Command_Validate.DateTimeToString(SDateTime.Now);
  331. }
  332. this.dgv.SelectedRows[i].Tag = "1";
  333. }
  334. }
  335. }
  336. }
  337. }