コード例 #1
0
 private void ReloadGridView(int IDSystemUser)
 {
     ContractsBO aContractsBO = new ContractsBO();
     SystemUsersBO aSystemUsersBO = new SystemUsersBO();
     List<ContractsEN> aListContractsEN = new List<ContractsEN>();
     List<Contracts> aListTemp = aContractsBO.Select_ByIDSystemUser(IDSystemUser);
     ContractsEN aContractsEN;
     if (aListTemp != null)
     {
         for (int i = 0; i < aListTemp.Count; i++)
         {
             aContractsEN = new ContractsEN();
             aContractsEN.SetValue(aListTemp[i]);
             aContractsEN.Name = aSystemUsersBO.Select_ByID(aListTemp[i].IDSystemUser).Name;
             aListContractsEN.Add(aContractsEN);
         }
     }
     dgvContracts.DataSource = aListContractsEN;
     dgvContracts.RefreshDataSource();
 }
コード例 #2
0
        private void btnAddNew_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.CheckDataBeforInsert() == true)
                {

                    ContractsBO aContractsBO = new ContractsBO();
                    //Disable hợp đồng cũ
                    Contracts aContracts_Old = new Contracts();
                    List<Contracts> aLisTemp = aContractsBO.Select_ByIDSystemUser(Convert.ToInt16(lueSystemUser.EditValue));

                    if (aLisTemp!= null)
                    {
                        aContracts_Old = aLisTemp.Where(a => a.Disable == false).ToList()[0];
                        aContracts_Old.Disable = true;
                        aContractsBO.Update(aContracts_Old);
                    }
                    // Tạo hợp đồng mới
                    Contracts aContracts = new Contracts();
                    aContracts.CreatedDate = DateTime.Now;
                    aContracts.ContractDate = dtpContractDate.DateTime;
                    aContracts.NumberContract = txtNumberContract.Text;
                    aContracts.NumberTemplateContract = txtNumberTemplateContract.Text;
                    aContracts.IDSystemUser = Convert.ToInt32(lueSystemUser.EditValue);
                    aContracts.Company = txtCompany.Text;
                    aContracts.StatutoryRepresent = txtStatutoryRepresent.Text;
                    aContracts.StatutoryRepresentGender = Convert.ToInt32(lueStatutoryRepresentGender.EditValue);
                    aContracts.StatutoryRepresentIdentifier = txtStatutoryRepresentIdentifier.Text;
                    aContracts.ContractType = Convert.ToInt32(lueContractType.EditValue);
                    aContracts.FromDate =dtpFrom.DateTime;
                    aContracts.ToDate = dtpTo.DateTime;

                    int SkuTableSalary = txtSkuTableSalary.Text.Length == 0 ? 0 : Convert.ToInt32(txtSkuTableSalary.Text);
                    double Coefficent = txtCoefficent.Text.Length == 0 ? 0 : Convert.ToDouble(txtCoefficent.Text);
                    decimal SalaryNet = txtSalaryNet.Text.Length == 0 ? 0 : Convert.ToDecimal(txtSalaryNet.Text);
                    decimal SalaryCross = txtSalaryCross.Text.Length == 0 ? 0 : Convert.ToDecimal(txtSalaryCross.Text);

                    aContracts.SkuTableSalary = SkuTableSalary;
                    aContracts.Coefficent = Coefficent;
                    aContracts.SalaryNet = SalaryNet;
                    aContracts.SalaryCross = SalaryCross;

                    aContracts.Type = Convert.ToInt32(lueType.EditValue);
                    aContracts.Status = cboStatus.SelectedIndex + 1;
                    aContracts.Disable = Convert.ToBoolean(cboDisable.Text);
                    aContractsBO.Insert(aContracts);
                    MessageBox.Show("Thêm mới thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    if (this.afrmLst_Contracts != null)
                    {
                        this.afrmLst_Contracts.ReloadData();
                        this.Close();
                    }
                    else if (this.afrmMain != null)
                    {
                        this.afrmMain.ReloadGridView();
                        this.Close();
                    }
                    else
                    {
                        int IDSystemUser = Convert.ToInt32(lueSystemUser.EditValue);
                        ReloadGridView(IDSystemUser);
                    }

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmIns_Contracts.btnAddNew_Click\n" + ex.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }