コード例 #1
0
ファイル: Print.cs プロジェクト: delcoker/POSAkorno
        private void btnPrnt_Click(object sender, EventArgs e)
        {
            //if (txtBChange.Text == "" || Convert.ToDecimal(txtBChange.Text) < 0)
            //{
            //    MessageBox.Show("The change is below zero (0)");
            //    return;
            //}

            //take out true to print without dialog
            printReceipt();

            // after it prints save to database

            // also update the inventory
            //try
            //{
                cSale sale = new cSale(0, loggedUser.UserID, dtpDtAdd.Value.ToString());
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show("You have not logged in " + ex.Message);

            //    //throw ex;
            //    return;
            //}

            int saleIDLastInseted = 0;
            try
            {
                saleIDLastInseted = Convert.ToInt16(sale.saveSaleRecord());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " could not get last insertedID for sale");

                throw ex;
            }

            //last inserted sale id

            foreach (ListViewItem lst in list.Items)
            {
                mealID = Convert.ToInt32(lst.SubItems[5].Text);
                int qty = Convert.ToInt32(lst.SubItems[2].Text);

                decimal subtotal = Convert.ToDecimal(lst.SubItems[1].Text) * Convert.ToInt32(lst.SubItems[2].Text);

                cSaleDetail saleDetail = new cSaleDetail(0, saleIDLastInseted, mealID, qty, subtotal, total, dtpDtAdd.Value.ToString());

                //////////////////////////////////////////////////////////////
                // because of staff discount, if total < 0, save 0
                //////////////////////////////////////////////////////////////
                //////////////////////////////////////////////////////////////
                // staff discount logic
                // if total < 0
                // if this is a staff discount, the amount that should be deducted to store a 0 is -4.50 - total devided by number of staff discounts
                //////////////////////////////////////////////////////////////
                if (total < 0)
                {
                    if (saleDetail.MealID == staffDiscountID)
                    {
                        saleDetail.Subtotal = subtotal - total;
                    }
                    saleDetail.Total = 0;
                }

                /////////////////////////////////////////////////////////////

                try
                {
                    if (!saleDetail.saveSaleDetailRecord())
                    {
                        MessageBox.Show("Could not save sale detail." + error);
                    }

                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    throw ex;
                }

                hasStock = Convert.ToBoolean(lst.SubItems[6].Text);

                if(hasStock)
                {
                    cInventoryDebit inv = new cInventoryDebit(0, Convert.ToUInt32(mealID), Convert.ToUInt32(qty), dtpDtAdd.Value.ToString(), loggedUser.UserID);

                    try
                    {
                        if (!inv.saveRecord())
                        {
                            MessageBox.Show("Could not save to inventory\n" + error);
                        }

                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        throw ex;
                    }
                }

            }
            Sale.transactionComplete = true;
            this.Close();
        }
コード例 #2
0
ファイル: InventoryView.cs プロジェクト: delcoker/POSAkorno
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!loggedUser.access(Convert.ToInt16(btnSave.Tag)))
            {
                return;
            }

            cInventory inv = new cInventory(0, Convert.ToUInt32(cmbItems.SelectedValue), Convert.ToUInt32(numQty.Value), dtpDtAdd.Value.ToString(), loggedUser.UserID);

            if (inv.checkInventory())
            {
                DialogResult dialogResult = MessageBox.Show("This item was already added to or deducted from today. Continue with update?", "Add", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {

                    // preventing adding twice to the same item because
                    //MessageBox.Show("Item not added");
                    //return;
                }
                else
                {
                    MessageBox.Show("Item not added");
                    return;
                }
            }

            if (rdbAddition.Checked)
            {

                if (inv.saveRecord())
                {
                    MessageBox.Show("Added");
                }
                else
                {
                    MessageBox.Show("Sorry could not be added");
                    return;
                }
            }
            else if (rdbDeduct.Checked)
            {
                if (!(Convert.ToInt32(dgvInv["SLeft", dgvInv.CurrentCell.RowIndex].Value) - Convert.ToUInt32(numQty.Value) >= 0))
                {
                    MessageBox.Show("Not enough stock on this item");
                    return;
                }

                cInventoryDebit invD = new cInventoryDebit(0, Convert.ToUInt32(cmbItems.SelectedValue), Convert.ToUInt32(numQty.Value), dtpDtAdd.Value.ToString(), loggedUser.UserID);

                try
                {
                    if (!invD.saveRecord())
                    {
                        MessageBox.Show("Could not save to inventory\n");
                    }

                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    throw ex;
                }

                MessageBox.Show("Deducted");
            }
            else
            {
                MessageBox.Show("Please select addition or deduction option");
                return;
            }
            LoadItems();
            pEdt.Enabled = false;
        }