コード例 #1
0
        private void PopulateDataGridView(String cond)
        {
            My_SQL         mysql = new My_SQL();
            OdbcDataReader res;

            res = mysql.hazConsulta("select " + cam[0] + "," + cam[1] + "," + cam[2] + "," + cam[3] + " from clientes,acciones,detalle where clientes.curp=detalle.curp and acciones.clave=detalle.clave and clientes.curp='" + val[0] + "'");
            int   i;
            float acc, tot = 0;

            String[] row = new String[4];
            if (res.HasRows)
            {
                while (res.Read())
                {
                    for (i = 0; i < 3; i++)
                    {
                        row[i] = res.GetString(i);
                    }
                    acc    = float.Parse(res.GetString(i)) * int.Parse(row[2]);
                    tot   += acc;
                    row[3] = acc.ToString();
                    dgv.Rows.Add(row);
                }
            }
            total.Text = tot.ToString();
        }
コード例 #2
0
 private void btnEliminar_Click(object sender, EventArgs e)
 {
     if (sel >= 0)
     {
         My_SQL         mysql;
         OdbcDataReader res;
         int            nq;
         mysql = new My_SQL();
         res   = mysql.hazConsulta("select * from detalle where " + cam[0] + "='" + val[0] + "'");
         if (res.HasRows)
         {
             MessageBox.Show("El registro esta vinculado a una transaccion");
         }
         else
         {
             mysql = new My_SQL();
             nq    = mysql.hazNoConsulta("delete from " + roll + " where " + cam[0] + " = '" + val[0] + "'");
             dgv.Hide();
             SetupDataGridView();
             PopulateDataGridView("");
             actualiza();
             MessageBox.Show("Registro Borrado");
         }
     }
 }
コード例 #3
0
 private void btnAgregar_Click(object sender, EventArgs e)
 {
     if (txbCURP.Text != "" && txbNombre.Text != "" && txbSaldo.Text != "")
     {
         try
         {
             float  saldo = float.Parse(txbSaldo.Text);
             My_SQL c     = new My_SQL();
             int    nq    = c.hazNoConsulta("insert into clientes values('" + txbCURP.Text.ToUpper() + "','" + txbNombre.Text + "','" + txbSaldo.Text + "')");
             this.Close();
         }
         catch (FormatException formato)
         {
             MessageBox.Show("El saldo debe ser de tipo flotante " + formato.ToString());
         }
         catch (Exception exc)
         {
             MessageBox.Show(exc.ToString());
         }
     }
     else
     {
         MessageBox.Show("No se admiten campos vacios");
     }
 }
コード例 #4
0
 private void btnModificar_Click(object sender, EventArgs e)
 {
     if (txbClave.Text != "" && txbStock.Text != "" && txbPrecio.Text != "")
     {
         try
         {
             int    s  = int.Parse(txbStock.Text);
             float  p  = float.Parse(txbPrecio.Text);
             My_SQL a  = new My_SQL();
             int    nq = a.hazNoConsulta("update acciones set clave='" + txbClave.Text.ToUpper() + "',stock='" + txbStock.Text + "',precio='" + txbPrecio.Text + "',descripcion='" + txbDesc.Text + "' where clave='" + clave + "'");
             this.Close();
         }
         catch (FormatException formato)
         {
             MessageBox.Show("El saldo debe ser de tipo flotante " + formato.ToString());
         }
         catch (Exception exc)
         {
             MessageBox.Show(exc.ToString());
         }
     }
     else
     {
         MessageBox.Show("No se admiten campos vacios");
     }
 }
コード例 #5
0
        private void dgv_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
        {
            My_SQL         mysql;
            OdbcDataReader res;
            int            nq;

            mysql = new My_SQL();
            res   = mysql.hazConsulta("select * from detalle where " + cam[0] + "='" + val[0] + "'");
            if (res.HasRows)
            {
                MessageBox.Show("El registro esta vinculado a una transaccion");
            }
            else
            {
                mysql = new My_SQL();
                nq    = mysql.hazNoConsulta("delete from " + roll + " where " + cam[0] + " = '" + val[0] + "'");
                int row = e.RowIndex;
                if (row >= e.RowCount)
                {
                    row = e.RowCount - 1;
                }
                if (row >= 0 && e.RowCount > 1)
                {
                    DataGridView ob = (DataGridView)sender;
                    for (int i = 0; i < colums; i++)
                    {
                        val[i] = (String)ob.Rows[e.RowIndex].Cells[i].Value;
                    }
                    sel = row;
                }
                MessageBox.Show("Registro Borrado");
            }
        }
