Esempio n. 1
0
        private void backupDatabaseToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveDb = new SaveFileDialog();
            string         path   = Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", "{374DE290-123F-4565-9164-39C4925E467B}", String.Empty).ToString();
            dbGc           db     = new dbGc();

            try
            {
                saveDb.Filter           = "bak files (*.bak)|*.bak|All files (*.*)|*.*";
                saveDb.InitialDirectory = path;
                saveDb.RestoreDirectory = true;
                saveDb.DefaultExt       = "bak";
                if (saveDb.ShowDialog() == DialogResult.OK)
                {
                    db.backupDb(saveDb.FileName);
                    notification notification = new notification("Database backup completed.", notification.AlertType.success);
                    notification.ShowDialog();
                }
            }
            catch (Exception a)
            {
                notification notification = new notification("Database backup error.", notification.AlertType.error);
                notification.ShowDialog();
                return;
            }
        }
Esempio n. 2
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (txtSuppName.Text != "" && txtContact.Text != "")
            {
                StringBuilder param  = new StringBuilder();
                StringBuilder values = new StringBuilder();
                StringBuilder where = new StringBuilder();

                param.Append(
                    "gc_supp_name," +
                    "gc_supp_add," +
                    "gc_contact," +
                    "gc_email," +
                    "gc_other_info"
                    );

                values.Append(
                    txtSuppName.Text + "," +
                    txtAddress.Text + "," +
                    txtContact.Text + "," +
                    txtEmail.Text + "," +
                    txtOtherInfo.Text
                    );

                where.Append("gc_supp_name='" + suppName + "'");
                db.GCUpdateDb("suppliers", param, values, where);
                notification = new notification("Supplier has been updated.", notification.AlertType.success);
                notification.ShowDialog();
            }
            else
            {
                notification = new notification("Error updating, Please check the fields.", notification.AlertType.success);
                notification.ShowDialog();
            }
        }
Esempio n. 3
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            StringBuilder param  = new StringBuilder();
            StringBuilder values = new StringBuilder();

            StringBuilder where = new StringBuilder();

            param.Append(
                "gc_item_name," +
                "gc_item_supp," +
                "gc_item_brand," +
                "gc_item_status," +
                "gc_delivery_date," +
                "gc_item_cost," +
                "gc_item_srp," +
                "gc_item_qty," +
                "gc_item_code," +
                "gc_item_type," +
                "gc_item_desc," +
                "gc_item_um"
                );

            values.Append(
                deliveryInfoPage.txtItemName.Text + "," +
                deliveryInfoPage.cmbSupp.Text + "," +
                deliveryInfoPage.txtBrand.Text + "," +
                deliveryInfoPage.cmbItemStatus.Text + "," +
                deliveryInfoPage.dtDeliveryDate.Value + "," +
                float.Parse(deliveryInfoPage.txtCost.Text) + "," +
                float.Parse(deliveryInfoPage.txtSrp.Text) + "," +
                int.Parse(deliveryInfoPage.txtQty.Text) + "," +
                deliveryInfoPage.txtItemCode.Text + "," +
                deliveryInfoPage.cmbItemType.Text + "," +
                deliveryInfoPage.txtDesc.Text + "," +
                deliveryInfoPage.txtUm.Text
                );

            where.Append("gc_item_name='" + deliveryInfoPage.itemName + "'");
            //where.Append("gc_item_brand='"+deliveryInfoPage.itemBrand+"'");
            //where.Append("gc_item_supp='"+deliveryInfoPage.itemSupp+"'");

            db.GCUpdateDb("delivery", param, values, where);

            DataTable dt = db.GCSelectFromDb("delivery", null, null);

            dgDelivery.DataSource = null;
            dgDelivery.DataSource = dt;

            notification = new notification("Changes has been saved.", notification.AlertType.success);
            notification.ShowDialog();

            deliveryInfoPage.Close();

            deliveryInfoPage.btnSave.Click -= BtnSave_Click;
        }
Esempio n. 4
0
        private void dgUsers_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridView senderGrid = (DataGridView)sender;

            if (e.ColumnIndex == 6)
            {
                editPage.txtFullName.Text  = senderGrid.Rows[e.RowIndex].Cells[0].Value.ToString();
                editPage.txtUsername.Text  = senderGrid.Rows[e.RowIndex].Cells[1].Value.ToString();
                editPage.txtPass.Text      = senderGrid.Rows[e.RowIndex].Cells[2].Value.ToString();
                editPage.txtEmail.Text     = senderGrid.Rows[e.RowIndex].Cells[3].Value.ToString();
                editPage.txtContact.Text   = senderGrid.Rows[e.RowIndex].Cells[4].Value.ToString();
                editPage.txtOtherInfo.Text = senderGrid.Rows[e.RowIndex].Cells[5].Value.ToString();

                editPage.lblFullName.Text = senderGrid.Rows[e.RowIndex].Cells[0].Value.ToString();
                editPage.lblUserName.Text = senderGrid.Rows[e.RowIndex].Cells[1].Value.ToString();
                editPage.lblEmail.Text    = senderGrid.Rows[e.RowIndex].Cells[3].Value.ToString();
                editPage.lblContact.Text  = senderGrid.Rows[e.RowIndex].Cells[4].Value.ToString();

                uname = senderGrid.Rows[e.RowIndex].Cells[1].Value.ToString();
                pword = senderGrid.Rows[e.RowIndex].Cells[2].Value.ToString();

                editPage.btnUpdate.Click += BtnUpdate_Click;

                editPage.ShowDialog();
            }
            else if (e.ColumnIndex == 7)
            {
                uname = senderGrid.Rows[e.RowIndex].Cells[1].Value.ToString();
                pword = senderGrid.Rows[e.RowIndex].Cells[2].Value.ToString();
                StringBuilder whereDel = new StringBuilder();
                StringBuilder valDel   = new StringBuilder();

                whereDel.Append("username,password");
                valDel.Append(uname + "," + pword);

                DialogResult delRes = MessageBox.Show("Are you sure you want to delete this record?", "Delete record?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (delRes == DialogResult.Yes)
                {
                    db.GCDeleteFromDb("users", valDel, whereDel);

                    DataTable dt = db.GCSelectFromDb("users", null, null);
                    dgUsers.DataSource = null;
                    dgUsers.DataSource = dt;

                    editPage.btnUpdate.Click -= BtnUpdate_Click;

                    notification = new notification("Successfully updated deleted Record.", notification.AlertType.success);
                    notification.ShowDialog();
                }
            }
        }
Esempio n. 5
0
        private void btnAddDeliver_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtItemName.Text != "")
                {
                    StringBuilder param  = new StringBuilder();
                    StringBuilder values = new StringBuilder();
                    param.Append(
                        "gc_item_name," +
                        "gc_item_supp," +
                        "gc_item_brand," +
                        "gc_item_status," +
                        "gc_order_terms," +
                        "gc_delivery_date," +
                        "gc_item_cost," +
                        "gc_total_price," +
                        "gc_item_qty"
                        );

                    values.Append(
                        txtItemName.Text + "," +
                        cmbSupp.Text + "," +
                        txtBrand.Text + "," +
                        "not delivered" + "," +
                        int.Parse(txtOrderTerms.Text) + "," +
                        dtDeliveryDate.Value.ToShortDateString() + "," +
                        float.Parse(txtItemPrice.Text) + "," +
                        int.Parse(txtQty.Text) * float.Parse(txtItemPrice.Text) + "," +
                        int.Parse(txtQty.Text)
                        );
                    delivery.saveDelivery(param, values);
                    dgDelivery.DataSource = null;
                    DataTable dt = db.GCSelectFromDb("delivery", null, null);
                    dgDelivery.DataSource = dt;

                    notification = new notification("Delivery of items is saved.", notification.AlertType.success);
                    notification.ShowDialog();
                }
                else
                {
                    notification = new notification("Error. Check fields before saving.", notification.AlertType.error);
                    notification.ShowDialog();
                }
            }
            catch (Exception a)
            {
                notification = new notification("Error. Check fields before saving.", notification.AlertType.error);
                notification.ShowDialog();
            }
        }
