Beispiel #1
0
        private void savebuttonstrip_Click(object sender, EventArgs e)
        {
            carga man = new carga();

            if (savebuttonstrip.Text == "GUARDAR")
            {
                man.WindowState = FormWindowState.Normal;

                if (gottendegree.Text == "" || nameEmployeeBox.Text == "" || idBox.Text == "" || telephoneNumberBox.Text == "" || schedule.Text == "" || cargobox.Text == "" || comboNacionalidad.Text == "" || ageBox.Text == "" || mensualitybox.Text == "" || personalReferenceBox.Text == "" || telephoneReferenceBox.Text == "" || relationReferenceBox.Text == "" || AlergyNmaeBox.Text == "" || DolenciaNameBox.Text == "" || nameMedicineBox.Text == "" || MotivoMedicineBox.Text == "")
                {
                    MessageBox.Show("Hay datos importantes vacios, termine el formulario.");



                    if (gottendegree.Text == "")
                    {
                        gottendegree.BackColor = Color.Red;
                    }
                    else
                    {
                        gottendegree.BackColor = Color.Green;
                    }

                    if (nameEmployeeBox.Text == "")
                    {
                        nameEmployeeBox.BackColor = Color.Red;
                    }
                    else
                    {
                        nameEmployeeBox.BackColor = Color.Green;
                    }

                    if (idBox.Text == "")
                    {
                        idBox.BackColor = Color.Red;
                    }
                    else
                    {
                        idBox.BackColor = Color.Green;
                    }

                    if (telephoneNumberBox.Text == "")
                    {
                        telephoneNumberBox.BackColor = Color.Red;
                    }
                    else
                    {
                        telephoneNumberBox.BackColor = Color.Green;
                    }

                    if (schedule.Text == "")
                    {
                        schedule.BackColor = Color.Red;
                    }
                    else
                    {
                        schedule.BackColor = Color.Green;
                    }

                    if (cargobox.Text == "")
                    {
                        cargobox.BackColor = Color.Red;
                    }
                    else
                    {
                        cargobox.BackColor = Color.Green;
                    }

                    if (comboNacionalidad.Text == "")
                    {
                        comboNacionalidad.BackColor = Color.Red;
                    }
                    else
                    {
                        comboNacionalidad.BackColor = Color.Green;
                    }

                    if (ageBox.Text == "")
                    {
                        ageBox.BackColor = Color.Red;
                    }
                    else
                    {
                        ageBox.BackColor = Color.Green;
                    }

                    if (mensualitybox.Text == "")
                    {
                        mensualitybox.BackColor = Color.Red;
                    }
                    else
                    {
                        mensualitybox.BackColor = Color.Green;
                    }

                    if (personalReferenceBox.Text == "")
                    {
                        personalReferenceBox.BackColor = Color.Red;
                    }
                    else
                    {
                        personalReferenceBox.BackColor = Color.Green;
                    }

                    if (telephoneReferenceBox.Text == "")
                    {
                        telephoneReferenceBox.BackColor = Color.Red;
                    }
                    else
                    {
                        telephoneReferenceBox.BackColor = Color.Green;
                    }

                    if (relationReferenceBox.Text == "")
                    {
                        relationReferenceBox.BackColor = Color.Red;
                    }
                    else
                    {
                        relationReferenceBox.BackColor = Color.Green;
                    }

                    if (AlergyNmaeBox.Text == "")
                    {
                        AlergyNmaeBox.BackColor = Color.Red;
                    }
                    else
                    {
                        AlergyNmaeBox.BackColor = Color.Green;
                    }

                    if (DolenciaNameBox.Text == "")
                    {
                        DolenciaNameBox.BackColor = Color.Red;
                    }
                    else
                    {
                        DolenciaNameBox.BackColor = Color.Green;
                    }

                    if (nameMedicineBox.Text == "")
                    {
                        nameMedicineBox.BackColor = Color.Red;
                    }
                    else
                    {
                        nameMedicineBox.BackColor = Color.Green;
                    }

                    if (MotivoMedicineBox.Text == "")
                    {
                        MotivoMedicineBox.BackColor = Color.Red;
                    }
                    else
                    {
                        MotivoMedicineBox.BackColor = Color.Green;
                    }
                }
                else
                {
                    try
                    {
                        string        userDataName = UserAccessForm.getusername() + "_employee_table";
                        EmployeeClass employee     = new EmployeeClass(UserAccessForm.getdbserver(), UserAccessForm.getdbname(), UserAccessForm.getdbuser(), UserAccessForm.getdbpassword(), UserAccessForm.getdbport());
                        employee.NameNoCopied(nameEmployeeBox.Text, userDataName);
                        int      age        = int.Parse(ageBox.Text);
                        double   mensuality = double.Parse(mensualitybox.Text);
                        DateTime birthdate  = Convert.ToDateTime(birthDateBox.Value.Date);
                        DateTime timegetin  = Convert.ToDateTime(dategetin.Value.ToShortTimeString());
                        string   access     = userDataName;

                        if (mensualitybox.BackColor == Color.Red)
                        {
                            MessageBox.Show("Arregle el campo no valido");
                        }
                        else
                        {
                            if (employee.NameNoCopied(nameEmployeeBox.Text, userDataName) == true)
                            {
                                man.Close();
                                MessageBox.Show("El Empleado " + nameEmployeeBox.Text + " ya existe.");
                                if (MessageBox.Show("Agregar a otro empleado?", "Agregar", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                                {
                                    employee = new EmployeeClass();

                                    DireccionGestor menu = new DireccionGestor();
                                    menu.WindowState = FormWindowState.Normal;
                                    menu.Show();
                                    this.Close();
                                }
                                else
                                {
                                    employee = new EmployeeClass();

                                    EmployeeForm menu = new EmployeeForm();
                                    menu.WindowState = FormWindowState.Normal;
                                    menu.Show();
                                    this.Close();
                                }
                            }
                            else if (employee.NameNoCopied(nameEmployeeBox.Text, userDataName) == false)
                            {
                                if (gottendegree.Text == "" || nameEmployeeBox.Text == "" || idBox.Text == "" || telephoneNumberBox.Text == "" || schedule.Text == "" || cargobox.Text == "" || comboNacionalidad.Text == "" || ageBox.Text == "" || mensualitybox.Text == "" || personalReferenceBox.Text == "" || telephoneReferenceBox.Text == "" || relationReferenceBox.Text == "" || AlergyNmaeBox.Text == "" || DolenciaNameBox.Text == "" || nameMedicineBox.Text == "" || MotivoMedicineBox.Text == "")
                                {
                                    MessageBox.Show("Hay datos importantes vacios, termine el formulario.");
                                }
                                else
                                {
                                    string date       = birthDateBox.Value.Day.ToString() + "/" + birthDateBox.Value.Month.ToString() + "/" + birthDateBox.Value.Year.ToString();
                                    string evento     = birthDateBox.Value.Day.ToString() + "/" + birthDateBox.Value.Month.ToString();
                                    string eventoname = "CUMPLEAÑOS DE " + nameEmployeeBox.Text;

                                    AgendaClass addevent = new AgendaClass(UserAccessForm.getdbserver(), UserAccessForm.getdbname(), UserAccessForm.getdbuser(), UserAccessForm.getdbpassword(), UserAccessForm.getdbport());
                                    addevent.saveData(UserAccessForm.getusername(), eventoname, 1, date, "7:20:0", "NO", "NO", "NO", "NO", "NO", "NO", "NO", evento, "SI", "");

                                    LoginClass add = new LoginClass(UserAccessForm.getdbserver(), UserAccessForm.getdbname(), UserAccessForm.getdbuser(), UserAccessForm.getdbpassword(), UserAccessForm.getdbport());
                                    add.AddContact(nameEmployeeBox.Text, telephoneNumberBox.Text, direccionbox.Text, emailcombo.Text, UserAccessForm.getusername().ToString());

                                    if (employee.SaveData(userDataName, dategetin, gottendegree.Text, nameEmployeeBox.Text, idBox.Text, birthDateBox, telephoneNumberBox.Text, schedule.Text, cargobox.Text, comboNacionalidad.Text, age, mensuality, personalReferenceBox.Text, telephoneReferenceBox.Text, relationReferenceBox.Text, AlergyNmaeBox.Text, DolenciaNameBox.Text, nameMedicineBox.Text, MotivoMedicineBox.Text, picturetextbox.Text, monedatipo.Text, sexobox.Text, direccionbox.Text, emailcombo.Text))
                                    {
                                        man.Close();
                                        employee.NameNoCopied(nameEmployeeBox.Text, userDataName);
                                        employee.OrderID(userDataName);
                                        MessageBox.Show("NUEVO EMPLEADO " + nameEmployeeBox.Text + " HA SIDO AGREGADO.");

                                        if (MessageBox.Show("Agregar a otro empleado?", "Agregar", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                                        {
                                            employee = new EmployeeClass();

                                            DireccionGestor menu = new DireccionGestor();
                                            menu.WindowState = FormWindowState.Normal;
                                            menu.Show();
                                            this.Close();
                                        }
                                        else
                                        {
                                            employee = new EmployeeClass();

                                            EmployeeForm menu = new EmployeeForm();
                                            menu.WindowState = FormWindowState.Normal;
                                            menu.Show();
                                            this.Close();
                                        }
                                    }

                                    else
                                    {
                                        man.Close();

                                        MessageBox.Show("NUEVO EMPLEADO " + nameEmployeeBox.Text + "HA SIDO AGREGADO.");
                                        if (MessageBox.Show("Agregar a otro empleado?", "Agregar", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                                        {
                                            employee = new EmployeeClass();

                                            DireccionGestor menu = new DireccionGestor();
                                            menu.WindowState = FormWindowState.Normal;
                                            menu.Show();
                                            this.Close();
                                        }
                                        else
                                        {
                                            employee = new EmployeeClass();

                                            EmployeeForm menu = new EmployeeForm();
                                            menu.WindowState = FormWindowState.Normal;
                                            menu.Show();
                                            this.Close();
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (FormatException datethis) { datethis.ToString(); }
                }
            }
            else if (savebuttonstrip.Text == "MODIFICAR")
            {
                man.WindowState = FormWindowState.Normal;

                if (referenciaopcionbox.Text == "NO")
                {
                    man.Close();
                    telephoneNumberBox.Text   = "NINGUNA";
                    relationReferenceBox.Text = "NINGUNA";
                    personalReferenceBox.Text = "NINGUNA";
                }

                try
                {
                    man.Close();
                    string        userDataName = UserAccessForm.getusername() + "_employee_table";
                    EmployeeClass save         = new EmployeeClass(UserAccessForm.getdbserver(), UserAccessForm.getdbname(), UserAccessForm.getdbuser(), UserAccessForm.getdbpassword(), UserAccessForm.getdbport());
                    AgendaClass   addevent     = new AgendaClass(UserAccessForm.getdbserver(), UserAccessForm.getdbname(), UserAccessForm.getdbuser(), UserAccessForm.getdbpassword(), UserAccessForm.getdbport());


                    double mensuality = double.Parse(mensualitybox.Text);

                    string nameevent  = "CUMPLEAÑOS DE " + nameEmployeeBox.Text;
                    string date       = birthDateBox.Value.Day.ToString() + "/" + birthDateBox.Value.Month.ToString() + "/" + birthDateBox.Value.Year.ToString();
                    string momentdate = birthDateBox.Value.Day.ToString() + "/" + birthDateBox.Value.Month.ToString();

                    save.ModifyData(DireccionGestor.getnombrestatic(), trabajando.Text, userDataName, dategetin, salidapicker, gottendegree.Text, nameEmployeeBox.Text, idBox.Text, birthDateBox,
                                    telephoneNumberBox.Text, schedule.Text, cargobox.Text, comboNacionalidad.Text, int.Parse(ageBox.Text), mensuality, personalReferenceBox.Text, telephoneNumberBox.Text,
                                    relationReferenceBox.Text, AlergyNmaeBox.Text, DolenciaNameBox.Text, nameMedicineBox.Text, MotivoMedicineBox.Text, picturetextbox.Text, monedatipo.Text,
                                    sexobox.Text, direccionbox.Text, emailcombo.Text, EmployeeClass.getids());
                    addevent.modifydata(UserAccessForm.getusername(), DireccionGestor.getnombrestatic(), nameevent, 1, date, "7:20:0", "NO", "NO", "NO", "NO", "NO", "NO", "NO", momentdate, "SI");
                    LoginClass add = new LoginClass(UserAccessForm.getdbserver(), UserAccessForm.getdbname(), UserAccessForm.getdbuser(), UserAccessForm.getdbpassword(), UserAccessForm.getdbport());
                    add.editContact(nameEmployeeBox.Text, telephoneNumberBox.Text, direccionbox.Text, emailcombo.Text, DireccionGestor.getnombrestatic(), UserAccessForm.getusername().ToString());

                    MessageBox.Show("EL EMPLEADO " + nameEmployeeBox.Text + " HA SIDO MODIFICADO");



                    EmployeeClass      studentobject = new EmployeeClass(UserAccessForm.getdbserver(), UserAccessForm.getdbname(), UserAccessForm.getdbuser(), UserAccessForm.getdbpassword(), UserAccessForm.getdbport());
                    EmployeeFormSearch buscar        = new EmployeeFormSearch();
                    buscar.WindowState = FormWindowState.Maximized;
                    buscar.Show();
                    this.Close();
                }
                catch (FormatException datethis) { datethis.ToString(); }
            }
        }
        private void OKbutton_Click(object sender, EventArgs e)
        {
            string fecharecordatorio = "00/00";

            fecha = datebox.Value.Day.ToString() + "/" + datebox.Value.Month.ToString() + "/" + datebox.Value.Year.ToString();
            string hora = timeBox.Value.Hour.ToString() + ":" + timeBox.Value.Minute.ToString() + ":" + timeBox.Value.Second.ToString();

            AgendaClass agenda = new AgendaClass(UserAccessForm.getdbserver(), UserAccessForm.getdbname(), UserAccessForm.getdbuser(), UserAccessForm.getdbpassword(), UserAccessForm.getdbport());
            string      user   = UserAccessForm.getusername();

            if (lunescheck.Checked == true)
            {
                dias[0] = "SI";
            }
            else
            {
                dias[0] = "NO";
            }
            if (martescheckBox.Checked == true)
            {
                dias[1] = "SI";
            }
            else
            {
                dias[1] = "NO";
            }
            if (miercolescheckBox.Checked == true)
            {
                dias[2] = "SI";
            }
            else
            {
                dias[2] = "NO";
            }
            if (juevescheckBox.Checked == true)
            {
                dias[3] = "SI";
            }
            else
            {
                dias[3] = "NO";
            }
            if (viernescheckbox.Checked == true)
            {
                dias[4] = "SI";
            }
            else
            {
                dias[4] = "NO";
            }
            if (sabadocheckBox.Checked == true)
            {
                dias[5] = "SI";
            }
            else
            {
                dias[5] = "NO";
            }
            if (domingocheckBox.Checked == true)
            {
                dias[6] = "SI";
            }
            else
            {
                dias[6] = "NO";
            }



            int prioridad = 1;

            if (priority.Text == "MUY IMPORTANTE")
            {
                prioridad = 0;
            }
            else if (priority.Text == "NORMAL")
            {
                prioridad = 1;
            }
            else
            {
                prioridad = 2;
            }



            if (comborepeticion.Text == "NO")
            {
                fecharecordatorio = datebox.Value.Day.ToString() + "/" + datebox.Value.Month.ToString();
            }
            else
            {
                fecharecordatorio = "00/00";
            }

            // 0 - MUY IMPORTANTE
            // 1 - NORMAL
            // 2 - POCO IMPORTANTE

            if (DireccionGestor.getorigen() == "inicio" || DireccionGestor.getorigen() == "buscador")
            {
                string activo = "SI";

                if (motivoBox.Text == "" || priority.Text == "")
                {
                    MessageBox.Show("COMPLETE EL FORMULARIO");
                    if (motivoBox.Text == "")
                    {
                        motivoBox.BackColor = Color.Red;
                    }
                    else
                    {
                        motivoBox.BackColor = Color.Green;
                    }

                    if (priority.Text == "")
                    {
                        priority.BackColor = Color.Red;
                    }
                    else
                    {
                        motivoBox.BackColor = Color.Green;
                    }
                }
                else
                {
                    if (agenda.saveData(user, motivoBox.Text, prioridad, fecha, hora, dias[0], dias[1], dias[2], dias[3], dias[4], dias[5], dias[6], fecharecordatorio, activo, melodybox.Text))
                    {
                        MessageBox.Show("TAREA GUARDADA");
                        if (MessageBox.Show("Agregar otra tarea?", "Agregar", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                        {
                            agenda = new AgendaClass();
                            this.Close();
                        }
                        else
                        {
                            agenda = new AgendaClass();
                            this.Close();
                            agendaAdd menu = new agendaAdd();
                        }
                    }
                    else
                    {
                        MessageBox.Show("TAREA GUARDADA" + " " + agenda.getmessageshow());
                        if (MessageBox.Show("Agregar otra tarea?", "Agregar", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                        {
                            agenda = new AgendaClass();
                            this.Close();
                        }
                        else
                        {
                            agenda = new AgendaClass();
                            this.Close();
                            agendaAdd menu = new agendaAdd();
                            menu.WindowState = FormWindowState.Normal;
                            menu.Show();
                        }
                    }
                }
            }
            else if (DireccionGestor.getorigen() == "modificar")
            {
                agenda.ordensql("UPDATE " + UserAccessForm.getusername() + "_events_table SET `DESCRIPCION`= '" + motivoBox.Text + "',  `FECHA` ='" + fecha + "',  `HORA` ='" + hora + "',  `PRIORIDAD` = '" + prioridad + "',  `LUNES`='" + dias[0] + "',  `MARTES` ='" + dias[1] + "', `MIERCOLES` ='" + dias[2] + "',  `JUEVES` ='" + dias[3] + "',  `VIERNES` ='" + dias[4] + "',  `SABADO` ='" + dias[5] + "',  `DOMINGO` ='" + dias[6] + "', `FECHA DE RECORDATORIO` ='" + fecharecordatorio + "', `ACTIVO` ='" + activobox.Text + "',`SONIDO`='" + melodybox.Text + "' WHERE  `DESCRIPCION`= '" + DireccionGestor.getnombrestatic() + "' AND FECHA ='" + DireccionGestor.getotrostatic() + "';");
                MessageBox.Show("TAREA MODIFICADA");

                AgendaEvents agendaobject = new AgendaEvents();
                agendaobject.WindowState = FormWindowState.Normal;
                agendaobject.Show();
                this.Close();
            }
        }