Ejemplo n.º 1
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            ArticiculoID = new Int64[listBox1.Items.Count];
            cantidad = new int[listBox1.Items.Count];
            total = new float[listBox1.Items.Count];
            cantidadexistencia = new int[listBox1.Items.Count];
            nombre = new string[listBox1.Items.Count];

            for (int cont = 0; cont < listBox1.Items.Count; cont++)
            {
                ArticiculoID[cont] = Int64.Parse(listBox1.Items[cont].ToString());
                cantidad[cont] = Int32.Parse(listBox2.Items[cont].ToString());
                total[cont] = float.Parse(listBox3.Items[cont].ToString());
                cantidadexistencia[cont] = cantidadexistenciatotal1[cont] - cantidadexistenciatotal2[cont];
                nombre[cont] = listBox4.Items[cont].ToString();
            }
            if (listBox1.Items.Count != 0)
            {
                float cambio = 0.0F;
                try
                {
                    cambio = float.Parse(textBox4.Text) - float.Parse(label18.Text);
                }
                catch
                {
                    cambio = -1;
                }
                if (cambio >= 0)
                {

                    float vtotal = 0.0F;
                    for (int i = 0; i < total.Length; i++)
                    {
                        vtotal += total[i];
                    }

                    try
                    {

                        string appPath = Path.GetDirectoryName(Application.ExecutablePath);
                        System.Data.SQLite.SQLiteConnection sqlConnection1 =
                                               new System.Data.SQLite.SQLiteConnection(@"Data Source=" + appPath + @"\DBPInc.s3db ;Version=3;");

                        System.Data.SQLite.SQLiteCommand cmd = new System.Data.SQLite.SQLiteCommand();
                        cmd.CommandType = System.Data.CommandType.Text;
                        //comando sql para insercion

                        cmd.CommandText = "INSERT INTO Ventas Values ('" + Int32.Parse(textBox1.Text) + "', '" + vtotal + "', '" + DateTime.Now.ToShortDateString() + "')";

                        cmd.Connection = sqlConnection1;

                        sqlConnection1.Open();
                        cmd.ExecuteNonQuery();

                        sqlConnection1.Close();

                        //ventas hechas
                        appPath = Path.GetDirectoryName(Application.ExecutablePath);
                        sqlConnection1 =
                                               new System.Data.SQLite.SQLiteConnection(@"Data Source=" + appPath + @"\DBPInc.s3db ;Version=3;");

                        cmd = new System.Data.SQLite.SQLiteCommand();
                        cmd.CommandType = System.Data.CommandType.Text;

                        for (int i = 0; i < ArticiculoID.Length; i++)
                        {
                            //comando sql para insercion
                            cmd.CommandText = "INSERT INTO Ventashechas Values ('" + Int32.Parse(textBox1.Text) + "', '" + ArticiculoID[i] + "', '" + nombre[i] + "', '" + cantidad[i] + "', '" + total[i] + "', '" + DateTime.Now.ToShortDateString() + "')";

                            cmd.Connection = sqlConnection1;

                            sqlConnection1.Open();
                            cmd.ExecuteNonQuery();

                            sqlConnection1.Close();

                            //comando sql para atualizar
                            cmd.CommandText = "UPDATE Almacen Set Cantidadexistencia = '" + cantidadexistencia[i] + "' Where ArticuloID = '" + ArticiculoID[i] + "'";

                            cmd.Connection = sqlConnection1;

                            sqlConnection1.Open();
                            cmd.ExecuteNonQuery();

                            sqlConnection1.Close();
                        }
                        DialogResult result = MessageBox.Show("Venta registrada exitosamente, su cambio es: $"+cambio.ToString()+" pesos , desea ver el documento de impresion?", "Impresion", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                        if (result == DialogResult.Yes)
                        {
                            Reporte reporte = new Reporte(textBox1.Text);
                            reporte.MdiParent = Sistema_Caritas.Bienvenida.ActiveForm;
                            reporte.Show();
                        }
                        textBox1.Text = (Int64.Parse(textBox1.Text) + 1).ToString();
                        textBox2.Text = "";
                        label6.Text = "";
                        label5.Text = "";
                        textBox3.Text = "";
                        label10.Text = "";
                        listBox1.Items.Clear();
                        listBox2.Items.Clear();
                        listBox3.Items.Clear();
                        listBox4.Items.Clear();
                        textBox4.Text = "";
                        label18.Text = "0";
                        ct = 0;
                        for (int i = 0; i < cantidadexistenciatotal1.Length; i++)
                        {
                            cantidadexistenciatotal1[i] = 0;
                            cantidadexistenciatotal2[i] = 0;
                        }
                    }
                    catch
                    {
                        int result;
                        bool accept = Int32.TryParse(textBox1.Text, out result);
                        if (accept == false)
                        {
                            MessageBox.Show("No ha introducido algun numero de venta o no es valido");
                        }
                        else
                        {
                            MessageBox.Show("El numero de venta ya ha sido tomado");
                        }
                    }

                }
                else
                {
                    MessageBox.Show("Cantidad a pagar insuficiente");
                }

            }
            else
            {
                MessageBox.Show("No hay ventas que registrar");
            }
        }
