//Adding a new user private void btnAddUser_Click(object sender, EventArgs e) { User user = new User(); try { user.CityId = Convert.ToInt32(cbxCity.SelectedValue); user.DistrictId = Convert.ToInt32(cbxDistrict.SelectedValue); user.Name = txtName.Text; user.Surname = txtSurname.Text; user.IdentityNumber = txtIdentidyNumber.Text; if (chcMale.Checked == true) { user.Gender = true; } else if (chcFemale.Checked == true) { user.Gender = false; } user.Birthday = dtpBirthday.Value; user.Address = txtAddress.Text; user.Point = 0; user.Username = txtUsername.Text; user.Password = txtPassword.Text; _wrt.Users.InsertOnSubmit(user); _wrt.SubmitChanges(); GetUsers(); Clear(); MessageBox.Show("Entity added successfully"); } catch { MessageBox.Show("We got a problem on the system.Try it another time."); } }
//Adding a new management private void btnAddManagement_Click(object sender, EventArgs e) { Management management = new Management(); try { management.ManagementTypeId = Convert.ToInt32(cbxManagementType.SelectedValue); management.CityId = Convert.ToInt32(cbxCity.SelectedValue); management.DistrictId = Convert.ToInt32(cbxDistrict.SelectedValue); management.Name = tbxName.Text; management.Point = 0; management.Address = tbxAddress.Text; management.Username = tbxUsername.Text; management.Password = tbxPassword.Text; _wrt.Managements.InsertOnSubmit(management); _wrt.SubmitChanges(); GetManagements(); Clear(); MessageBox.Show("Entity deleted successfully"); } catch { MessageBox.Show("We got a problem on the system.Try it another time."); } }
//Adding a new animal private void btnAddAnimal_Click(object sender, EventArgs e) { try { Animal animal = new Animal(); animal.KindOfAnimalId = Convert.ToInt32(cbxKindOfAnimal.SelectedValue); animal.ShelterId = Convert.ToInt32(cbxShelterId.SelectedValue); animal.Name = tbxName.Text; animal.DateOfRegister = dtpAnimal.Value; animal.Note = tbxNote.Text; if (cbxTrue.Checked == true) { animal.Pet = true; } else if (cbxFalse.Checked == false) { animal.Pet = false; } _wrt.Animals.InsertOnSubmit(animal); _wrt.SubmitChanges(); GetAnimals(); Clear(); MessageBox.Show("Entity deleted successfully"); } catch { MessageBox.Show("We got a problem on the system.Try it another time."); } }
private void btnAddShelter_Click(object sender, EventArgs e) { Shelter shelter = new Shelter(); try { shelter.CityId = Convert.ToInt32(cbxCity.SelectedValue); shelter.DistrictId = Convert.ToInt32(cbxDistrict.SelectedValue); shelter.Name = tbxName.Text; shelter.Address = tbxAddress.Text; shelter.Phone = tbxPhone.Text; _wrt.Shelters.InsertOnSubmit(shelter); _wrt.SubmitChanges(); GetShelters(); Clear(); MessageBox.Show("Entity deleted successfully"); } catch { MessageBox.Show("We got a problem on the system.Try it another time."); } }
//We can update our register with that button click private void btnUpdate_Click(object sender, EventArgs e) { try { if (Convert.ToInt32(dgwManagementWorker.CurrentRow.Cells[1].Value) == Convert.ToInt32(tbxManagementId.Text)) { int id = Convert.ToInt32(dgwManagementWorker.CurrentRow.Cells[0].Value); _managementFood = _wrt.ManagementFoods.FirstOrDefault(mf => mf.Id == id); _managementFood.DateOfFood = dtpDateOfFood.Value; _wrt.SubmitChanges(); GetManagementFoodsTable(); MessageBox.Show("Entity updated successfully"); } else { MessageBox.Show("You cannot update the register which isn't yours"); } } catch { MessageBox.Show("We got a problem on the system.Try it another time."); } }
private void btnAddPart1_Click(object sender, EventArgs e) { try { if (cbxType.SelectedIndex == 0) { _phoneType.Name = tbxName.Text; _wrt.PhoneTypes.InsertOnSubmit(_phoneType); _wrt.SubmitChanges(); GetPhoneTypesTable(); MessageBox.Show("Entity added successfully"); tbxName.Text = ""; } else if (cbxType.SelectedIndex == 1) { _managementType.Name = tbxName.Text; _wrt.ManagementTypes.InsertOnSubmit(_managementType); _wrt.SubmitChanges(); GetManagementTypesTable(); MessageBox.Show("Entity added successfully"); tbxName.Text = ""; } else if (cbxType.SelectedIndex == 2) { _kindOfAnimal.Name = tbxName.Text; _wrt.KindOfAnimals.InsertOnSubmit(_kindOfAnimal); _wrt.SubmitChanges(); GetKindOfAnimalsTable(); MessageBox.Show("Entity added successfully"); tbxName.Text = ""; } } catch { MessageBox.Show("We got a problem on the system.Try it another time."); } }
//We'll create a register on the griedview private void btnTakeMission_Click(object sender, EventArgs e) { try { using (var context = new WeAreTogetherDataContext()) { var managementFood = new ManagementFood { ManagementId = Convert.ToInt32(tbxManagementId.Text), DateOfFood = dtpDateOfFood.Value, SupplyDelivery = false }; context.ManagementFoods.InsertOnSubmit(managementFood); context.SubmitChanges(); GetManagementFoodsTable(); dtpDateOfFood.Text = ""; MessageBox.Show("Entity added successfully"); } } catch { MessageBox.Show("We got a problem on the system.Try it another time."); } }
//To update the register which belong to user private void btnTakeMission_Click(object sender, EventArgs e) { try { int id = Convert.ToInt32(dgwVoluteerWorker.CurrentRow.Cells[0].Value); _managementFood = _wrt.ManagementFoods.FirstOrDefault(mid => mid.Id == id); if (cbxTrue.Checked == true) { _managementFood.SupplyDelivery = true; int managementId = Convert.ToInt32(dgwVoluteerWorker.CurrentRow.Cells[1].Value); _management = _wrt.Managements.FirstOrDefault(mi => mi.Id == managementId); _management.Point += 1; _wrt.SubmitChanges(); int userId = Convert.ToInt32(tbxUserId.Text); _user = _wrt.Users.FirstOrDefault(ui => ui.Id == userId); _user.Point += 1; _wrt.SubmitChanges(); } else if (cbxFalse.Checked == true) { _managementFood.SupplyDelivery = false; } _managementFood.DeliveryTime = dtpDeliveryTime.Value; _managementFood.ResponsibleUser = Convert.ToInt32(tbxUserId.Text); _wrt.SubmitChanges(); GetManagementFoodsTable(); cbxFalse.Checked = false; cbxTrue.Checked = false; MessageBox.Show("Register delivered successfully"); } catch { MessageBox.Show("We got a problem on the system.Try it another time."); } }
private void btnAddPart2_Click(object sender, EventArgs e) { try { if (cbxList2.SelectedIndex == 0) { _userPhone.UserId = Convert.ToInt32(cbxUserId.SelectedValue); _userPhone.PhoneId = Convert.ToInt32(cbxPhoneTypeId.SelectedValue); _userPhone.PhoneNumber = tbxNameIki.Text; _wrt.UserPhones.InsertOnSubmit(_userPhone); _wrt.SubmitChanges(); GetUserPhoneTable(); MessageBox.Show("Entity added successfully"); } else if (cbxList2.SelectedIndex == 1) { _ManagementPhone.ManagementId = Convert.ToInt32(cbxManagementId.SelectedValue); _ManagementPhone.PhoneTypeId = Convert.ToInt32(cbxPhoneTypeId.SelectedValue); _ManagementPhone.PhoneNumber = tbxNameIki.Text; _wrt.ManagementPhones.InsertOnSubmit(_ManagementPhone); _wrt.SubmitChanges(); GetManagementPhoneTable(); MessageBox.Show("Entity added successfully"); } else if (cbxList2.SelectedIndex == 2) { _ManagementShelter.ManagementId = Convert.ToInt32(cbxManagementId.SelectedValue); _ManagementShelter.ShelterId = Convert.ToInt32(cbxShelterId.SelectedValue); if (cbxTrue.Checked == true) { _ManagementShelter.Active = true; } else if (cbxFalse.Checked == true) { _ManagementShelter.Active = false; } _wrt.ManagementShelters.InsertOnSubmit(_ManagementShelter); _wrt.SubmitChanges(); GetManagementShelterTable(); MessageBox.Show("Entity added successfully"); } else if (cbxList2.SelectedIndex == 3) { _rOf.UserId = Convert.ToInt32(cbxUserId.SelectedValue); _rOf.ManagementId = Convert.ToInt32(cbxManagementId.SelectedValue); _wrt.ResponsibleOfManagements.InsertOnSubmit(_rOf); _wrt.SubmitChanges(); GetResponsibleOfManagementTable(); MessageBox.Show("Entity added successfully"); } else if (cbxList2.SelectedIndex == 4) { _sOu.UserId = Convert.ToInt32(cbxUserId.SelectedValue); _sOu.ShelterId = Convert.ToInt32(cbxShelterId.SelectedValue); if (cbxTrue.Checked == true) { _sOu.Active = true; } else if (cbxFalse.Checked == true) { _sOu.Active = false; } _wrt.ShelterOfUsers.InsertOnSubmit(_sOu); _wrt.SubmitChanges(); GetShelterOfUserTable(); MessageBox.Show("Entity added successfully"); } } catch { MessageBox.Show("We got a problem on the system.Try it another time."); } }