private void bt_SavePlan_Click(object sender, EventArgs e) { using (AxaContext ctx = new AxaContext()) { if (tb_Description.Text == "") { MessageBox.Show("Please filled up all fields"); } else { if (dataGridView_Plan.SelectedRows.Count > 0) { int tempIdplan = Int32.Parse(dataGridView_Plan.SelectedRows[0].Cells[0].Value.ToString()); var planUpdate = new Plan { PlanId = tempIdplan, Description = tb_Description.Text, PlanType = cb_PlanType.SelectedItem.ToString(), Category = cb_PlanCategory.SelectedItem.ToString(), }; ctx.Plans.Attach(planUpdate); ctx.Entry(planUpdate).State = System.Data.Entity.EntityState.Modified; ctx.SaveChanges(); ClearTextField(); AddEditPlan_Load(null, null); MessageBox.Show("Plan Succesfully Updated"); } else { var plan = new Plan { Description = tb_Description.Text, PlanType = cb_PlanType.SelectedItem.ToString(), Category = cb_PlanCategory.SelectedItem.ToString(), }; ctx.Plans.Add(plan); ctx.SaveChanges(); ClearTextField(); AddEditPlan_Load(null, null); MessageBox.Show("Plan SUccesfully Added"); } } } }
private void SaveEmployee() { if (dgvrAddEditEmployee == null) { try { using (AxaContext ctx = new AxaContext()) { var employee = new Employee { IdPicture = textBox1.Text, ELastName = tb_LastName.Text, EMiddleName = tb_MiddleName.Text, EFirstName = tb_FirstName.Text, BirthDate = dateTimePicker1.Value.Date, Age = tb_Age.Text, EmailAddress = tb_EmailAddress.Text, Gender = cb_Gender.SelectedItem.ToString(), CivilStatus = cb_CivilStatus.Text, CellphoneNo = tb_CellphoneNo.Text, Address = tb_Address.Text, DesignatedPostion = cb_DisignatedPosition.SelectedItem.ToString(), }; ctx.Employees.Add(employee); ctx.SaveChanges(); MessageBox.Show("Save Successful"); this.Close(); this.Dispose(); // Clearfields(); } } catch (System.Exception) { MessageBox.Show("Save unSuccessful"); } } else { try { int tempEployeeId = Int32.Parse(dgvrAddEditEmployee.Cells[0].Value.ToString()); using (AxaContext ctx = new AxaContext()) { var employeeUpdate = new Employee { EmployeeId = tempEployeeId, IdPicture = textBox1.Text, ELastName = tb_LastName.Text, EMiddleName = tb_MiddleName.Text, EFirstName = tb_FirstName.Text, BirthDate = dateTimePicker1.Value.Date, Age = tb_Age.Text, EmailAddress = tb_EmailAddress.Text, Gender = cb_Gender.SelectedItem.ToString(), CivilStatus = cb_CivilStatus.Text, CellphoneNo = tb_CellphoneNo.Text, Address = tb_Address.Text, DesignatedPostion = cb_DisignatedPosition.SelectedItem.ToString(), }; ctx.Employees.Attach(employeeUpdate); ctx.Entry(employeeUpdate).State = System.Data.Entity.EntityState.Modified; ctx.SaveChanges(); MessageBox.Show("Update Successful"); this.Close(); this.Dispose(); } } catch { } } }
private void SaveClient() { //Add Client user using (AxaContext ctx = new AxaContext()) { var clientInfo = new Client { CLastName = tb_LastName.Text, CMiddleName = tb_MiddleName.Text, CFirstName = tb_FirstName.Text, SpouseLastName = tb_SLastName.Text, SpouseMiddleName = tb_SMiddleName.Text, SpouseFirstName = tb_SFirstName.Text, Gender = cb_Gender.Text, CivilStatus = cb_CivilStatus.Text, PolicyStatus = cb_PolicyStatus.Text, CBirthday = dtp_Dob.Value, Age = tb_Age.Text, PlaceOfBirth = tb_PlaceOfBirth.Text, Height = 11, //Height = float.Parse(tb_Height.Text), //Weight = float.Parse(tb_Weight.Text), Weight = 11, CAddress = tb_Address.Text, CellphoneNo = tb_CellphoneNo.Text, TelephoneNo = tb_TelephoneNo.Text, EmailAddress = tb_EmailAddress.Text, Occupation = tb_COccupation.Text, //WorkSalary = float.Parse(tb_CWorkSalary.Text), //BusinessIncome = float.Parse(tb_CBusinessIncome.Text), //OtherSource = float.Parse(tb_COtherSource.Text), WorkSalary = 11, BusinessIncome = 11, OtherSource = 11, CompanyName = tb_CName.Text, CompanyAddress = tb_CAddress.Text, CompanyContact = tb_CompanyContactNo.Text, NatureOfBusiness = tb_CNatureOfBusiness.Text, TaxIdNumber = tb_TaxIdentication.Text, Sss_gsisNumber = tb_SSSorGSIS_Number.Text, ValidId1 = idPic1.Text, ValidId2 = idPic2.Text, // EmployeeId = tempEmployeeId EmployeeId = 1 }; ctx.Clients.Add(clientInfo); ctx.SaveChanges(); // save client plan var clientPlan = new ClientPlan(); for (int row = 0; row < dataGridView_LoadPlans.Rows.Count; row++) { clientPlan.PolicyNo = dataGridView_LoadPlans.Rows[row].Cells["col_PolicyNo"].Value.ToString(); clientPlan.SumInsured = dataGridView_LoadPlans.Rows[row].Cells["col_SumInsured"].Value.ToString(); clientPlan.ModeOfPayment = dataGridView_LoadPlans.Rows[row].Cells["col_ModeOfPayment"].Value.ToString(); clientPlan.DueOfPayment = Int32.Parse(dataGridView_LoadPlans.Rows[row].Cells["col_DueOfPayment"].Value.ToString()); string tempPlanCategory = dataGridView_LoadPlans.Rows[row].Cells["col_PlanCategory"].Value.ToString(); string tempPlanAvail = dataGridView_LoadPlans.Rows[row].Cells["col_PlanAvail"].Value.ToString(); var tempPlanId = ctx.Plans.Where(x => x.Category == tempPlanCategory && x.Description == tempPlanAvail).Select(p => p.PlanId).FirstOrDefault().ToString(); clientPlan.PlanId = Convert.ToInt32(tempPlanId); clientPlan.ClientId = clientInfo.ClientId; ctx.ClientPlans.Add(clientPlan); ctx.SaveChanges(); } } }
private void SaveUser() { using (AxaContext ctx = new AxaContext()) { if (tb_FName.Text == "") { MessageBox.Show("Please Filled up all the fields"); } else { if (dataGridView_User.SelectedRows.Count > 0) { try { bool statusAccount = false; if (radioButton1.Checked == true) { statusAccount = true; } else { statusAccount = false; } int userId = Int32.Parse(dataGridView_User.SelectedRows[0].Cells[0].Value.ToString()); var userUpdate = new User { UserId = userId, UFirstName = tb_FName.Text, UMiddleName = tb_MName.Text, ULastName = tb_LName.Text, ContactNumber = tb_ContactNo.Text, UserName = tb_Username.Text, Password = tb_Password.Text, UAddress = tb_Address.Text, UGender = cb_Gender.GetItemText(cb_Gender.SelectedItem), Role = cb_Role.GetItemText(cb_Role.SelectedItem), IsActive = statusAccount }; ctx.Users.Attach(userUpdate); ctx.Entry(userUpdate).State = System.Data.Entity.EntityState.Modified; ctx.SaveChanges(); ClearTextField(); LoadUserList(); MessageBox.Show("Update Successful"); } catch (Exception) { } } else { var user = new User { UFirstName = tb_FName.Text, UMiddleName = tb_MName.Text, ULastName = tb_LName.Text, ContactNumber = tb_ContactNo.Text, UserName = tb_Username.Text, Password = tb_Password.Text, UAddress = tb_Address.Text, UGender = cb_Gender.GetItemText(cb_Gender.SelectedItem), Role = cb_Role.GetItemText(cb_Role.SelectedItem) }; ctx.Users.Add(user); ctx.SaveChanges(); ClearTextField(); LoadUserList(); MessageBox.Show("Save Successful"); } } } }