コード例 #6
0
        private void PopulateDataGridView(String cond)
        {
            My_SQL         mysql = new My_SQL();
            OdbcDataReader res;

            if (roll == "clientes" || roll == "acciones")
            {
                res = mysql.hazConsulta("select * from " + roll + "" + cond);
            }
            else
            {
                if (roll == "comprasClientes")
                {
                    res = mysql.hazConsulta("select * from clientes" + cond);
                }
                else
                {
                    if (roll == "comprasAcciones")
                    {
                        res = mysql.hazConsulta("select * from acciones" + cond);
                    }
                    else
                    {
                        res = mysql.hazConsulta("select " + cam[0] + "," + cam[1] + "," + cam[2] + "," + cam[3] + "," + cam[4] + " from clientes,acciones,detalle where clientes.curp=detalle.curp and acciones.clave=detalle.clave" + cond);
                    }
                }
            }
            int i;

            String[] row = new String[colums];
            if (res.HasRows)
            {
                while (res.Read())
                {
                    for (i = 0; i < colums; i++)
                    {
                        row[i] = res.GetString(i);
                    }
                    dgv.Rows.Add(row);
                }
            }
        }
コード例 #7
0
        private void PopulateDataGridView(String cond)
        {
            My_SQL         mysql = new My_SQL();
            OdbcDataReader res   = mysql.hazConsulta("select * from clientes" + cond);
            int            i;

            String[] row = new String[3];
            if (res.HasRows)
            {
                while (res.Read())
                {
                    for (i = 0; i < 3; i++)
                    {
                        row[i] = res.GetString(i);
                    }
                    dgv.Rows.Add(row);
                    p++;
                }
            }
        }
コード例 #8
0
        private void dgv_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
        {
            My_SQL mysql = new My_SQL();
            int    nq    = mysql.hazNoConsulta("delete from clientes where curp = '" + curp + "'");
            int    row   = e.RowIndex;

            if (row >= e.RowCount)
            {
                row = e.RowCount - 1;
            }
            if (row >= 0 && e.RowCount > 1)
            {
                DataGridView ob = (DataGridView)sender;
                curp   = (String)ob.Rows[e.RowIndex].Cells[0].Value;
                nombre = (String)ob.Rows[e.RowIndex].Cells[1].Value;
                saldo  = (String)ob.Rows[e.RowIndex].Cells[2].Value;
                sel    = row;
            }
            MessageBox.Show("Registro Borrado");
        }
コード例 #9
0
 private void btnEliminar_Click(object sender, EventArgs e)
 {
     if (sel >= 0)
     {
         My_SQL mysql = new My_SQL();
         int    nq    = mysql.hazNoConsulta("delete from clientes where curp = '" + curp + "'");
         dgv.Hide();
         SetupDataGridView();
         PopulateDataGridView("");
         if (dgv.Rows.Count > 0)
         {
             sel    = dgv.SelectedRows[0].Index;
             curp   = (String)dgv.Rows[sel].Cells[0].Value;
             nombre = (String)dgv.Rows[sel].Cells[1].Value;
             saldo  = (String)dgv.Rows[sel].Cells[2].Value;
         }
         else
         {
             sel = -1;
         }
         MessageBox.Show("Registro Borrado");
     }
 }
