示例#1
0
 private void DGVItems_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
 {
     if (e.ColumnIndex == 4)
     {
         try
         {
             int value = Convert.ToInt32(e.FormattedValue);
             if (value >= 0)
             {
                 if (selectedReceipt.ReceiptItems[e.RowIndex].Quantity - value < 0)
                 {
                     DGVItems.Rows[e.RowIndex].ErrorText = "Refund quantity cannot exceed quantity.";
                     e.Cancel = true;
                 }
             }
             else
             {
                 DirectMessage.ShowError("Refund quantity cannot be negative.");
                 e.Cancel = true;
             }
         }
         catch (FormatException)
         {
             DirectMessage.ShowError("This is not a quantity number.");
             e.Cancel = true;
         }
     }
 }
示例#2
0
 private void btnRefundSelected_Click(object sender, EventArgs e)
 {
     if (DGVItems.SelectedCells.Count == 1)
     {
         if (Convert.ToInt32(DGVItems.CurrentRow.Cells[4].Value) > 0)
         {
             btnRefundSelected.Enabled = false;
             Basket basket = new Basket();
             basket.AddProduct(new Product(Convert.ToInt32(DGVItems.CurrentRow.Cells[0].Value), Convert.ToInt32(DGVItems.CurrentRow.Cells[4].Value), Convert.ToDecimal(DGVItems.CurrentRow.Cells[3].Value)));
             shop.RefundProduct(new Receipt(selectedReceipt.ID, shop, selectedReceipt.Client, selectedReceipt.Assistant, basket, Convert.ToDecimal(DGVItems.CurrentRow.Cells[3].Value) * Convert.ToInt32(DGVItems.CurrentRow.Cells[4].Value)));
             UpdateLastInvoices();
             selectedReceipt = shop.GetReceipt(selectedReceipt.ID);
             LoadReceipt(selectedReceipt);
             MessageBox.Show("Refund successfully completed.");
             btnRefundSelected.Enabled = true;
         }
         else
         {
             DirectMessage.ShowInfo("Refund quantity must be at least 1.");
         }
     }
     else
     {
         DirectMessage.ShowError("You have to select an item.");
     }
 }
 private void DGVItems_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
 {
     if (e.ColumnIndex == 4)
     {
         try
         {
             int value = Convert.ToInt32(e.FormattedValue);
             if (value < 1)
             {
                 DirectMessage.ShowError("Quantity cannot be less than 1.");
                 e.Cancel = true;
             }
             else
             {
                 if (shop.FindProductByCode(Convert.ToInt32(DGVItems.CurrentRow.Cells[0].Value)).Quantity - value < 0)
                 {
                     string error = "Quantity cannot exceed available quantity.";
                     DirectMessage.ShowError(error);
                     DGVItems.Rows[e.RowIndex].ErrorText = error;
                     e.Cancel = true;
                 }
             }
         }
         catch (FormatException)
         {
             DirectMessage.ShowError("This is not a quantity number.");
             e.Cancel = true;
         }
     }
 }
示例#4
0
 private void btnRefresh_Click(object sender, EventArgs e)
 {
     UpdateLastInvoices();
     if (selectedReceipt != null)
     {
         selectedReceipt = shop.GetReceipt(selectedReceipt.ID);
         LoadReceipt(selectedReceipt);
     }
     DirectMessage.ShowInfo("Successfully updated.");
 }
        private void btnFinalize_Click(object sender, EventArgs e)
        {
            int id = 0;

            using (DBHelper helper = new DBHelper())
            {
                MySqlCommand command = new MySqlCommand("SELECT AUTO_INCREMENT FROM information_schema.tables WHERE table_name = 'ml_shop_bill';", helper.GetConnection());
                helper.Open();
                MySqlDataReader ReceiptReader = command.ExecuteReader();
                //command.Parameters.AddWithValue("@field", validField);
                if (ReceiptReader.Read())
                {
                    id = Convert.ToInt32(ReceiptReader["AUTO_INCREMENT"]);
                }
            }
            if (basket.BasketProducts.Count >= 1)
            {
                try
                {
                    if (shop.FinalizeReceipt(new Receipt(id, new Shop(shop.ID), new Client(client.ID), new Assistant(assistant.ID), basket, Convert.ToDecimal(tbxNetAmount.Text))))
                    {
                        for (int i = 0; i < lbxResult.Items.Count; i++)
                        {
                            lbxResult.Items[i] = lbxResult.Items[i];
                        }
                        MessageBox.Show("Successfully completed.");
                        PrintReceipt();
                        client = null;
                        EnableActions(false);
                        btnPrint.Enabled = true;
                    }
                    else
                    {
                        DirectMessage.ShowError("Something went wrong with the transaction.");
                    }
                }
                catch (InsufficientBalanceException ex)
                {
                    DirectMessage.ShowError(ex.Message);
                }
            }
            else
            {
                DirectMessage.ShowError("There are no products added.");
            }
        }
