protected void SaveButton_Click(object sender, EventArgs e) { SqlTransaction transaction = null; var sql = _MainRepository.ConnectionString(); using (SqlConnection Sqlcon = new SqlConnection(sql)) { Sqlcon.Open(); transaction = Sqlcon.BeginTransaction(); try { AccountSales _AccountSales = new AccountSales(); _AccountSales.Serial = txtSerial.Text; _AccountSales.CashierName = txtCashierName.Text; _AccountSales.CustomerName = txtCustomerName.Text; _AccountSales.GrandTotal = Convert.ToDecimal(txtTotalCost.Text); _AccountSales.Discount = Convert.ToDecimal(txtDiscount.Text); _AccountSales.PaidAmount = Convert.ToDecimal(txtPaidAmount.Text); _AccountSales.ChangesAmount = Convert.ToDecimal(lblChanges.Text); SqlCommand command1 = new SqlCommand("Insert Into AccountSales(Serial,CashierName,CustomerName,GrandTotal,Discount,PaidAmount,ChangesAmount,Date) Values ('" + _AccountSales.Serial + "','" + _AccountSales.CashierName + "','" + _AccountSales.CustomerName + "','" + _AccountSales.GrandTotal + "','" + _AccountSales.Discount + "','" + _AccountSales.PaidAmount + "','" + _AccountSales.ChangesAmount + "','" + DateTime.Now.ToShortDateString() + "')", Sqlcon, transaction); command1.CommandType = CommandType.Text; command1.ExecuteNonQuery(); //AccountSale Save; //ItemSales Start With foreach DataTable dt = (DataTable)ViewState["Details"]; foreach (DataRow dr in dt.Rows) { ItemSales _ItemSales = new ItemSales(); _ItemSales.Name = dr["Name"].ToString(); _ItemSales.Qty = Convert.ToInt32(dr["Qty"].ToString()); _ItemSales.Per_Price = Convert.ToDecimal(dr["Perprice"].ToString()); _ItemSales.Sub_Price = Convert.ToDecimal(dr["Subprice"].ToString()); _ItemSales.Serial = txtSerial.Text; SqlCommand command = new SqlCommand("Insert Into ItemSales(Name,Qty,Per_Price,Sub_Price,Serial,Date) Values ('" + _ItemSales.Name + "','" + _ItemSales.Qty + "','" + _ItemSales.Per_Price + "','" + _ItemSales.Sub_Price + "','" + _ItemSales.Serial + "','" + DateTime.Now.ToShortDateString() + "')", Sqlcon, transaction); command.CommandType = CommandType.Text; command.ExecuteNonQuery(); } transaction.Commit(); Response.Redirect(Request.Url.AbsoluteUri); //CreatePdf(); } catch { transaction.Rollback(); } finally { Sqlcon.Close(); } } }
public AccountSales GetLastCode() { AccountSales _AccountSales = null; string query = "Select top 1 Serial from AccountSales Where Date Between'" + DateTime.Now.ToShortDateString() + "' And '" + DateTime.Now.ToShortDateString() + "' order by Serial desc"; var reader = _MainRepository.Reader(query, _MainRepository.ConnectionString()); if (reader.HasRows) { reader.Read(); _AccountSales = new AccountSales(); _AccountSales.Serial = (reader["Serial"].ToString()); } reader.Close(); return(_AccountSales); }
public int AddAccountSale(AccountSales _AccountSales) { string query = "Insert Into AccountSales(Serial,CashierName,CustomerName,GrandTotal,Discount,PaidAmount,ChangesAmount,Date) Values ('" + _AccountSales.Serial + "','" + _AccountSales.CashierName + "','" + _AccountSales.CustomerName + "','" + _AccountSales.GrandTotal + "','" + _AccountSales.Discount + "','" + _AccountSales.PaidAmount + "','" + _AccountSales.ChangesAmount + "','" + DateTime.Now.ToShortDateString() + "')"; return(_MainRepository.ExecuteNonQuery(query, _MainRepository.ConnectionString())); }