Example #1
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;
                }
            }
        }
Example #2
0
        public void loadData()
        {
            Database db = new Database();

            db.openConnection();

            String q1 = "SELECT * FROM rental_details";

            db.sqlQuery(q1);
            DataTable dt = db.executeQuery();

            bunifuCustomDataGrid1.DataSource = dt;


            for (int i = 0; i < bunifuCustomDataGrid1.Columns.Count; i++)
            {
                bunifuCustomDataGrid1.Columns[i].Visible = false;
            }

            bunifuCustomDataGrid1.Columns[0].Visible    = true;
            bunifuCustomDataGrid1.Columns[0].HeaderText = "Rent ID";
            bunifuCustomDataGrid1.Columns[1].Visible    = true;
            bunifuCustomDataGrid1.Columns[1].HeaderText = "Customer ID";
            bunifuCustomDataGrid1.Columns[2].Visible    = true;
            bunifuCustomDataGrid1.Columns[2].HeaderText = "Vehicle ID";
            bunifuCustomDataGrid1.Columns[3].Visible    = true;
            bunifuCustomDataGrid1.Columns[3].HeaderText = "Rent Date";
            bunifuCustomDataGrid1.Columns[4].Visible    = true;
            bunifuCustomDataGrid1.Columns[4].HeaderText = "Return Date";
            bunifuCustomDataGrid1.Columns[5].Visible    = true;
            bunifuCustomDataGrid1.Columns[5].HeaderText = "Minimum Deposit";


            //get customer id's to combo box
            String q2 = "SELECT c_code FROM customers";

            db.sqlQuery(q2);
            DataTable table = db.executeQuery();

            // select distinct valuves to the combo box
            IList <string> list1 = new List <string>();

            foreach (DataRow dr in table.Rows)
            {
                list1.Add("Select Customer");
                list1.Add(dr["c_code"].ToString());
            }

            list1 = list1.Distinct().ToList();
            cmb_cus_id.DataSource = list1;



            //get Available Vehicle's to combo box
            String q3 = "SELECT rv_id FROM rental_vehicle WHERE rv_status = 'Available'";

            db.sqlQuery(q3);
            DataTable table1 = db.executeQuery();

            // select distinct valuves to the combo box
            IList <string> list = new List <string>();

            foreach (DataRow dr in table1.Rows)
            {
                list.Add("Select A Vehicle");
                list.Add(dr["rv_id"].ToString());
            }

            list = list.Distinct().ToList();
            cmb_vehicle_id.DataSource = list;

            db.closeConnection();

            btn_update.Visible = false;
            btn_remove.Visible = false;
            btn_add.Enabled    = true;

            clear();
            txt_rnt_id.Text = CodeGenerator.generateRentalDetailsCode();
        }
Example #3
0
        private void bunifuFlatButton1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtName.Text) && string.IsNullOrWhiteSpace(txtAddress.Text) && string.IsNullOrWhiteSpace(txttelephone.Text))
            {
                MyDialog.Show("Error...!", "Please fill Personal details");
            }

            else
            {
                if (txtName.Enabled)
                {
                    String Cus_id = CodeGenerator.generateSalescustomercode();

                    string   query = "INSERT INTO salescustomer VALUES('" + Cus_id + "','" + txtName.Text + "','" + txtAddress.Text + "','" + txtAddress.Text + "')";
                    Database db    = new Database();
                    db.openConnection();
                    db.sqlQuery(query);

                    if (db.nonQuery())
                    {
                        MyDialog.Show("Success...!", "Customer added");
                    }
                    else
                    {
                        MyDialog.Show("Error...!", "Customer not added");
                    }


                    string SalesID = CodeGenerator.generateSalescode();

                    string query1 = "INSERT INTO sales VALUES('" + SalesID + "','" + Cus_id + "','" + totalLabel.Text + "','" + DateTime.Now + "')";

                    db.sqlQuery(query1);

                    if (db.nonQuery())
                    {
                        MyDialog.Show("Success...!", "Sales added");
                    }
                    else
                    {
                        MyDialog.Show("Error...!", "Sales not added");
                    }
                }

                else
                {
                    String CusID = getCusID(txtName.Text);


                    string SalesID = CodeGenerator.generateSalescode();

                    string   query1 = "INSERT INTO sales VALUES('" + SalesID + "','" + CusID + "','" + totalLabel.Text + "','" + DateTime.Now + "')";
                    Database db     = new Database();
                    db.openConnection();
                    db.sqlQuery(query1);

                    if (db.nonQuery())
                    {
                        MyDialog.Show("Success...!", "Sales added");
                    }
                    else
                    {
                        MyDialog.Show("Error...!", "Sales notadded");
                    }
                }

                for (int i = 0; i < SalesdataGrid.Rows.Count; i++)
                {
                    string SIid    = SalesdataGrid.Rows[i].Cells[0].Value.ToString();
                    string Stockid = SalesdataGrid.Rows[i].Cells[1].Value.ToString();
                    string Salesid = SalesdataGrid.Rows[i].Cells[2].Value.ToString();

                    string Description = SalesdataGrid.Rows[i].Cells[3].Value.ToString();

                    float Quntity  = float.Parse(SalesdataGrid.Rows[i].Cells[4].Value.ToString());
                    float Discount = float.Parse(SalesdataGrid.Rows[i].Cells[5].Value.ToString());
                    float price    = float.Parse(SalesdataGrid.Rows[i].Cells[6].Value.ToString());
                    int   rncount  = Convert.ToInt32(SalesdataGrid.Rows[i].Cells[7].Value.ToString());


                    Database db = new Database();

                    db.openConnection();
                    string query = "INSERT INTO sales_items(item_id,stock_id,sales_id,description,quantity,discount,price,return_cnt) VALUES('" + SIid + "','" + Stockid + "','" + Salesid + "','" + Description + "','" + Quntity + "','" + Discount + "','" + price + "','" + rncount + "')";


                    db.sqlQuery(query);

                    if (db.nonQuery())
                    {
                        MyDialog.Show("Success...!", "Sale Item added");
                    }
                    else
                    {
                        MyDialog.Show("Error...!", "Sale Item not added");
                    }
                }



                new Sales_Bill().Show();
                totalLabel.Text = "0.0";
            }
        }