示例#6
0
        private void btnRefundAll_Click(object sender, EventArgs e)
        {
            if (DGVItems.SelectedCells.Count == 1)
            {
                Basket basket = new Basket();
                for (int i = 0; i < DGVItems.Rows.Count; ++i)
                {
                    if (Convert.ToInt32(DGVItems.Rows[i].Cells[5].Value) > 0)
                    {
                        basket.AddProduct(new Product(Convert.ToInt32(DGVItems.Rows[i].Cells[0].Value), Convert.ToInt32(DGVItems.Rows[i].Cells[5].Value), Convert.ToDecimal(DGVItems.Rows[i].Cells[3].Value)));
                    }
                }
                if (basket.BasketProducts.Count == 0)
                {
                    DirectMessage.ShowInfo("There are no products left for refund.");
                }
                else
                {
                    string            messageBoxText = "This will refund all products in their ORIGINAL quantities from the invoice. Do you want to proceed?";
                    string            caption        = "Important";
                    MessageBoxButtons button         = MessageBoxButtons.YesNoCancel;
                    MessageBoxIcon    icon           = MessageBoxIcon.Warning;
                    DialogResult      result         = MessageBox.Show(messageBoxText, caption, button, icon);
                    switch (result)
                    {
                    case DialogResult.Yes:
                        btnRefundSelected.Enabled = false;
                        shop.RefundProduct(new Receipt(selectedReceipt.ID, shop, selectedReceipt.Client, selectedReceipt.Assistant, basket, Convert.ToDecimal(tbxNetAmount.Text)));
                        UpdateLastInvoices();
                        selectedReceipt = shop.GetReceipt(selectedReceipt.ID);
                        LoadReceipt(selectedReceipt);
                        MessageBox.Show("Refund successfully completed.");
                        btnRefundSelected.Enabled = true;
                        break;

                    default:
                        break;
                    }
                }
            }
            else
            {
                DirectMessage.ShowError("You have to select an invoice.");
            }
        }
示例#7
0
 private void btnPrint_Click(object sender, EventArgs e)
 {
     if (selectedReceipt != null)
     {
         PrintDialog   printDialog   = new PrintDialog();
         PrintDocument printDocument = new PrintDocument();
         printDialog.Document     = printDocument;
         printDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(CreateReceipt);
         DialogResult result = printDialog.ShowDialog();
         if (result == DialogResult.OK)
         {
             printDocument.Print();
         }
     }
     else
     {
         DirectMessage.ShowError("You have to select a receipt first.");
     }
 }
示例#8
0
 private void btnInvoiceSearch_Click(object sender, EventArgs e)
 {
     try
     {
         Receipt r = shop.GetReceipt(Convert.ToInt32(tbxInvoiceSearch.Text));
         if (r != null)
         {
             selectedReceipt = r;
             LoadReceipt(r);
         }
         else
         {
             DirectMessage.ShowInfo("Invoice not found.");
         }
     }
     catch (FormatException)
     {
         DirectMessage.ShowError("Input is not in correct format.");
     }
 }
        void rfid_Tag(object sender, RFIDTagEventArgs e)
        {
            lblTag.Text = e.Tag;
            if (client == null)
            {
                client = Client.FindUser(e.Tag);
                if (client != null)
                {
                    Console.Beep(1500, 100);
                    Console.Beep(2000, 100);
                    UpdateClientInfo();
                    EnableActions(true);
                    lastTag = e.Tag;
                }
                else
                {
                    DirectMessage.ShowError("Invalid visitor RFID code.");
                }
            }
            else
            {
                if (client != null && e.Tag != lastTag && lblTag.Text != "-")
                {
                    Product p = shop.FindProductByRFIDCode(e.Tag);
                    if (p != null)
                    {
                        Product productToAdd = new Product(p.ID, 1, p.Price);
                        if (basket.FindProduct(p.ID) == null)
                        {
                            if (p.Quantity - 1 < 0)
                            {
                                MessageBox.Show("Insufficient available quantity.");
                            }
                            else
                            {
                                Console.Beep(2000, 200);
                                basket.AddProduct(productToAdd);
                                dataTable.Rows.Add(p.ID, p.Name, p.Description, p.Price, 1);
                                UpdateNetAmount();
                            }
                        }
                        else
                        {
                            if (p.Quantity - basket.FindProduct(p.ID).Quantity - 1 < 0)
                            {
                                MessageBox.Show("Insufficient available quantity.");
                            }
                            else
                            {
                                Console.Beep(2000, 200);
                                basket.IncrementingAddProduct(productToAdd);
                                DGVItems.Rows[DGVItems.Rows.Count - 1].Cells[4].Value = Convert.ToInt32(DGVItems.Rows[DGVItems.Rows.Count - 1].Cells[4].Value) + 1;
                                UpdateNetAmount();
                            }
                        }
                    }
                    else
                    {
                        string            messageBoxText = "Another client ID is read. Do you want to change it?";
                        string            caption        = "New client ID read";
                        MessageBoxButtons button         = MessageBoxButtons.YesNoCancel;
                        MessageBoxIcon    icon           = MessageBoxIcon.Warning;
                        DialogResult      result         = MessageBox.Show(messageBoxText, caption, button, icon);
                        switch (result)
                        {
                        case DialogResult.Yes:
                            Client newClient = Client.FindUser(e.Tag);
                            if (newClient != null)
                            {
                                client = newClient;
                                EnableActions(true);
                                lastTag = e.Tag;
                                break;
                            }
                            else
                            {
                                DirectMessage.ShowError("Invalid visitor RFID code. Current client not changed.");
                                break;
                            }

                        default:
                            break;
                        }
                    }
                }
            }
        }