private void AddingDataIntoTextboxesAfterProductSelection(string selectedProductId)
        {
            StockDetail selectedProduct = availableProducts.FirstOrDefault(obj => obj.ProductId.ToString().Equals(Product_Search_Textbox.Text) || obj.ProductName.Equals(selectedProductId));

            if (selectedProduct == null)
            {
                return;
            }
            Product_Search_Textbox.Text = selectedProduct.ProductId.ToString();
            Product_Name_Textbox.Text   = selectedProduct.ProductName;
            Retail_Price_Textbox.Text   = string.Format("{0:0.00}", selectedProduct.RetailPrice);
            Available_Qty_Textbox.Text  = string.Format("{0:0.00}", selectedProduct.Quantity);
            Gst_Percent_Textbox.Text    = selectedProduct.GSTPercentage.ToString();
            HideResults();
            if (selectedProduct.Quantity != 0)
            {
                Quantity_textBox.Focus();
                Quantity_textBox.ReadOnly = false;
            }
            else
            {
                if (MessageBox.Show("Selected Product Is Not Available, It's Available Quantity is Zero", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop) == DialogResult.OK)
                {
                    Product_Search_Textbox.Focus();
                    Product_Search_Textbox.Text = Product_Name_Textbox.Text = Retail_Price_Textbox.Text = string.Empty;
                    Available_Qty_Textbox.Text  = Gst_Percent_Textbox.Text = string.Empty;
                }
            }
        }
예제 #2
0
 private void Reset_button_Click(object sender, EventArgs e)
 {
     Book_ID_textBox.Clear();
     Book_Name_textBox.Clear();
     Author_textBox.Clear();
     Category_textBox.Clear();
     Quantity_textBox.Clear();
     Arrival_Date_textBox.Clear();
 }
        private void Add_button_Click(object sender, EventArgs e)
        {
            decimal purchasedQuantity = 0;
            decimal purchasedPrice    = 0;
            decimal gstDividend       = 0;
            decimal selectedProductBillAmount;
            decimal selectedProductGSTAmount;

            try
            {
                Product_Search_Textbox.Focus();

                if (!string.IsNullOrWhiteSpace(Quantity_textBox.Text) && decimal.TryParse(Quantity_textBox.Text, out decimal quantityValidaton))
                {
                    purchasedQuantity = Convert.ToDecimal(Quantity_textBox.Text);
                    purchasedPrice    = Convert.ToDecimal(Retail_Price_Textbox.Text);
                }

                if (Product_Search_Textbox.Text == string.Empty)
                {
                    Error_Message_Label.Text = Constants.SELECT_ANY_PRODUCT_ERROR_MESSAGE;
                    HideWarningMessage();
                    Product_Search_Textbox.Focus();
                }
                else if (purchasedQuantity == 0)
                {
                    Error_Message_Label.Text = Constants.ENTER_VALID_QUANTITY_ERROR_MESSAGE;
                    HideWarningMessage();
                    Quantity_textBox.Focus();
                }
                else if (purchasedQuantity > Convert.ToDecimal(Available_Qty_Textbox.Text))
                {
                    MessageBox.Show("Entered Quantity Is Greater Than Available Quantity", "Information", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    Quantity_textBox.Focus();
                }
                else
                {
                    selectedProductBillAmount = purchasedQuantity * purchasedPrice;
                    if (Gst_Percent_Textbox.Text != "0")
                    {
                        gstDividend = Convert.ToDecimal(Gst_Percent_Textbox.Text) / 100;
                    }
                    selectedProductGSTAmount = selectedProductBillAmount * gstDividend;

                    BilledProducts_GridView.Rows.Add((BilledProducts_GridView.Rows.Count + 1).ToString(), Product_Search_Textbox.Text, Product_Name_Textbox.Text, string.Format("{0:0.00}", purchasedQuantity), string.Format("{0:0.00}", purchasedPrice), string.Format("{0:0.00}", selectedProductBillAmount), Gst_Percent_Textbox.Text, string.Format("{0:0.00}", selectedProductGSTAmount), string.Format("{0:0.00}", selectedProductGSTAmount + selectedProductBillAmount));

                    if (BillAmount_Textbox.Text == string.Empty)
                    {
                        BillAmount_Textbox.Text     = string.Format("{0:0.00}", selectedProductBillAmount);
                        GSTAmount_TextBox.Text      = string.Format("{0:0.00}", selectedProductGSTAmount);
                        Total_Bill_Qty_Textbox.Text = string.Format("{0:0}", purchasedQuantity);
                        Total_Amount_Textbox.Text   = string.Format("{0:0.00}", Math.Round(selectedProductBillAmount + selectedProductGSTAmount, MidpointRounding.ToEven));
                    }
                    else
                    {
                        BillAmount_Textbox.Text     = string.Format("{0:0.00}", Convert.ToDecimal(BillAmount_Textbox.Text) + selectedProductBillAmount);
                        GSTAmount_TextBox.Text      = string.Format("{0:0.00}", Convert.ToDecimal(GSTAmount_TextBox.Text) + selectedProductGSTAmount);
                        Total_Bill_Qty_Textbox.Text = string.Format("{0:0}", Convert.ToDecimal(Total_Bill_Qty_Textbox.Text) + purchasedQuantity);
                        Total_Amount_Textbox.Text   = string.Format("{0:0.00}", Math.Round(Convert.ToDecimal(Total_Amount_Textbox.Text) + selectedProductBillAmount + selectedProductGSTAmount, MidpointRounding.ToEven));
                    }

                    Quantity_textBox.ReadOnly = true;
                    AssignEmptyToAvailableTextboxes();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.StackTrace.ToString(), "Error Occured at Bill Page", MessageBoxButtons.OK);
            }
        }