private void listBoxEmpleado_MouseDown(object sender, MouseEventArgs e) { try { TuplaPDF = new string[1]; string dato = listBoxEmpleado.Items[listBoxEmpleado.SelectedIndex].ToString(); string[] tupla = EmpleadosEnLista.Find(x => x.Contains(dato)).Split(',');//regresa el empleado con todos sus datos necesarios //codigo para convertir internamente el nombre de la sucursal al id de la sucursal //Validacion en esquema de localizacion--------------------------------------------------------------------------------------------------------------- //variables necesarias para sacar datos del esquema de localizacion List <string> idFragmentos = new List <string>(); List <string> nombreTablaBDFragmento = new List <string>(); string nombreTablaGeneral = ""; string tipoFragmento = ""; List <string> sitios = new List <string>(); List <string> condicion = new List <string>(); SitioCentral st = new SitioCentral(); st.LeeEsquemaLocalizacion("Sucursal", ref idFragmentos, ref nombreTablaBDFragmento, ref nombreTablaGeneral, ref sitios, ref tipoFragmento, ref condicion); SqlDataAdapter idSucursal = new SqlDataAdapter("Select nombre from " + nombreTablaBDFragmento[0] + " where id_Sucursal = '" + tupla[10] + "'", cnSQL); cmd = new SqlCommand("Select nombre from " + nombreTablaBDFragmento[0] + " where id_Sucursal = '" + tupla[10] + "'", cnSQL); dr = cmd.ExecuteReader(); dr.Read(); string nombreSucural = (dr[0].ToString()); dr.Close(); //sustituimos el idsucursal por el nombre obtenido para mandarlo al pdf tupla[10] = tupla.ElementAt(10).Replace(tupla.ElementAt(10), nombreSucural); TuplaPDF = tupla; } catch (System.Exception ex) { MessageBox.Show("Error en listbox"); } }
private void BtnModificar_Click(object sender, EventArgs e) { if (!validaDatosEntrada()) { return; } try { string nombre = textBoxNombre.Text; string telefono = textBoxTelefono.Text; string direccion = textBoxDireccion.Text; string email = textBoxEmail.Text; string tipo = comboBoxTipo.SelectedItem.ToString(); //Validacion en esquema de localizacion--------------------------------------------------------------------------------------------------------------- //variables necesarias para sacar datos del esquema de localizacion List <string> idFragmentos = new List <string>(); List <string> nombreTablaBDFragmento = new List <string>(); string nombreTablaGeneral = ""; string tipoFragmento = ""; List <string> sitios = new List <string>(); List <string> condicion = new List <string>(); SitioCentral st = new SitioCentral(); st.LeeEsquemaLocalizacion("Proveedor", ref idFragmentos, ref nombreTablaBDFragmento, ref nombreTablaGeneral, ref sitios, ref tipoFragmento, ref condicion); switch (tipoFragmento) { case "Horizontal": break; case "Vertical": //MODIFICACION en sql server string consulta = "UPDATE " + nombreTablaBDFragmento[0].ToString() + " SET nombre = '" + nombre + "', email = '" + email + "',teléfono = '" + telefono + "' WHERE id_Proveedor = " + dataGridViewProveedor.CurrentRow.Cells[0].Value.ToString() + ""; cmd = new SqlCommand(consulta, cnSQL); cmd.ExecuteNonQuery(); //modificar en postgresql NpgsqlCommand command = new NpgsqlCommand("UPDATE " + nombreTablaBDFragmento[1].ToString() + " SET direccion = '" + direccion + "', tipo = '" + tipo + "' WHERE id_Proveedor = " + dataGridViewProveedor.CurrentRow.Cells[0].Value.ToString() + "", conNPG); command.ExecuteNonQuery(); cargaTabla(); limpiarCampos(); break; case "Replica": //insertar en ambos sitios break; default: break; } } catch (Exception ex) { Console.WriteLine("no se modifico" + ex.Message); } }
public Producto() { InitializeComponent(); //Conexion a SQL SERVER SITIO1 try { cnSQL = new SqlConnection(@"Data Source=DESKTOP-D898I0K\SQLEXPRESS;initial catalog=Sitio1; integrated Security=true"); cnSQL.Open(); //MessageBox.Show("abierto"); } catch (Exception ex) { MessageBox.Show("Error con la conexion a la base de datos" + ex.ToString()); } //COONEXION A POSTGERSQL SITIO2 conNPG.ConnectionString = parametros; try { conNPG.Open(); } catch (Exception error) { MessageBox.Show("Error en la conexion con NpgSQL" + error.Message); } //Validacion en esquema de localizacion--------------------------------------------------------------------------------------------------------------- //variables necesarias para sacar datos del esquema de localizacion List <string> idFragmentos = new List <string>(); List <string> nombreTablaBDFragmento = new List <string>(); string nombreTablaGeneral = ""; string tipoFragmento = ""; List <string> sitios = new List <string>(); List <string> condicion = new List <string>(); SitioCentral st = new SitioCentral(); st.LeeEsquemaLocalizacion("Proveedor", ref idFragmentos, ref nombreTablaBDFragmento, ref nombreTablaGeneral, ref sitios, ref tipoFragmento, ref condicion); //carga una lista con id y nombre de los productos SqlDataAdapter daProveedor = new SqlDataAdapter("Select * from " + nombreTablaBDFragmento.ElementAt(0) + "", cnSQL); DataTable dtProveedor = new DataTable(); daProveedor.Fill(dtProveedor); // For each row, print the values of each column. foreach (DataRow row in dtProveedor.Rows) { listaidProvyNombre.Add(row[dtProveedor.Columns[0]].ToString() + "," + row[dtProveedor.Columns[1]].ToString()); } cargaTabla(); }
private void mezcaBDNormalDelSitio(List <string> sitios, List <string> nombreTablaBDFragmento) { switch (sitios.ElementAt(0)) { case "1": //Validacion en esquema de localizacion--------------------------------------------------------------------------------------------------------------- //variables necesarias para sacar datos del esquema de localizacion List <string> idFragmentos = new List <string>(); List <string> nombreTablaBDFragmentoProd = new List <string>(); string nombreTablaGeneral = ""; string tipoFragmento = ""; List <string> sitiosprod = new List <string>(); List <string> condicion = new List <string>(); SitioCentral st = new SitioCentral(); st.LeeEsquemaLocalizacion("Producto", ref idFragmentos, ref nombreTablaBDFragmentoProd, ref nombreTablaGeneral, ref sitiosprod, ref tipoFragmento, ref condicion); //codigo para hacer el select al sitio1 string query = "select id_Oferta , descripcion , vigencia , descuento, Prod.nombre, cantidad from " + nombreTablaBDFragmento.ElementAt(0) + " as OFE," + nombreTablaBDFragmentoProd[0] + " as Prod where OFE.id_Producto= Prod.id_Producto "; da = new SqlDataAdapter(query, cnSQL); dt = new DataTable(); da.Fill(dt); //dt.Columns.RemoveAt(0);//Para quitar el campo RFC dataGridViewOferta.DataSource = dt; //para esconder el campor id dataGridViewOferta.Columns[0].Visible = false; break; case "2": //Validacion en esquema de localizacion--------------------------------------------------------------------------------------------------------------- //variables necesarias para sacar datos del esquema de localizacion idFragmentos = new List <string>(); nombreTablaBDFragmentoProd = new List <string>(); nombreTablaGeneral = ""; tipoFragmento = ""; sitiosprod = new List <string>(); condicion = new List <string>(); st = new SitioCentral(); st.LeeEsquemaLocalizacion("Producto", ref idFragmentos, ref nombreTablaBDFragmentoProd, ref nombreTablaGeneral, ref sitiosprod, ref tipoFragmento, ref condicion); //Codigo para hacer el select from a al sitio2 NpgsqlDataAdapter add = new NpgsqlDataAdapter("select id_Oferta , descripcion , vigencia , descuento, Prod.nombre, cantidad from " + nombreTablaBDFragmento.ElementAt(0) + " as OFE," + nombreTablaBDFragmentoProd[0] + " as Prod where OFE.id_Producto= Prod.id_Producto ", conNPG); dtNPG = new DataTable(); add.Fill(dtNPG); dataGridViewOferta.DataSource = dtNPG; //para esconder el campor id dataGridViewOferta.Columns[0].Visible = false; break; } }
private void cargaTabla() { try { //Validacion en esquema de localizacion--------------------------------------------------------------------------------------------------------------- //variables necesarias para sacar datos del esquema de localizacion List <string> idFragmentos = new List <string>(); List <string> nombreTablaBDFragmento = new List <string>(); string nombreTablaGeneral = ""; string tipoFragmento = ""; List <string> sitios = new List <string>(); List <string> condicion = new List <string>(); SitioCentral st = new SitioCentral(); st.LeeEsquemaLocalizacion("Oferta", ref idFragmentos, ref nombreTablaBDFragmento, ref nombreTablaGeneral, ref sitios, ref tipoFragmento, ref condicion); switch (tipoFragmento) { //si es horizontal tiene las mismas columnas y solo hacemos merge en las rows case "Horizontal": break; case "Vertical": break; case "Replica": MezclaBDReplica(nombreTablaBDFragmento); break; default: mezcaBDNormalDelSitio(sitios, nombreTablaBDFragmento); break; } } catch (Exception ex) { MessageBox.Show("No se pudo actualizar" + ex); } }
private void cargaTablaProveedor() { try { //Validacion en esquema de localizacion--------------------------------------------------------------------------------------------------------------- //variables necesarias para sacar datos del esquema de localizacion List <string> idFragmentos = new List <string>(); List <string> nombreTablaBDFragmento = new List <string>(); string nombreTablaGeneral = ""; string tipoFragmento = ""; List <string> sitios = new List <string>(); List <string> condicion = new List <string>(); SitioCentral st = new SitioCentral(); st.LeeEsquemaLocalizacion("Proveedor", ref idFragmentos, ref nombreTablaBDFragmento, ref nombreTablaGeneral, ref sitios, ref tipoFragmento, ref condicion); switch (tipoFragmento) { case "Horizontal": MezclaBDHorizontal(); break; case "Vertical": MezclaBDVertical(); break; case "Replica": break; default: break; } } catch (Exception ex) { MessageBox.Show("No se pudo actualizar" + ex); } }
private void MezclaBDReplica(List <string> nombreTablaBDFragmento) { //Validacion en esquema de localizacion--------------------------------------------------------------------------------------------------------------- //variables necesarias para sacar datos del esquema de localizacion List <string> idFragmentos = new List <string>(); List <string> nombreTablaBDFragmentoProd = new List <string>(); string nombreTablaGeneral = ""; string tipoFragmento = ""; List <string> sitios = new List <string>(); List <string> condicion = new List <string>(); SitioCentral st = new SitioCentral(); st.LeeEsquemaLocalizacion("Producto", ref idFragmentos, ref nombreTablaBDFragmentoProd, ref nombreTablaGeneral, ref sitios, ref tipoFragmento, ref condicion); //codigo para hacer el select al sitio1 string query = "select id_Oferta , descripcion , vigencia , descuento, Prod.nombre, cantidad from " + nombreTablaBDFragmento.ElementAt(0) + " as OFE," + nombreTablaBDFragmentoProd[0] + " as Prod where OFE.id_Producto= Prod.id_Producto "; da = new SqlDataAdapter(query, cnSQL); dt = new DataTable(); da.Fill(dt); //dt.Columns.RemoveAt(0);//Para quitar el campo RFC dataGridViewOferta.DataSource = dt; //para esconder el campor RFC dataGridViewOferta.Columns[0].Visible = false; }
private void BtnInsertar_Click(object sender, System.EventArgs e) { if (!validaDatosEntrada()) { return; } try { string hora_Apertura = dateTimePickerHoraApertura.Value.ToString("hh:mm:ss"); string hora_Cierre = dateTimePickerCierre.Value.ToString("hh:mm:ss"); string nombre = textBoxSucursal.Text; string direccion = textBoxDireccion.Text; string telefono = textBoxTelefono.Text; decimal cantidad = numericCantDeEmpleados.Value; //Validacion en esquema de localizacion--------------------------------------------------------------------------------------------------------------- //variables necesarias para sacar datos del esquema de localizacion List <string> idFragmentos = new List <string>(); List <string> nombreTablaBDFragmento = new List <string>(); string nombreTablaGeneral = ""; string tipoFragmento = ""; List <string> sitios = new List <string>(); List <string> condicion = new List <string>(); SitioCentral st = new SitioCentral(); st.LeeEsquemaLocalizacion("Sucursal", ref idFragmentos, ref nombreTablaBDFragmento, ref nombreTablaGeneral, ref sitios, ref tipoFragmento, ref condicion); switch (tipoFragmento) { case "Horizontal": //si es insercion se hace en el sitio de la condicion break; case "Vertical": break; case "Replica": //insertar en ambos sitios //si es insercion se hace en el sitio de la condicion try { if (sitios.ElementAt(0).Contains("1")) { //Insercion en sql server sitio1 string consulta = "Insert into " + nombreTablaBDFragmento.ElementAt(0).ToString() + " values('" + nombre + "','" + direccion + "','" + telefono + "'," + cantidad + ",'" + hora_Apertura + "','" + hora_Cierre + "')"; cmd = new SqlCommand(consulta, cnSQL); cmd.ExecuteNonQuery(); cargaTabla(); limpiaCampos(); //fin de insercion //Insercion en NPG sitio2 NpgsqlCommand command = new NpgsqlCommand("Insert into " + nombreTablaBDFragmento.ElementAt(1).ToString() + "(nombre,dirección,teléfono,cantidad_Empleados,hora_Apertura,hora_Cierre) values('" + nombre + "','" + direccion + "','" + telefono + "'," + cantidad + ",'" + hora_Apertura + "','" + hora_Cierre + "')", conNPG); command.ExecuteNonQuery(); } else { //Insercion en sql server sitio1 string consulta = "Insert into " + nombreTablaBDFragmento.ElementAt(1).ToString() + " values('" + nombre + "','" + direccion + "','" + telefono + "'," + cantidad + ",'" + hora_Apertura + "','" + hora_Cierre + "')"; cmd = new SqlCommand(consulta, cnSQL); cmd.ExecuteNonQuery(); cargaTabla(); limpiaCampos(); //fin de insercion //Insercion en NPG sitio2 NpgsqlCommand command = new NpgsqlCommand("Insert into " + nombreTablaBDFragmento.ElementAt(0).ToString() + "(nombre,dirección,teléfono,cantidad_Empleados,hora_Apertura,hora_Cierre) values('" + nombre + "','" + direccion + "','" + telefono + "'," + cantidad + ",'" + hora_Apertura + "','" + hora_Cierre + "')", conNPG); command.ExecuteNonQuery(); } } catch (Exception error) { MessageBox.Show("ERROR al insertar : " + error.Message); } break; default: switch (sitios.ElementAt(0)) { case "1": //Insercion en sql server string consulta = "Insert into " + nombreTablaBDFragmento.ElementAt(0).ToString() + " values('" + nombre + "','" + direccion + "','" + telefono + "'," + cantidad + ",'" + hora_Apertura + "','" + hora_Cierre + "')"; cmd = new SqlCommand(consulta, cnSQL); cmd.ExecuteNonQuery(); cargaTabla(); limpiaCampos(); break; case "2": NpgsqlCommand command = new NpgsqlCommand("Insert into " + nombreTablaBDFragmento.ElementAt(0).ToString() + "(nombre,dirección,teléfono,cantidad_Empleados,hora_Apertura,hora_Cierre) values('" + nombre + "','" + direccion + "','" + telefono + "'," + cantidad + ",'" + hora_Apertura + "','" + hora_Cierre + "')", conNPG); command.ExecuteNonQuery(); cargaTabla(); limpiaCampos(); break; } break; } } catch (Exception ex) { Console.WriteLine("no se inserto" + ex.Message); } }
private void comboBoxidSucursal_Enter_1(object sender, EventArgs e) { comboBoxidSucursal.Items.Clear(); //Validacion en esquema de localizacion--------------------------------------------------------------------------------------------------------------- //variables necesarias para sacar datos del esquema de localizacion List <string> idFragmentos = new List <string>(); List <string> nombreTablaBDFragmento = new List <string>(); string nombreTablaGeneral = ""; string tipoFragmento = ""; List <string> sitios = new List <string>(); List <string> condicion = new List <string>(); SitioCentral st = new SitioCentral(); st.LeeEsquemaLocalizacion("Sucursal", ref idFragmentos, ref nombreTablaBDFragmento, ref nombreTablaGeneral, ref sitios, ref tipoFragmento, ref condicion); switch (sitios.ElementAt(0))//por si esta en el sitio 1 o 2 { case "1": //agregar campos SqlDataAdapter daSucursal = new SqlDataAdapter("Select nombre from " + nombreTablaBDFragmento.ElementAt(0) + "", cnSQL); DataTable dtSucursal = new DataTable(); daSucursal.Fill(dtSucursal); string dato = ""; // For each row, print the values of each column. foreach (DataRow row in dtSucursal.Rows) { dato = row[dtSucursal.Columns[0]].ToString(); //para todas las rows dame el dato de la columna posicion 1 osea el nombre de la sucursal /* foreach (DataColumn column in dtSucursal.Columns) * { * ITERA TODOS LOS CAMPOS DE LAS COLUMNAS * }*/ comboBoxidSucursal.Items.Add(dato); //agrega como campo el nombre de la sucursal } break; case "2": //agregar campos NpgsqlDataAdapter daSucursalNP = new NpgsqlDataAdapter("Select nombre from " + nombreTablaBDFragmento.ElementAt(0) + "", conNPG); DataTable dtSucursalNP = new DataTable(); daSucursalNP.Fill(dtSucursalNP); string dat = ""; // For each row, print the values of each column. foreach (DataRow row in dtSucursalNP.Rows) { dat = row[dtSucursalNP.Columns[0]].ToString(); //para todas las rows dame el dato de la columna posicion 1 osea el nombre de la sucursal /* foreach (DataColumn column in dtSucursal.Columns) * { * ITERA TODOS LOS CAMPOS DE LAS COLUMNAS * }*/ comboBoxidSucursal.Items.Add(dat); //agrega como campo el nombre de la sucursal } break; default: break; } }
private void BtnElimina_Click(object sender, EventArgs e) { if (!validaDatosEntrada()) { return; } try { //Validacion en esquema de localizacion--------------------------------------------------------------------------------------------------------------- //variables necesarias para sacar datos del esquema de localizacion List <string> idFragmentos = new List <string>(); List <string> nombreTablaBDFragmento = new List <string>(); string nombreTablaGeneral = ""; string tipoFragmento = ""; List <string> sitios = new List <string>(); List <string> condicion = new List <string>(); SitioCentral st = new SitioCentral(); st.LeeEsquemaLocalizacion("Empleado", ref idFragmentos, ref nombreTablaBDFragmento, ref nombreTablaGeneral, ref sitios, ref tipoFragmento, ref condicion); //validacion de datos obtenidos //Juntamos los datos en renglones string renglon = ""; String[] atributos = new String[20]; for (int i = 0; i < idFragmentos.Count; i++) { renglon += idFragmentos.ElementAt(i).ToString() + "," + nombreTablaBDFragmento.ElementAt(i).ToString() + "," + nombreTablaGeneral + "," + tipoFragmento + "," + sitios.ElementAt(i).ToString() + "," + condicion.ElementAt(i).ToString(); //Orden : idfragmento , nombrefragmento , tabla , tipo , sitio , condicion atributos = renglon.Split(','); if (atributos.ElementAt(5).Contains(GlobalPuesto)) { break; } renglon = ""; } switch (tipoFragmento) { case "Horizontal": if (tipoFragmento == "Horizontal") { //si es insercion se hace en el sitio de la condicion switch (GlobalPuesto) { //Sitio1 case "Empleado": switch (atributos[4].ToString()) { case "1": //eliminar en sql server string consulta = "DELETE FROM " + atributos[1].ToString() + " WHERE RFC = " + dataGridViewEmpleado.CurrentRow.Cells[0].Value.ToString() + ""; cmd = new SqlCommand(consulta, cnSQL); dr.Close(); cmd.ExecuteNonQuery(); //fin de eliminacion break; case "2": //eliminar en NPG try { NpgsqlCommand command = new NpgsqlCommand("DELETE FROM " + atributos[1].ToString() + " WHERE RFC = " + dataGridViewEmpleado.CurrentRow.Cells[0].Value.ToString() + "", conNPG); dr.Close(); command.ExecuteNonQuery(); } catch (Exception error) { MessageBox.Show("ERROR al eliminar en NPG: " + error.Message); } break; default: break; } break; //Sitio2 case "Administrador": switch (atributos[4].ToString()) { case "1": //eliminar en sql server string consulta = "DELETE FROM " + atributos[1].ToString() + " WHERE RFC = " + dataGridViewEmpleado.CurrentRow.Cells[0].Value.ToString() + ""; cmd = new SqlCommand(consulta, cnSQL); dr.Close(); cmd.ExecuteNonQuery(); //fin de eliminacion break; case "2": //eliminar en NPG try { NpgsqlCommand command = new NpgsqlCommand("DELETE FROM " + atributos[1].ToString() + " WHERE RFC = " + dataGridViewEmpleado.CurrentRow.Cells[0].Value.ToString() + "", conNPG); dr.Close(); command.ExecuteNonQuery(); } catch (Exception error) { MessageBox.Show("ERROR al eliminar en NPG: " + error.Message); } break; default: break; } break; default: break; } } break; case "Vertical": break; case "Replica": //insertar en ambos sitios break; default: break; } if (!bandModifica) { cargaTabla(); limpiarCampos(); }//fin de eliminacion } catch (Exception ex) { Console.WriteLine("no se inserto" + ex.Message); } }
private void BtnInsertar_Click(object sender, EventArgs e) { if (!validaDatosEntrada()) { return; } try { string fecha_nacimiento = dateTimePickerFechaNacimiento.Value.ToString("yyyy-MM-dd"); string hora_Entrada = dateTimePickerHoraEntrada.Value.ToString("hh:mm:ss"); string hora_Salida = dateTimePickerHoraSalida.Value.ToString("hh:mm:ss"); string genero = (radioButtonFemenino.Checked == true) ? "F" : "M"; //Validacion en esquema de localizacion--------------------------------------------------------------------------------------------------------------- //variables necesarias para sacar datos del esquema de localizacion List <string> idFragmentos = new List <string>(); List <string> nombreTablaBDFragmento = new List <string>(); string nombreTablaGeneral = ""; string tipoFragmento = ""; List <string> sitios = new List <string>(); List <string> condicion = new List <string>(); SitioCentral st = new SitioCentral(); st.LeeEsquemaLocalizacion("Sucursal", ref idFragmentos, ref nombreTablaBDFragmento, ref nombreTablaGeneral, ref sitios, ref tipoFragmento, ref condicion); //codigo para convertir internamente el nombre de la sucursal al id de la sucursal SqlDataAdapter idSucursal = new SqlDataAdapter("Select id_Sucursal from " + nombreTablaBDFragmento[0] + " where nombre = '" + comboBoxidSucursal.Text + "'", cnSQL); cmd = new SqlCommand("Select id_Sucursal from " + nombreTablaBDFragmento[0] + " where nombre = '" + comboBoxidSucursal.Text + "'", cnSQL); dr = cmd.ExecuteReader(); dr.Read(); int idSuc = (Convert.ToInt32(dr[0])); //Validacion en esquema de localizacion--------------------------------------------------------------------------------------------------------------- //variables necesarias para sacar datos del esquema de localizacion idFragmentos = new List <string>(); nombreTablaBDFragmento = new List <string>(); nombreTablaGeneral = ""; tipoFragmento = ""; sitios = new List <string>(); condicion = new List <string>(); st = new SitioCentral(); st.LeeEsquemaLocalizacion("Empleado", ref idFragmentos, ref nombreTablaBDFragmento, ref nombreTablaGeneral, ref sitios, ref tipoFragmento, ref condicion); //validacion de datos obtenidos //Juntamos los datos en renglones string renglon = ""; String[] atributos = new String[20]; for (int i = 0; i < idFragmentos.Count; i++) { renglon += idFragmentos.ElementAt(i).ToString() + "," + nombreTablaBDFragmento.ElementAt(i).ToString() + "," + nombreTablaGeneral + "," + tipoFragmento + "," + sitios.ElementAt(i).ToString() + "," + condicion.ElementAt(i).ToString(); //Orden : idfragmento , nombrefragmento , tabla , tipo , sitio , condicion atributos = renglon.Split(','); if (atributos.ElementAt(5).Contains(ComboBoxPuesto.Text)) { break; } renglon = ""; } switch (tipoFragmento) { case "Horizontal": //si es insercion se hace en el sitio de la condicion switch (ComboBoxPuesto.Text) { //Sitio1 case "Empleado": switch (atributos[4].ToString()) { case "1": //Insercion en sql server string consulta = "Insert into " + atributos[1].ToString() + " values('" + TextBoxNombre.Text + "'," + NumericSueldo.Value + ",'" + ComboBoxPuesto.Text + "','" + TextBoxTelefono.Text + "','" + TextBoxDireccion.Text + "','" + fecha_nacimiento + "','" + genero + "','" + hora_Entrada + "','" + hora_Salida + "'," + idSuc + ")"; cmd = new SqlCommand(consulta, cnSQL); dr.Close(); cmd.ExecuteNonQuery(); cargaTabla(); limpiarCampos(); //fin de insercion break; case "2": try { NpgsqlCommand command = new NpgsqlCommand("Insert into " + atributos[1].ToString() + "(nombre,sueldo,puesto,teléfono,dirección,fecha_nacimiento,genero,hora_entrada,hora_salida,id_Sucursal) values('" + TextBoxNombre.Text + "'," + NumericSueldo.Value + ",'" + ComboBoxPuesto.Text + "','" + TextBoxTelefono.Text + "','" + TextBoxDireccion.Text + "','" + fecha_nacimiento + "','" + genero + "','" + hora_Entrada + "','" + hora_Salida + "'," + idSuc + ")", conNPG); dr.Close(); command.ExecuteNonQuery(); } catch (Exception error) { MessageBox.Show("ERROR al insertar en NPG: " + error.Message); } cargaTabla(); limpiarCampos(); //fin de insercion break; default: break; } break; //Sitio2 case "Administrador": //Insercion en NPG switch (atributos[4].ToString()) { case "1": //Insercion en sql server string consulta = "Insert into " + atributos[1].ToString() + " values('" + TextBoxNombre.Text + "'," + NumericSueldo.Value + ",'" + ComboBoxPuesto.Text + "','" + TextBoxTelefono.Text + "','" + TextBoxDireccion.Text + "','" + fecha_nacimiento + "','" + genero + "','" + hora_Entrada + "','" + hora_Salida + "'," + idSuc + ")"; cmd = new SqlCommand(consulta, cnSQL); dr.Close(); cmd.ExecuteNonQuery(); cargaTabla(); limpiarCampos(); //fin de insercion break; case "2": try { NpgsqlCommand command = new NpgsqlCommand("Insert into " + atributos[1].ToString() + "(nombre,sueldo,puesto,teléfono,dirección,fecha_nacimiento,genero,hora_entrada,hora_salida,id_Sucursal) values('" + TextBoxNombre.Text + "'," + NumericSueldo.Value + ",'" + ComboBoxPuesto.Text + "','" + TextBoxTelefono.Text + "','" + TextBoxDireccion.Text + "','" + fecha_nacimiento + "','" + genero + "','" + hora_Entrada + "','" + hora_Salida + "'," + idSuc + ")", conNPG); dr.Close(); command.ExecuteNonQuery(); } catch (Exception error) { MessageBox.Show("ERROR al insertar en NPG: " + error.Message); } cargaTabla(); limpiarCampos(); //fin de insercion break; default: break; } break; default: break; } break; case "Vertical": break; case "Replica": //insertar en ambos sitios break; default: break; } } catch (Exception ex) { Console.WriteLine("no se inserto" + ex.Message); } }
private void BtnModificar_Click(object sender, System.EventArgs e) { if (!validaDatos()) { return; } try { string Vigencia = dateTimePickerVigencia.Value.ToString("yyyy-MM-dd"); string descripcion = textBoxDescripcion.Text; string idProducto = ""; foreach (var item in ListaIdNombre) { if (item.Contains(comboBoxidProducto.Text)) { idProducto = item.ElementAt(0).ToString(); } } decimal Descuento = numericDescuento.Value; //Validacion en esquema de localizacion--------------------------------------------------------------------------------------------------------------- //variables necesarias para sacar datos del esquema de localizacion List <string> idFragmentos = new List <string>(); List <string> nombreTablaBDFragmento = new List <string>(); string nombreTablaGeneral = ""; string tipoFragmento = ""; List <string> sitios = new List <string>(); List <string> condicion = new List <string>(); SitioCentral st = new SitioCentral(); st.LeeEsquemaLocalizacion("Oferta", ref idFragmentos, ref nombreTablaBDFragmento, ref nombreTablaGeneral, ref sitios, ref tipoFragmento, ref condicion); switch (tipoFragmento) { case "Horizontal": //si es insercion se hace en el sitio de la condicion break; case "Vertical": break; case "Replica": //insertar en ambos sitios //si es insercion se hace en el sitio de la condicion try { if (sitios.ElementAt(0).Contains("1")) { //Insercion en sql server sitio1 string consulta = "UPDATE " + nombreTablaBDFragmento.ElementAt(0).ToString() + " SET descripcion = '" + descripcion + "',vigencia = '" + Vigencia + "',descuento = " + Descuento + " WHERE id_Oferta = " + dataGridViewOferta.CurrentRow.Cells[0].Value.ToString() + ""; cmd = new SqlCommand(consulta, cnSQL); cmd.ExecuteNonQuery(); cargaTabla(); limpiarCampos(); //fin de insercion //Insercion en NPG sitio2 NpgsqlCommand command = new NpgsqlCommand("UPDATE " + nombreTablaBDFragmento.ElementAt(1).ToString() + " SET descripcion = '" + descripcion + "',vigencia = '" + Vigencia + "',descuento = " + Descuento + " WHERE id_Oferta = " + dataGridViewOferta.CurrentRow.Cells[0].Value.ToString() + "", conNPG); command.ExecuteNonQuery(); } else { //Insercion en sql server sitio1 string consulta = "UPDATE " + nombreTablaBDFragmento.ElementAt(1).ToString() + " SET descripcion = '" + descripcion + "',vigencia = '" + Vigencia + "',descuento = " + Descuento + " WHERE id_Oferta = " + dataGridViewOferta.CurrentRow.Cells[0].Value.ToString() + ""; cmd = new SqlCommand(consulta, cnSQL); cmd.ExecuteNonQuery(); cargaTabla(); limpiarCampos(); //fin de insercion //Insercion en NPG sitio2 NpgsqlCommand command = new NpgsqlCommand("UPDATE " + nombreTablaBDFragmento.ElementAt(0).ToString() + " SET descripcion = '" + descripcion + "',vigencia = '" + Vigencia + "',descuento = " + Descuento + " WHERE id_Oferta = " + dataGridViewOferta.CurrentRow.Cells[0].Value.ToString() + "", conNPG); command.ExecuteNonQuery(); } } catch (Exception error) { MessageBox.Show("ERROR al insertar : " + error.Message); } break; default: switch (sitios.ElementAt(0)) { case "1": //Insercion en sql server string consulta = "UPDATE " + nombreTablaBDFragmento.ElementAt(0).ToString() + " SET descripcion = '" + descripcion + "',vigencia = '" + Vigencia + "',descuento = " + Descuento + " WHERE id_Oferta = " + dataGridViewOferta.CurrentRow.Cells[0].Value.ToString() + ""; cmd = new SqlCommand(consulta, cnSQL); cmd.ExecuteNonQuery(); cargaTabla(); limpiarCampos(); break; case "2": NpgsqlCommand command = new NpgsqlCommand("UPDATE " + nombreTablaBDFragmento.ElementAt(0).ToString() + " SET descripcion = '" + descripcion + "',vigencia = '" + Vigencia + "',descuento = " + Descuento + "WHERE id_Oferta = " + dataGridViewOferta.CurrentRow.Cells[0].Value.ToString() + "", conNPG); command.ExecuteNonQuery(); cargaTabla(); limpiarCampos(); break; } break; } } catch (Exception ex) { Console.WriteLine("no se inserto" + ex.Message); } }
private void BtnInsertar_Click(object sender, EventArgs e) { if (!validaDatosEntrada()) { return; } string nombre = textBoxNombre.Text; string telefono = textBoxTelefono.Text; string direccion = textBoxDireccion.Text; string email = textBoxEmail.Text; string tipo = comboBoxTipo.SelectedItem.ToString(); int idProveedor = CalculaPrimaryKey(); try { //Validacion en esquema de localizacion--------------------------------------------------------------------------------------------------------------- //variables necesarias para sacar datos del esquema de localizacion List <string> idFragmentos = new List <string>(); List <string> nombreTablaBDFragmento = new List <string>(); string nombreTablaGeneral = ""; string tipoFragmento = ""; List <string> sitios = new List <string>(); List <string> condicion = new List <string>(); SitioCentral st = new SitioCentral(); st.LeeEsquemaLocalizacion("Proveedor", ref idFragmentos, ref nombreTablaBDFragmento, ref nombreTablaGeneral, ref sitios, ref tipoFragmento, ref condicion); switch (tipoFragmento) { case "Horizontal": break; case "Vertical": try { List <string> atributosSitio1 = new List <string>(); List <string> atributosSitio2 = new List <string>(); st.LeeEsquemaAtributos(idFragmentos, ref atributosSitio1, ref atributosSitio2); //Insercion en sql server string consulta = "Insert into " + nombreTablaBDFragmento[0].ToString() + " values(" + idProveedor + ",'" + textBoxNombre.Text + "','" + textBoxEmail.Text + "','" + textBoxTelefono.Text + "')"; cmd = new SqlCommand(consulta, cnSQL); // dr.Close(); cmd.ExecuteNonQuery(); //fin de insercion NpgsqlCommand command = new NpgsqlCommand("Insert into " + nombreTablaBDFragmento[1].ToString() + "(id_Proveedor,direccion,tipo) values(" + idProveedor + ",'" + textBoxDireccion.Text + "','" + comboBoxTipo.Text + "')", conNPG); // dr.Close(); command.ExecuteNonQuery(); } catch (Exception error) { MessageBox.Show("ERROR al insertar en NPG: " + error.Message); } cargaTabla(); limpiarCampos(); break; case "Replica": //insertar en ambos sitios break; default: break; } } catch (Exception ex) { Console.WriteLine("no se inserto" + ex.Message); } }
private void BtnEliminar_Click(object sender, System.EventArgs e) { if (!validaDatosEntrada()) { return; } try { //Validacion en esquema de localizacion--------------------------------------------------------------------------------------------------------------- //variables necesarias para sacar datos del esquema de localizacion List <string> idFragmentos = new List <string>(); List <string> nombreTablaBDFragmento = new List <string>(); string nombreTablaGeneral = ""; string tipoFragmento = ""; List <string> sitios = new List <string>(); List <string> condicion = new List <string>(); SitioCentral st = new SitioCentral(); st.LeeEsquemaLocalizacion("Sucursal", ref idFragmentos, ref nombreTablaBDFragmento, ref nombreTablaGeneral, ref sitios, ref tipoFragmento, ref condicion); switch (tipoFragmento) { case "Horizontal": break; case "Vertical": break; case "Replica": //Eliminar en ambos sitios try { if (sitios.ElementAt(0).Contains("1")) { //eliminar en sql server string consulta = "DELETE FROM " + nombreTablaBDFragmento.ElementAt(0).ToString() + " WHERE id_Sucursal = " + dataGridViewSucursal.CurrentRow.Cells[0].Value.ToString() + ""; cmd = new SqlCommand(consulta, cnSQL); cmd.ExecuteNonQuery(); //eliminar en postgressql NpgsqlCommand command = new NpgsqlCommand("DELETE FROM " + nombreTablaBDFragmento.ElementAt(1).ToString() + " WHERE id_Sucursal = " + dataGridViewSucursal.CurrentRow.Cells[0].Value.ToString() + "", conNPG); command.ExecuteNonQuery(); cargaTabla(); limpiaCampos(); } else { //eliminar en sql server string consulta = "DELETE FROM " + nombreTablaBDFragmento.ElementAt(1).ToString() + " WHERE id_Sucursal = " + dataGridViewSucursal.CurrentRow.Cells[0].Value.ToString() + ""; cmd = new SqlCommand(consulta, cnSQL); cmd.ExecuteNonQuery(); //eliminar en postgressql NpgsqlCommand command = new NpgsqlCommand("DELETE FROM " + nombreTablaBDFragmento.ElementAt(0).ToString() + " WHERE id_Sucursal = " + dataGridViewSucursal.CurrentRow.Cells[0].Value.ToString() + "", conNPG); command.ExecuteNonQuery(); cargaTabla(); limpiaCampos(); } } catch (Exception) { throw; } break; default: switch (sitios.ElementAt(0)) { case "1": //Insercion en sql server string consulta = "DELETE FROM " + nombreTablaBDFragmento.ElementAt(0).ToString() + " WHERE id_Sucursal = " + dataGridViewSucursal.CurrentRow.Cells[0].Value.ToString() + ""; cmd = new SqlCommand(consulta, cnSQL); cmd.ExecuteNonQuery(); cargaTabla(); limpiaCampos(); break; case "2": NpgsqlCommand command = new NpgsqlCommand("DELETE FROM " + nombreTablaBDFragmento.ElementAt(0).ToString() + " WHERE id_Sucursal = " + dataGridViewSucursal.CurrentRow.Cells[0].Value.ToString() + "", conNPG); command.ExecuteNonQuery(); cargaTabla(); limpiaCampos(); break; } break; } } catch (Exception ex) { Console.WriteLine("no se inserto" + ex.Message); } }
private void BtnModificar_Click(object sender, System.EventArgs e) { if (!validaDatos()) { return; } try { string nombre = textBoxNombre.Text; string fecha_caducidad = dateTimePickerCaducidad.Value.ToString("yyyy-MM-dd"); decimal precio = numericPrecio.Value; decimal cantidad = numericCantidad.Value; var idProveedor = dataGridViewProducto.CurrentRow.Cells[5].Value; //Validacion en esquema de localizacion--------------------------------------------------------------------------------------------------------------- //variables necesarias para sacar datos del esquema de localizacion List <string> idFragmentos = new List <string>(); List <string> nombreTablaBDFragmento = new List <string>(); string nombreTablaGeneral = ""; string tipoFragmento = ""; List <string> sitios = new List <string>(); List <string> condicion = new List <string>(); SitioCentral st = new SitioCentral(); st.LeeEsquemaLocalizacion("Producto", ref idFragmentos, ref nombreTablaBDFragmento, ref nombreTablaGeneral, ref sitios, ref tipoFragmento, ref condicion); switch (tipoFragmento) { case "Horizontal": break; case "Vertical": break; case "Replica": if (sitios.ElementAt(0).Contains("1")) { //MODIFICACION en sql server string consulta = "UPDATE " + nombreTablaBDFragmento[0].ToString() + " SET nombre = '" + nombre + "',precio=" + precio + ",caducidad='" + fecha_caducidad + "',cantidad=" + cantidad + ",id_Proveedor = " + idProveedor + " WHERE id_Producto = " + dataGridViewProducto.CurrentRow.Cells[0].Value.ToString() + ""; cmd = new SqlCommand(consulta, cnSQL); cmd.ExecuteNonQuery(); //modificar en postgresql NpgsqlCommand command = new NpgsqlCommand("UPDATE " + nombreTablaBDFragmento[1].ToString() + " SET nombre = '" + nombre + "',precio=" + precio + ",caducidad='" + fecha_caducidad + "',cantidad=" + cantidad + ",id_Proveedor =" + idProveedor + " WHERE id_Producto = " + dataGridViewProducto.CurrentRow.Cells[0].Value.ToString() + "", conNPG); command.ExecuteNonQuery(); cargaTabla(); limpiarCampos(); } else { //MODIFICACION en sql server string consulta = "UPDATE " + nombreTablaBDFragmento[1].ToString() + " SET nombre = '" + nombre + "',precio=" + precio + ",caducidad='" + fecha_caducidad + "',cantidad=" + cantidad + ",id_Proveedor = " + idProveedor + " WHERE id_Producto = " + dataGridViewProducto.CurrentRow.Cells[0].Value.ToString() + ""; cmd = new SqlCommand(consulta, cnSQL); cmd.ExecuteNonQuery(); //modificar en postgresql NpgsqlCommand command = new NpgsqlCommand("UPDATE " + nombreTablaBDFragmento[0].ToString() + " SET nombre = '" + nombre + "',precio=" + precio + ",caducidad='" + fecha_caducidad + "',cantidad=" + cantidad + ",id_Proveedor =" + idProveedor + " WHERE id_Producto = " + dataGridViewProducto.CurrentRow.Cells[0].Value.ToString() + "", conNPG); command.ExecuteNonQuery(); cargaTabla(); limpiarCampos(); } break; default: switch (sitios.ElementAt(0)) { case "1": //Insercion en sql server string consultaS = "UPDATE " + nombreTablaBDFragmento[0].ToString() + " SET nombre = '" + nombre + "',precio=" + precio + ",caducidad='" + fecha_caducidad + "',cantidad=" + cantidad + ",id_Proveedor = " + idProveedor + " WHERE id_Producto = " + dataGridViewProducto.CurrentRow.Cells[0].Value.ToString() + ""; cmd = new SqlCommand(consultaS, cnSQL); cmd.ExecuteNonQuery(); cargaTabla(); limpiarCampos(); break; case "2": NpgsqlCommand commandS = new NpgsqlCommand("UPDATE " + nombreTablaBDFragmento[1].ToString() + " SET nombre = '" + nombre + "',precio=" + precio + ",caducidad='" + fecha_caducidad + "',cantidad=" + cantidad + ",id_Proveedor =" + idProveedor + " WHERE id_Producto = " + dataGridViewProducto.CurrentRow.Cells[0].Value.ToString() + "", conNPG); commandS.ExecuteNonQuery(); cargaTabla(); limpiarCampos(); break; } break; } } catch (Exception ex) { MessageBox.Show("no se modifico" + ex.Message); } }
private void ChecaSiExisteOferta(string idProducto) { try { SqlDataReader dr; //PARA CARGAR LISTA DE PRODUCTOS //Validacion en esquema de localizacion--------------------------------------------------------------------------------------------------------------- //variables necesarias para sacar datos del esquema de localizacion List <string> idFragmentos = new List <string>(); List <string> nombreTablaBDFragmento = new List <string>(); string nombreTablaGeneral = ""; string tipoFragmento = ""; List <string> sitios = new List <string>(); List <string> condicion = new List <string>(); SitioCentral st = new SitioCentral(); st.LeeEsquemaLocalizacion("Oferta", ref idFragmentos, ref nombreTablaBDFragmento, ref nombreTablaGeneral, ref sitios, ref tipoFragmento, ref condicion); //carga lista de ofertas SqlDataAdapter daOferta = new SqlDataAdapter("Select * from " + nombreTablaBDFragmento.ElementAt(0) + "", cnSQL); DataTable dtOferta = new DataTable(); daOferta.Fill(dtOferta); listaOfertas = new List <string>(); // For each row, print the values of each column. //idOferta,descripcon,fecha,descuento,idProducto foreach (DataRow row in dtOferta.Rows) { listaOfertas.Add(row[dtOferta.Columns[0]].ToString() + "," + row[dtOferta.Columns[1]].ToString() + "," + row[dtOferta.Columns[2]].ToString() + "," + row[dtOferta.Columns[3]].ToString() + "," + row[dtOferta.Columns[4]].ToString()); } List <string> existeOferta = listaOfertas.FindAll(x => x.Contains(idProducto)); string[] substringOferta; if (existeOferta.Count == 0)//si el count es igual a 0 significa que ese producto no tiene oferta { return; } else { substringOferta = existeOferta.ElementAt(0).Split(','); } switch (tipoFragmento) { case "Horizontal": //si es insercion se hace en el sitio de la condicion break; case "Vertical": break; case "Replica": //insertar en ambos sitios //si es insercion se hace en el sitio de la condicion try { if (sitios.ElementAt(0).Contains("1")) { //Insercion en sql server sitio1 string consulta = "DELETE FROM " + nombreTablaBDFragmento.ElementAt(0).ToString() + " WHERE id_Oferta = " + substringOferta.ElementAt(0) + ""; cmd = new SqlCommand(consulta, cnSQL); cmd.ExecuteNonQuery(); cargaTabla(); limpiarCampos(); //fin de insercion //Insercion en NPG sitio2 NpgsqlCommand command = new NpgsqlCommand("DELETE FROM " + nombreTablaBDFragmento.ElementAt(1).ToString() + " WHERE id_Oferta = " + substringOferta.ElementAt(0) + "", conNPG); command.ExecuteNonQuery(); } else { //Insercion en sql server sitio1 string consulta = "DELETE FROM " + nombreTablaBDFragmento.ElementAt(1).ToString() + " WHERE id_Oferta = " + substringOferta.ElementAt(0) + ""; cmd = new SqlCommand(consulta, cnSQL); cmd.ExecuteNonQuery(); cargaTabla(); limpiarCampos(); //fin de insercion //Insercion en NPG sitio2 NpgsqlCommand command = new NpgsqlCommand("DELETE FROM " + nombreTablaBDFragmento.ElementAt(0).ToString() + " WHERE id_Oferta = " + substringOferta.ElementAt(0) + "", conNPG); command.ExecuteNonQuery(); } } catch (Exception error) { MessageBox.Show("ERROR al insertar : " + error.Message); } break; default: switch (sitios.ElementAt(0)) { case "1": //Insercion en sql server string consulta = "DELETE FROM " + nombreTablaBDFragmento.ElementAt(0).ToString() + " WHERE id_Oferta = " + substringOferta.ElementAt(0) + ""; cmd = new SqlCommand(consulta, cnSQL); cmd.ExecuteNonQuery(); //cargaTabla(); // limpiarCampos(); break; case "2": NpgsqlCommand command = new NpgsqlCommand("DELETE FROM " + nombreTablaBDFragmento.ElementAt(0).ToString() + " WHERE id_Oferta = " + substringOferta.ElementAt(0) + "", conNPG); command.ExecuteNonQuery(); cargaTabla(); limpiarCampos(); break; } break; } } catch (Exception) { throw; } }
private void BtnInsertar_Click(object sender, System.EventArgs e) { if (!validaDatos()) { return; } //CHECAR SI EL PRODUCTo YA EXISTE if (ChecaExistenciaProducto())//si existe manda mensaje de error y se sale de la funcion { MessageBox.Show("Error , Producto ya en existencía"); return; } try { string fecha_caducidad = dateTimePickerCaducidad.Value.ToString("yyyy-MM-dd"); string nombre = textBoxNombre.Text; var arreglo = new string[3]; foreach (var renglon in listaidProvyNombre) { if (renglon.Contains(comboBoxidProveedor.Text)) { arreglo = renglon.Split(','); break; } } int idproveedor = Int32.Parse((arreglo[0].ToString())); decimal precio = numericPrecio.Value; decimal cantidaad = numericCantidad.Value; //Validacion en esquema de localizacion--------------------------------------------------------------------------------------------------------------- //variables necesarias para sacar datos del esquema de localizacion List <string> idFragmentos = new List <string>(); List <string> nombreTablaBDFragmento = new List <string>(); string nombreTablaGeneral = ""; string tipoFragmento = ""; List <string> sitios = new List <string>(); List <string> condicion = new List <string>(); SitioCentral st = new SitioCentral(); st.LeeEsquemaLocalizacion("Producto", ref idFragmentos, ref nombreTablaBDFragmento, ref nombreTablaGeneral, ref sitios, ref tipoFragmento, ref condicion); switch (tipoFragmento) { case "Replica": //si es insercion se hace en el sitio de la condicion try { if (sitios.ElementAt(0).Contains("1")) { //Insercion en sql server sitio1 string consulta = "Insert into " + nombreTablaBDFragmento[0].ToString() + " values('" + nombre + "'," + precio + ",'" + fecha_caducidad + "'," + cantidaad + ",'" + idproveedor + "','" + -1 + "')"; cmd = new SqlCommand(consulta, cnSQL); cmd.ExecuteNonQuery(); cargaTabla(); limpiarCampos(); //fin de insercion //Insercion en NPG sitio2 NpgsqlCommand command = new NpgsqlCommand("Insert into " + nombreTablaBDFragmento[1].ToString() + "(nombre,precio,caducidad,cantidad,id_Proveedor,id_Venta) values('" + nombre + "'," + precio + ",'" + fecha_caducidad + "'," + cantidaad + ",'" + idproveedor + "','" + -1 + "')", conNPG); command.ExecuteNonQuery(); } else { //Insercion en sql server sitio1 string consulta = "Insert into " + nombreTablaBDFragmento[1].ToString() + " values('" + nombre + "'," + precio + ",'" + fecha_caducidad + "'," + cantidaad + ",'" + idproveedor + "','" + -1 + "')"; cmd = new SqlCommand(consulta, cnSQL); cmd.ExecuteNonQuery(); cargaTabla(); limpiarCampos(); //fin de insercion //Insercion en NPG sitio2 NpgsqlCommand command = new NpgsqlCommand("Insert into " + nombreTablaBDFragmento[0].ToString() + "(nombre,precio,caducidad,cantidad,id_Proveedor,id_Venta) values('" + nombre + "'," + precio + ",'" + fecha_caducidad + "'," + cantidaad + ",'" + idproveedor + "','" + -1 + "')", conNPG); command.ExecuteNonQuery(); } } catch (Exception error) { MessageBox.Show("ERROR al insertar en NPG: " + error.Message); } //fin de insercion break; default: switch (sitios.ElementAt(0)) { case "1": //Insercion en sql server sitio1 string consulta = "Insert into " + nombreTablaBDFragmento[0].ToString() + " values('" + nombre + "'," + precio + ",'" + fecha_caducidad + "'," + cantidaad + ",'" + idproveedor + "','" + -1 + "')"; cmd = new SqlCommand(consulta, cnSQL); cmd.ExecuteNonQuery(); cargaTabla(); limpiarCampos(); //fin de insercion break; case "2": //Insercion en NPG sitio2 NpgsqlCommand command = new NpgsqlCommand("Insert into " + nombreTablaBDFragmento[0].ToString() + "(nombre,precio,caducidad,cantidad,id_Proveedor,id_Venta) values('" + nombre + "'," + precio + ",'" + fecha_caducidad + "'," + cantidaad + ",'" + idproveedor + "','" + -1 + "')", conNPG); command.ExecuteNonQuery(); break; } break; } } catch (Exception ex) { MessageBox.Show("no se inserto" + ex.Message); } cargaTabla(); limpiarCampos(); }
private void BtnEliminar_Click(object sender, EventArgs e) { try { //Validacion en esquema de localizacion--------------------------------------------------------------------------------------------------------------- //variables necesarias para sacar datos del esquema de localizacion List <string> idFragmentos = new List <string>(); List <string> nombreTablaBDFragmento = new List <string>(); string nombreTablaGeneral = ""; string tipoFragmento = ""; List <string> sitios = new List <string>(); List <string> condicion = new List <string>(); SitioCentral st = new SitioCentral(); st.LeeEsquemaLocalizacion("Proveedor", ref idFragmentos, ref nombreTablaBDFragmento, ref nombreTablaGeneral, ref sitios, ref tipoFragmento, ref condicion); switch (tipoFragmento) { case "Horizontal": break; case "Vertical": try { //Primero hay que checar si el provedor tiene productos registrados para evitar la entidad referencial //Validacion en esquema de localizacion--------------------------------------------------------------------------------------------------------------- //variables necesarias para sacar datos del esquema de localizacion List <string> idFragmentosProducto = new List <string>(); List <string> nombreTablaBDFragmentoProducto = new List <string>(); string nombreTablaGeneralProducto = ""; string tipoFragmentoProducto = ""; List <string> sitiosProducto = new List <string>(); List <string> condicionProducto = new List <string>(); SitioCentral stProducto = new SitioCentral(); stProducto.LeeEsquemaLocalizacion("Producto", ref idFragmentosProducto, ref nombreTablaBDFragmentoProducto, ref nombreTablaGeneralProducto, ref sitiosProducto, ref tipoFragmentoProducto, ref condicionProducto); switch (tipoFragmentoProducto) { case "Replica": switch (sitiosProducto.ElementAt(0)) { case "1": //eliminar campos SqlDataAdapter daProducto = new SqlDataAdapter("Select id_Producto from " + nombreTablaBDFragmentoProducto.ElementAt(0) + " where id_Proveedor = '" + dataGridViewProveedor.CurrentRow.Cells[0].Value.ToString() + "'", cnSQL); DataTable dtProducto = new DataTable(); daProducto.Fill(dtProducto); string dato = ""; // For each row, print the values of each column. //Borrar los productos del proveedor que se va a borrar foreach (DataRow row in dtProducto.Rows) { //esta funcion checa si el producto tiene oferta y si tiene la borra string idProductoo = row[dtProducto.Columns[0]].ToString(); ChecaSiExisteOferta(row[dtProducto.Columns[0]].ToString()); dato = row[dtProducto.Columns[0]].ToString(); //para todas las rows dame el dato de la columna posicion 1 osea el nombre de la sucursal string consultaProd = "DELETE FROM " + nombreTablaBDFragmentoProducto[0].ToString() + " WHERE id_Producto = " + dato + ""; cmd = new SqlCommand(consultaProd, cnSQL); cmd.ExecuteNonQuery(); } //eliminar campos NpgsqlDataAdapter daProductoNP = new NpgsqlDataAdapter("Select id_Producto from " + nombreTablaBDFragmentoProducto.ElementAt(1) + " where id_Proveedor = '" + dataGridViewProveedor.CurrentRow.Cells[0].Value.ToString() + "'", conNPG); DataTable dtProductoNP = new DataTable(); daProductoNP.Fill(dtProductoNP); string dat = ""; // For each row, print the values of each column. //Borrar los productos del proveedor que se va a borrar foreach (DataRow row in dtProductoNP.Rows) { //esta funcion checa si el producto tiene oferta y si tiene la borra string idProductoo = row[dtProductoNP.Columns[0]].ToString(); ChecaSiExisteOferta(row[dtProductoNP.Columns[0]].ToString()); dat = row[dtProductoNP.Columns[0]].ToString(); //para todas las rows dame el dato de la columna posicion 1 osea el nombre de la sucursal NpgsqlCommand commandProd = new NpgsqlCommand("DELETE FROM " + nombreTablaBDFragmentoProducto[1].ToString() + " WHERE id_Producto = " + dat + "", conNPG); commandProd.ExecuteNonQuery(); } break; case "2": //eliminar campos daProducto = new SqlDataAdapter("Select id_Producto from " + nombreTablaBDFragmentoProducto.ElementAt(1) + " where id_Proveedor = '" + dataGridViewProveedor.CurrentRow.Cells[0].Value.ToString() + "'", cnSQL); dtProducto = new DataTable(); daProducto.Fill(dtProducto); dato = ""; // For each row, print the values of each column. //Borrar los productos del proveedor que se va a borrar foreach (DataRow row in dtProducto.Rows) { ChecaSiExisteOferta(row[dtProducto.Columns[0]].ToString()); dato = row[dtProducto.Columns[0]].ToString(); //para todas las rows dame el dato de la columna posicion 1 osea el nombre de la sucursal string consultaProd = "DELETE FROM " + nombreTablaBDFragmentoProducto[1].ToString() + " WHERE id_Producto = " + dato + ""; cmd = new SqlCommand(consultaProd, cnSQL); cmd.ExecuteNonQuery(); } //eliminar campos daProductoNP = new NpgsqlDataAdapter("Select id_Producto from " + nombreTablaBDFragmentoProducto.ElementAt(0) + " where id_Proveedor = '" + dataGridViewProveedor.CurrentRow.Cells[0].Value.ToString() + "'", conNPG); dtProductoNP = new DataTable(); daProductoNP.Fill(dtProductoNP); dat = ""; // For each row, print the values of each column. //Borrar los productos del proveedor que se va a borrar foreach (DataRow row in dtProductoNP.Rows) { //esta funcion checa si el producto tiene oferta y si tiene la borra ChecaSiExisteOferta(row[dtProducto.Columns[0]].ToString()); dat = row[dtProductoNP.Columns[0]].ToString(); //para todas las rows dame el dato de la columna posicion 1 osea el nombre de la sucursal NpgsqlCommand commandProd = new NpgsqlCommand("DELETE FROM " + nombreTablaBDFragmentoProducto[0].ToString() + " WHERE id_Producto = " + dat + "", conNPG); commandProd.ExecuteNonQuery(); } break; } break; default: //si no tiene una fragmentacion switch (sitiosProducto.ElementAt(0)) //por si esta en el sitio 1 o 2 { case "1": //agregar campos SqlDataAdapter daProducto = new SqlDataAdapter("Select id_Producto from " + nombreTablaBDFragmentoProducto.ElementAt(0) + " where id_Proveedor = '" + dataGridViewProveedor.CurrentRow.Cells[0].Value.ToString() + "'", cnSQL); DataTable dtProducto = new DataTable(); daProducto.Fill(dtProducto); string dato = ""; // For each row, print the values of each column. //Borrar los productos del proveedor que se va a borrar foreach (DataRow row in dtProducto.Rows) { ChecaSiExisteOferta(row[dtProducto.Columns[0]].ToString()); dato = row[dtProducto.Columns[0]].ToString(); //para todas las rows dame el dato de la columna posicion 1 osea el nombre de la sucursal string consultaProd = "DELETE FROM " + nombreTablaBDFragmentoProducto[0].ToString() + " WHERE id_Producto = " + dato + ""; cmd = new SqlCommand(consultaProd, cnSQL); cmd.ExecuteNonQuery(); } break; case "2": //agregar campos NpgsqlDataAdapter daProductoNP = new NpgsqlDataAdapter("Select id_Producto from " + nombreTablaBDFragmentoProducto.ElementAt(0) + " where id_Proveedor = '" + dataGridViewProveedor.CurrentRow.Cells[0].Value.ToString() + "'", conNPG); DataTable dtProductoNP = new DataTable(); daProductoNP.Fill(dtProductoNP); string dat = ""; // For each row, print the values of each column. //Borrar los productos del proveedor que se va a borrar foreach (DataRow row in dtProductoNP.Rows) { ChecaSiExisteOferta(row[dtProductoNP.Columns[0]].ToString()); dat = row[dtProductoNP.Columns[0]].ToString(); //para todas las rows dame el dato de la columna posicion 1 osea el nombre de la sucursal NpgsqlCommand commandProd = new NpgsqlCommand("DELETE FROM " + nombreTablaBDFragmentoProducto[0].ToString() + " WHERE id_Producto = " + dat + "", conNPG); commandProd.ExecuteNonQuery(); } break; } break; } //eliminar en sql server string consulta = "DELETE FROM " + nombreTablaBDFragmento[0].ToString() + " WHERE id_Proveedor = " + dataGridViewProveedor.CurrentRow.Cells[0].Value.ToString() + ""; cmd = new SqlCommand(consulta, cnSQL); cmd.ExecuteNonQuery(); //eliminar en postgressql NpgsqlCommand command = new NpgsqlCommand("DELETE FROM " + nombreTablaBDFragmento[1].ToString() + " WHERE id_Proveedor = " + dataGridViewProveedor.CurrentRow.Cells[0].Value.ToString() + "", conNPG); command.ExecuteNonQuery(); cargaTabla(); limpiarCampos(); } catch (Exception) { throw; } break; case "Replica": //insertar en ambos sitios break; default: break; } } catch (Exception ex) { Console.WriteLine("no se inserto" + ex.Message); } }
private void BtnModificar_Click(object sender, System.EventArgs e) { if (!validaDatosEntrada()) { return; } try { string hora_Apertura = dateTimePickerHoraApertura.Value.ToString("hh:mm:ss"); string hora_Cierre = dateTimePickerCierre.Value.ToString("hh:mm:ss"); string nombre = textBoxSucursal.Text; string direccion = textBoxDireccion.Text; string telefono = textBoxTelefono.Text; decimal cantidad = numericCantDeEmpleados.Value; //Validacion en esquema de localizacion--------------------------------------------------------------------------------------------------------------- //variables necesarias para sacar datos del esquema de localizacion List <string> idFragmentos = new List <string>(); List <string> nombreTablaBDFragmento = new List <string>(); string nombreTablaGeneral = ""; string tipoFragmento = ""; List <string> sitios = new List <string>(); List <string> condicion = new List <string>(); SitioCentral st = new SitioCentral(); st.LeeEsquemaLocalizacion("Sucursal", ref idFragmentos, ref nombreTablaBDFragmento, ref nombreTablaGeneral, ref sitios, ref tipoFragmento, ref condicion); switch (tipoFragmento) { case "Horizontal": //si es insercion se hace en el sitio de la condicion break; case "Vertical": break; case "Replica": //modifcar en ambos sitios if (sitios.ElementAt(0).Contains("1")) { //MODIFICACION en sql server string consulta = "UPDATE " + nombreTablaBDFragmento.ElementAt(0).ToString() + " SET nombre = '" + nombre + "',dirección ='" + direccion + "',teléfono = '" + telefono + "',cantidad_Empleados=" + cantidad + ",hora_Apertura ='" + hora_Apertura + "',hora_Cierre='" + hora_Cierre + "' WHERE id_Sucursal = " + dataGridViewSucursal.CurrentRow.Cells[0].Value.ToString() + ""; cmd = new SqlCommand(consulta, cnSQL); cmd.ExecuteNonQuery(); //modificar en postgresql NpgsqlCommand command = new NpgsqlCommand("UPDATE " + nombreTablaBDFragmento.ElementAt(1).ToString() + " SET nombre = '" + nombre + "',dirección ='" + direccion + "',teléfono = '" + telefono + "',cantidad_Empleados=" + cantidad + ",hora_Apertura ='" + hora_Apertura + "',hora_Cierre='" + hora_Cierre + "' WHERE id_Sucursal = " + dataGridViewSucursal.CurrentRow.Cells[0].Value.ToString() + "", conNPG); command.ExecuteNonQuery(); cargaTabla(); limpiaCampos(); } else { //MODIFICACION en sql server string consulta = "UPDATE " + nombreTablaBDFragmento.ElementAt(1).ToString() + " SET nombre = '" + nombre + "',dirección ='" + direccion + "',teléfono = '" + telefono + "',cantidad_Empleados=" + cantidad + ",hora_Apertura ='" + hora_Apertura + "',hora_Cierre='" + hora_Cierre + "' WHERE id_Sucursal = " + dataGridViewSucursal.CurrentRow.Cells[0].Value.ToString() + ""; cmd = new SqlCommand(consulta, cnSQL); cmd.ExecuteNonQuery(); //modificar en postgresql NpgsqlCommand command = new NpgsqlCommand("UPDATE " + nombreTablaBDFragmento.ElementAt(0).ToString() + " SET nombre = '" + nombre + "',dirección ='" + direccion + "',teléfono = '" + telefono + "',cantidad_Empleados=" + cantidad + ",hora_Apertura ='" + hora_Apertura + "',hora_Cierre='" + hora_Cierre + "' WHERE id_Sucursal = " + dataGridViewSucursal.CurrentRow.Cells[0].Value.ToString() + "", conNPG); command.ExecuteNonQuery(); cargaTabla(); limpiaCampos(); } break; default: switch (sitios.ElementAt(0)) { case "1": //Insercion en sql server string consultaS = "UPDATE " + nombreTablaBDFragmento.ElementAt(0).ToString() + " SET nombre = '" + nombre + "',dirección ='" + direccion + "',teléfono = '" + telefono + "',cantidad_Empleados=" + cantidad + ",hora_Apertura ='" + hora_Apertura + "',hora_Cierre='" + hora_Cierre + "' WHERE id_Sucursal = " + dataGridViewSucursal.CurrentRow.Cells[0].Value.ToString() + ""; cmd = new SqlCommand(consultaS, cnSQL); cmd.ExecuteNonQuery(); cargaTabla(); limpiaCampos(); break; case "2": NpgsqlCommand commandS = new NpgsqlCommand("UPDATE " + nombreTablaBDFragmento.ElementAt(0).ToString() + " SET nombre = '" + nombre + "',dirección ='" + direccion + "',teléfono = '" + telefono + "',cantidad_Empleados=" + cantidad + ",hora_Apertura ='" + hora_Apertura + "',hora_Cierre='" + hora_Cierre + "' WHERE id_Sucursal = " + dataGridViewSucursal.CurrentRow.Cells[0].Value.ToString() + "", conNPG); commandS.ExecuteNonQuery(); cargaTabla(); limpiaCampos(); break; } break; } } catch (Exception ex) { MessageBox.Show("no se modifico" + ex.Message); } }
private void MezclaBDVertical() { /*CODIGO PARA ITERAR LAS CELDAS DE UN DATATABLE POR RENGLONES * int numberOfColumns = dt.Columns.Count; * * // go through each row * foreach (DataRow dr in dt.Rows) * { * // go through each column in the row * for (int i = 0; i < numberOfColumns; i++) * { * // access cell as set or get * // dr[i] = "something"; * // string something = Convert.ToString(dr[i]); * } * } */ //Validacion en esquema de localizacion--------------------------------------------------------------------------------------------------------------- //variables necesarias para sacar datos del esquema de localizacion List <string> idFragmentos = new List <string>(); List <string> nombreTablaBDFragmento = new List <string>(); string nombreTablaGeneral = ""; string tipoFragmento = ""; List <string> sitios = new List <string>(); List <string> condicion = new List <string>(); SitioCentral st = new SitioCentral(); st.LeeEsquemaLocalizacion("Proveedor", ref idFragmentos, ref nombreTablaBDFragmento, ref nombreTablaGeneral, ref sitios, ref tipoFragmento, ref condicion); NpgsqlDataAdapter add; //codigo para hacer el select al sitio1 da = new SqlDataAdapter("Select * from " + nombreTablaBDFragmento[0] + " ORDER BY id_Proveedor DESC", cnSQL); dt = new DataTable(); da.Fill(dt); //dt.Columns.RemoveAt(0);//Para quitar el campo RFC dataGridViewProveedor.DataSource = dt; //Codigo para hacer el select from a al sitio2 add = new NpgsqlDataAdapter("select * from " + nombreTablaBDFragmento[1] + " ORDER BY id_Proveedor DESC", conNPG); //add.Fill(datos); dtNPG = new DataTable(); add.Fill(dtNPG); // dtNPG.Columns.RemoveAt(0);//para quitar el campo RFC // dt.Merge(dtNPG); //Hacer merge entre los dos select del sito1 y el sitio2 foreach (var column in dtNPG.Columns) { if (column.ToString().Contains("id"))//esto con la finalidad de corregir por q el ide copia el daato en las celdas que se llaman igual { dt.Columns.Add(column.ToString() + "2"); } else { dt.Columns.Add(column.ToString()); } } int numberOfColumns = dt.Columns.Count; int contadorRows = 0; //para esconder el campor id // dataGridViewProveedor.Columns[0].Visible = false; // dataGridViewProveedor.Columns[4].Visible = false; // go through each row int contadorPK = 0; listPrimaryKeysProveedor = new List <int>(); foreach (DataRow dr in dt.Rows) { // go through each column in the row for (int i = dtNPG.Columns.Count; i < numberOfColumns - 1; i++)//-1 por q adelante le sumo mas 1 { // access cell as set or get var dato = dtNPG.Rows[contadorRows][(i - dtNPG.Columns.Count)]; if (contadorPK == 0)//se agrega la llave primaria a la lista global para evaluar una autonumerica programada { listPrimaryKeysProveedor.Add(Convert.ToInt32(dato)); } contadorPK++; dr[i + 1] = dato;//+| para evitar q copie el idproveedor de la base de datos de npg //string something = Convert.ToString(dr[i+2]); } contadorRows++; } //dt tiene los campos del sitio1 y del sitio2 dataGridViewProveedor.DataSource = dt; //para esconder el campor id dataGridViewProveedor.Columns[0].Visible = false; dataGridViewProveedor.Columns[4].Visible = false; }