public bool Update(DonorBLL d) { //create a boolean variable and set its default value to false bool isSuccess = false; //create an object of sql connection to connect database SqlConnection conn = new SqlConnection(myconstn); try { //create the string variable to hold the sql query string SQL = "UPDATE DonorTbl SET dFullName=@dFullName,demail=@demail,dcontact=@dcontact,daddress=@daddress,dGender=@dGender,dimSource=@dimSource,dBloodG=@dBloodG,dEllig=@dEllig WHERE donorId=@donorId "; //create a sql command to pass the value in query SqlCommand cmd = new SqlCommand(SQL, conn); //create the parameters to pass get the value from UI and pass it on sql query above cmd.Parameters.AddWithValue("@donorId", d.donorId); cmd.Parameters.AddWithValue("@dFullName", d.DFullName); cmd.Parameters.AddWithValue("@demail", d.dEmail); cmd.Parameters.AddWithValue("@dcontact", d.DConatct); cmd.Parameters.AddWithValue("@daddress", d.DAddress); cmd.Parameters.AddWithValue("@addDate", d.AddDate); cmd.Parameters.AddWithValue("@dGender", d.DGender); cmd.Parameters.AddWithValue("@dimSource", d.DImageSource); cmd.Parameters.AddWithValue("@dBloodG", d.DBloodG); cmd.Parameters.AddWithValue("@dEllig", d.DEllig); //open database connection conn.Open(); //create a variable to hold the value after query executed int rows = cmd.ExecuteNonQuery(); if (rows > 0) { //query executed successfully isSuccess = true; } else { //failed to execute query isSuccess = false; } } catch (Exception Ex) { //dispose error message if there is any exceptional error MessageBox.Show(Ex.Message); } finally { //close database connection conn.Close(); } return(isSuccess); }
public void GetDonor() { //Crea un donador DonorBM donorBm = create_donor(); DonorBLL donorBll = new DonorBLL(); ResultBM donorResult = donorBll.GetDonor(donorBm.donorId); Assert.IsTrue(donorResult.IsValid(), "El donador debería existir."); }
private DonorBM create_donor() { //Crea un donador OrganizationBLL organizationBll = new OrganizationBLL(); ResultBM result = organizationBll.GetOrganization(1); PersonBM personBm = create_person(); DonorBM donorBm = new DonorBM(true, personBm, result.GetValue <OrganizationBM>()); DonorBLL donorBll = new DonorBLL(); ResultBM saveResult = donorBll.SaveDonor(donorBm); Assert.IsTrue(saveResult.IsValid(), "El donador debería haberse creado."); return(saveResult.GetValue <DonorBM>()); }
public bool Delete(DonorBLL d) { //create a boolean variable and set its default value to false bool isSuccess = false; //create an object of sql connection to connect database SqlConnection conn = new SqlConnection(myconstn); try { //create the string variable to hold the sql query to delete data string SQL = "DELETE DonorTbl WHERE donorId=@donorId "; //create a sql command to pass the value in query SqlCommand cmd = new SqlCommand(SQL, conn); //now pass the vale to sql query cmd.Parameters.AddWithValue("@donorId", d.donorId); //open database connection conn.Open(); //create a variable to hold the value after query executed int rows = cmd.ExecuteNonQuery(); if (rows > 0) { //query executed successfully isSuccess = true; //open database connection conn.Close(); } else { //failed to execute query isSuccess = false; //open database connection conn.Close(); } } catch (Exception Ex) { //dispose error message if there is any exceptional error MessageBox.Show(Ex.Message); } finally { //close database connection conn.Close(); } return(isSuccess); }
private void cmdAccept_Click(object sender, EventArgs e) { DialogResult pressed = MessageBox.Show(SessionHelper.GetTranslation("SAVE_CHANGES_QUESTION"), "Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (pressed == DialogResult.No) { return; } try { DonorBLL donorBll = new DonorBLL(); ResultBM donorResult; //Se encargan de completar la entidad con los valores necesarios FillPersonData(this.Entity); FillAddressData(this.Entity); FillCompanyData(this.Entity); if (isUpdate) { donorResult = donorBll.UpdateDonor(this.Entity); } else { donorResult = donorBll.SaveDonor(this.Entity); } if (donorResult.IsValid()) { Close(); } else { MessageBox.Show(donorResult.description, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception exception) { MessageBox.Show("Se ha producido el siguiente error: " + exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void DonationFrm_Load(object sender, EventArgs e) { try { dateArrival.CustomFormat = "dd/MM/yyyy hh:mm"; ChangeSize(); if (this.Entity != null && this.Entity.IsStored()) { MessageBox.Show("Está intentando editar una donación ya almacenada.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); groupBox1.Enabled = false; cmdAccept.Enabled = false; } //Traducciones SessionHelper.RegisterForTranslation(this, Codes.MNU_GE011); SessionHelper.RegisterForTranslation(cmdAccept, Codes.BTN_ACCEPT); SessionHelper.RegisterForTranslation(cmdClose, Codes.BTN_CLOSE); SessionHelper.RegisterForTranslation(lblLot, Codes.LBL_LOT); SessionHelper.RegisterForTranslation(lblArrival, Codes.LBL_ARRIVAL); SessionHelper.RegisterForTranslation(lblResponsible, Codes.LBL_RESPONSIBLE); SessionHelper.RegisterForTranslation(lblDonor, Codes.LBL_DONOR); SessionHelper.RegisterForTranslation(lblItems, Codes.LBL_ITEMS); SessionHelper.RegisterForTranslation(lblComment, Codes.LBL_OBSERVATION); SessionHelper.RegisterForTranslation(lblContact, Codes.LBL_CONTACT_INFO); SessionHelper.RegisterForTranslation(chkPickup, Codes.LBL_PICKUP); DonorBLL donorBll = new DonorBLL(); ResultBM donorResult = donorBll.GetDonors(); VolunteerBLL volunteerBll = new VolunteerBLL(); ResultBM volunteerResult = volunteerBll.GetVolunteers(); if (donorResult.IsValid()) { cmbDonor.SelectedIndexChanged -= cmbDonor_SelectedIndexChanged; cmbDonor.DataSource = donorResult.GetValue <List <DonorBM> >(); cmbDonor.DisplayMember = "FullName"; cmbDonor.SelectedIndexChanged += cmbDonor_SelectedIndexChanged; } else { MessageBox.Show(donorResult.description, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } if (volunteerResult.IsValid()) { //Se debe agregar un voluntario "Sin voluntario". List <VolunteerBM> volunteers = new List <VolunteerBM>(); VolunteerBM noVolunteer = new VolunteerBM(); noVolunteer.name = "-------------"; volunteers.Add(noVolunteer); volunteers.AddRange(volunteerResult.GetValue <List <VolunteerBM> >()); cmbVolunteer.DataSource = volunteers; cmbVolunteer.DisplayMember = "FullName"; } else { MessageBox.Show(volunteerResult.description, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } if (this.IsUpdate) { DonationBLL donationBll = new DonationBLL(); ResultBM donationResult = donationBll.GetDonation(this.Entity.id); if (donationResult.IsValid()) { //Estoy asumiento que se recuperó algo, más alla de que la operación fue exitosa this.Entity = donationResult.GetValue <DonationBM>(); lblLotId.Text = this.Entity.Lot.ToString(); dateArrival.Value = this.Entity.Arrival; chkPickup.Checked = this.Entity.IsToBeRetrieved(); numericItems.Value = this.Entity.Items; txtComment.Text = this.Entity.Comment; txtContact.Text = this.Entity.donor.GetContectInfo(); //Posicionar donador bool found = false; for (int i = 0; i < cmbDonor.Items.Count && !found; ++i) { found = ((DonorBM)cmbDonor.Items[i]).donorId == this.Entity.donor.donorId; if (found) { cmbDonor.SelectedIndex = i; } } found = false; for (int i = 0; i < cmbVolunteer.Items.Count && !found; ++i) { int id = this.Entity.volunteer == null ? 0 : this.Entity.volunteer.volunteerId; found = ((VolunteerBM)cmbVolunteer.Items[i]).volunteerId == id; if (found) { cmbVolunteer.SelectedIndex = i; } } } else { MessageBox.Show(donationResult.description, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { this.Entity = new DonationBM(); } } catch (Exception exception) { MessageBox.Show("Se ha producido el siguiente error: " + exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void FrmDonor_Load(object sender, EventArgs e) { try { //Traducciones SessionHelper.RegisterForTranslation(this, Codes.MNU_GE009); SessionHelper.RegisterForTranslation(cmdAccept, Codes.BTN_ACCEPT); SessionHelper.RegisterForTranslation(cmdClose, Codes.BTN_CLOSE); SessionHelper.RegisterForTranslation(lblName, Codes.LBL_NAME); SessionHelper.RegisterForTranslation(lblLastName, Codes.LBL_LAST_NAME); SessionHelper.RegisterForTranslation(lblBirthday, Codes.LBL_BIRTHDAY); SessionHelper.RegisterForTranslation(lblMail, Codes.LBL_EMAIL); SessionHelper.RegisterForTranslation(lblPhone, Codes.LBL_PHONE); SessionHelper.RegisterForTranslation(rbuttonFemale, Codes.LBL_FEMALE); SessionHelper.RegisterForTranslation(rButtonMale, Codes.LBL_MALE); SessionHelper.RegisterForTranslation(lblDocument, Codes.LBL_UID); SessionHelper.RegisterForTranslation(lblStreet, Codes.LBL_STREET); SessionHelper.RegisterForTranslation(lblNumber, Codes.LBL_NUMBER); SessionHelper.RegisterForTranslation(lblApartment, Codes.LBL_APARTMENT); SessionHelper.RegisterForTranslation(lblComment, Codes.LBL_OBSERVATION); SessionHelper.RegisterForTranslation(lblCountry, Codes.LBL_COUNTRY); SessionHelper.RegisterForTranslation(lblCompany, Codes.LBL_COMPANY); SessionHelper.RegisterForTranslation(lblCategory, Codes.LBL_CATEGORY); SessionHelper.RegisterForTranslation(lblCommentCpny, Codes.LBL_OBSERVATION); SessionHelper.RegisterForTranslation(lblMailCmpny, Codes.LBL_EMAIL); SessionHelper.RegisterForTranslation(lblPhoneCmpny, Codes.LBL_PHONE); SessionHelper.RegisterForTranslation(chkBoxContact, Codes.LBL_CAN_CONTACT); ResultBM countryResult = new CountryBLL().GetCountries(); cmbCountry.DataSource = countryResult.GetValue <List <CountryBM> >(); cmbCountry.DisplayMember = "Name"; if (IsUpdate) { DonorBLL donorBll = new DonorBLL(); ResultBM resultDonor = donorBll.GetDonor(entity.donorId); if (resultDonor.IsValid()) { this.Entity = resultDonor.GetValue <DonorBM>(); CompletePersonData(this.Entity); CompleteAddressData(this.Entity); CompleteCompanyData(this.Entity); } else { MessageBox.Show(resultDonor.description, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { entity = new DonorBM(); } } catch (Exception exception) { MessageBox.Show("Se ha producido el siguiente error: " + exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }