public void ShowInfo(int plnum) { dtgPlannedOrderDetail.DataSource = DetailBusiness.GetListDetailFromPlnum(plnum); Plannde objPlannedOrder = PlanndeBusiness.GetPlannde(plnum); txtMaterial.Text = objPlannedOrder.matnr; txtOrderQuantitty.Text = objPlannedOrder.gsmng.ToString(); txtDocumentName.Text = objPlannedOrder.maktx.ToString(); txtPlanNumber.Text = objPlannedOrder.plnum.ToString();// txtStog.Text = objPlannedOrder.lgort; //dtgPlannedOrderDetail.Columns["plnum"].DisplayIndex = 0; //dtgPlannedOrderDetail.Columns["matnr"].DisplayIndex = 1; //dtgPlannedOrderDetail.Columns["maktx"].DisplayIndex = 2; //dtgPlannedOrderDetail.Columns["erfmg"].DisplayIndex = 3; //dtgPlannedOrderDetail.Columns["count"].DisplayIndex = 4; //dtgPlannedOrderDetail.Columns["erfme"].DisplayIndex = 5; //dtgPlannedOrderDetail.Columns["plwrk"].DisplayIndex = 6; //dtgPlannedOrderDetail.Columns["lgpro"].DisplayIndex = 7; //dtgPlannedOrderDetail.Columns["charg"].DisplayIndex = 8; //dtgPlannedOrderDetail.Columns["posnr"].DisplayIndex = 9; dtgPlannedOrderDetail.Columns["plnum"].HeaderText = "Planned order"; dtgPlannedOrderDetail.Columns["plnum"].Visible = false; dtgPlannedOrderDetail.Columns[1].HeaderText = "Mã sản phẩm con"; dtgPlannedOrderDetail.Columns[2].HeaderText = "Tên sản phẩm con"; dtgPlannedOrderDetail.Columns[3].HeaderText = "Số lượng ban đầu"; dtgPlannedOrderDetail.Columns[4].HeaderText = "SỐ LƯỢNG THỰC TẾ"; dtgPlannedOrderDetail.Columns[5].HeaderText = "Đơn vị tính"; dtgPlannedOrderDetail.Columns[6].HeaderText = "Plant"; dtgPlannedOrderDetail.Columns[7].HeaderText = "Kho"; dtgPlannedOrderDetail.Columns[8].HeaderText = "Số batch"; dtgPlannedOrderDetail.Columns[9].HeaderText = "Số thứ tự"; dtgPlannedOrderDetail.Columns["dateCreated"].Visible = false; dtgPlannedOrderDetail.Columns["dateEdited"].Visible = false; dtgPlannedOrderDetail.Columns["status"].Visible = false; }
private void CheckPlan() { try { int plnum = int.Parse(txtDocument.Text); Plannde objPlan = PlanndeBusiness.GetPlannde(plnum); //Trường hợp nếu đã tồn tại plan này và đã post if (objPlan != null && objPlan.status == true) { string query = "update dbo.PlannedOrder set status = 0 where plnum =" + plnum; DataProvider.Execute(query, null, false); frmDocumentDetail f = new frmDocumentDetail(plnum, lblAccount.Text); txtDocument.Clear(); this.Hide(); f.ShowDialog(); this.Show(); } else { List <Plannde> lstPlan = PlanndeBusiness.GetListPlannedOrder(); int planCount = 0; foreach (Plannde item in lstPlan) { if (item.plnum == plnum.ToString()) { planCount++; } } if (planCount == 1) { LoadListPlannedOrder(); frmDocumentDetail f = new frmDocumentDetail(plnum, lblAccount.Text); txtDocument.Clear(); this.Hide(); f.ShowDialog(); this.Show(); } else { AccessToken objToken = DataProvider.GetTokenDictionary("*****@*****.**", "Wuvl@1234", ConfigurationManager.AppSettings["tokenUrl"].ToString()); string url = ConfigurationManager.AppSettings["get_planned_order"].ToString() + plnum; string jsonString = DataProvider.GetRESTDats(url, objToken.accessToken.ToString()); List <Plannde> lstPlannedOrder = new List <Plannde>(); lstPlannedOrder = JsonConvert.DeserializeObject <List <Plannde> >(jsonString); if (lstPlannedOrder.Count == 0) { txtDocument.BackColor = Color.OrangeRed; MessageBox.Show("K tồn tại Planned Order bạn muốn tìm!", "Thong bao!"); txtDocument.Clear(); txtDocument.BackColor = Color.White; } else { PlanndeBusiness.AddPlannedOrder(lstPlannedOrder[0]); var lstPlannedOrderDetail = lstPlannedOrder[0].detail.ToList(); foreach (Detail item in lstPlannedOrderDetail) { DetailBusiness.AddDetail(item, false); } LoadListPlannedOrder(); frmDocumentDetail f = new frmDocumentDetail(plnum, lblAccount.Text); txtDocument.Clear(); this.Hide(); f.ShowDialog(); this.Show(); } } } } catch (FormatException) { txtDocument.BackColor = Color.OrangeRed; MessageBox.Show("Bạn nhập sai mã plan number!", "Thông báo!"); txtDocument.Clear(); txtDocument.BackColor = Color.White; } LoadListPlannedOrder(); }
private void BtnChooseBatch_Click(object sender, EventArgs e) { //Neu da ton tai plannedOrderDetail + Batch do thi + them //Neu chua co batch do cho plannedOrderDetail do thi add 1 dong moi string matnr = txtMatnr.Text; List <Itemcode> lstItem = ItemCodeBusiness.GetITemList(matnr); string maktx = lstItem[0].maktx; int loai = int.Parse(lblLoai.Text); int plnum = int.Parse(lblPlnum.Text); double count = (double)nmItemCount.Value; string charg = ""; string erfme = txtErfme.Text; List <string> lstBatch = BatchBusiness.GetBatchList2(plnum.ToString(), matnr); if (lstBatch.Count == 0) { if (!String.IsNullOrEmpty(cboChooseBatch.Text)) { MessageBox.Show("Không tồn tại batch tương ứng với Planned Order Detail này!", "Thông báo!"); return; } else { charg = ""; } } else { if (String.IsNullOrEmpty(cboChooseBatch.Text)) { charg = ""; } else { int i = 0; foreach (string item in lstBatch) { if (item == cboChooseBatch.Text) { i++; } } if (i == 0) { MessageBox.Show("Không tồn tại batch tương ứng với Planned Order Detail này!", "Thông báo!"); return; } else { charg = cboChooseBatch.Text; } } } //Xử lý trường hợp nếu item không có batch ( ví dụ 1 số sản phẩm như chai lọ) //string lgort = (PlanndeBusiness.GetPlannedOrderFromPlnum(plnum)).lgort; string lgort = txtlg.Text; string lgpro = cboLgpro.SelectedItem.ToString(); int posnr = DetailBusiness.GetMaxPosnrFromMatnr(plnum); //Truong hop da ton tai matnr do trong list Detail //Them moi neu k trung batch, update neu trung batch //Kiểm tra xem batch đó có trong danh sách batch tương ứng với if (count == 0) { MessageBox.Show("So luong khong duoc bang 0!", "Thong bao!"); } else { if (loai == 0) { Detail objDetail = DetailBusiness.GetDetail(matnr, plnum, lgpro, charg); List <Detail> lstDetail = DetailBusiness.GetListDetailFromPlnum(plnum); #region code thừa //int i = 0; //foreach (Detail item in lstDetail) //{ // if (item.charg == charg && item.matnr == matnr) // { // i++; // } //} #endregion if (objDetail.charg == charg && objDetail.lgpro == lgpro) { //Neu da co thi update them erfmg DetailBusiness.UpdateCountForDetail(plnum, objDetail.count + count, matnr, charg, lgpro); } else { //if (cboErfme.SelectedItem == null) //{ // erfme = ""; //} //Neu chua co thi add them objDetail.plnum = plnum.ToString(); objDetail.matnr = matnr; objDetail.maktx = maktx; objDetail.charg = charg; objDetail.erfmg = objDetail.erfmg; objDetail.plwrk = PlanndeBusiness.GetPlannde(plnum).plwrk; objDetail.posnr = (posnr + 10); objDetail.erfme = erfme; objDetail.lgpro = lgpro; objDetail.count = count; DetailBusiness.AddDetail(objDetail); } } //Them moi 1 Detail else { //if (cboErfme.SelectedItem == null) //{ // erfme = ""; //} //else //{ Detail objDetail = new Detail(); objDetail.plnum = plnum.ToString(); objDetail.matnr = matnr; objDetail.maktx = maktx; objDetail.erfmg = 0; objDetail.plwrk = PlanndeBusiness.GetPlannde(plnum).plwrk; objDetail.lgpro = lgort; objDetail.charg = charg; objDetail.posnr = (posnr + 10); objDetail.erfme = erfme; objDetail.count = count; DetailBusiness.AddDetail(objDetail); //} } } this.Close(); #region code cũ /* * string matnr = txtMatnr.Text; * Detail objDetail = DetailBusiness.GetPlannedOrderDetailFromMatnr(matnr); * List<Detail> lstPlannedOrderDetail = DetailBusiness.GetListPlannedOrderDetail(int.Parse(objDetail.plnum)); * string charg = (cboChooseBatch.SelectedItem as Batch).charg; * Detail obj = DetailBusiness.GetPlannedOrderDetailFromMatnr(matnr); * float plannedOrderDetailCount = float.Parse(nmItemCount.Value.ToString()); * int count = 0; * foreach (Detail item in lstPlannedOrderDetail) * { * if (item.matnr == matnr && item.charg == charg) * { * count++; * } * } * if (count > 0) * { * DetailBusiness.UpdateErfmgForPlannedOrderDetail(plannedOrderDetailCount + obj.erfmg, matnr, charg); * } * else * { * obj.erfmg = plannedOrderDetailCount; * obj.charg = charg; * obj.posnr = (DetailBusiness.GetMaxPosnrFromMatnr(matnr) + 10).ToString(); * DetailBusiness.AddPlannedOrderDetail(obj); * } */ #endregion }