Exemplo n.º 1
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();
            }
        }
Exemplo n.º 2
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;
        }
Exemplo n.º 3
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();
                }
            }
        }
Exemplo n.º 4
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;
            }
        }