示例#1
0
        private void pay_button_Click(object sender, EventArgs e)
        {
            try
            {
                if (gross_textBox.Text != "" && discount_textBox.Text != "" && payment_Type_comboBox.SelectedIndex != -1 && change_to_give_textBox.Text != "" && amount_given_textBox.Text != "")
                {
                    Hashtable ht = new Hashtable();

                    ht.Add("@done", LoginCodeClass.USERID);

                    ht.Add("@date", DateTime.Now);

                    ht.Add("@totalamt", Convert.ToSingle(gross_textBox.Text));

                    ht.Add("@totaldisc", Convert.ToSingle(discount_textBox.Text));

                    ht.Add("@givenamt", Convert.ToSingle(amount_given_textBox.Text));

                    ht.Add("@return", Convert.ToSingle(change_to_give_textBox.Text));

                    if (payment_Type_comboBox.SelectedIndex == 0)
                    {
                        ht.Add("@payType", 0); //0 means cash
                    }
                    else if (payment_Type_comboBox.SelectedIndex == 1)
                    {
                        ht.Add("@payType", 1);//1 means debit
                    }
                    else
                    {
                        ht.Add("@payType", 2);
                    }                               //2 means credit

                    DialogResult dr = MessageBox.Show("\n\tTotal Amount: " + gross_textBox.Text + "\n\tTotal Discount: " + discount_textBox.Text + "\n\tAmount Given: " + amount_given_textBox.Text + "\n\tAmount to return: " + change_to_give_textBox.Text + "\n\tPayment Type: " + payment_Type_comboBox.SelectedItem.ToString() + " \n\nAre you sure you want to submit current sales?", "Question...", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                    if (DialogResult.Yes == dr)
                    {
                        using (TransactionScope sc = new TransactionScope())
                        {
                            if (SQL_TASKS.insert_update_delete("st_insertSALES", ht) > 0)
                            {
                                foreach (DataGridViewRow row in sales_dataGridView.Rows)
                                {
                                    int CurrentProductQuan = SQL_TASKS.getStockwrtProduct(Convert.ToInt32(row.Cells["ProductIDGV"].Value));

                                    Hashtable ht1 = new Hashtable();

                                    int x = CurrentProductQuan - Convert.ToInt32(row.Cells["ProductquantityGV"].Value);

                                    ht1.Add("@prodID", Convert.ToInt32(row.Cells["ProductIDGV"].Value));

                                    ht1.Add("@quan", x);

                                    SQL_TASKS.insert_update_delete("st_updateSTOCK", ht1);

                                    Hashtable ht2 = new Hashtable();

                                    ht2.Add("@saleID", SQL_TASKS.getLASTID("st_getSalesID"));

                                    ht2.Add("@prodID", Convert.ToInt64(row.Cells["productIDGV"].Value.ToString()));

                                    ht2.Add("@quantity", Convert.ToInt32(row.Cells["productquantityGV"].Value.ToString()));

                                    ht2.Add("@discount", Convert.ToSingle(row.Cells["discountGV"].Value.ToString()));

                                    ht2.Add("@sellingprice", Convert.ToSingle(row.Cells["TotalAmountGV"].Value.ToString()));

                                    SQL_TASKS.insert_update_delete("st_insertSalesDetails", ht2);
                                }

                                MainClass.ShowMsg("Record saved successfully.", "Success");

                                MainClass.disbale_reset(left_panel_sample2);

                                sales_dataGridView.Rows.Clear();

                                SALES_REPORT sr = new SALES_REPORT();

                                sr.ShowDialog();

                                gross_total_price_label.Text = "0.00";
                            }
                            else
                            {
                                throw new Exception("Unable to save record.");
                            }
                            sc.Complete();
                        }
                    }
                }
                else
                {
                    throw new Exception("Please fill all required fields.");
                }
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");
            }
        }