//Author : Hiennv
 public int Insert(Contracts aContracts)
 {
     try
     {
         aDatabaseDA.Contracts.Add(aContracts);
         return aDatabaseDA.SaveChanges();
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("ContractsBO.Insert :"+ ex.Message.ToString()));
     }
 }
 public void SetValue(Contracts aContracts)
 {
     this.ID = aContracts.ID;
     this.CreatedDate = aContracts.CreatedDate;
     this.ContractDate = aContracts.ContractDate;
     this.NumberContract = aContracts.NumberContract;
     this.NumberTemplateContract = aContracts.NumberTemplateContract;
     this.IDSystemUser = aContracts.IDSystemUser;
     this.Company = aContracts.Company;
     this.StatutoryRepresent = aContracts.StatutoryRepresent;
     this.StatutoryRepresentGender = aContracts.StatutoryRepresentGender;
     this.StatutoryRepresentIdentifier = aContracts.StatutoryRepresentIdentifier;
     this.ContractType = aContracts.ContractType;
     this.FromDate = aContracts.FromDate;
     this.ToDate = aContracts.ToDate;
     this.SkuTableSalary = aContracts.SkuTableSalary;
     this.Coefficent = aContracts.Coefficent;
     this.SalaryNet = aContracts.SalaryNet;
     this.SalaryCross = aContracts.SalaryCross;
     this.Type = aContracts.Type;
     this.Status = aContracts.Status;
     this.Disable = aContracts.Disable;
 }
        private void btnRemoverContracts_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            try
            {
                Contracts aContracts = new Contracts();
                aContracts.ID = Convert.ToInt32(viewSelectContracts.GetFocusedRowCellValue("ID"));
                aContracts.NumberContract = Convert.ToString(viewSelectContracts.GetFocusedRowCellValue("NumberContract"));
                aContracts.ContractDate = Convert.ToDateTime(viewSelectContracts.GetFocusedRowCellValue("ContractDate"));
                aContracts.Coefficent = Convert.ToDouble(viewSelectContracts.GetFocusedRowCellValue("Coefficent"));

                aListAvailableContracts.Add(aContracts);
                dgvAvailableContracts.DataSource = aListAvailableContracts;
                dgvAvailableContracts.RefreshDataSource();

                AllowancesEN aAllowancesEN = aContracts_AllowancesEN.aListAllowances.Where(d => d.ID == Convert.ToInt32(lueIDAllowances.EditValue)).ToList()[0];
                int Index = aContracts_AllowancesEN.aListAllowances.IndexOf(aAllowancesEN);
                Contracts Temps = aContracts_AllowancesEN.aListAllowances[Index].aListContracts.Where(d => d.ID == Convert.ToInt32(viewSelectContracts.GetFocusedRowCellValue("ID"))).ToList()[0];
                aContracts_AllowancesEN.aListAllowances[Index].aListContracts.Remove(Temps);
                dgvSelectContracts.DataSource = aContracts_AllowancesEN.aListAllowances[Index].aListContracts;
                dgvSelectContracts.RefreshDataSource();
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmIns_Contracts_Allowances.btnRemoverContracts_ButtonClick\n" + ex.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        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);
            }
        }
        //Author : Hiennv
        public List<Contracts> Select_ByIDAllowances(int IDAllowances)
        {
            try
            {
                List<sp_Contracts_GetCurrentHaveNotAllowances_Result> aListTemps = new List<sp_Contracts_GetCurrentHaveNotAllowances_Result>();
                aListTemps = aDatabaseDA.sp_Contracts_GetCurrentHaveNotAllowances(IDAllowances).ToList();
                List<Contracts> aListContracts = new List<Contracts>();
                for (int i = 0; i < aListTemps.Count; i++)
                {
                    Contracts aContracts = new Contracts();
                    aContracts.ID = aListTemps[i].ID;
                    aContracts.CreatedDate = aListTemps[i].CreatedDate;
                    aContracts.ContractDate = aListTemps[i].ContractDate;
                    aContracts.NumberContract = aListTemps[i].NumberContract;
                    aContracts.NumberTemplateContract = aListTemps[i].NumberTemplateContract;
                    aContracts.IDSystemUser = aListTemps[i].IDSystemUser;
                    aContracts.Company = aListTemps[i].Company;
                    aContracts.StatutoryRepresent = aListTemps[i].StatutoryRepresent;
                    aContracts.StatutoryRepresentGender = aListTemps[i].StatutoryRepresentGender;
                    aContracts.StatutoryRepresentIdentifier = aListTemps[i].StatutoryRepresentIdentifier;
                    aContracts.ContractType = aListTemps[i].ContractType;
                    aContracts.FromDate = aListTemps[i].FromDate;
                    aContracts.ToDate = aListTemps[i].ToDate;
                    aContracts.SkuTableSalary = aListTemps[i].SkuTableSalary;
                    aContracts.Coefficent = aListTemps[i].Coefficent;
                    aContracts.SalaryNet = aListTemps[i].SalaryNet;
                    aContracts.SalaryCross = aListTemps[i].SalaryCross;
                    aContracts.Type = aListTemps[i].Type;
                    aContracts.Status = aListTemps[i].Status;
                    aContracts.Disable = aListTemps[i].Disable;

                    aListContracts.Add(aContracts);
                }
                return aListContracts;
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("ContractsBO.Select_ByIDAllowances :"+ ex.Message.ToString()));
            }
        }