Ejemplo n.º 2
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            ArticiculoID       = new Int64[listBox1.Items.Count];
            cantidad           = new int[listBox1.Items.Count];
            total              = new float[listBox1.Items.Count];
            cantidadexistencia = new int[listBox1.Items.Count];
            nombre             = new string[listBox1.Items.Count];

            for (int cont = 0; cont < listBox1.Items.Count; cont++)
            {
                ArticiculoID[cont]       = Int64.Parse(listBox1.Items[cont].ToString());
                cantidad[cont]           = Int32.Parse(listBox2.Items[cont].ToString());
                total[cont]              = float.Parse(listBox3.Items[cont].ToString());
                cantidadexistencia[cont] = cantidadexistenciatotal1[cont] - cantidadexistenciatotal2[cont];
                nombre[cont]             = listBox4.Items[cont].ToString();
            }
            if (listBox1.Items.Count != 0)
            {
                float cambio = 0.0F;
                try
                {
                    cambio = float.Parse(textBox4.Text) - float.Parse(label18.Text);
                }
                catch
                {
                    cambio = -1;
                }
                if (cambio >= 0)
                {
                    float vtotal = 0.0F;
                    for (int i = 0; i < total.Length; i++)
                    {
                        vtotal += total[i];
                    }

                    try
                    {
                        string appPath = Path.GetDirectoryName(Application.ExecutablePath);
                        System.Data.SQLite.SQLiteConnection sqlConnection1 =
                            new System.Data.SQLite.SQLiteConnection(@"Data Source=" + appPath + @"\DBPInc.s3db ;Version=3;");

                        System.Data.SQLite.SQLiteCommand cmd = new System.Data.SQLite.SQLiteCommand();
                        cmd.CommandType = System.Data.CommandType.Text;
                        //comando sql para insercion

                        cmd.CommandText = "INSERT INTO Ventas Values ('" + Int32.Parse(textBox1.Text) + "', '" + vtotal + "', '" + DateTime.Now.ToShortDateString() + "')";

                        cmd.Connection = sqlConnection1;

                        sqlConnection1.Open();
                        cmd.ExecuteNonQuery();

                        sqlConnection1.Close();

                        //ventas hechas
                        appPath        = Path.GetDirectoryName(Application.ExecutablePath);
                        sqlConnection1 =
                            new System.Data.SQLite.SQLiteConnection(@"Data Source=" + appPath + @"\DBPInc.s3db ;Version=3;");

                        cmd             = new System.Data.SQLite.SQLiteCommand();
                        cmd.CommandType = System.Data.CommandType.Text;

                        for (int i = 0; i < ArticiculoID.Length; i++)
                        {
                            //comando sql para insercion
                            cmd.CommandText = "INSERT INTO Ventashechas Values ('" + Int32.Parse(textBox1.Text) + "', '" + ArticiculoID[i] + "', '" + nombre[i] + "', '" + cantidad[i] + "', '" + total[i] + "', '" + DateTime.Now.ToShortDateString() + "')";

                            cmd.Connection = sqlConnection1;

                            sqlConnection1.Open();
                            cmd.ExecuteNonQuery();

                            sqlConnection1.Close();

                            //comando sql para atualizar
                            cmd.CommandText = "UPDATE Almacen Set Cantidadexistencia = '" + cantidadexistencia[i] + "' Where ArticuloID = '" + ArticiculoID[i] + "'";

                            cmd.Connection = sqlConnection1;

                            sqlConnection1.Open();
                            cmd.ExecuteNonQuery();

                            sqlConnection1.Close();
                        }
                        DialogResult result = MessageBox.Show("Venta registrada exitosamente, su cambio es: $" + cambio.ToString() + " pesos , desea ver el documento de impresion?", "Impresion", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                        if (result == DialogResult.Yes)
                        {
                            Reporte reporte = new Reporte(textBox1.Text);
                            reporte.MdiParent = Sistema_Caritas.Bienvenida.ActiveForm;
                            reporte.Show();
                        }
                        textBox1.Text = (Int64.Parse(textBox1.Text) + 1).ToString();
                        textBox2.Text = "";
                        label6.Text   = "";
                        label5.Text   = "";
                        textBox3.Text = "";
                        label10.Text  = "";
                        listBox1.Items.Clear();
                        listBox2.Items.Clear();
                        listBox3.Items.Clear();
                        listBox4.Items.Clear();
                        textBox4.Text = "";
                        label18.Text  = "0";
                        ct            = 0;
                        for (int i = 0; i < cantidadexistenciatotal1.Length; i++)
                        {
                            cantidadexistenciatotal1[i] = 0;
                            cantidadexistenciatotal2[i] = 0;
                        }
                    }
                    catch
                    {
                        int  result;
                        bool accept = Int32.TryParse(textBox1.Text, out result);
                        if (accept == false)
                        {
                            MessageBox.Show("No ha introducido algun numero de venta o no es valido");
                        }
                        else
                        {
                            MessageBox.Show("El numero de venta ya ha sido tomado");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Cantidad a pagar insuficiente");
                }
            }
            else
            {
                MessageBox.Show("No hay ventas que registrar");
            }
        }