Exemple #1
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (empId != null)
     {
         try
         {
             var emp = mega.Employees.Where(x => x.Code == empId).FirstOrDefault();
             emp.IsActive          = false;
             mega.Entry(emp).State = System.Data.Entity.EntityState.Modified;
             mega.SaveChanges();
             lblDelete.Show();
             loadEmployee();
             empId = null;
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
Exemple #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 ReturnToWH

                var ReturnToWh = new ReturnToWH()
                {
                    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.ReturnToWHs.Add(ReturnToWh);

                #endregion

                #region isert into table ReturnToWHDetail and update stock

                for (int i = 0; i < dgvList.Rows.Count; i++)
                {
                    var ReturnToWHView = new ReturnToWHDetail()
                    {
                        MasterCode = ReturnToWh.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.ReturnToWHDetails.Add(ReturnToWHView);

                    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();
            }
        }
Exemple #3
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 (string.IsNullOrEmpty(txtRefer2.Text.Trim()))
            {
                errorMS.SetError(txtRefer2, "Please input reference 2");
                txtRefer2.Focus();
                return;
            }
            else
            {
                errorMS.Clear();
            }

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

            #endregion

            if (dgvList.Rows.Count > 0)
            {
                try
                {
                    #region insert_into_issued

                    var issued = new Issued()
                    {
                        IssuedDate    = dtpIssuedDate.Value,
                        Reference1    = txtRefer1.Text,
                        Reference2    = txtRefer2.Text,
                        ApplicantCode = cboApplicant.SelectedValue.ToString(),
                        ProjectId     = int.Parse(cboProject.SelectedValue.ToString()),
                        Purpose       = txtPurpose.Text,
                        Car           = txtCar.Text,
                        ComputerCode  = Services.MegaService.GetComputerCode(),
                        ComputeTime   = Services.MegaService.GetComputeTime()
                    };
                    mega.Issueds.Add(issued);

                    #endregion

                    for (int i = 0; i < dgvList.Rows.Count; i++)
                    {
                        #region insert_into_issuedDetail_and_update_stock

                        var issuedDetail = new IssuedDetail()
                        {
                            MasterCode = issued.Id,
                            ItemCode   = dgvList.Rows[i].Cells[1].Value.ToString(),
                            UnitPrice  = decimal.Parse(dgvList.Rows[i].Cells[3].Value.ToString()),
                            Quantity   = int.Parse(dgvList.Rows[i].Cells[4].Value.ToString()),
                            Amount     = decimal.Parse(dgvList.Rows[i].Cells[3].Value.ToString()) * int.Parse(dgvList.Rows[i].Cells[4].Value.ToString())
                        };
                        mega.IssuedDetails.Add(issuedDetail);

                        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();

                    lblSaved.Show();
                    txtRefer1.Text             = txtRefer2.Text = txtCar.Text = txtPurpose.Text = txtGrandTotal.Text = "";
                    cboApplicant.SelectedIndex = cboProject.SelectedIndex = -1;
                    dgvList.Rows.Clear();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }