public static ReturnToSupplier CreateReturnToSupplier(int returnToSupplierID)
 {
     ReturnToSupplier returnToSupplier = new ReturnToSupplier();
     returnToSupplier.ReturnToSupplierID = returnToSupplierID;
     return returnToSupplier;
 }
示例#2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (Edit_Flage)
            {
                return;
            }

            int qty_from_stock;   //get quantity from table stock

            int qty_from_dgvlist; //get quantity from datagridview

            string itm;           //get item code from datagridview

            #region condition if

            if (string.IsNullOrEmpty(txtRefer1.Text.Trim()))
            {
                errorMS.SetError(txtRefer1, "Please input reference 1");
                txtRefer1.Focus();
                return;
            }
            else
            {
                errorMS.Clear();
            }

            if (cboApplicant.SelectedIndex < 0)
            {
                errorMS.SetError(cboApplicant, "Please select applicant");
                cboApplicant.Focus();
                return;
            }
            else
            {
                errorMS.Clear();
            }

            if (cboApprover.SelectedIndex < 0)
            {
                errorMS.SetError(cboApprover, "Please select approver");
                cboApprover.Focus();
                return;
            }
            else
            {
                errorMS.Clear();
            }

            #endregion

            if (dgvList.Rows.Count > 0)
            {
                #region insert into table ReturnToSupplier

                var ReturnToSupplier = new ReturnToSupplier()
                {
                    ReturnDate    = dtpIssuedDate.Value,
                    Reference     = txtRefer1.Text,
                    ApplicantCode = cboApplicant.SelectedValue.ToString(),
                    ApproverCode  = cboApprover.SelectedValue.ToString(),
                    ProjectId     = int.Parse(cboProject.SelectedValue.ToString()),
                    Remark        = txtPurpose.Text,
                    ComputerCode  = Services.MegaService.GetComputerCode(),
                    ComputeTime   = Services.MegaService.GetComputeTime()
                };

                mega.ReturnToSuppliers.Add(ReturnToSupplier);

                #endregion

                #region isert into table ReturnToSupplierDetail and update stock

                for (int i = 0; i < dgvList.Rows.Count; i++)
                {
                    var ReturnToSupplierView = new ReturnToSupplierDetail()
                    {
                        MasterCode = ReturnToSupplier.Id,
                        ItemCode   = dgvList.Rows[i].Cells[1].Value.ToString(),
                        Quantity   = int.Parse(dgvList.Rows[i].Cells[4].Value.ToString()),
                        UnitPrice  = decimal.Parse(dgvList.Rows[i].Cells[3].Value.ToString()),
                        Amount     = decimal.Parse(dgvList.Rows[i].Cells[3].Value.ToString()) * int.Parse(dgvList.Rows[i].Cells[4].Value.ToString())
                    };

                    mega.ReturnToSupplierDetails.Add(ReturnToSupplierView);

                    itm = dgvList.Rows[i].Cells[1].Value.ToString();

                    qty_from_dgvlist = int.Parse(dgvList.Rows[i].Cells[4].Value.ToString());

                    var stock = mega.Stocks.Where(x => x.ItemCode == itm).FirstOrDefault();

                    qty_from_stock = stock.Quantity;
                    stock.Quantity = (qty_from_stock - qty_from_dgvlist);

                    mega.Entry(stock).State = EntityState.Modified;
                }

                #endregion

                mega.SaveChanges();

                dgvList.Rows.Clear();
                txtGrandTotal.Text    = txtRefer1.Text = txtPurpose.Text = "";
                cboItem.SelectedIndex = cboApplicant.SelectedIndex = cboApprover.SelectedIndex = cboProject.SelectedIndex = -1;
                lblSaved.Show();
            }
        }
 public void AddToReturnToSupplier(ReturnToSupplier returnToSupplier)
 {
     base.AddObject("ReturnToSupplier", returnToSupplier);
 }