Esempio n. 6
0
        private void dgProducts_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridView senderGrid = (DataGridView)sender;

            if (e.ColumnIndex == 10)
            {
                editItemPage.itemCode         = senderGrid.Rows[e.RowIndex].Cells[1].Value.ToString();
                editItemPage.txtItemName.Text = senderGrid.Rows[e.RowIndex].Cells[0].Value.ToString();
                editItemPage.txtItemCode.Text = senderGrid.Rows[e.RowIndex].Cells[1].Value.ToString();
                editItemPage.txtUm.Text       = senderGrid.Rows[e.RowIndex].Cells[2].Value.ToString();
                editItemPage.txtDesc.Text     = senderGrid.Rows[e.RowIndex].Cells[3].Value.ToString();
                editItemPage.cmbSupp.Text     = senderGrid.Rows[e.RowIndex].Cells[4].Value.ToString();
                editItemPage.txtBrand.Text    = senderGrid.Rows[e.RowIndex].Cells[5].Value.ToString();
                editItemPage.txtCost.Text     = senderGrid.Rows[e.RowIndex].Cells[6].Value.ToString();
                editItemPage.txtSrp.Text      = senderGrid.Rows[e.RowIndex].Cells[7].Value.ToString();
                editItemPage.cmbItemType.Text = senderGrid.Rows[e.RowIndex].Cells[8].Value.ToString();

                editItemPage.btnSave.Click += BtnSave_Click;

                editItemPage.ShowDialog();
            }
            else if (e.ColumnIndex == 11)
            {
                StringBuilder whereDelProd  = new StringBuilder();
                StringBuilder valuesDelProd = new StringBuilder();

                StringBuilder whereDelInv  = new StringBuilder();
                StringBuilder valuesDelInv = new StringBuilder();

                DialogResult delRes = MessageBox.Show("Are you sure you want to delete this Product?", "Delete Product?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (delRes == DialogResult.Yes)
                {
                    whereDelProd.Append("gc_item_code");
                    valuesDelProd.Append(senderGrid.Rows[e.RowIndex].Cells[1].Value.ToString());

                    whereDelInv.Append("gc_item_code");
                    valuesDelInv.Append(senderGrid.Rows[e.RowIndex].Cells[1].Value.ToString());

                    db.GCDeleteFromDb("inventory", valuesDelInv, whereDelInv);
                    db.GCDeleteFromDb("products", valuesDelProd, whereDelProd);

                    notification = new notification("Product has been deleted.", notification.AlertType.success);
                    notification.ShowDialog();
                    DataTable dt = db.GCSelectFromDb("products", null, null, "ORDER BY id DESC");
                    dgProducts.DataSource = null;
                    dgProducts.DataSource = dt;
                }
            }
        }
Esempio n. 7
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            StringBuilder where = new StringBuilder();
            where.Append("username='******' AND password='******'");
            int resUser = db.searchData("users", null, where);

            if (resUser >= 1)
            {
                notification notification = new notification("Username or password already existing.", notification.AlertType.error);
                notification.ShowDialog();
            }
            else if (txtUsername.Text != "" && txtPassword.Text != "" && txtFullName.Text != "")
            {
                StringBuilder param  = new StringBuilder();
                StringBuilder values = new StringBuilder();

                param.Append(
                    "username," +
                    "password," +
                    "email," +
                    "contact," +
                    "other_info," +
                    "full_name"
                    );

                values.Append(
                    txtUsername.Text + "," +
                    txtPassword.Text + "," +
                    txtEmail.Text + "," +
                    txtContact.Text + "," +
                    txtOtherInfo.Text + "," +
                    txtFullName.Text
                    );

                db.GCInsertToDb("users", param, values);
                notification notification = new notification("User has been saved to the database.", notification.AlertType.success);
                notification.Show();

                DataTable dt = db.GCSelectFromDb("users", null, null);
                dgUsers.DataSource = null;
                dgUsers.DataSource = dt;
            }
            else
            {
                notification notification = new notification("Check the fields before saving.", notification.AlertType.error);
                notification.Show();
            }
        }
Esempio n. 8
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtSuppName.Text != "" && txtContact.Text != "")
            {
                StringBuilder whereSearch = new StringBuilder();
                whereSearch.Append("gc_supp_name LIKE '" + txtSuppName.Text + "'");
                int resSupp = db.searchData("suppliers", null, whereSearch);

                if (resSupp >= 1)
                {
                    notification = new notification("Supplier already existing.", notification.AlertType.error);
                    notification.ShowDialog();
                }
                else
                {
                    StringBuilder param  = new StringBuilder();
                    StringBuilder values = new StringBuilder();

                    param.Append(
                        "gc_supp_name," +
                        "gc_supp_add," +
                        "gc_contact," +
                        "gc_email," +
                        "gc_other_info"
                        );

                    values.Append(
                        txtSuppName.Text + "," +
                        txtAddress.Text + "," +
                        txtContact.Text + "," +
                        txtEmail.Text + "," +
                        txtOtherInfo.Text
                        );

                    db.GCInsertToDb("suppliers", param, values);

                    DataTable dt = db.GCSelectFromDb("suppliers", null, null);
                    dgSuppliers.DataSource = null;
                    dgSuppliers.DataSource = dt;

                    notification = new notification("Supplier saved to the database.", notification.AlertType.success);
                    notification.ShowDialog();
                }
            }
        }
Esempio n. 9
0
 private void progressTimer_Tick(object sender, EventArgs e)
 {
     if (pBar.Value <= 99)
     {
         pBar.Value      = counter;
         lblPercent.Text = counter.ToString() + "%";
     }
     else
     {
         progressTimer.Stop();
         this.Hide();
         main = new Inventory_Main();
         main.Show();
         notification notification = new notification("Welcome Admin!", notification.AlertType.info);
         notification.ShowDialog();
     }
     counter++;
 }
