예제 #1
0
        private void NoExistsButton_Click(object sender, EventArgs e)
        {
            MainConn NewConObj = new MainConn();

            NoExistsButton.Enabled = false;

            for (int i = 0; i < MainGrid.Rows.Count - 1; i++)
            {
                if (int.Parse(MainGrid.Rows[i].Cells["Existencia"].Value.ToString()) == 0)
                {
                    //Delete items whit zero exists
                    NewConObj.ExecuteQuery("DELETE FROM zapateria.zapatos WHERE idZapato = "
                                           + int.Parse(MainGrid.Rows[i].Cells["idZapato"].Value.ToString()));
                }
            }
            for (int i = 0; i < this.MainGrid.Rows.Count - 1; i++)
            {
                if (int.Parse(MainGrid.Rows[i].Cells["Existencia"].Value.ToString()) == 0)
                {
                    //Delete items whit zero exists
                    NewConObj.ExecuteQuery("DELETE FROM zapateria.zapatos WHERE idZapato = "
                                           + int.Parse(MainGrid.Rows[i].Cells["idZapato"].Value.ToString()));
                }
            }
            this.StartRowsView();
            NoExistsButton.Enabled = true;
        }
예제 #2
0
        public MainForm()
        {
            this.FormBorderStyle = FormBorderStyle.FixedDialog;
            // Set the MaximizeBox to false to remove the maximize box.
            this.MaximizeBox = false;
            // Set the start position of the form to the center of the screen.
            this.StartPosition = FormStartPosition.CenterScreen;
            InitializeComponent();
            MainConn NewConObj = new MainConn();

            if (NewConObj.TestCon())
            {
                this.StartMainTable();
            }
            else
            {
                while (!NewConObj.TestCon())
                {
                    DialogResult dr = AlertGenericYesNo("Error no se encuentra la base de datos desea volver " +
                                                        "¿Desea volver a intentar conectarse?", "Error");

                    if (dr == DialogResult.Yes)
                    {
                        continue;
                    }
                    else
                    {
                        System.Environment.Exit(1);
                    }
                }

                this.StartMainTable();
            }
        }
        //-------------------------------- DELETAR CONTA ------------------------------//

        public void DeletarConta(ContaCorrente UI)
        {
            MainConn.Open();
            string     myCommand       = $@"Delete from ContaCorrente where id = {UI.Id}";
            SqlCommand myCommandDelete = new SqlCommand(myCommand, MainConn);

            myCommandDelete.ExecuteNonQuery();
            MainConn.Close();
        }
        //-------------------------------- CRIAR CONTA ------------------------------//

        public void CriarConta(ContaCorrente UI)
        {
            MainConn.Open();
            string     myCommand       = $@"Insert Into ContaCorrente (CurrentValue, MaximumLimit) values ('{UI.CurrentValue}', '{UI.MaximumLimit}')";
            SqlCommand myCommandCreate = new SqlCommand(myCommand, MainConn);

            myCommandCreate.ExecuteNonQuery();
            MainConn.Close();
        }
예제 #5
0
        protected void StartRowsView()
        {
            MainConn         NewConObj         = new MainConn();
            MySqlDataAdapter ObjAdapterZapatos = NewConObj.ExecuteQueryAndGetData("SELECT * FROM zapatosyexists");

            this.MainGrid.Visible             = true;
            this.MainGrid.AutoGenerateColumns = true;
            // 'zapatos' All Shoes whitout number of shoes , 'tallas' Table numbers of Shoes
            this.MainGrid.DataSource = NewConObj.DataMySqlToDataTable(ObjAdapterZapatos, "zapatosyexists");
            this.HideColumnsMainTable();
            this.AutoSizeColums();
        }
예제 #6
0
        private void DeleteShoe_Click(object sender, EventArgs e)
        {
            DataGridViewSelectedRowCollection selectionCol = (DataGridViewSelectedRowCollection)MainGrid.SelectedRows;
            MainConn NewConObj = new MainConn();

            string code     = string.Empty;
            int    numshoes = selectionCol.Count;

            if (selectionCol.Count == 1)
            {
                code = GetIDSelectedOneRowTableView().ToString();

                //get one items for delete one row

                DialogResult dr = AlertGenericYesNo("Desea eliminar el el zapato " +
                                                    "con el codigo: " + code + " ?", "Confirmar");
                if (dr == DialogResult.Yes)
                {
                    //delete one shoe
                    NewConObj.ExecuteQuery("DELETE FROM zapateria.zapatos WHERE idZapato = "
                                           + int.Parse(GetIDZapatoSelectedOneRowTableView().ToString()));
                    this.GenericMainGridReload();
                }
            }
            else if (selectionCol.Count > 1)
            {
                //get all items in this par for all rows and columns  and for delete

                DialogResult dr = AlertGenericYesNo("Desea eliminar los " + numshoes + " zapatos ?", "Confirmar");

                if (dr == DialogResult.Yes)
                {
                    // delete multiple shoes
                    for (int i = 0; i < selectionCol.Count; i++)
                    {
                        NewConObj.ExecuteQuery("DELETE FROM zapateria.zapatos WHERE idZapato = "
                                               + int.Parse(selectionCol[i].Cells[0].Value.ToString()));
                    }
                    this.GenericMainGridReload();
                }
            }
            else
            {
                AlertGenericOK("Ningun zapato seleccionado ", "Alerta");
            }
        }
        //-------------------------------- UPDATE CONTA ------------------------------//

        public void DebitoCredito(ContaCorrente UI, bool TipoConta)
        {
            MainConn.Open();
            if (TipoConta == false)
            {
                string     MyCommand        = $@"update ContaCorrente set CurrentValue = CurrentValue - {UI.CurrentValue} where id = {UI.Id}";
                SqlCommand myCommandUpdate1 = new SqlCommand(MyCommand, MainConn);
                myCommandUpdate1.ExecuteNonQuery();
                MainConn.Close();
            }
            if (TipoConta == true)
            {
                string     MyCommand        = $@"update ContaCorrente set MaximumLimit = MaximumLimit - {UI.CurrentValue} where id = {UI.Id}";
                SqlCommand myCommandUpdate2 = new SqlCommand(MyCommand, MainConn);
                myCommandUpdate2.ExecuteNonQuery();
                MainConn.Close();
            }
        }
        //-------------------------------- SELECT CONTA ------------------------------//

        public List <ContaCorrente> ObterContas()
        {
            List <ContaCorrente> listResult = new List <ContaCorrente>();

            MainConn.Open();
            string MyCommand = "select * from ContaCorrente";

            myCommand = new SqlCommand(MyCommand, MainConn);
            myReader  = myCommand.ExecuteReader();

            while (myReader.Read())
            {
                listResult.Add(new ContaCorrente
                {
                    Id           = (int)myReader["ID"],
                    CurrentValue = (decimal)myReader["CurrentValue"],
                    MaximumLimit = (decimal)myReader["MaximumLimit"]
                });
            }
            MainConn.Close();
            return(listResult);
        }