Beispiel #1
0
        private void BtnAccept_Click(object sender, EventArgs e)
        {
            flag = 0;

            if (txtName.Text.Trim() == "")
            {
                Error.SetError(txtName, "Debe ingresar un nombre para registrar la actividad");
                flag = 1;
            }
            if (flag == 0)
            {
                validActivity = A.FindActivity(txtName.Text);
                if (validActivity == true)
                {
                    MessageBox.Show("Ya existe una actividad con el nombre " + "'" + txtName.Text + "'.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtName.Clear();
                    txtName.Focus();
                    flag = 1;
                }
            }

            if (flag == 0)
            {
                A.Name        = txtName.Text.Trim();
                A.Observation = txtDescription.Text.Trim();
                A.NewActivity(A);
                Combo.Combo2Campos(owner.cbActivity, "Id", "Name", "Activity");
                owner.BtnDelete.Enabled = true;
                owner.CargarGrilla();
                L.Action     = "El usuario " + Users.CacheUser.Nick + " registró una nueva actividad: " + txtName.Text.ToString();
                L.ActionDate = DateTime.Now;
                L._users.Id  = Users.CacheUser.Id;
                L.WriteLog(L);
                DialogResult answ = MessageBox.Show("Se ha guardado la actividad exitosamente." + "\n ¿Desea agregar feligreses a la actividad?", "Ok", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (answ == DialogResult.Yes)
                {
                    this.Dispose();
                    this.Close();
                    frmActivities     FA  = new frmActivities();
                    frmModifyActivity FMA = new frmModifyActivity(A.GetLastId(), FA);
                    FMA.txtName.Text        = A.GetActivityName(A.GetLastId());
                    FMA.txtDescription.Text = A.GetActivityObservation(A.GetLastId());
                    FMA.ShowDialog();
                }
                else
                {
                    txtName.Clear();
                    txtDescription.Clear();
                    Combo.Combo2Campos(owner.cbActivity, "Id", "Name", "Activity");
                    owner.CargarGrilla();
                    owner.CheckComboItems();
                }
            }
        }
 private void FrmModifyActivity_FormClosed(object sender, FormClosedEventArgs e)
 {
     Combo.Combo2Campos(owner.cbActivity, "Id", "Name", "Activity");
     owner.CargarGrilla();
     owner.CheckComboItems();
 }
        private void BtnAccept_Click(object sender, EventArgs e)
        {
            flag = 0;
            if (Action == "NewParish")
            {
                if (txtName.Text.Trim() != "")
                {
                    if (txtSurname.Text.Trim() != "")
                    {
                        P.Name    = txtName.Text.ToString();
                        P.Surname = txtSurname.Text.ToString();
                        if (chbDateTime.Checked == true)
                        {
                            P.BirthDate = dtBornDate.Value;
                        }
                        else
                        {
                            P.BirthDate = null;
                        }
                        if (txtDocumento.Text.Trim() != "")
                        {
                            documento   = txtDocumento.Text.Trim();
                            validParish = P.FindParishioner(documento);
                            if (validParish == true)
                            {
                                Error.SetError(txtDocumento, "Ya existe un feligrés con el documento " + "'" + documento + "'.");
                                txtDocumento.Clear();
                                txtDocumento.Focus();
                                return;
                            }
                            else
                            {
                                flag          = 0;
                                P.Documento   = txtDocumento.Text.ToString();
                                P.Observation = txtObservation.Text.ToString();
                                P.NewParishioner(P);
                                int lastParish = P.GetLastId();
                                PD.NewParishionerData("tel", lastParish, txtTelephone.Text.ToString(), 1);
                                PD.NewParishionerData("address", lastParish, txtAddress.Text.ToString(), 1);
                                PD.NewParishionerData("mail", lastParish, txtMail.Text.ToString(), 1);
                                L.Action     = "El usuario " + Users.CacheUser.Nick + " registró el feligrés " + txtName.Text + " " + txtSurname.Text + " (" + lastParish.ToString() + ").";
                                L.ActionDate = DateTime.Now;
                                L._users.Id  = Users.CacheUser.Id;
                                L.WriteLog(L);
                                MessageBox.Show("Se han ingresado los datos del feligrés correctamente", "Registro de feligrés", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                txtName.Clear();
                                txtSurname.Clear();
                                txtDocumento.Clear();
                                dtBornDate.Value = DateTime.Now;
                                Error.Clear();
                                txtTelephone.Clear();
                                txtAddress.Clear();
                                txtMail.Clear();
                                txtObservation.Clear();
                                _owner.CargarGrilla();
                                _owner2.CargarGrilla();
                                _owner.dgv_Parish.Rows[_owner.dgv_Parish.Rows.Count - 1].Selected = true;
                            }
                        }
                        else
                        {
                            flag          = 0;
                            P.Documento   = txtDocumento.Text.ToString();
                            P.Observation = txtObservation.Text.ToString();
                            P.NewParishioner(P);
                            int lastParish = P.GetLastId();
                            PD.NewParishionerData("tel", lastParish, txtTelephone.Text.ToString(), 1);
                            PD.NewParishionerData("address", lastParish, txtAddress.Text.ToString(), 1);
                            PD.NewParishionerData("mail", lastParish, txtMail.Text.ToString(), 1);
                            L.Action     = "El usuario " + Users.CacheUser.Nick + " registró el feligrés " + txtName.Text + " " + txtSurname.Text + " (" + lastParish.ToString() + ").";
                            L.ActionDate = DateTime.Now;
                            L._users.Id  = Users.CacheUser.Id;
                            L.WriteLog(L);
                            MessageBox.Show("Se han ingresado los datos del feligrés correctamente", "Registro de feligrés", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            txtName.Clear();
                            txtSurname.Clear();
                            txtDocumento.Clear();
                            dtBornDate.Value = DateTime.Now;
                            Error.Clear();
                            txtTelephone.Clear();
                            txtAddress.Clear();
                            txtMail.Clear();
                            txtObservation.Clear();
                            _owner.CargarGrilla();
                            _owner2.CargarGrilla();
                            _owner.dgv_Parish.Rows[_owner.dgv_Parish.Rows.Count - 1].Selected = true;
                        }
                    }
                    else
                    {
                        Error.SetError(txtSurname, "Debe ingresar un apellido");
                        flag = 1;
                    }
                }
                else
                {
                    Error.SetError(txtName, "Debe ingresar un Nombre");
                    flag = 1;
                }
            }

            if (Action == "ModifyParish")
            {
                if (txtName.Text.Trim() == "" && flag == 0)
                {
                    Error.SetError(txtName, "Debe ingresar un nombre.");
                    flag = 1;
                }
                else if (txtSurname.Text.Trim() == "" && flag == 0)
                {
                    Error.SetError(txtSurname, "Debe ingresar un apellido.");
                    flag = 1;
                }
            }
            if (flag == 0 && Action == "ModifyParish")
            {
                documento = txtDocumento.Text.Trim().ToString();
                if (oldDocument == documento)
                {
                    flag = 0;
                }
                else
                {
                    documento   = txtDocumento.Text.Trim().ToString();
                    validParish = P.FindParishioner(documento);
                    if (validParish == true)
                    {
                        Error.SetError(txtDocumento, "Ya existe un feligrés con el documento " + "'" + documento + "'.");
                        txtDocumento.Clear();
                        txtDocumento.Focus();
                        flag = 1;
                    }
                }
                if (validParish == false && flag == 0)
                {
                    P.Id      = parishId;
                    P.Name    = txtName.Text.ToString();
                    P.Surname = txtSurname.Text.ToString();
                    if (chbDateTime.Checked == true)
                    {
                        P.BirthDate = dtBornDate.Value;
                    }
                    else
                    {
                        P.BirthDate = null;
                    }
                    P.Documento   = txtDocumento.Text.ToString();
                    P.Observation = txtObservation.Text.ToString();
                    P.UpdateParishioner(P);
                    PD.UpdateParishionerData(telephoneId, txtTelephone.Text.ToString());
                    PD.UpdateParishionerData(addressId, txtAddress.Text.ToString());
                    PD.UpdateParishionerData(mailId, txtMail.Text.ToString());
                    L.Action     = "El usuario " + Users.CacheUser.Nick + " modificó el feligrés " + txtName.Text + " " + txtSurname.Text + " (" + parishId.ToString() + ").";
                    L.ActionDate = DateTime.Now;
                    L._users.Id  = Users.CacheUser.Id;
                    L.WriteLog(L);
                    MessageBox.Show("Se han actualizado los datos del feligrés correctamente", "Registro de feligrés", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    _owner.CargarGrilla();
                    Combo.Combo2Campos(_owner2.cbActivity, "Id", "Name", "Activity");
                    _owner2.CargarGrilla();
                    this.Close();
                }
            }
        }