Esempio n. 10
0
        private void BtnUpdate_Click(object sender, EventArgs e)
        {
            StringBuilder param  = new StringBuilder();
            StringBuilder values = new StringBuilder();

            StringBuilder where = new StringBuilder();

            param.Append("username,password,email,contact,other_info,full_name");
            values.Append(
                editPage.txtUsername.Text + "," +
                editPage.txtPass.Text + "," +
                editPage.txtEmail.Text + "," +
                editPage.txtContact.Text + "," +
                editPage.txtOtherInfo.Text + "," +
                editPage.txtFullName.Text
                );

            where.Append("username='******' AND password='******'");

            if (editPage.txtFullName.Text != "" && editPage.txtUsername.Text != "" && editPage.txtPass.Text != "")
            {
                db.GCUpdateDb("users", param, values, where);

                DataTable dt = db.GCSelectFromDb("users", null, null);
                dgUsers.DataSource = null;
                dgUsers.DataSource = dt;

                editPage.btnUpdate.Click -= BtnUpdate_Click;

                notification = new notification("Successfully updated fields.", notification.AlertType.success);
                notification.ShowDialog();
            }
            else
            {
                editPage.btnUpdate.Click -= BtnUpdate_Click;
                notification              = new notification("Error updating. Please check fields.", notification.AlertType.error);
                notification.ShowDialog();
            }

            editPage.Close();
        }
Esempio n. 11
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            DataTable dtSave = db.GCSelectFromDb("inventory", null, null, "ORDER BY id DESC");

            dgStock.DataSource = null;
            dgStock.DataSource = dtSave;
            foreach (DataGridViewRow row in dgStock.Rows)
            {
                if (row.Cells[0].Value != null)
                {
                    if (int.Parse(row.Cells[2].Value.ToString()) <= 5)
                    {
                        row.DefaultCellStyle.BackColor = Color.Maroon;
                        row.DefaultCellStyle.ForeColor = Color.White;
                    }
                }
            }
            inventoryInfoPage.btnSave.Click -= BtnSave_Click;
            notification = new notification("Product has been updated.", notification.AlertType.success);
            notification.ShowDialog();
            inventoryInfoPage.Close();
        }
Esempio n. 12
0
        private void dgSuppliers_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridView senderGrid = (DataGridView)sender;

            if (e.ColumnIndex == 5)
            {
                editSuppPage.txtSuppName.Text  = senderGrid.Rows[e.RowIndex].Cells[0].Value.ToString();
                editSuppPage.txtAddress.Text   = senderGrid.Rows[e.RowIndex].Cells[1].Value.ToString();
                editSuppPage.txtContact.Text   = senderGrid.Rows[e.RowIndex].Cells[2].Value.ToString();
                editSuppPage.txtEmail.Text     = senderGrid.Rows[e.RowIndex].Cells[3].Value.ToString();
                editSuppPage.txtOtherInfo.Text = senderGrid.Rows[e.RowIndex].Cells[4].Value.ToString();

                editSuppPage.suppName = senderGrid.Rows[e.RowIndex].Cells[0].Value.ToString();

                editSuppPage.btnUpdate.Click += BtnUpdate_Click;

                editSuppPage.ShowDialog();
            }
            else if (e.ColumnIndex == 6)
            {
                StringBuilder whereDelSupp  = new StringBuilder();
                StringBuilder valuesDelSupp = new StringBuilder();
                DialogResult  delRes        = MessageBox.Show("Are you sure you want to delete this supplier?", "Delete Supplier?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (delRes == DialogResult.Yes)
                {
                    whereDelSupp.Append("gc_supp_name");
                    valuesDelSupp.Append(senderGrid.Rows[e.RowIndex].Cells[0].Value.ToString());
                    db.GCDeleteFromDb("suppliers", valuesDelSupp, whereDelSupp);

                    notification = new notification("Supplier has been deleted.", notification.AlertType.success);
                    notification.ShowDialog();
                    DataTable dt = db.GCSelectFromDb("suppliers", null, null);
                    dgSuppliers.DataSource = null;
                    dgSuppliers.DataSource = dt;
                }
            }
        }