コード例 #10
0
        private void movimiento(int cant, String c, String a)
        {
            int            i, nq;
            My_SQL         buy;
            OdbcDataReader res;


            buy = new My_SQL();
            res = buy.hazConsulta(c);
            String[] cliente = new String[3];
            if (res.HasRows)
            {
                while (res.Read())
                {
                    for (i = 0; i < 3; i++)
                    {
                        cliente[i] = res.GetString(i);
                    }
                }
            }
            else
            {
                MessageBox.Show("El cliente" + val[0] + " dejo de existir");
                return;
            }
            buy = new My_SQL();
            res = buy.hazConsulta(a);
            String[] accion = new String[4];
            if (res.HasRows)
            {
                while (res.Read())
                {
                    for (i = 0; i < 4; i++)
                    {
                        accion[i] = res.GetString(i);
                    }
                }
            }
            else
            {
                MessageBox.Show("Las acciones" + val[2] + " dejaron de existir");
                return;
            }
            float saldo  = float.Parse(cliente[2]);
            float precio = float.Parse(accion[2]);
            int   stock  = int.Parse(accion[1]);

            if (uso == "Comprar")
            {
                if (cant * precio > saldo)
                {
                    MessageBox.Show(cliente[1] + " no tiene saldo Suficiente");
                }
                else
                {
                    if (stock < cant)
                    {
                        MessageBox.Show(accion[0] + " no tiene acciones suficientes");
                    }
                    else
                    {
                        buy = new My_SQL();
                        nq  = buy.hazNoConsulta("update clientes set saldo='" + (saldo - (precio * cant)).ToString() + "' where curp='" + cliente[0] + "'");
                        buy = new My_SQL();
                        nq  = buy.hazNoConsulta("update acciones set stock='" + (stock - cant).ToString() + "' where clave='" + accion[0] + "'");
                        buy = new My_SQL();
                        res = buy.hazConsulta("select * from detalle where curp='" + cliente[0] + "' and clave='" + accion[0] + "'");
                        String[] detalle = new String[3];
                        if (res.HasRows)
                        {
                            while (res.Read())
                            {
                                for (i = 0; i < 3; i++)
                                {
                                    detalle[i] = res.GetString(i);
                                }
                            }
                            buy = new My_SQL();
                            nq  = int.Parse(detalle[0]);
                            nq  = buy.hazNoConsulta("update detalle set cant='" + (nq + cant).ToString() + "' where curp='" + cliente[0] + "' && clave='" + accion[0] + "'");
                        }
                        else
                        {
                            buy = new My_SQL();
                            nq  = buy.hazNoConsulta("insert into detalle values('" + cant.ToString() + "','" + cliente[0] + "','" + accion[0] + "')");
                        }
                        frmGrafica reporte = new frmGrafica("Reporte", 5);
                        reporte.Show();
                        this.Close();
                    }
                }
            }
            else
            {
                nq = int.Parse(val[4]);
                if (cant > nq)
                {
                    MessageBox.Show(cliente[1] + " no tiene Acciones Suficientes");
                }
                else
                {
                    buy = new My_SQL();
                    nq  = buy.hazNoConsulta("update clientes set saldo='" + (saldo + (precio * cant)).ToString() + "' where curp='" + cliente[0] + "'");
                    buy = new My_SQL();
                    nq  = buy.hazNoConsulta("update acciones set stock='" + (stock + cant).ToString() + "' where clave='" + accion[0] + "'");
                    nq  = int.Parse(val[4]);
                    nq -= cant;
                    if (nq > 0)
                    {
                        buy = new My_SQL();
                        nq  = buy.hazNoConsulta("update detalle set cant='" + nq.ToString() + "' where curp='" + cliente[0] + "' and clave='" + accion[0] + "'");
                    }
                    else
                    {
                        buy = new My_SQL();
                        nq  = buy.hazNoConsulta("delete from detalle where curp='" + val[0] + "' and clave='" + val[2] + "'");
                    }
                    this.Close();
                }
            }
        }
