Пример #1
0
 private void resetFields()
 {
     try
     {
         SalesdataGrid.ClearSelection();
     }
     catch (Exception e)
     {
         Console.Write(e.Message);
     }
     Nametxt.Text      = string.Empty;
     Quntitytxt.Text   = string.Empty;
     Telephonetxt.Text = string.Empty;
     Addresstxt.Text   = string.Empty;
     itemidtxt.Text    = string.Empty;
     Discounttxt.Text  = string.Empty;
 }
Пример #2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtItemID.Text) || string.IsNullOrWhiteSpace(txtQuty.Text) || string.IsNullOrWhiteSpace(txtDiscount.Text))
            {
                MyDialog.Show("Error...!", "All Fields should be filled");
            }
            else
            {
                int selectedrowindex = ItemsdataGrid.SelectedCells[0].RowIndex;

                DataGridViewRow selectedRow = ItemsdataGrid.Rows[selectedrowindex];

                string ItemID      = Convert.ToString(selectedRow.Cells[0].Value);
                string description = Convert.ToString(selectedRow.Cells[2].Value);
                string unitPrice   = Convert.ToString(selectedRow.Cells[5].Value);
                string Quntity     = Convert.ToString(selectedRow.Cells[4].Value);
                float  QuntityF    = float.Parse(Quntity);
                float  unitprice1  = float.Parse(unitPrice);
                float  fQuntity    = float.Parse(txtQuty.Text);
                float  TOt         = unitprice1 * fQuntity;
                float  Discount    = float.Parse(txtDiscount.Text);
                if (fQuntity > QuntityF)
                {
                    MyDialog.Show("Error...!", "Invalid Quantity");
                    resetFields1();
                }

                else if (Discount >= TOt)
                {
                    MyDialog.Show("Error...!", "Invalid Discount Amount");
                    resetFields1();
                }
                else

                {
                    float total = float.Parse(totalLabel.Text);
                    total           = total + unitprice1 * float.Parse(txtQuty.Text) - float.Parse(txtDiscount.Text);
                    totalLabel.Text = Convert.ToString(total);
                    string SalsItemID = CodeGenerator.generateSalesItemCode();
                    string SalsID     = CodeGenerator.generateSalescode();


                    if (SalesdataGrid.Rows.Count == 0)
                    {
                        QuntityF = QuntityF - float.Parse(txtQuty.Text);
                        updateStocks(ItemID, QuntityF);
                        lodesalesItem(SalsItemID, ItemID, SalsID, description, txtQuty.Text, txtDiscount.Text, unitPrice, "0");

                        int             selectedrowindex1 = SalesdataGrid.SelectedCells[0].RowIndex;
                        DataGridViewRow selectedRow1      = SalesdataGrid.Rows[selectedrowindex1];
                        ItemID1 = Convert.ToString(selectedRow1.Cells[0].Value);

                        resetFields1();
                    }
                    else
                    {
                        int             selectedrowindex1 = SalesdataGrid.SelectedCells[0].RowIndex;
                        DataGridViewRow selectedRow1      = SalesdataGrid.Rows[selectedrowindex1];
                        ItemID1 = Convert.ToString(selectedRow1.Cells[0].Value);
                        String XItemID1  = Convert.ToString(selectedRow1.Cells[1].Value);
                        String sDescount = Convert.ToString(selectedRow1.Cells[5].Value);
                        String Squntity  = Convert.ToString(selectedRow1.Cells[4].Value);

                        float SFQuntity  = float.Parse(Squntity);
                        float SFDescount = float.Parse(sDescount);

                        float RealQuntity  = SFQuntity + float.Parse(txtQuty.Text);
                        float RealDescount = SFDescount + float.Parse(txtDiscount.Text);

                        float QuntityF1 = float.Parse(Quntity);
                        QuntityF1 = QuntityF1 - float.Parse(txtQuty.Text);

                        if (ItemID == XItemID1)
                        {
                            selectedRow1.Cells[4].Value = Convert.ToString(RealQuntity);
                            selectedRow1.Cells[5].Value = Convert.ToString(RealDescount);
                            updateStocks(ItemID, QuntityF1);
                        }
                        else
                        {
                            String NUMBER_FORMAT = "{0:D4}";
                            string SalsItemID1   = ItemID1.Substring(2);
                            string SalesItemid   = ("SI" + String.Format(NUMBER_FORMAT, (Convert.ToInt32(SalsItemID1) + 1)));
                            updateStocks(ItemID, QuntityF1);
                            lodesalesItem(SalesItemid, ItemID, SalsID, description, txtQuty.Text, txtDiscount.Text, unitPrice, "0");

                            resetFields1();
                        }
                    }

                    SalesdataGrid.Sort(SalesdataGrid.Columns["ItemID"], ListSortDirection.Descending);
                    SalesdataGrid.Rows[0].Selected = true;
                }
            }
        }