private void btnAddNew_Click(object sender, EventArgs e) { try { if (ValidateData() == true) { DivisionsBO aDivisionsBO = new DivisionsBO(); Divisions aDivisions = new Divisions(); aDivisions.Name = txtName.Text; aDivisions.Type = cboType.SelectedIndex + 1; aDivisions.Status = cboStatus.SelectedIndex + 1; aDivisions.Disable = Convert.ToBoolean(cboDisable.Text); aDivisionsBO.Insert(aDivisions); if (this.afrmLst_Divisions != null) { this.afrmLst_Divisions.ReloadData(); } MessageBox.Show("Thêm mới thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } catch (Exception ex) { MessageBox.Show("frmIns_Divisions.btnAddNew_Click\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
//Author : LinhTing //Function : Insert Divisions public int Insert(Divisions aDivisions) { try { aDatabaseDA.Divisions.Add(aDivisions); return aDatabaseDA.SaveChanges(); } catch (Exception ex) { throw new Exception(string.Format("DivisionsBO.Insert :"+ ex.Message.ToString().ToString())); } }