コード例 #1
0
ファイル: Dashboardcs.cs プロジェクト: ronkervy/inventory-sys
        private void Dashboardcs_Load(object sender, EventArgs e)
        {
            StringBuilder where = new StringBuilder();
            StringBuilder param = new StringBuilder();

            where.Append("gc_item_qty < 10");
            int resStock = db.searchData("stock", null, where);

            if (resStock < 10)
            {
                lblStockLow.Text = "0" + resStock.ToString();
            }
            else
            {
                lblStockLow.Text = resStock.ToString();
            }


            int resInv = db.searchData("inventory", null, null);

            if (resInv < 10)
            {
                lblInvTotal.Text = "0" + resInv.ToString();
            }
            else
            {
                lblInvTotal.Text = resInv.ToString();
            }

            int resDelivery = db.searchData("delivery", null, null);

            if (resInv < 10)
            {
                lblDelivery.Text = "0" + resDelivery.ToString();
            }
            else
            {
                lblDelivery.Text = resDelivery.ToString();
            }
        }
コード例 #2
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();
            }
        }
コード例 #3
0
ファイル: Login.cs プロジェクト: ronkervy/inventory-sys
        private void btnLogin_Click(object sender, EventArgs e)
        {
            StringBuilder where = new StringBuilder();
            where.Append("username='******' AND password='******'");
            int resLog = db.searchData("users", null, where);

            if (resLog >= 1)
            {
                main = new Inventory_Main();
                main.Show();
                notification notification = new notification("Welcome Admin!", notification.AlertType.info);
                notification.ShowDialog();
            }
            else
            {
            }
        }
コード例 #4
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();
                }
            }
        }
コード例 #5
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();
        }
コード例 #6
0
        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;
        }
コード例 #7
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();
            }
        }
コード例 #8
0
ファイル: Delivery.cs プロジェクト: ronkervy/inventory-sys
        private void dgDelivery_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            var senderGrid = (DataGridView)sender;

            if (e.ColumnIndex == 0)
            {
                try
                {
                    StringBuilder whereItem = new StringBuilder();

                    whereItem.Append(
                        "gc_item_name='" + senderGrid.Rows[e.RowIndex].Cells[1].Value.ToString() + "' " +
                        "AND gc_item_supp='" + senderGrid.Rows[e.RowIndex].Cells[3].Value.ToString() + "' " +
                        "AND gc_item_brand='" + senderGrid.Rows[e.RowIndex].Cells[4].Value.ToString() + "'"
                        );

                    int resItem = db.searchData("products", null, whereItem);

                    if (resItem == 1)
                    {
                        StringBuilder paramItemSelected = new StringBuilder();
                        StringBuilder whereItemSelected = new StringBuilder();

                        paramItemSelected.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"
                            );

                        whereItemSelected.Append(
                            "gc_item_name='" + senderGrid.Rows[e.RowIndex].Cells[1].Value.ToString() + "' " +
                            "AND gc_item_supp='" + senderGrid.Rows[e.RowIndex].Cells[3].Value.ToString() + "' " +
                            "AND gc_item_brand='" + senderGrid.Rows[e.RowIndex].Cells[4].Value.ToString() + "'"
                            );

                        DataTable dt = db.GCSelectFromDb("products", paramItemSelected, whereItemSelected);

                        foreach (DataRow row in dt.Rows)
                        {
                            deliveryInfoPage.txtItemName.Text     = row[0].ToString();
                            deliveryInfoPage.txtItemCode.Text     = row[1].ToString();
                            deliveryInfoPage.txtUm.Text           = row[2].ToString();
                            deliveryInfoPage.txtDesc.Text         = row[3].ToString();
                            deliveryInfoPage.cmbSupp.Text         = row[4].ToString();
                            deliveryInfoPage.txtBrand.Text        = row[5].ToString();
                            deliveryInfoPage.txtCost.Text         = row[6].ToString();
                            deliveryInfoPage.txtSrp.Text          = row[7].ToString();
                            deliveryInfoPage.cmbItemType.Text     = row[8].ToString();
                            deliveryInfoPage.cmbItemStatus.Text   = row[9].ToString();
                            deliveryInfoPage.orderTerms           = int.Parse(senderGrid.Rows[e.RowIndex].Cells[7].Value.ToString());
                            deliveryInfoPage.dtDeliveryDate.Value = DateTime.Parse(senderGrid.Rows[e.RowIndex].Cells[8].Value.ToString());

                            deliveryInfoPage.itemName  = row[0].ToString();
                            deliveryInfoPage.itemSupp  = row[4].ToString();
                            deliveryInfoPage.itemBrand = row[5].ToString();
                        }
                        deliveryInfoPage.txtQty.Text      = senderGrid.Rows[e.RowIndex].Cells[2].Value.ToString();
                        deliveryInfoPage.btnMove.Click   += BtnMove_Click;
                        deliveryInfoPage.btnDelete.Click += BtnDelete_Click;
                        deliveryInfoPage.btnSave.Click   += BtnSave_Click;

                        deliveryInfoPage.ShowDialog();
                    }
                    else
                    {
                        deliveryInfoPage.txtItemName.Text     = senderGrid.Rows[e.RowIndex].Cells[1].Value.ToString();
                        deliveryInfoPage.txtQty.Text          = senderGrid.Rows[e.RowIndex].Cells[2].Value.ToString();
                        deliveryInfoPage.cmbSupp.Text         = senderGrid.Rows[e.RowIndex].Cells[3].Value.ToString();
                        deliveryInfoPage.txtBrand.Text        = senderGrid.Rows[e.RowIndex].Cells[4].Value.ToString();
                        deliveryInfoPage.txtCost.Text         = senderGrid.Rows[e.RowIndex].Cells[5].Value.ToString();
                        deliveryInfoPage.cmbItemStatus.Text   = senderGrid.Rows[e.RowIndex].Cells[6].Value.ToString();
                        deliveryInfoPage.orderTerms           = int.Parse(senderGrid.Rows[e.RowIndex].Cells[7].Value.ToString());
                        deliveryInfoPage.dtDeliveryDate.Value = DateTime.Parse(senderGrid.Rows[e.RowIndex].Cells[8].Value.ToString());
                        deliveryInfoPage.txtItemCode.Text     = senderGrid.Rows[e.RowIndex].Cells[9].Value.ToString();
                        deliveryInfoPage.cmbItemType.Text     = senderGrid.Rows[e.RowIndex].Cells[10].Value.ToString();
                        deliveryInfoPage.txtSrp.Text          = senderGrid.Rows[e.RowIndex].Cells[11].Value.ToString();
                        deliveryInfoPage.txtDesc.Text         = senderGrid.Rows[e.RowIndex].Cells[12].Value.ToString();
                        deliveryInfoPage.txtUm.Text           = senderGrid.Rows[e.RowIndex].Cells[13].Value.ToString();

                        deliveryInfoPage.itemName  = senderGrid.Rows[e.RowIndex].Cells[1].Value.ToString();
                        deliveryInfoPage.itemSupp  = senderGrid.Rows[e.RowIndex].Cells[3].Value.ToString();
                        deliveryInfoPage.itemBrand = senderGrid.Rows[e.RowIndex].Cells[4].Value.ToString();

                        deliveryInfoPage.btnMove.Click   += BtnMove_Click;
                        deliveryInfoPage.btnDelete.Click += BtnDelete_Click;
                        deliveryInfoPage.btnSave.Click   += BtnSave_Click;

                        deliveryInfoPage.ShowDialog();
                    }
                }
                catch (Exception a)
                {
                    return;
                }
            }
        }
コード例 #9
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();
            }
        }