コード例 #11
0
 private void btnAceptar_Click(object sender, EventArgs e)
 {
     if (uso == "Agregar" || uso == "Modificar")
     {
         if (txbCampo[0].Text != "" && txbCampo[1].Text != "" && txbCampo[2].Text != "")
         {
             if (roll == "clientes")
             {
                 try
                 {
                     float  sa = float.Parse(txbCampo[2].Text);
                     My_SQL c  = new My_SQL();
                     int    nq;
                     if (uso == "Agregar")
                     {
                         nq = c.hazNoConsulta("insert into clientes values('" + txbCampo[0].Text.ToUpper() + "','" + txbCampo[1].Text + "','" + txbCampo[2].Text + "')");
                     }
                     if (uso == "Modificar")
                     {
                         nq = c.hazNoConsulta("update clientes set curp='" + txbCampo[0].Text.ToUpper() + "',nom='" + txbCampo[1].Text + "',saldo='" + txbCampo[2].Text + "' where curp='" + val[0] + "'");
                     }
                     this.Close();
                 }
                 catch (FormatException formato1)
                 {
                     MessageBox.Show("El saldo debe ser de tipo flotante " + formato1.ToString());
                 }
                 catch (Exception exc1)
                 {
                     MessageBox.Show(exc1.ToString());
                 }
             }
             if (roll == "acciones")
             {
                 try
                 {
                     int    st = int.Parse(txbCampo[1].Text);
                     float  p  = float.Parse(txbCampo[2].Text);
                     My_SQL a  = new My_SQL();
                     int    nq;
                     if (uso == "Agregar")
                     {
                         nq = a.hazNoConsulta("insert into acciones values('" + txbCampo[0].Text.ToUpper() + "','" + txbCampo[1].Text + "','" + txbCampo[2].Text + "','" + txbCampo[3].Text + "')");
                     }
                     if (uso == "Modificar")
                     {
                         nq = a.hazNoConsulta("update acciones set clave='" + txbCampo[0].Text.ToUpper() + "',stock='" + txbCampo[1].Text + "',precio='" + txbCampo[2].Text + "',descripcion='" + txbCampo[3].Text + "' where clave='" + val[0] + "'");
                     }
                     this.Close();
                 }
                 catch (FormatException formato2)
                 {
                     MessageBox.Show("Uno de los campos contiene datos inválidos " + formato2.ToString());
                 }
                 catch (Exception exc2)
                 {
                     MessageBox.Show(exc2.ToString());
                 }
             }
         }
         else
         {
             MessageBox.Show("No se admiten campos vacios");
         }
     }
     if (uso == "Buscar")
     {
         if (txbCampo[0].Text != "")
         {
             Sval[0] = txbCampo[0].Text.ToUpper();
         }
         if (roll == "clientes" || roll == "comprasClientes")
         {
             if (txbCampo[1].Text != "")
             {
                 Sval[1] = txbCampo[1].Text;
             }
             if (txbCampo[2].Text != "")
             {
                 try
                 {
                     float s1 = float.Parse(txbCampo[2].Text);
                     Sval[2] = s1.ToString();
                 }
                 catch (FormatException formato31)
                 {
                     MessageBox.Show("El saldo debe ser de tipo flotante " + formato31.ToString());
                 }
                 catch (Exception exc31)
                 {
                     MessageBox.Show(exc31.ToString());
                 }
             }
         }
         if (roll == "acciones")
         {
             if (txbCampo[1].Text != "")
             {
                 try
                 {
                     int s1 = int.Parse(txbCampo[1].Text);
                     Sval[1] = s1.ToString();
                 }
                 catch (FormatException formato11)
                 {
                     MessageBox.Show("El stock debe ser de tipo entero " + formato11.ToString());
                 }
                 catch (Exception exc11)
                 {
                     MessageBox.Show(exc11.ToString());
                 }
             }
             if (txbCampo[2].Text != "")
             {
                 try
                 {
                     float p1 = float.Parse(txbCampo[2].Text);
                     Sval[2] = p1.ToString();
                 }
                 catch (FormatException formato21)
                 {
                     MessageBox.Show("El precio debe ser de tipo flotante " + formato21.ToString());
                 }
                 catch (Exception exc21)
                 {
                     MessageBox.Show(exc21.ToString());
                 }
             }
         }
         if (roll == "Reporte" || roll == "ventasReporte")
         {
             if (txbCampo[1].Text != "")
             {
                 Sval[1] = txbCampo[1].Text;
             }
             if (txbCampo[2].Text != "")
             {
                 Sval[2] = txbCampo[2].Text;
             }
             if (txbCampo[3].Text != "")
             {
                 try
                 {
                     int s11 = int.Parse(txbCampo[3].Text);
                     Sval[3] = s11.ToString();
                 }
                 catch (FormatException formato61)
                 {
                     MessageBox.Show("La cantidad debe ser de tipo entero " + formato61.ToString());
                 }
                 catch (Exception exc61)
                 {
                     MessageBox.Show(exc61.ToString());
                 }
             }
         }
         this.Close();
     }
     if (uso == "Comprar" || uso == "Vender")
     {
         if (txbCampo[0].Text != "")
         {
             try
             {
                 if (uso == "Comprar")
                 {
                     movimiento(int.Parse(txbCampo[0].Text), "select * from clientes where curp='" + Scurp + "'", "select * from acciones where clave='" + val[0] + "'");
                 }
                 else
                 {
                     movimiento(int.Parse(txbCampo[0].Text), "select * from clientes where curp='" + val[0] + "'", "select * from acciones where clave='" + val[2] + "'");
                 }
             }
             catch (FormatException formato41)
             {
                 MessageBox.Show("La cantidad debe ser de tipo entero " + formato41.ToString());
             }
             catch (Exception exc41)
             {
                 MessageBox.Show(exc41.ToString());
             }
         }
         else
         {
             MessageBox.Show("Debe introducir una Cantidad");
         }
     }
 }
コード例 #12
0
        public frmPrincipal()
        {
            My_SQL mys = new My_SQL();

            InitializeComponent();
        }