示例#1
0
        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();
        }
示例#2
0
        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
        }