public bool Insert(Transactionbll u, out int transactionid)
        {
            bool issuccess = false;

            transactionid = -1;
            SqlConnection conn = new SqlConnection(myconnstring);

            try
            {
                String     sql = "INSERT INTO transactions_tbl(Type,dea_cust_id,Grand_total,transaction_date,tax,discount,added_by) VALUES (@Type,@dea_cust_id,@Grand_total,@transaction_date,@tax,@discount,@added_by) ; SELECT @@IDENTITY;";
                SqlCommand cmd = new SqlCommand(sql, conn);

                cmd.Parameters.AddWithValue("@Type", u.Type);
                cmd.Parameters.AddWithValue("@dea_cust_id", u.dea_cust_id);
                cmd.Parameters.AddWithValue("@Grand_total", u.Grand_total);
                cmd.Parameters.AddWithValue("@transaction_date", u.transaction_date);
                cmd.Parameters.AddWithValue("@tax", u.tax);
                cmd.Parameters.AddWithValue("@discount", u.discount);
                cmd.Parameters.AddWithValue("@added_by", u.added_by);
                conn.Open();
                object o = cmd.ExecuteScalar();
                if (o != null)
                {
                    transactionid = int.Parse(o.ToString());
                    issuccess     = true;
                }
                else
                {
                    issuccess = false;
                }
            }
            catch (Exception e)

            {
                MessageBox.Show(e.Message);
            }
            finally
            {
                conn.Close();
            }



            return(issuccess);
        }
Exemplo n.º 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            Transactionbll transaction = new Transactionbll();

            transaction.Type = label1.Text;
            string dea_csname = dcname.Text;
            DCbll  dc         = dcdal.getid(dea_csname);

            transaction.dea_cust_id      = dc.id;
            transaction.Grand_total      = Math.Round(decimal.Parse(grandtotal.Text), 2);
            transaction.transaction_date = DateTime.Now;
            transaction.tax      = decimal.Parse(vat.Text);
            transaction.discount = decimal.Parse(discount.Text);
            string  usrname = Formlogin.loggdin;
            userbll u       = udal.getid(usrname);

            transaction.added_by           = u.id;
            transaction.transactiondetails = transactiondt;

            bool success = false;

            //inserting transaction and transaction details
            using (TransactionScope scope = new TransactionScope())

            {
                int  transactionid = -1;
                bool w             = tdal.Insert(transaction, out transactionid);

                for (int i = 0; i < transactiondt.Rows.Count; i++)
                {
                    trnsctiondetailbll tddetail = new trnsctiondetailbll();
                    String             prdname  = transactiondt.Rows[i][0].ToString();
                    productsbll        p        = pdal.getpid(prdname);
                    tddetail.pid = p.id;

                    tddetail.rate        = decimal.Parse(transactiondt.Rows[i][1].ToString());
                    tddetail.qty         = decimal.Parse(transactiondt.Rows[i][2].ToString());
                    tddetail.Total       = Math.Round(decimal.Parse(transactiondt.Rows[i][3].ToString()), 2);
                    tddetail.dea_cust_id = dc.id;
                    tddetail.added_date  = DateTime.Now;
                    tddetail.added_by    = u.id;
                    //INC OR DEC QTY
                    string ttype = label1.Text;
                    bool   x     = false;
                    if (ttype == "PURCHASE")
                    {
                        x = pdal.increaseqty(tddetail.pid, tddetail.qty);
                    }
                    else if (ttype == "SALES")
                    {
                        x = pdal.decreaseqty(tddetail.pid, tddetail.qty);
                    }



                    bool y = tddal.Insert(tddetail);

                    success = w && y && x;
                }
                if (success == true)
                {
                    scope.Complete();
                    DGVPrinter print = new DGVPrinter();
                    print.Title               = "\r\n\r\n MIKE'S STORES  PVT LTD \r\n";
                    print.SubTitle            = "KOCHI ,KERALA ,phone - +919537583616\r\n\r\n";
                    print.SubTitleFormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoClip;
                    print.PageNumbers         = true;
                    print.PageNumberInHeader  = false;
                    print.PorportionalColumns = true;
                    print.HeaderCellAlignment = StringAlignment.Near;
                    print.Footer              = "Discount :" + discount.Text + "% \r\n" + "vat :" + vat.Text + "%\r\n" + "GRAND_TOTAL:" + grandtotal.Text + "\r\n" + "Date & time of purchase:" + dateTimePicker1.Value + "\r\n\r" + " THANK YOU";
                    print.FooterSpacing       = 40;
                    print.PrintDataGridView(dgvproducts);

                    MessageBox.Show("TRANSACTION C0MPLETED SUCCESSFULLY");
                    dgvproducts.DataSource = null;
                    dgvproducts.Rows.Clear();
                    dgvproducts.DataSource = null;
                    dgvproducts.Rows.Clear();
                    dcsearch.Text  = "";
                    dcname.Text    = "";
                    dcemail.Text   = "";
                    dccontact.Text = "";
                    dcaddress.Text = "";
                    clear();
                    sbtotal.Text    = "";
                    discount.Text   = "0";
                    grandtotal.Text = "0";
                    vat.Text        = "0";
                    PA.Text         = "0";
                    RA.Text         = "0";
                }



                else
                {
                    MessageBox.Show("TRANSACTION FAILED");
                }
            }
        }