Esempio n. 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrWhiteSpace(this.billToAdd.Text) && !String.IsNullOrWhiteSpace(this.deliveryToAdd.Text) && !String.IsNullOrWhiteSpace(this.txtTax.Text) && !String.IsNullOrWhiteSpace(this.txtFright.Text))
            {
                BillData billData = new BillData();
                billData.BillToAdd     = this.billToAdd.Text;
                billData.DeliveryToAdd = this.deliveryToAdd.Text;
                billData.InvoiceNo     = Convert.ToInt64(this.lblInvoiceNo.Text);
                billData.yourRefNo     = this.yourRefNo.Text;
                billData.ourRefNo      = this.ourRefNo.Text;
                billData.tax           = Convert.ToDouble(this.txtTax.Text);
                billData.freight       = Convert.ToDouble(this.txtFright.Text);

                BillItems        billItms;
                List <BillItems> lstBillItms = new List <BillItems>();
                foreach (DataGridViewRow dgR in dataGridView1.Rows)
                {
                    if (!String.IsNullOrWhiteSpace(Convert.ToString(dgR.Cells["ItmDescription"].Value)) && !String.IsNullOrWhiteSpace(Convert.ToString(dgR.Cells["Quantity"].Value)) && !String.IsNullOrWhiteSpace(Convert.ToString(dgR.Cells["Quantity"].Value)))
                    {
                        billItms = new BillItems();
                        billItms.ItmDescription = Convert.ToString(dgR.Cells["ItmDescription"].Value);
                        billItms.Quantity       = Convert.ToDouble(dgR.Cells["Quantity"].Value);
                        billItms.Rate           = Convert.ToDouble(dgR.Cells["Quantity"].Value);
                        lstBillItms.Add(billItms);
                    }
                }
                billData.billItms = lstBillItms;

                DataAccess dataAcc = new DataAccess();
                if (dataAcc.SaveData(billData))
                {
                    this.lblInvoiceNo.Text = dataAcc.getInvoiceNumber();
                    MessageBox.Show("Bill Saved Successfuly");
                }
            }
        }
Esempio n. 2
0
        public bool SaveData(BillData billData)
        {
            bool          chkBool = false;
            Int64         chkflag = 0;
            SqlConnection con     = new SqlConnection(conStr);

            try
            {
                SqlParameter[] para = new SqlParameter[] {
                    new SqlParameter("BillToAdd", billData.BillToAdd),
                    new SqlParameter("DeliverytoAdd", billData.DeliveryToAdd),
                    new SqlParameter("InvoiceNo", billData.InvoiceNo),
                    new SqlParameter("yourRefNo", billData.yourRefNo),
                    new SqlParameter("ourRefNo", billData.ourRefNo),
                    new SqlParameter("tax", billData.tax),
                    new SqlParameter("freight", billData.freight),
                    new SqlParameter("billID", SqlDbType.BigInt, Int32.MaxValue),
                };
                SqlCommand com = new SqlCommand("InBillMst", con);
                com.Parameters.AddRange(para);
                com.Parameters["billID"].Direction = ParameterDirection.Output;
                com.CommandType = CommandType.StoredProcedure;
                con.Open();
                chkflag = com.ExecuteNonQuery();
                if (chkflag > 0)
                {
                    chkflag = Convert.ToInt64(com.Parameters["billID"].Value);

                    if (chkflag > 0)
                    {
                        //Loop insert for bill details.
                        foreach (BillItems BillItm in billData.billItms)
                        {
                            para = new SqlParameter[] {
                                new SqlParameter("BillId", chkflag),
                                new SqlParameter("ItmDescription", BillItm.ItmDescription),
                                new SqlParameter("Quantity", BillItm.Quantity),
                                new SqlParameter("Rate", BillItm.Rate)
                            };
                            com = new SqlCommand("InBillDetail", con);
                            com.Parameters.AddRange(para);
                            com.CommandType = CommandType.StoredProcedure;
                            com.ExecuteNonQuery();
                        }
                    }
                    chkBool = true;
                }
                con.Close();
            }
            catch (Exception ex)
            {
                chkBool = false;
            }
            finally
            {
                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
            }
            return(chkBool);
        }