public bool insertsales(salesBLL s, out int salesID)
        {
            bool isSuccess = false;

            salesID = -1;
            SqlConnection con = new SqlConnection(myconnstrng);

            try
            {
                String sql = "INSERT INTO tbl_transactions (type,dea_cust_id,grandTotal,transaction_date,tax,discount,added_by) VALUES(@type,@custid,@grandTotal,@salesdate,@gst,@discount,@added_by);select @@IDENTITY;";

                SqlCommand cmd = new SqlCommand(sql, con);
                cmd.Parameters.AddWithValue("@type", "Sales");
                cmd.Parameters.AddWithValue("@custid", s.custid);
                cmd.Parameters.AddWithValue("@grandtotal", s.grandtotal);
                cmd.Parameters.AddWithValue("@salesdate", s.salesdate);
                cmd.Parameters.AddWithValue("@gst", s.gst);
                cmd.Parameters.AddWithValue("@discount", s.discount);
                cmd.Parameters.AddWithValue("@added_by", 8);

                con.Open();
                //open connection

                object o = cmd.ExecuteScalar();

                if (o != null)
                {
                    isSuccess = true;
                    salesID   = int.Parse(o.ToString());
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }
            return(isSuccess);
        }
Beispiel #2
0
        public void save()
        {
            salesBLL sales = new salesBLL();

            string cname = txtName.Text;

            if (cname != "")
            {
                customerBLL c = cDAL.getCustomerIdFromName(cname);

                sales.salesdate  = dtpBillDate.Value;
                sales.custid     = c.id;
                sales.grandtotal = decimal.Parse(txtGrandTotal.Text);
                sales.gst        = decimal.Parse(txtGst.Text);
                sales.discount   = decimal.Parse(txtDiscount.Text);

                sales.salesdetails = salesdt;
                bool isSuccess = false;

                // using (TransactionScope scope = new TransactionScope())
                {
                    int  salesid = -1;
                    bool b       = s.insertsales(sales, out salesid);
                    for (int i = 0; i < salesdt.Rows.Count; i++)
                    {
                        salesdetailsBLL sdb         = new salesdetailsBLL();
                        string          productName = salesdt.Rows[i][1].ToString();

                        productBLL p = pDAL.GetProductIDFromName(productName);

                        sdb.productid = p.id;
                        sdb.rate      = decimal.Parse(salesdt.Rows[i][2].ToString());
                        sdb.qty       = decimal.Parse(salesdt.Rows[i][3].ToString());
                        sdb.total     = Math.Round(decimal.Parse(salesdt.Rows[i][4].ToString()), 2);
                        sdb.custid    = c.id;
                        sdb.addeddate = dtpBillDate.Value;

                        if (b == true)
                        {
                            bool x = pDAL.DecreaseProduct(sdb.productid, sdb.qty);
                        }

                        bool y = sd.insertsalesdetails(sdb);
                        isSuccess = b && y;
                    }
                    if (isSuccess == true)
                    {
                        //scope.Complete();
                        MessageBox.Show("Transaction Completed");
                        clear();
                    }
                    else
                    {
                        MessageBox.Show("Transaction Failed");
                    }
                }
            }
            else
            {
                MessageBox.Show("Please Select Customer Details");
            }
        }