FrmProcurementApplication.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. using LYFZ.ComponentLibrary;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Windows.Forms;
  11. namespace LYFZ.Software.MainBusiness.InventoryManagement
  12. {
  13. public partial class FrmProcurementApplication : LYFZ.Software.UI.InventoryManagement.FrmProcurementApplication
  14. {
  15. LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
  16. LYFZ.BLL.BLL_ErpPurchaseOrder porbll = new BLL.BLL_ErpPurchaseOrder();
  17. LYFZ.BLL.BLL_ErpPurchaseProduct porptbll = new BLL.BLL_ErpPurchaseProduct();
  18. private delegate void UpdateControl();
  19. public FrmProcurementApplication()
  20. {
  21. this.btnDeleteOrder.Click += btnDeleteOrder_Click;
  22. }
  23. /// <summary>
  24. /// 加载
  25. /// </summary>
  26. /// <param name="sender"></param>
  27. /// <param name="e"></param>
  28. protected override void FrmProcurementApplication_Shown(object sender, EventArgs e)
  29. {
  30. this.dgv1.Rows.Clear();
  31. this.dgv2.Rows.Clear();
  32. string StrWhere = "";
  33. if (!string.IsNullOrEmpty(this.cmbPord_PurchaseStatus.Text))
  34. {
  35. if (this.cmbPord_PurchaseStatus.Text == "采购中")
  36. { StrWhere = "Pord_PurchaseStatus='0'"; }
  37. else if (this.cmbPord_PurchaseStatus.Text == "采购完成")
  38. { StrWhere = "Pord_PurchaseStatus='1'"; }
  39. else if (this.cmbPord_PurchaseStatus.Text == "采购取消")
  40. { StrWhere = "Pord_PurchaseStatus='2'"; }
  41. else if (this.cmbPord_PurchaseStatus.Text == "申请中")
  42. { StrWhere = "Pord_PurchaseStatus='3'"; }
  43. }
  44. else
  45. { StrWhere = "Pord_PurchaseStatus='3' or Pord_PurchaseStatus='0'"; }
  46. DataTable dt = orbll.GetView_Custom("tb_ErpPurchaseOrder Left Join tb_ErpUser on User_EmployeeID = Pord_RequisitionName", StrWhere: StrWhere, ShowColumnName: "tb_ErpPurchaseOrder.ID,Pord_PurchaseNumber AS 采购单号,User_Name AS 采购申请人,dbo.fn_CheckDateTime(Pord_RequisitionTime) AS 申请采购时间,Pord_PurchaseStatus AS 采购状态").Tables[0];
  47. if (dt.Rows.Count > 0)
  48. {
  49. for (int t = 0; t < dt.Rows.Count; t++)
  50. {
  51. DataGridViewRow dgvr = new DataGridViewRow();
  52. DataGridViewCell cell = null;
  53. cell = new DataGridViewTextBoxCell();
  54. cell.Value = dt.Rows[t]["ID"].ToString().Trim();
  55. dgvr.Cells.Add(cell);
  56. cell = new DataGridViewTextBoxCell();
  57. cell.Value = dt.Rows[t]["采购单号"].ToString().Trim();
  58. dgvr.Cells.Add(cell);
  59. cell = new DataGridViewTextBoxCell();
  60. LYFZ.BLL.BLL_ErpUser ErpUserBll = new BLL.BLL_ErpUser();
  61. cell.Value = dt.Rows[t]["采购申请人"].ToString().Trim();
  62. dgvr.Cells.Add(cell);
  63. cell = new DataGridViewTextBoxCell();
  64. cell.Value = dt.Rows[t]["申请采购时间"].ToString().Trim();
  65. dgvr.Cells.Add(cell);
  66. cell = new DataGridViewTextBoxCell();
  67. cell.Value = Enum.GetName(typeof(LYFZ.EnumPublic.Ppt_PurchaseStatus), Convert.ToInt32(dt.Rows[t]["采购状态"]));
  68. dgvr.Cells.Add(cell);
  69. if (dt.Rows[t]["采购状态"].ToString().Trim() == "0" || dt.Rows[t]["采购状态"].ToString().Trim() == "1")
  70. { dgvr.DefaultCellStyle.ForeColor = Color.Orange; }
  71. this.dgv2.Rows.Add(dgvr);
  72. }
  73. this.dgv2.ClearSelection();
  74. }
  75. }
  76. /// <summary>
  77. /// 查询采购订单
  78. /// </summary>
  79. /// <param name="sender"></param>
  80. /// <param name="e"></param>
  81. protected override void cmbPord_PurchaseStatus_SelectedIndexChanged(object sender, EventArgs e)
  82. {
  83. this.FrmProcurementApplication_Shown(this, null);
  84. }
  85. /// <summary>
  86. /// 关闭
  87. /// </summary>
  88. /// <param name="sender"></param>
  89. /// <param name="e"></param>
  90. protected override void btnClose_Click(object sender, EventArgs e)
  91. {
  92. this.Close();
  93. }
  94. /// <summary>
  95. /// 查询采购商品
  96. /// </summary>
  97. /// <param name="sender"></param>
  98. /// <param name="e"></param>
  99. protected override void dgv2_Click(object sender, EventArgs e)
  100. {
  101. if (this.dgv2.Rows.Count > 0)
  102. {
  103. this.dgv1.Rows.Clear();
  104. DataTable dt = orbll.GetView_Custom("tb_ErpPurchaseProduct Left Join tb_ErpProduct on Prod_Number = Ppt_ProductNumber Left Join tb_ErpSystemCategory on Sc_ClassCode = Ppt_ProductCategory", StrWhere: "Ppt_PurchaseNumber = '" + this.dgv2.CurrentRow.Cells["Pord_PurchaseNumber"].Value.ToString().Trim() + "'", ShowColumnName: "tb_ErpPurchaseProduct.ID,Ppt_PurchaseNumber AS 采购单号,Prod_Name AS 商品名称,Ppt_PurchaseQuantity AS 采购数量,Sc_ClassName AS 商品类别,Ppt_PurchaseStatus AS 采购状态,dbo.fn_CheckDateTime(Ppt_PurchaseTime) AS 采购时间").Tables[0];
  105. if (dt.Rows.Count > 0)
  106. {
  107. for (int t = 0; t < dt.Rows.Count; t++)
  108. {
  109. DataGridViewRow dgvr = new DataGridViewRow();
  110. DataGridViewCell cell = null;
  111. cell = new DataGridViewTextBoxCell();
  112. cell.Value = dt.Rows[t]["ID"].ToString().Trim();
  113. dgvr.Cells.Add(cell);
  114. cell = new DataGridViewTextBoxCell();
  115. cell.Value = dt.Rows[t]["采购单号"].ToString().Trim();
  116. dgvr.Cells.Add(cell);
  117. cell = new DataGridViewTextBoxCell();
  118. cell.Value = dt.Rows[t]["商品名称"].ToString().Trim();
  119. dgvr.Cells.Add(cell);
  120. cell = new DataGridViewTextBoxCell();
  121. cell.Value = dt.Rows[t]["采购数量"].ToString().Trim();
  122. dgvr.Cells.Add(cell);
  123. cell = new DataGridViewTextBoxCell();
  124. cell.Value = dt.Rows[t]["商品类别"].ToString().Trim();
  125. dgvr.Cells.Add(cell);
  126. cell = new DataGridViewTextBoxCell();
  127. cell.Value = Enum.GetName(typeof(LYFZ.EnumPublic.Ppt_PurchaseStatus), Convert.ToInt32(dt.Rows[t]["采购状态"]));
  128. dgvr.Cells.Add(cell);
  129. cell = new DataGridViewTextBoxCell();
  130. cell.Value = dt.Rows[t]["采购时间"].ToString().Trim();
  131. dgvr.Cells.Add(cell);
  132. if (dt.Rows[t]["采购状态"].ToString().Trim() == "0" || dt.Rows[t]["采购状态"].ToString().Trim() == "3")
  133. { dgvr.DefaultCellStyle.ForeColor = Color.Orange; }
  134. this.dgv1.Rows.Add(dgvr);
  135. }
  136. this.dgv1.ClearSelection();
  137. }
  138. }
  139. }
  140. /// <summary>
  141. /// 保存
  142. /// </summary>
  143. /// <param name="sender"></param>
  144. /// <param name="e"></param>
  145. protected override void btnSave_Click(object sender, EventArgs e)
  146. {
  147. if (this.dgv2.Rows.Count > 0)
  148. {
  149. List<Helper.CommandInfo> clist = new List<Helper.CommandInfo>();
  150. List<LYFZ.Model.Model_ErpPurchaseProduct> mlist = porptbll.GetModelList("Ppt_PurchaseNumber = '" + this.dgv2.CurrentRow.Cells["Pord_PurchaseNumber"].Value.ToString().Trim() + "'");
  151. int NotDelete = 0;
  152. for (int i = 0; i < mlist.Count; i++)
  153. {
  154. for (int j = 0; j < this.dgv1.Rows.Count; j++)
  155. {
  156. if (mlist[i].ID.ToString().Trim() == this.dgv1.Rows[j].Cells["ID"].Value.ToString().Trim())
  157. {
  158. if (this.dgv1.Rows[j].Cells["Status"].Value.ToString().Trim() != "申请中")
  159. { NotDelete++; }
  160. else
  161. {
  162. if (this.dgv1.Rows[j].Cells["Prod_Quantity"].Value == null)
  163. { MessageBoxCustom.Show("采购数量不能为空!"); return; }
  164. else if (this.dgv1.Rows[j].Cells["Prod_Quantity"].Value.ToString().Trim() == "")
  165. { MessageBoxCustom.Show("采购数量不能为空!"); return; }
  166. else if (!Command.Command_Validate.IsNumber(this.dgv1.Rows[j].Cells["Prod_Quantity"].Value.ToString().Trim()))
  167. { MessageBoxCustom.Show("只能输入纯数字!"); return; }
  168. mlist[i].Ppt_PurchaseQuantity = Convert.ToInt32(this.dgv1.Rows[j].Cells["Prod_Quantity"].Value);
  169. clist.Add(porptbll.GetUpdateCommandInfo(mlist[i]));
  170. }
  171. break;
  172. }
  173. }
  174. }
  175. if (clist.Count > 0)
  176. {
  177. if (NotDelete > 0)
  178. {
  179. if (MessageBoxCustom.Show("有商品不属‘申请中’不能更改数量,您确定要继续保存吗?", "增加提示", MessageBoxButtons.YesNo) == DialogResult.No)
  180. { return; }
  181. }
  182. else
  183. {
  184. if (MessageBoxCustom.Show("你确定修改采购列表中的商品数量吗?", "增加提示", MessageBoxButtons.YesNo) == DialogResult.No)
  185. { return; }
  186. }
  187. if (LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist) > 0)
  188. {
  189. this.dgv2_Click(sender, e);
  190. MessageBoxCustom.Show("保存成功!");
  191. }
  192. else
  193. { MessageBoxCustom.Show("保存失败!"); }
  194. }
  195. else
  196. {
  197. if (NotDelete > 0)
  198. { MessageBoxCustom.Show("商品不属‘申请中’不能更改数量!"); }
  199. }
  200. }
  201. }
  202. /// <summary>
  203. /// 删除此商品采购
  204. /// </summary>
  205. /// <param name="sender"></param>
  206. /// <param name="e"></param>
  207. protected override void btndelete_Click(object sender, EventArgs e)
  208. {
  209. if (this.dgv1.SelectedCells.Count == 0)
  210. { MessageBoxCustom.Show("请选择你要删除的数据!"); return; }
  211. string Status = this.dgv1.CurrentRow.Cells["Status"].Value.ToString();
  212. if (Status.ToString() == "申请中")
  213. {
  214. if (MessageBoxCustom.Show("你确定要删除吗?", "删除提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
  215. {
  216. int id = Convert.ToInt32(this.dgv1.CurrentRow.Cells["ID"].Value);
  217. if (porptbll.Delete(id) == true)
  218. { this.dgv2_Click(sender, e); }
  219. else
  220. { MessageBoxCustom.Show("删除失败!"); }
  221. }
  222. }
  223. else
  224. { MessageBoxCustom.Show("此商品正在 " + Status + " 不能删除!"); }
  225. }
  226. /// <summary>
  227. /// 删除订单
  228. /// </summary>
  229. /// <param name="sender"></param>
  230. /// <param name="e"></param>
  231. void btnDeleteOrder_Click(object sender, EventArgs e)
  232. {
  233. if (this.dgv2.Rows.Count > 0)
  234. {
  235. if (this.dgv2.CurrentRow != null)
  236. {
  237. string StrNumber = this.dgv2.CurrentRow.Cells["Pord_PurchaseNumber"].Value.ToString().Trim();
  238. if (!string.IsNullOrEmpty(StrNumber))
  239. {
  240. List<Helper.CommandInfo> clist = new List<Helper.CommandInfo>();
  241. DataTable dt = orbll.GetView_Custom("tb_ErpPurchaseProduct", StrWhere: "Ppt_PurchaseNumber = '" + StrNumber + "'", ShowColumnName: "ID").Tables[0];
  242. for (int i = 0; i < dt.Rows.Count; i++)
  243. {
  244. clist.Add(porptbll.GetDeleteCommandInfo("ID", "=", Convert.ToInt32(dt.Rows[i]["ID"].ToString().Trim())));
  245. }
  246. clist.Add(porbll.GetDeleteCommandInfo("ID", "=", Convert.ToInt32(this.dgv2.CurrentRow.Cells["PID"].Value)));
  247. if (clist.Count > 0)
  248. {
  249. if (MessageBoxCustom.Show("删除订单也会一同删除订单下的采购商品,你确定要删除吗?", "温馨提示!", MessageBoxButtons.YesNo) == DialogResult.No)
  250. { return; }
  251. if (LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist) > 0)
  252. {
  253. MessageBoxCustom.Show("删除成功!");
  254. this.FrmProcurementApplication_Shown(this, null);
  255. }
  256. else
  257. { MessageBoxCustom.Show("删除失败!"); }
  258. }
  259. }
  260. else
  261. { MessageBoxCustom.Show("获取采购单号出错!"); }
  262. }
  263. else
  264. { MessageBoxCustom.Show("请选择要删除的采购单号!"); }
  265. }
  266. }
  267. /// <summary>
  268. /// 导出
  269. /// </summary>
  270. /// <param name="sender"></param>
  271. /// <param name="e"></param>
  272. protected override void btnExport_Click(object sender, EventArgs e)
  273. {
  274. if (this.dgv1.Rows.Count > 0)
  275. { this.dgv1.ExportDataTable(); }
  276. }
  277. /// <summary>
  278. /// 打印
  279. /// </summary>
  280. /// <param name="sender"></param>
  281. /// <param name="e"></param>
  282. protected override void btnPrint_Click(object sender, EventArgs e)
  283. {
  284. if (this.dgv1.Rows.Count == 0)
  285. { MessageBoxCustom.Show("无打印的数据!"); return; }
  286. Hashtable htData = new Hashtable();
  287. htData["dgvData1"] = this.dgv1;
  288. htData["dgvData2"] = this.dgv2;
  289. LYFZ.Software.MainBusiness.ReportPrint.ReportFixedFormat.PrintFixedFormat(LYFZ.EnumPublic.PrintTypeEnum.库存采购申请单, htData);
  290. }
  291. }
  292. }