private void CompanyGrid_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 0) { DataGridViewRow row = CompanyGrid.Rows[e.RowIndex]; EmpresaEspectaculo empresa = new EmpresaEspectaculo((int)row.Cells["cod_empresa"].Value, row.Cells["Razon Social"].Value.ToString(), row.Cells["Telefono"].Value.ToString(), row.Cells["E-mail"].Value.ToString(), row.Cells["Domicilio"].Value.ToString(), row.Cells["Altura"].Value.ToString(), row.Cells["Piso"].Value.ToString(), row.Cells["Departamento"].Value.ToString(), row.Cells["Ciudad"].Value.ToString(), row.Cells["Codigo Postal"].Value.ToString(), row.Cells["CUIT"].Value.ToString(), (bool)row.Cells["Habilitado"].Value); Program.openPopUpWindow(this, new CreateCompany(empresa)); empresas.Clear(); } }
public CreateCompany(EmpresaEspectaculo _empresa, bool registro = false) { InitializeComponent(); if (registro) { registroDeUsuario = true; } else { edicion = true; } empresa = _empresa; SaveButton.Text = "Guardar"; }
private void nuevaEmpresa_Click(object sender, EventArgs e) { var nuevo = new Abm_Empresa_Espectaculo.EmpresaEspectaculo(_main.session); nuevo.Show(); }
private void SaveButton_Click(object sender, EventArgs e) { bool todoBien = true; int aux; if (String.IsNullOrWhiteSpace(SocialReasonBox.Text)) { todoBien = false; MessageBox.Show("La razon social no puede estar vacia"); } if (String.IsNullOrWhiteSpace(AddressBox.Text) || String.IsNullOrWhiteSpace(AddressNroBox.Text)) { todoBien = false; MessageBox.Show("La direccion no puede estar vacia"); } else if (!int.TryParse(AddressNroBox.Text, out aux)) { todoBien = false; MessageBox.Show("La altura debe ser un numero"); } if (String.IsNullOrWhiteSpace(PostalCodeBox.Text)) { todoBien = false; MessageBox.Show("El codigo postal no puede estar vacio"); } if (String.IsNullOrWhiteSpace(CUITBox.Text)) { todoBien = false; MessageBox.Show("El CUIT es un campo obligatorio"); } else if (!EmpresaEspectaculo.CheckCUIT(CUITBox.Text)) { todoBien = false; MessageBox.Show("El CUIT ingresado no es valido"); } if (String.IsNullOrWhiteSpace(MailBox.Text)) { todoBien = false; MessageBox.Show("El mail es un campo obligatorio"); } else if (!Regex.IsMatch(MailBox.Text, @"^.+@.+\.\w+")) { todoBien = false; MessageBox.Show("El mail no es valido"); } if (!(String.IsNullOrWhiteSpace(PhoneBox.Text) || Program.checkIfOnlyNumbers(PhoneBox.Text))) { todoBien = false; MessageBox.Show("El telefono solo pueden ser numeros"); } if (todoBien) { if (edicion) { byte yaExiste = EmpresaEspectaculo.checkIfExistInDataBase(Program.DBconn, SocialReasonBox.Text, CUITBox.Text); if (EnabledBox.Checked && (!empresa.habilitado || empresa.nombre != SocialReasonBox.Text) && yaExiste == 2) { MessageBox.Show("Ya hay una empresa registrada con esa razon social"); } else if (EnabledBox.Checked && (!empresa.habilitado || empresa.CUIT != CUITBox.Text) && yaExiste == 1) { MessageBox.Show("Ya hay una empresa registrada con ese CUIT"); } else { empresa.updateValues(SocialReasonBox.Text, PhoneBox.Text, MailBox.Text, AddressBox.Text, AddressNroBox.Text, FloorBox.Text, DeptBox.Text, CityBox.Text, PostalCodeBox.Text, CUITBox.Text, EnabledBox.Checked).UpdateToDataBase(Program.DBconn); } } else { switch (EmpresaEspectaculo.checkIfExistInDataBase(Program.DBconn, SocialReasonBox.Text, CUITBox.Text)) { case 0: if (registroDeUsuario) { empresa.updateValues(SocialReasonBox.Text, PhoneBox.Text, MailBox.Text, AddressBox.Text, AddressNroBox.Text, FloorBox.Text, DeptBox.Text, CityBox.Text, PostalCodeBox.Text, CUITBox.Text, EnabledBox.Checked); DialogResult = DialogResult.OK; } else { string usuario = SocialReasonBox.Text.Substring(0, Math.Min(SocialReasonBox.Text.Length, 50)), contrasenia = Program.getRandomPassword(5); while (Usuario.checkIfExistInDataBase(Program.DBconn, usuario)) { usuario = SocialReasonBox.Text.Substring(0, Math.Min(SocialReasonBox.Text.Length, 30)) + Program.getRandomPassword(5); } EmpresaEspectaculo.CreateToDataBase(Program.DBconn, SocialReasonBox.Text, PhoneBox.Text, MailBox.Text, AddressBox.Text, AddressNroBox.Text, FloorBox.Text, DeptBox.Text, CityBox.Text, PostalCodeBox.Text, CUITBox.Text, usuario, Program.sha256(contrasenia), true); MessageBox.Show("Usuario: " + usuario + " | Contraseña: " + contrasenia); } break; case 1: MessageBox.Show("Ya existe una empresa con ese CUIT"); break; case 2: MessageBox.Show("Ya existe una empresa con esa razon social"); break; } } } }