public Empresas_View(String nomb_empresa) { InitializeComponent(); this.nomb_emp = nomb_empresa; eta = new CADINDataSetTableAdapters.EmpresaTableAdapter(); edt = new CADINDataSet.EmpresaDataTable(); edt = eta.GetDataByNombEmpresa(nomb_empresa); this.dataGridViewEmpresas.DataSource = edt; this.dataGridViewEmpresas.Columns[1].Visible = false; }
private void EnlazarControlesBasicos() { emprAgrupTableA = new CADINDataSetTableAdapters.Empresa_AgrupacionTableAdapter(); ta2 = new CADINDataSetTableAdapters.DepartamentosTableAdapter(); ta3 = new CADINDataSetTableAdapters.SectoresTableAdapter(); ta4 = new CADINDataSetTableAdapters.Tipo_MembresiaTableAdapter(); ta5 = new CADINDataSetTableAdapters.Tipo_TarifaTableAdapter(); ta6 = new CADINDataSetTableAdapters.Tipo_EmpresaTableAdapter(); taPagoMembresia = new CADINDataSetTableAdapters.Pago_MembresiaTableAdapter(); s2 = new BindingSource(); s3 = new BindingSource(); s4 = new BindingSource(); s5 = new BindingSource(); s6 = new BindingSource(); s8 = new BindingSource(); dt2 = ta2.GetData(); dt3 = ta3.GetData(); dt4 = ta4.GetData(); dt5 = ta5.GetData(); dt6 = ta6.GetData(); emprAgrupDataT = emprAgrupTableA.GetData(); s2.DataSource = dt2; s3.DataSource = dt3; s4.DataSource = dt4; s5.DataSource = dt5; s6.DataSource = dt6; s8.DataSource = emprAgrupDataT; ta1 = new CADINDataSetTableAdapters.EmpresaTableAdapter(); ta7 = new CADINDataSetTableAdapters.Contacto_EmpresaTableAdapter(); s1 = new BindingSource(); s7 = new BindingSource(); dt1 = ta1.GetDataByEmpresasActivas(); dt7 = ta7.GetData(); s1.DataSource = dt1; s7.DataSource = dt7; comboBoxEx1.DataSource = s2; comboBoxEx1.DisplayMember = "nombre"; comboBoxEx1.ValueMember = "cod_dept"; comboBoxEx2.DataSource = s3; comboBoxEx2.DisplayMember = "nombre"; comboBoxEx2.ValueMember = "cod_sect"; cboAgrupacion.DataSource = s8; cboAgrupacion.DisplayMember = "nombre"; cboAgrupacion.ValueMember="cod_gremio"; comboBoxEx3.DataSource = s4; comboBoxEx3.DisplayMember = "nombre"; comboBoxEx3.ValueMember = "cod_memb"; comboBoxEx4.DataSource = s5; comboBoxEx4.DisplayMember = "nombre"; comboBoxEx4.ValueMember = "cod_tari"; comboBoxEx5.DataSource = s6; comboBoxEx5.DisplayMember = "nombre"; comboBoxEx5.ValueMember = "cod_tipo_empr"; //Controles de eventos de los combobox de los contactos supleantes this.comboBoxEx6.Click += new EventHandler(comboBoxEx6_Click); this.comboBoxEx7.Click += new EventHandler(comboBoxEx7_Click); this.comboBoxEx8.Click += new EventHandler(comboBoxEx8_Click); this.comboBoxEx9.Click += new EventHandler(comboBoxEx9_Click); //eventos del datagrid this.comboBoxEx4.SelectedIndexChanged += new EventHandler(comboBoxEx4_SelectedIndexChanged); }
public bool Guardar() { string mensaje = ""; if (superValidator1.Validate()) { if (!modo) { removeCordobas(); s1.EndEdit(); ta1.Update(dt1.Rows[s1.IndexOf(s1.Current)]); codigo = Convert.ToInt32(dt1.Rows[s1.Position].ItemArray.GetValue(0)); string consulta; SqlCommand comand; this.dataGridViewX1.ReadOnly = true; foreach (DataGridViewRow row in dataGridViewX1.Rows) { if (!row.IsNewRow) { if (row.Cells[0].Value != DBNull.Value) { consulta = "Update Contacto_Empresa set " + "nomb='" + row.Cells[2].Value.ToString().TrimStart().TrimEnd() + "'" + ",carg='" + row.Cells[3].Value.ToString().TrimStart().TrimEnd() + "'" + ",telf='" + row.Cells[4].Value.ToString().Trim() + "'" + ",email='" + row.Cells[5].Value.ToString().TrimStart().TrimEnd() + "'" + ",observacion='" + row.Cells[6].Value.ToString().TrimStart().TrimEnd() + "'" + " where cod_cont=" + row.Cells[1].Value + ";"; } else { consulta = "Insert into Contacto_Empresa(cod_empr,nomb,carg,telf,email,observacion) values(" + codigo + ",'" + row.Cells[2].Value + "'" + ",'" + row.Cells[3].Value + "'" + ",'" + row.Cells[4].Value + "'" + ",'" + row.Cells[5].Value + "'" + ",'" + row.Cells[6].Value + "'" + ");"; } comand = new SqlCommand(consulta, ta7.Connection); comand.Connection.Open(); comand.ExecuteNonQuery(); comand.Connection.Close(); } } consulta = "Delete from Pago_Membresia where cod_empr=" + codigo; comand = new SqlCommand(consulta, ta7.Connection); comand.Connection.Open(); comand.ExecuteNonQuery(); comand.Connection.Close(); foreach (DataRow row in tabla.Rows) { if (row.ItemArray.GetValue(7).Equals(DBNull.Value)) { double monto; if (row.ItemArray.GetValue(4).ToString().Contains("$")) monto = Convert.ToDouble(row.ItemArray.GetValue(4).ToString().Substring(1)); else monto = Convert.ToDouble(row.ItemArray.GetValue(4).ToString()); taPagoMembresia.Insert(codigo, Convert.ToInt32(row.ItemArray.GetValue(2)), Convert.ToInt32(row.ItemArray.GetValue(3)), monto, Convert.ToDateTime(row.ItemArray.GetValue(5)), Convert.ToBoolean(row.ItemArray.GetValue(6)), null, "",1); } else { taPagoMembresia.Insert(codigo, Convert.ToInt32(row.ItemArray.GetValue(2)), Convert.ToInt32(row.ItemArray.GetValue(3)), Convert.ToDouble(row.ItemArray.GetValue(4).ToString().Substring(1)), Convert.ToDateTime(row.ItemArray.GetValue(5)), Convert.ToBoolean(row.ItemArray.GetValue(6)), Convert.ToInt32(row.ItemArray.GetValue(7).ToString()), row.ItemArray.GetValue(8).ToString(),Convert.ToInt32(row.ItemArray.GetValue(9).ToString())); } } } else { //Procedimiento para agregar una nueva empresa s1.AddNew(); s1.MoveLast(); DataRow c1 = dt7.NewRow(); int monto1, monto2,cant; if (textBoxX9.Text.Equals("")) { monto1 = 0; } else { monto1=Convert.ToInt32(textBoxX9.Text); } if (textBoxX10.Text.Equals("")) { monto2 = 0; } else { monto2=Convert.ToInt32(textBoxX10.Text); } if (textBoxX8.Text.Equals("")) { cant = 0; } else { cant = Convert.ToInt32(textBoxX10.Text); } ta1.Insert(txtCodCiiu.Text, textBoxX1.Text, textBoxX2.Text, dateTimeInput1.Value, textBoxX3.Text, Convert.ToInt32(comboBoxEx1.SelectedValue), textBoxX4.Text, textBoxX5.Text, textBoxX6.Text, textBoxX7.Text, Convert.ToInt32(comboBoxEx2.SelectedValue),Convert.ToInt32(this.cboAgrupacion.SelectedValue),null,null,null /*Convert.ToInt32(textBoxX8.Text),Convert.ToInt32(textBoxX9.Text), Convert.ToInt32(textBoxX10.Text)*/, textBoxX11.Text, textBoxX12.Text, cant, monto1, monto2, null, checkBoxX1.Checked, checkBoxX2.Checked, Convert.ToInt32(comboBoxEx3.SelectedValue), Convert.ToInt32(comboBoxEx4.SelectedValue), Convert.ToInt32(comboBoxEx5.SelectedValue), checkBoxX3.Checked, dateTimeInput2.Value, 15/*Convert.ToDouble(textBoxX17.Text.Substring(3))*/,null,true); //vincularControlesDesvinculados(); string consulta = "Select MAX(cod_empr) from Empresa"; SqlDataAdapter da = new SqlDataAdapter(consulta, ta1.Connection); DataTable table = new DataTable(); da.Fill(table); codigo = Convert.ToInt32(table.Rows[0].ItemArray.GetValue(0)); //obtener el carnet consulta = "Select carnet from Empresa where cod_empr="+codigo+";"; da = new SqlDataAdapter(consulta, ta1.Connection); table = new DataTable(); da.Fill(table); int carnet = Convert.ToInt32(table.Rows[0].ItemArray.GetValue(0)); mensaje += "con número de carné "+carnet; //INSERTAR PAGOS for (int i = 0; i < tabla.Rows.Count; i++) { DataRow row = tabla.Rows[i]; taPagoMembresia.Insert(codigo, Convert.ToInt32(row.ItemArray.GetValue(2)), Convert.ToInt32(row.ItemArray.GetValue(3)), Convert.ToDouble(row.ItemArray.GetValue(4).ToString().Substring(1)), Convert.ToDateTime(row.ItemArray.GetValue(5)), false, null, null,1); } //INSERTAR CONTACTOS DE EMPRESA SqlCommand command; foreach (DataGridViewRow row in dataGridViewX1.Rows) { if (!row.IsNewRow) { consulta = "Insert into Contacto_Empresa(cod_empr,nomb,carg,telf,email,observacion) values(" + codigo + ",'" + row.Cells[2].Value + "'" + ",'" + row.Cells[3].Value + "'" + ",'" + row.Cells[4].Value + "'" + ",'" + row.Cells[5].Value + "'" + ",'" + row.Cells[6].Value + "'" + ");"; command = new SqlCommand(consulta, ta7.Connection); command.Connection.Open(); command.ExecuteNonQuery(); command.Connection.Close(); } } } this.comboBoxEx6.Enabled = false; this.comboBoxEx7.Enabled = false; this.comboBoxEx8.Enabled = false; //Agregar los contactos principales string consulta2; SqlDataAdapter dataAdapter; SqlCommandBuilder builder; DataTable dataTable; SqlCommand command2; //PROPIETARIO consulta2 = "Select cod_cont from Contacto_Empresa where cod_empr=" +codigo+" and nomb='"+comboBoxEx6.Text+"';"; dataAdapter = new SqlDataAdapter(consulta2, ta7.Connection); builder = new SqlCommandBuilder(dataAdapter); dataTable = new DataTable(); dataAdapter.Fill(dataTable); if (comboBoxEx6.Text != "") { consulta2 = "update Empresa set cont_principal=" + dataTable.Rows[0].ItemArray.GetValue(0) + " where cod_empr=" + codigo + ";"; } else { consulta2 = "update Empresa set cont_principal=NULL" + " where cod_empr=" + codigo + ";"; } command2 = new SqlCommand(consulta2, ta1.Connection); command2.Connection.Open(); command2.ExecuteNonQuery(); command2.Connection.Close(); //PRIMER SUPLENTE consulta2 = "Select cod_cont from Contacto_Empresa where cod_empr=" + codigo + " and nomb='" + comboBoxEx7.Text + "';"; dataAdapter = new SqlDataAdapter(consulta2, ta7.Connection); builder = new SqlCommandBuilder(dataAdapter); dataTable = new DataTable(); dataAdapter.Fill(dataTable); if (comboBoxEx7.Text != "") { consulta2 = "update Empresa set primS=" + dataTable.Rows[0].ItemArray.GetValue(0) + " where cod_empr=" + codigo + ";"; } else { consulta2 = "update Empresa set primS=NULL" + " where cod_empr=" + codigo + ";"; } command2 = new SqlCommand(consulta2, ta1.Connection); command2.Connection.Open(); command2.ExecuteNonQuery(); command2.Connection.Close(); //SEGUNDO SUPLENTE consulta2 = "Select cod_cont from Contacto_Empresa where cod_empr=" + codigo + " and nomb='" + comboBoxEx8.Text + "';"; dataAdapter = new SqlDataAdapter(consulta2, ta7.Connection); builder = new SqlCommandBuilder(dataAdapter); dataTable = new DataTable(); dataAdapter.Fill(dataTable); if (comboBoxEx8.Text != "") { consulta2 = "update Empresa set seguS=" + dataTable.Rows[0].ItemArray.GetValue(0) + " where cod_empr=" + codigo + ";"; } else { consulta2 = "update Empresa set seguS=NULL"+ " where cod_empr=" + codigo + ";"; } command2 = new SqlCommand(consulta2, ta1.Connection); command2.Connection.Open(); command2.ExecuteNonQuery(); command2.Connection.Close(); //TERCER SUPLENTE consulta2 = "Select cod_cont from Contacto_Empresa where cod_empr=" + codigo + " and nomb='" + comboBoxEx9.Text + "';"; dataAdapter = new SqlDataAdapter(consulta2, ta7.Connection); builder = new SqlCommandBuilder(dataAdapter); dataTable = new DataTable(); dataAdapter.Fill(dataTable); if (comboBoxEx9.Text != "") { consulta2 = "update Empresa set tercS=" + dataTable.Rows[0].ItemArray.GetValue(0) + " where cod_empr=" + codigo + ";"; } else { consulta2 = "update Empresa set tercS=NULL"+ " where cod_empr=" + codigo + ";"; } command2 = new SqlCommand(consulta2, ta1.Connection); command2.Connection.Open(); command2.ExecuteNonQuery(); command2.Connection.Close(); dt1 = ta1.GetDataByEmpresasActivas(); s1.DataSource = dt1; Cancelar(); MessageBox.Show("Guardado "+mensaje); return true; }else MessageBox.Show("Verificar Informacion"); return false; }