Esempio n. 13
0
        private void BtnAddQty_Click(object sender, EventArgs e)
        {
            try
            {
                StringBuilder paramInv    = new StringBuilder();
                StringBuilder whereInv    = new StringBuilder();
                StringBuilder whereSearch = new StringBuilder();

                whereSearch.Append("gc_item_code='" + itemCode + "'");
                int resItemCode = db.searchData("stock", null, whereSearch);

                paramInv.Append("gc_item_qty");
                whereInv.Append("gc_item_code='" + itemCode + "'");

                DataTable dtInv = db.GCSelectFromDb("inventory", paramInv, whereInv);
                foreach (DataRow rowInv in dtInv.Rows)
                {
                    currInventory = int.Parse(rowInv[0].ToString());
                }

                if (currInventory >= int.Parse(invQtyPage.txtQty.Text))
                {
                    StringBuilder param = new StringBuilder();
                    StringBuilder where = new StringBuilder();

                    param.Append("gc_item_qty");
                    where.Append("gc_item_code='" + itemCode + "'");

                    DataTable dt = db.GCSelectFromDb("stock", param, where);
                    foreach (DataRow row in dt.Rows)
                    {
                        currStock = int.Parse(row[0].ToString());
                    }

                    if (resItemCode == 1)
                    {
                        StringBuilder paramUpdate  = new StringBuilder();
                        StringBuilder valuesUpdate = new StringBuilder();
                        StringBuilder whereUpdate  = new StringBuilder();

                        whereUpdate.Append("gc_item_code='" + itemCode + "'");
                        paramUpdate.Append("gc_item_qty");
                        valuesUpdate.Append(currStock + int.Parse(invQtyPage.txtQty.Text));
                        db.GCUpdateDb("stock", paramUpdate, valuesUpdate, whereUpdate);
                        notification = new notification("Stock has been updated", notification.AlertType.success);
                        notification.ShowDialog();
                        invQtyPage.btnAddQty.Click -= BtnAddQty_Click;
                    }
                    else
                    {
                        StringBuilder paramInsert  = new StringBuilder();
                        StringBuilder valuesInsert = new StringBuilder();

                        paramInsert.Append(
                            "gc_item_name," +
                            "gc_item_qty," +
                            "gc_item_desc," +
                            "gc_item_supp," +
                            "gc_item_brand," +
                            "gc_item_um," +
                            "gc_item_cost," +
                            "gc_item_srp," +
                            "gc_date_added," +
                            "gc_item_code," +
                            "gc_item_type"
                            );

                        valuesInsert.Append(
                            itemName + "," +
                            int.Parse(invQtyPage.txtQty.Text) + "," +
                            itemDesc + "," +
                            itemSupp + "," +
                            itemBrand + "," +
                            itemUm + "," +
                            itemCost + "," +
                            itemSrp + "," +
                            DateTime.Today.ToString("MM/dd/yyyy") + "," +
                            itemCode + "," +
                            itemType
                            );
                        db.GCInsertToDb("stock", paramInsert, valuesInsert);
                        notification = new notification("Item has been added to stock!", notification.AlertType.success);
                        notification.ShowDialog();
                        invQtyPage.btnAddQty.Click -= BtnAddQty_Click;
                    }

                    updateTrans("stock", itemCode, "in", int.Parse(invQtyPage.txtQty.Text), currStock, itemName);

                    StringBuilder paramUpdateInv = new StringBuilder();
                    StringBuilder valuesUpdteInv = new StringBuilder();
                    StringBuilder whereUpdateInv = new StringBuilder();

                    whereUpdateInv.Append("gc_item_code='" + itemCode + "'");
                    paramUpdateInv.Append("gc_item_qty");

                    valuesUpdteInv.Append(currInventory - int.Parse(invQtyPage.txtQty.Text));
                    db.GCUpdateDb("inventory", paramUpdateInv, valuesUpdteInv, whereUpdateInv);
                    updateTrans("inventory", itemCode, "out", int.Parse(invQtyPage.txtQty.Text), currInventory, itemName);


                    dgStock.DataSource = null;

                    DataTable dtRefresh = db.GCSelectFromDb("inventory", null, null, "ORDER BY id DESC");
                    dgStock.DataSource          = dtRefresh;
                    invQtyPage.btnAddQty.Click -= BtnAddQty_Click;
                }
                else
                {
                    MessageBox.Show("Not enough item on inventory", "Inventory Dont have enought Item", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                    invQtyPage.btnAddQty.Click -= BtnAddQty_Click;
                }
            }
            catch (Exception a)
            {
                MessageBox.Show(a.Message);
                invQtyPage.btnAddQty.Click -= BtnAddQty_Click;
            }

            invQtyPage.btnAddQty.Click -= BtnAddQty_Click;
            dgStock.Refresh();
            invQtyPage.Close();
        }
Esempio n. 14
0
        private void BtnAddQty_Click(object sender, EventArgs e)
        {
            StringBuilder paramStock  = new StringBuilder();
            StringBuilder whereStock  = new StringBuilder();
            StringBuilder valuesStock = new StringBuilder();

            StringBuilder paramInv = new StringBuilder();
            StringBuilder whereInv = new StringBuilder();

            paramInv.Append("gc_item_qty");
            whereInv.Append("gc_item_code='" + itemCode + "'");
            DataTable dtInv = db.GCSelectFromDb("inventory", paramInv, whereInv);

            foreach (DataRow row in dtInv.Rows)
            {
                currInventory = int.Parse(row[0].ToString());
            }

            foreach (DataGridViewRow row in dgStock.Rows)
            {
                if (row.Cells[0].Value != null)
                {
                    if (int.Parse(row.Cells[2].Value.ToString()) <= 5)
                    {
                        row.DefaultCellStyle.BackColor = Color.Maroon;
                        row.DefaultCellStyle.ForeColor = Color.White;
                    }
                }
            }

            if (currInventory >= int.Parse(stockAddPage.txtQty.Text))
            {
                paramStock.Append("gc_item_qty");
                valuesStock.Append(qty + int.Parse(stockAddPage.txtQty.Text));
                whereStock.Append("gc_item_code='" + itemCode + "'");

                db.GCUpdateDb("stock", paramStock, valuesStock, whereStock);

                StringBuilder paramUpdateInv  = new StringBuilder();
                StringBuilder valuesUpdateInv = new StringBuilder();
                StringBuilder whereUpdateInv  = new StringBuilder();

                paramUpdateInv.Append("gc_item_qty");
                valuesUpdateInv.Append(currInventory - int.Parse(stockAddPage.txtQty.Text));
                whereUpdateInv.Append("gc_item_code='" + itemCode + "'");

                db.GCUpdateDb("inventory", paramUpdateInv, valuesUpdateInv, whereUpdateInv);

                updateTrans("stock", itemCode, "in", int.Parse(stockAddPage.txtQty.Text), qty, itemName);
                updateTrans("inventory", itemCode, "out", int.Parse(stockAddPage.txtQty.Text), currInventory, itemName);

                notification = new notification("Stock has been updated.", notification.AlertType.success);
                notification.ShowDialog();

                dgStock.DataSource = null;
                DataTable dt = db.GCSelectFromDb("stock", null, null, "ORDER BY id DESC");
                dgStock.DataSource = dt;
                stockAddPage.Close();
            }
            else
            {
                notification = new notification("Not enough item on inventory.", notification.AlertType.error);
                notification.ShowDialog();
            }
        }
        private void dgTransHistory_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridView senderGrid = (DataGridView)sender;

            if (e.ColumnIndex == 7)
            {
                StringBuilder where = new StringBuilder();
                StringBuilder param = new StringBuilder();

                param.Append(
                    "gc_item_name," +
                    "gc_item_code," +
                    "gc_item_qty," +
                    "gc_item_srp," +
                    "gc_item_cost," +
                    "gc_um," +
                    "gc_item_desc," +
                    "gc_curr_qty," +
                    "gc_cust_cash," +
                    "gc_cust_change," +
                    "gc_customer_name," +
                    "gc_customer_add," +
                    "gc_unique_id"
                    );

                where.Append(
                    "gc_unique_id='" + senderGrid.Rows[e.RowIndex].Cells[0].Value.ToString() + "' " +
                    "AND gc_customer_name='" + senderGrid.Rows[e.RowIndex].Cells[1].Value.ToString() + "'"
                    );

                DataTable dt = db.GCSelectFromDb("transact", param, where);
                transPage.lvCart.Items.Clear();
                foreach (DataRow row in dt.Rows)
                {
                    items[0] = row[0].ToString();
                    items[1] = row[1].ToString();
                    items[2] = row[2].ToString();
                    items[3] = row[3].ToString();
                    items[4] = row[4].ToString();
                    items[5] = row[5].ToString();
                    items[6] = row[6].ToString();
                    items[7] = row[7].ToString();
                    transPage.txtCustomerName.Text = row[10].ToString();
                    transPage.txtAddress.Text      = row[11].ToString();
                    transPage.txtCash.Text         = row[8].ToString();
                    transID = row[12].ToString();
                    ListViewItem lvi = new ListViewItem(items);
                    transPage.lvCart.Items.Add(lvi);
                }
                //transPage.lblTotal.Text = row[12].ToString();

                transPage.btnSaveTrans.Text = "Update Transaction";
                transPage.SaveMode          = false;

                totalPrice = 0;

                foreach (ListViewItem lviTotal in transPage.lvCart.Items)
                {
                    totalPrice += float.Parse(lviTotal.SubItems[3].Text) * float.Parse(lviTotal.SubItems[2].Text);
                }

                transPage.lblTotal.Text = totalPrice.ToString();

                transPage.btnSaveTrans.Click += BtnSaveTrans_Click;

                transPage.ShowDialog();
            }
            else if (e.ColumnIndex == 8)
            {
                receiptPage.transID = senderGrid.Rows[e.RowIndex].Cells[0].Value.ToString();
                receiptPage.ShowDialog();
            }
            else if (e.ColumnIndex == 9)
            {
                DialogResult delTransHist = MessageBox.Show("Are you sure you want to delete this purchase history?", "Delete purchased History?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (delTransHist == DialogResult.Yes)
                {
                    StringBuilder whereDelHist  = new StringBuilder();
                    StringBuilder valuesDelHist = new StringBuilder();
                    StringBuilder whereHist     = new StringBuilder();
                    StringBuilder paramHist     = new StringBuilder();

                    paramHist.Append("DISTINCT gc_unique_id,gc_customer_name,gc_customer_add,gc_trans_date,gc_cust_cash,gc_cust_change");
                    whereHist.Append("gc_from_tbl='sales'");

                    whereDelHist.Append("gc_unique_id,gc_customer_name");
                    valuesDelHist.Append(
                        senderGrid.Rows[e.RowIndex].Cells[0].Value.ToString() + "," +
                        senderGrid.Rows[e.RowIndex].Cells[1].Value.ToString()
                        );
                    db.GCDeleteFromDb("transact", valuesDelHist, whereDelHist);

                    dgTransHistory.DataSource = null;
                    DataTable dtDelHist = db.GCSelectFromDb("transact", paramHist, whereHist);
                    dgTransHistory.DataSource = dtDelHist;

                    notification = new notification("Purchased history deleted", notification.AlertType.error);
                    notification.ShowDialog();
                }
            }
        }
        private void BtnSaveTrans_Click(object sender, EventArgs e)
        {
            if (float.Parse(transPage.lblTotal.Text) > float.Parse(transPage.txtCash.Text))
            {
                notification = new notification("Cash is not enough to make transaction.", notification.AlertType.error);
                notification.ShowDialog();
                return;
            }

            StringBuilder whereTransUpdate  = new StringBuilder();
            StringBuilder paramTransUpdate  = new StringBuilder();
            StringBuilder valuesTransUpdate = new StringBuilder();

            foreach (ListViewItem lvi in transPage.lvCart.Items)
            {
                StringBuilder whereRes = new StringBuilder();
                StringBuilder whereDel = new StringBuilder();

                whereRes.Append("gc_item_code='" + lvi.SubItems[1].Text + "' AND gc_unique_id='" + transID + "'");
                int result = db.searchData("transact", null, whereRes);
                if (result == 0)
                {
                    StringBuilder values = new StringBuilder();

                    StringBuilder paramUpdate  = new StringBuilder();
                    StringBuilder valuesUpdate = new StringBuilder();
                    StringBuilder whereUpdate  = new StringBuilder();

                    values.Append(
                        "Sales," +
                        "out," +
                        lvi.SubItems[2].Text + "," +
                        itemQty + "," +
                        DateTime.Now.ToString("MM/dd/yyyy") + "," +
                        transID + "," +
                        lvi.SubItems[1].Text + "," +
                        transPage.txtCustomerName.Text + "," +
                        transPage.txtAddress.Text + "," +
                        lvi.SubItems[5].Text + "," +
                        lvi.SubItems[6].Text + "," +
                        lvi.Text + "," +
                        float.Parse(lvi.SubItems[3].Text) * float.Parse(lvi.SubItems[2].Text) + "," +
                        float.Parse(lvi.SubItems[4].Text) + "," +
                        float.Parse(lvi.SubItems[3].Text) + "," +
                        float.Parse(transPage.txtCash.Text) + "," +
                        (float.Parse(transPage.txtCash.Text) - totalPrice) + "," +
                        float.Parse(lvi.SubItems[4].Text) * float.Parse(lvi.SubItems[2].Text)
                        );

                    paramUpdate.Append("gc_item_qty");
                    valuesUpdate.Append(int.Parse(lvi.SubItems[7].Text) - int.Parse(lvi.SubItems[2].Text));
                    whereUpdate.Append("gc_item_code='" + lvi.SubItems[1].Text + "'");

                    db.GCUpdateDb("stock", paramUpdate, valuesUpdate, whereUpdate);
                    transaction.insertToTrans(values);
                }

                whereDel.Append("gc_unique_id='" + transID + "'");
                DataTable dt = db.GCSelectFromDb("transact", null, whereDel);
                foreach (DataRow row in dt.Rows)
                {
                    var resItem = transPage.lvCart.FindItemWithText(row[7].ToString(), true, 0);
                    if (resItem == null)
                    {
                        StringBuilder whereDelItem = new StringBuilder();
                        StringBuilder valueDelItem = new StringBuilder();

                        StringBuilder paramStockUpdate  = new StringBuilder();
                        StringBuilder valuesStockUpdate = new StringBuilder();
                        StringBuilder whereStockUpdate  = new StringBuilder();

                        StringBuilder paramStock = new StringBuilder();
                        StringBuilder whereStock = new StringBuilder();

                        paramStock.Append("gc_item_qty");
                        whereStock.Append("gc_item_code='" + row[7].ToString() + "'");
                        DataTable dtQty = db.GCSelectFromDb("stock", paramStock, whereStock);

                        foreach (DataRow dtQtyRow in dtQty.Rows)
                        {
                            currStockQty = int.Parse(dtQtyRow[0].ToString());
                        }

                        whereDelItem.Append("gc_item_code,gc_unique_id");
                        valueDelItem.Append(row[7].ToString() + "," + row[6].ToString());
                        db.GCDeleteFromDb("transact", valueDelItem, whereDelItem);

                        paramStockUpdate.Append("gc_item_qty");
                        whereStockUpdate.Append("gc_item_code='" + row[7].ToString() + "'");
                        valuesStockUpdate.Append(currStockQty + int.Parse(row[3].ToString()));
                        db.GCUpdateDb("stock", paramStockUpdate, valuesStockUpdate, whereStockUpdate);

                        DataTable dtStock = db.GCSelectFromDb("stock", null, null);
                        transPage.dgStock.DataSource = null;
                        transPage.dgStock.DataSource = dtStock;
                    }
                    else if (resItem != null)
                    {
                        StringBuilder wheretSelStock = new StringBuilder();
                        StringBuilder paramSelStock  = new StringBuilder();

                        paramSelStock.Append("gc_item_qty");
                        wheretSelStock.Append("gc_item_code='" + lvi.SubItems[1].Text + "' AND gc_unique_id='" + transID + "'");
                        DataTable dtSelectStock = db.GCSelectFromDb("transact", paramSelStock, wheretSelStock);

                        foreach (DataRow rowQty in dtSelectStock.Rows)
                        {
                            StringBuilder paramUpdateStock  = new StringBuilder();
                            StringBuilder whereUpdateStock  = new StringBuilder();
                            StringBuilder valuesUpdateStock = new StringBuilder();

                            StringBuilder whereSelItem = new StringBuilder();
                            StringBuilder paramSelItem = new StringBuilder();

                            paramSelItem.Append("gc_item_qty");
                            whereSelItem.Append("gc_item_code='" + lvi.SubItems[1].Text + "'");

                            DataTable dtSelItem = db.GCSelectFromDb("stock", paramSelItem, whereSelItem);

                            foreach (DataRow rowSelItem in dtSelItem.Rows)
                            {
                                currStock = int.Parse(rowSelItem[0].ToString());
                            }

                            paramUpdateStock.Append("gc_item_qty");
                            whereUpdateStock.Append("gc_item_code='" + lvi.SubItems[1].Text + "'");

                            if (int.Parse(rowQty[0].ToString()) < int.Parse(lvi.SubItems[2].Text))
                            {
                                addedQty = int.Parse(lvi.SubItems[2].Text) - int.Parse(rowQty[0].ToString());
                                valuesUpdateStock.Append(currStock - addedQty);
                                db.GCUpdateDb("stock", paramUpdateStock, valuesUpdateStock, whereUpdateStock);
                            }
                            else if (int.Parse(rowQty[0].ToString()) > int.Parse(lvi.SubItems[2].Text))
                            {
                                addedQty = int.Parse(rowQty[0].ToString()) - int.Parse(lvi.SubItems[2].Text);
                                valuesUpdateStock.Append(currStock + addedQty);
                                db.GCUpdateDb("stock", paramUpdateStock, valuesUpdateStock, whereUpdateStock);
                            }
                        }

                        whereTransUpdate.Append(
                            "gc_from_tbl='sales' " +
                            "AND gc_unique_id='" + transID + "' " +
                            "AND gc_item_code='" + lvi.SubItems[1].Text + "'"
                            );

                        paramTransUpdate.Append(
                            "gc_item_qty," +
                            "gc_total_price," +
                            "gc_item_cost," +
                            "gc_cust_cash," +
                            "gc_cust_change," +
                            "gc_trans_date," +
                            "gc_cost_total"
                            );

                        valuesTransUpdate.Append(
                            lvi.SubItems[2].Text + "," +
                            (float.Parse(lvi.SubItems[3].Text) * float.Parse(lvi.SubItems[2].Text)) + "," +
                            float.Parse(lvi.SubItems[4].Text) + "," +
                            float.Parse(transPage.txtCash.Text) + "," +
                            (float.Parse(transPage.txtCash.Text) - float.Parse(transPage.lblTotal.Text)) + "," +
                            DateTime.Now.ToString("MM/dd/yyyy") + "," +
                            float.Parse(lvi.SubItems[2].Text) * float.Parse(lvi.SubItems[4].Text)
                            );

                        try
                        {
                            transaction.GCUpdateDb("transact", paramTransUpdate, valuesTransUpdate, whereTransUpdate);
                            DataTable dtStock = db.GCSelectFromDb("stock", null, null);
                            transPage.dgStock.DataSource = null;
                            transPage.dgStock.DataSource = dtStock;
                            notification = new notification("Transaction has been updated.", notification.AlertType.success);
                            notification.Show();
                        }
                        catch (Exception a)
                        {
                            notification = new notification("Transaction error. Please check fields.", notification.AlertType.error);
                            MessageBox.Show(a.Message);
                            notification.Show();
                        }
                    }
                }
            }
            transPage.dgStock.DataSource = null;
            DataTable dtTransHist = db.GCSelectFromDb("stock", null, null);

            transPage.dgStock.DataSource  = dtTransHist;
            transPage.btnSaveTrans.Click -= BtnSaveTrans_Click;
        }
Esempio n. 17
0
        private void btnSaveTrans_Click(object sender, EventArgs e)
        {
            if (SaveMode == true)
            {
                if (txtCustomerName.Text == "" && txtAddress.Text == "")
                {
                    notification = new notification("Error saving. Check fields before saving.", notification.AlertType.error);
                    notification.Show();
                    return;
                }

                string randID = view.Random("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", 5);
                foreach (ListViewItem lvi in lvCart.Items)
                {
                    StringBuilder values = new StringBuilder();

                    StringBuilder paramUpdate  = new StringBuilder();
                    StringBuilder valuesUpdate = new StringBuilder();
                    StringBuilder whereUpdate  = new StringBuilder();

                    values.Append(
                        "Sales," +
                        "out," +
                        lvi.SubItems[2].Text + "," +
                        itemQty + "," +
                        DateTime.Today + "," +
                        randID + "," +
                        lvi.SubItems[1].Text + "," +
                        txtCustomerName.Text + "," +
                        txtAddress.Text + "," +
                        lvi.SubItems[5].Text + "," +
                        lvi.SubItems[6].Text + "," +
                        lvi.Text + "," +
                        float.Parse(lvi.SubItems[3].Text) * float.Parse(lvi.SubItems[2].Text) + "," +
                        float.Parse(lvi.SubItems[4].Text) + "," +
                        float.Parse(lvi.SubItems[3].Text) + "," +
                        float.Parse(txtCash.Text) + "," +
                        (float.Parse(txtCash.Text) - totalPrice) + "," +
                        float.Parse(lvi.SubItems[4].Text) * float.Parse(lvi.SubItems[2].Text)
                        );

                    paramUpdate.Append("gc_item_qty");
                    valuesUpdate.Append(int.Parse(lvi.SubItems[7].Text) - int.Parse(lvi.SubItems[2].Text));
                    whereUpdate.Append("gc_item_code='" + lvi.SubItems[1].Text + "'");

                    db.GCUpdateDb("stock", paramUpdate, valuesUpdate, whereUpdate);
                    transaction.insertToTrans(values);
                }

                dgStock.DataSource = null;
                DataTable dt = db.GCSelectFromDb("stock", null, null);
                dgStock.DataSource = dt;

                foreach (Control ctrl in panel1.Controls)
                {
                    if (ctrl.GetType() == typeof(TextBox))
                    {
                        ctrl.Text = "";
                    }
                }
                lvCart.Items.Clear();
                DialogResult drPrint = MessageBox.Show("Do you want to print this transaction?", "Print this transaction?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (drPrint == DialogResult.Yes)
                {
                    receiptPage.transID = randID;
                    receiptPage.ShowDialog();
                }
                else
                {
                    notification = new notification("Transaction has been saved.", notification.AlertType.success);
                    notification.Show();
                }
            }
        }
Esempio n. 18
0
        private void BtnAddQty_Click(object sender, EventArgs e)
        {
            if (salesQtyPage.txtQty.Text != "")
            {
                if (itemQty >= int.Parse(salesQtyPage.txtQty.Text))
                {
                    string[] items =
                    {
                        itemName,
                        itemCode,
                        salesQtyPage.txtQty.Text,
                        itemPrice.ToString(),
                        itemCost.ToString(),
                        itemUm,
                        itemDesc,
                        itemQty.ToString()
                    };

                    ListViewItem strValues = new ListViewItem(items);
                    if (lvCart.Items.Count > 0)
                    {
                        var resItem = lvCart.FindItemWithText(itemCode, true, 0, false);
                        if (resItem != null && resItem.SubItems[1].Text == itemCode)
                        {
                            int resTotal = int.Parse(resItem.SubItems[2].Text) + int.Parse(salesQtyPage.txtQty.Text);
                            resItem.SubItems[2].Text = resTotal.ToString();
                        }
                        else
                        {
                            lvCart.Items.Add(strValues);
                        }
                    }
                    else
                    {
                        lvCart.Items.Add(strValues);
                    }

                    totalPrice = 0;
                    foreach (ListViewItem lvi in lvCart.Items)
                    {
                        totalPrice += float.Parse(lvi.SubItems[2].Text) * float.Parse(lvi.SubItems[3].Text);
                    }

                    lblTotal.Text = totalPrice.ToString();
                    salesQtyPage.btnAddQty.Click -= BtnAddQty_Click;
                    salesQtyPage.Close();
                }
                else
                {
                    MessageBox.Show("Invalid Quantity, not enough item on stock.", "Not enough item on stock", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                    salesQtyPage.btnAddQty.Click -= BtnAddQty_Click;
                    return;
                }
            }
            else
            {
                notification notification = new notification("Cannot insert blank value!", notification.AlertType.error);
                notification.Show();
                salesQtyPage.btnAddQty.Click -= BtnAddQty_Click;
            }
        }
Esempio n. 19
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            StringBuilder whereItemCode = new StringBuilder();

            StringBuilder whereUpdate  = new StringBuilder();
            StringBuilder paramUpdate  = new StringBuilder();
            StringBuilder valuesUpdate = new StringBuilder();

            StringBuilder whereInvUpdate  = new StringBuilder();
            StringBuilder paramInvUpdate  = new StringBuilder();
            StringBuilder valuesInvUpdate = new StringBuilder();

            StringBuilder whereStockUpdate  = new StringBuilder();
            StringBuilder paramStockUpdate  = new StringBuilder();
            StringBuilder valuesStockUpdate = new StringBuilder();

            if (itemCode != "" && itemCode != txtItemCode.Text)
            {
                whereItemCode.Append("gc_item_code='" + txtItemCode.Text + "'");
                int resItemCode = db.searchData("products", null, whereItemCode);
                if (resItemCode == 1)
                {
                    notification = new notification("Item Code already Existing", notification.AlertType.error);
                    notification.ShowDialog();
                }
                else
                {
                    paramInvUpdate.Append(
                        "gc_item_name," +
                        "gc_item_code," +
                        "gc_item_um," +
                        "gc_item_desc," +
                        "gc_item_supp," +
                        "gc_item_brand," +
                        "gc_item_cost," +
                        "gc_item_srp," +
                        "gc_item_type"
                        );

                    valuesInvUpdate.Append(
                        txtItemName.Text + "," +
                        txtItemCode.Text + "," +
                        txtUm.Text + "," +
                        txtDesc.Text + "," +
                        cmbSupp.Text + "," +
                        txtBrand.Text + "," +
                        float.Parse(txtCost.Text) + "," +
                        float.Parse(txtSrp.Text) + "," +
                        cmbItemType.Text
                        );

                    paramStockUpdate.Append(
                        "gc_item_name," +
                        "gc_item_code," +
                        "gc_item_um," +
                        "gc_item_desc," +
                        "gc_item_supp," +
                        "gc_item_brand," +
                        "gc_item_cost," +
                        "gc_item_srp," +
                        "gc_item_type"
                        );

                    valuesStockUpdate.Append(
                        txtItemName.Text + "," +
                        txtItemCode.Text + "," +
                        txtUm.Text + "," +
                        txtDesc.Text + "," +
                        cmbSupp.Text + "," +
                        txtBrand.Text + "," +
                        float.Parse(txtCost.Text) + "," +
                        float.Parse(txtSrp.Text) + "," +
                        cmbItemType.Text
                        );

                    paramUpdate.Append(
                        "gc_item_name," +
                        "gc_item_code," +
                        "gc_item_um," +
                        "gc_item_desc," +
                        "gc_item_supp," +
                        "gc_item_brand," +
                        "gc_item_cost," +
                        "gc_item_srp," +
                        "gc_item_type," +
                        "gc_item_status"
                        );

                    valuesUpdate.Append(
                        txtItemName.Text + "," +
                        txtItemCode.Text + "," +
                        txtUm.Text + "," +
                        txtDesc.Text + "," +
                        cmbSupp.Text + "," +
                        txtBrand.Text + "," +
                        float.Parse(txtCost.Text) + "," +
                        float.Parse(txtSrp.Text) + "," +
                        cmbItemType.Text + "," +
                        "in-active"
                        );

                    whereInvUpdate.Append("gc_item_code='" + itemCode + "'");
                    whereStockUpdate.Append("gc_item_code='" + itemCode + "'");
                    whereUpdate.Append("gc_item_code='" + itemCode + "'");

                    db.GCUpdateDb("stock", paramStockUpdate, valuesStockUpdate, whereStockUpdate);
                    db.GCUpdateDb("inventory", paramInvUpdate, valuesInvUpdate, whereInvUpdate);
                    db.GCUpdateDb("products", paramUpdate, valuesUpdate, whereUpdate);

                    notification = new notification("Product information updated.", notification.AlertType.success);
                    notification.ShowDialog();
                }
            }
            else if (itemCode != "" && txtItemName.Text != "")
            {
                paramInvUpdate.Append(
                    "gc_item_name," +
                    "gc_item_code," +
                    "gc_item_um," +
                    "gc_item_desc," +
                    "gc_item_supp," +
                    "gc_item_brand," +
                    "gc_item_cost," +
                    "gc_item_srp," +
                    "gc_item_type"
                    );

                valuesInvUpdate.Append(
                    txtItemName.Text + "," +
                    txtItemCode.Text + "," +
                    txtUm.Text + "," +
                    txtDesc.Text + "," +
                    cmbSupp.Text + "," +
                    txtBrand.Text + "," +
                    float.Parse(txtCost.Text) + "," +
                    float.Parse(txtSrp.Text) + "," +
                    cmbItemType.Text
                    );

                paramStockUpdate.Append(
                    "gc_item_name," +
                    "gc_item_code," +
                    "gc_item_um," +
                    "gc_item_desc," +
                    "gc_item_supp," +
                    "gc_item_brand," +
                    "gc_item_cost," +
                    "gc_item_srp," +
                    "gc_item_type"
                    );

                valuesStockUpdate.Append(
                    txtItemName.Text + "," +
                    txtItemCode.Text + "," +
                    txtUm.Text + "," +
                    txtDesc.Text + "," +
                    cmbSupp.Text + "," +
                    txtBrand.Text + "," +
                    float.Parse(txtCost.Text) + "," +
                    float.Parse(txtSrp.Text) + "," +
                    cmbItemType.Text
                    );

                paramUpdate.Append(
                    "gc_item_name," +
                    "gc_item_code," +
                    "gc_item_um," +
                    "gc_item_desc," +
                    "gc_item_supp," +
                    "gc_item_brand," +
                    "gc_item_cost," +
                    "gc_item_srp," +
                    "gc_item_type," +
                    "gc_item_status"
                    );

                valuesUpdate.Append(
                    txtItemName.Text + "," +
                    txtItemCode.Text + "," +
                    txtUm.Text + "," +
                    txtDesc.Text + "," +
                    cmbSupp.Text + "," +
                    txtBrand.Text + "," +
                    float.Parse(txtCost.Text) + "," +
                    float.Parse(txtSrp.Text) + "," +
                    cmbItemType.Text + "," +
                    "in-active"
                    );

                whereInvUpdate.Append("gc_item_code='" + itemCode + "'");
                whereStockUpdate.Append("gc_item_code='" + itemCode + "'");
                whereUpdate.Append("gc_item_code='" + itemCode + "'");

                db.GCUpdateDb("stock", paramStockUpdate, valuesStockUpdate, whereStockUpdate);
                db.GCUpdateDb("inventory", paramInvUpdate, valuesInvUpdate, whereInvUpdate);
                db.GCUpdateDb("products", paramUpdate, valuesUpdate, whereUpdate);

                notification = new notification("Product information updated.", notification.AlertType.success);
                notification.ShowDialog();
            }
            else
            {
                notification = new notification("Error. Please check fields before saving.", notification.AlertType.error);
                notification.ShowDialog();
            }
        }
Esempio n. 20
0
        private void dgStock_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            var senderGrid = (DataGridView)sender;

            if (e.ColumnIndex == 12)
            {
                try
                {
                    itemName  = senderGrid.Rows[e.RowIndex].Cells[0].Value.ToString();
                    itemCode  = senderGrid.Rows[e.RowIndex].Cells[1].Value.ToString();
                    qty       = int.Parse(senderGrid.Rows[e.RowIndex].Cells[2].Value.ToString());
                    itemDesc  = senderGrid.Rows[e.RowIndex].Cells[3].Value.ToString();
                    itemSupp  = senderGrid.Rows[e.RowIndex].Cells[4].Value.ToString();
                    itemBrand = senderGrid.Rows[e.RowIndex].Cells[5].Value.ToString();
                    itemUm    = senderGrid.Rows[e.RowIndex].Cells[6].Value.ToString();
                    itemCost  = float.Parse(senderGrid.Rows[e.RowIndex].Cells[7].Value.ToString());
                    itemSrp   = float.Parse(senderGrid.Rows[e.RowIndex].Cells[8].Value.ToString());
                    itemType  = senderGrid.Rows[e.RowIndex].Cells[10].Value.ToString();

                    stockAddPage.btnAddQty.Click += BtnAddQty_Click;
                    stockAddPage.ShowDialog();
                }
                catch (Exception a)
                {
                    MessageBox.Show(a.Message);
                }
            }
            else if (e.ColumnIndex == 11)
            {
                StringBuilder whereDel  = new StringBuilder();
                StringBuilder valuesDel = new StringBuilder();

                StringBuilder paramInvUpdate  = new StringBuilder();
                StringBuilder valuesInvUpdate = new StringBuilder();
                StringBuilder whereInvUpdate  = new StringBuilder();

                StringBuilder paramInvAdd = new StringBuilder();
                StringBuilder whereInvAdd = new StringBuilder();

                DialogResult delRes = MessageBox.Show("Are you sure you want to delete this stock?", "Delete Supplier?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (delRes == DialogResult.Yes)
                {
                    paramInvAdd.Append("gc_item_qty");
                    whereInvAdd.Append("gc_item_code='" + senderGrid.Rows[e.RowIndex].Cells[1].Value.ToString() + "'");
                    DataTable dtInv = db.GCSelectFromDb("inventory", paramInvAdd, whereInvAdd);
                    foreach (DataRow row in dtInv.Rows)
                    {
                        currInventory = int.Parse(row[0].ToString());
                    }
                    whereDel.Append("gc_item_code");
                    valuesDel.Append(senderGrid.Rows[e.RowIndex].Cells[1].Value.ToString());
                    db.GCDeleteFromDb("stock", valuesDel, whereDel);

                    paramInvUpdate.Append("gc_item_qty");
                    valuesInvUpdate.Append(currInventory + int.Parse(senderGrid.Rows[e.RowIndex].Cells[2].Value.ToString()));
                    whereInvUpdate.Append("gc_item_code='" + senderGrid.Rows[e.RowIndex].Cells[1].Value.ToString() + "'");
                    db.GCUpdateDb("inventory", paramInvUpdate, valuesInvUpdate, whereInvUpdate);

                    notification = new notification("Stock has been deleted.", notification.AlertType.success);
                    notification.ShowDialog();

                    dgStock.DataSource = null;
                    DataTable dtRemove = db.GCSelectFromDb("stock", null, null, "ORDER BY id DESC");
                    dgStock.DataSource = dtRemove;
                }
            }
        }
Esempio n. 21
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            StringBuilder whereSearch      = new  StringBuilder();
            StringBuilder whereSearchInv   = new StringBuilder();
            StringBuilder whereSearchStock = new StringBuilder();

            main = new Inventory_Main();
            whereSearch.Append("gc_item_code='" + txtItemCode.Text + "'");
            whereSearchInv.Append("gc_item_code='" + txtItemCode.Text + "'");
            whereSearchStock.Append("gc_item_code='" + txtItemCode.Text + "'");
            int resInv   = db.searchData("inventory", null, whereSearchInv);
            int resStock = db.searchData("stock", null, whereSearchStock);
            int resProd  = db.searchData("products", null, whereSearch);

            if (resProd >= 1 || resInv >= 1 || resStock >= 1)
            {
                notification = new notification("Item Code is already existing.", notification.AlertType.error);
                notification.ShowDialog();
            }
            else if (txtItemName.Text != "" && txtItemCode.Text != "")
            {
                try
                {
                    StringBuilder param          = new StringBuilder();
                    StringBuilder paramInv       = new StringBuilder();
                    StringBuilder values         = new StringBuilder();
                    StringBuilder valuesInv      = new StringBuilder();
                    StringBuilder whereInvSearch = new StringBuilder();

                    StringBuilder paramStock  = new StringBuilder();
                    StringBuilder valuesStock = new StringBuilder();

                    param.Append(
                        "gc_item_name," +
                        "gc_item_code," +
                        "gc_item_brand," +
                        "gc_item_type," +
                        "gc_item_supp," +
                        "gc_item_um," +
                        "gc_item_cost," +
                        "gc_item_srp," +
                        "gc_item_desc," +
                        "gc_item_status"
                        );

                    values.Append(
                        txtItemName.Text + "," +
                        txtItemCode.Text + "," +
                        txtBrand.Text + "," +
                        cmbItemType.Text + "," +
                        cmbSupp.Text + "," +
                        txtUm.Text + "," +
                        float.Parse(txtCost.Text) + "," +
                        float.Parse(txtSrp.Text) + "," +
                        txtDesc.Text + "," +
                        cmbStatus.Text
                        );

                    paramInv.Append(
                        "gc_item_name," +
                        "gc_item_code," +
                        "gc_item_brand," +
                        "gc_item_type," +
                        "gc_item_supp," +
                        "gc_item_um," +
                        "gc_item_cost," +
                        "gc_item_srp," +
                        "gc_item_desc," +
                        "gc_item_status," +
                        "gc_item_qty"
                        );

                    valuesInv.Append(
                        txtItemName.Text + "," +
                        txtItemCode.Text + "," +
                        txtBrand.Text + "," +
                        cmbItemType.Text + "," +
                        cmbSupp.Text + "," +
                        txtUm.Text + "," +
                        float.Parse(txtCost.Text) + "," +
                        float.Parse(txtSrp.Text) + "," +
                        txtDesc.Text + "," +
                        "registered," +
                        int.Parse(txtInvQty.Text)
                        );

                    whereInvSearch.Append("gc_item_code='" + txtItemCode.Text + "'");
                    int invSearch = db.searchData("inventory", null, whereInvSearch);
                    if (invSearch <= 0)
                    {
                        db.GCInsertToDb("inventory", paramInv, valuesInv);
                    }

                    paramStock.Append(
                        "gc_item_name," +
                        "gc_item_code," +
                        "gc_item_brand," +
                        "gc_item_type," +
                        "gc_item_supp," +
                        "gc_item_um," +
                        "gc_item_cost," +
                        "gc_item_srp," +
                        "gc_item_desc," +
                        "gc_item_status," +
                        "gc_item_qty"
                        );

                    valuesStock.Append(
                        txtItemName.Text + "," +
                        txtItemCode.Text + "," +
                        txtBrand.Text + "," +
                        cmbItemType.Text + "," +
                        cmbSupp.Text + "," +
                        txtUm.Text + "," +
                        float.Parse(txtCost.Text) + "," +
                        float.Parse(txtSrp.Text) + "," +
                        txtDesc.Text + "," +
                        "registered," +
                        int.Parse(txtStockQty.Text)
                        );

                    db.GCInsertToDb("stock", paramStock, valuesStock);
                    db.GCInsertToDb("products", param, values);

                    DataTable dt = db.GCSelectFromDb("products", null, null, "ORDER BY id DESC");
                    dgProducts.DataSource = null;
                    dgProducts.DataSource = dt;



                    notification = new notification("Product saved to the database", notification.AlertType.success);
                    notification.ShowDialog();
                }
                catch (Exception a)
                {
                    notification = new notification("Please check the values on the fields. : ", notification.AlertType.error);
                    notification.ShowDialog();
                }
            }
            else
            {
                notification = new notification("Please check the values on the fields.", notification.AlertType.error);
                notification.ShowDialog();
            }
        }