protected void btnSave_Click(object sender, EventArgs e) { //id, customerid, invoiceid, reason, disctypepercentage, amount, freightdiscount, createddate, isdeleted Decimal amount = 0; String disctypepercentage = String.Empty; Int64 Result = 0; if (Convert.ToDecimal(txttradDis.Text) > 0) { disctypepercentage = "Trade Discount " + txttradDis.Text + "%"; amount = Convert.ToDecimal(txttradAmt.Text); } else if (Convert.ToDecimal(txttaxableDis.Text) > 0) { disctypepercentage = "Taxable Discount " + txttaxableDis.Text + "%"; amount = Convert.ToDecimal(txttaxableDisamt.Text); } creditnotes objcreditnotes = new creditnotes(); objcreditnotes.customerid = Convert.ToInt64(hfcustomer.Value); objcreditnotes.invoiceid = Convert.ToInt32(hfinvoiceno.Value); objcreditnotes.reason = hfreason.Value; objcreditnotes.disctypepercentage = disctypepercentage; objcreditnotes.amount = amount; objcreditnotes.freightdiscount = Convert.ToDecimal(txtfreightdis.Text); objcreditnotes.otheramount = Convert.ToDecimal(txtotherAmt.Text); Result = (new Cls_creditnotes_b().Insert(objcreditnotes)); if (Result > 0) { Clear(); spnMessgae.InnerText = "Credit Note Saved Successfully !!!"; //Response.Redirect(Page.ResolveUrl("~/manageEmployee.aspx?mode=i")); Response.Redirect("addCreditNoteInvoice.aspx?id=" + Result); } else { Clear(); spnMessgae.Style.Add("color", "red"); spnMessgae.InnerText = "Credit Note Not Saved..."; } }
/* * public DataTable SelectAll() * { * DataSet ds = new DataSet(); * SqlDataAdapter da; * try * { * SqlCommand cmd = new SqlCommand(); * cmd.CommandText = "creditnotes_SelectAll"; * cmd.CommandType = CommandType.StoredProcedure; * cmd.Connection = ConnectionString; * ConnectionString.Open(); * da = new SqlDataAdapter(cmd); * da.Fill(ds); * } * catch (Exception ex) * { * ErrHandler.writeError(ex.Message, ex.StackTrace); * return null; * } * finally * { * ConnectionString.Close(); * } * return ds.Tables[0]; * } * * * public creditnotes SelectById(Int64 oid) * { * SqlDataAdapter da; * DataSet ds = new DataSet(); * creditnotes objcreditnotes = new creditnotes(); * try * { * SqlCommand cmd = new SqlCommand(); * cmd.CommandText = "creditnotes_SelectById"; * cmd.CommandType = CommandType.StoredProcedure; * cmd.Connection = ConnectionString; * cmd.Parameters.AddWithValue("@o" + * "id", oid); * ConnectionString.Open(); * da = new SqlDataAdapter(cmd); * da.Fill(ds); * * if (ds != null) * { * if (ds.Tables.Count > 0) * { * if (ds.Tables[0] != null) * { * if (ds.Tables[0].Rows.Count > 0) * { * { * objcreditnotes.oid = Convert.ToInt64(ds.Tables[0].Rows[0]["oid"]); * objcreditnotes.uid = Convert.ToInt64(ds.Tables[0].Rows[0]["uid"]); * objcreditnotes.productquantites = Convert.ToInt32(ds.Tables[0].Rows[0]["productquantites"]); * objcreditnotes.billpaidornot = string.IsNullOrEmpty(ds.Tables[0].Rows[0]["billpaidornot"].ToString()) ? false : Convert.ToBoolean(ds.Tables[0].Rows[0]["billpaidornot"]); * objcreditnotes.amount = Convert.ToDecimal(ds.Tables[0].Rows[0]["amount"]); * objcreditnotes.discount = Convert.ToDecimal(ds.Tables[0].Rows[0]["discount"]); * objcreditnotes.tax = Convert.ToDecimal(ds.Tables[0].Rows[0]["tax"]); * objcreditnotes.totalamount = Convert.ToDecimal(ds.Tables[0].Rows[0]["totalamount"]); * objcreditnotes.orderdate = string.IsNullOrEmpty(ds.Tables[0].Rows[0]["orderdate"].ToString()) ? DateTime.MinValue : Convert.ToDateTime(ds.Tables[0].Rows[0]["orderdate"]); * objcreditnotes.isdelete = string.IsNullOrEmpty(ds.Tables[0].Rows[0]["isdelete"].ToString()) ? false : Convert.ToBoolean(ds.Tables[0].Rows[0]["isdelete"]); * } * } * } * } * } * } * catch (Exception ex) * { * ErrHandler.writeError(ex.Message, ex.StackTrace); * return null; * } * finally * { * ConnectionString.Close(); * } * return objcreditnotes; * } */ public Int64 Insert(creditnotes objcreditnotes) { //id, customerid, invoiceid, reason, disctypepercentage, amount, freightdiscount, createddate, isdeleted Int64 result = 0; try { SqlCommand cmd = new SqlCommand(); cmd.CommandText = "creditnotes_Insert"; cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = ConnectionString; SqlParameter param = new SqlParameter(); param.ParameterName = "@id"; param.Value = objcreditnotes.id; param.SqlDbType = SqlDbType.BigInt; param.Direction = ParameterDirection.InputOutput; cmd.Parameters.Add(param); cmd.Parameters.AddWithValue("@customerid", objcreditnotes.customerid); cmd.Parameters.AddWithValue("@invoiceid", objcreditnotes.invoiceid); cmd.Parameters.AddWithValue("@reason", objcreditnotes.reason); cmd.Parameters.AddWithValue("@disctypepercentage", objcreditnotes.disctypepercentage); cmd.Parameters.AddWithValue("@amount", objcreditnotes.amount); cmd.Parameters.AddWithValue("@freightdiscount", objcreditnotes.freightdiscount); cmd.Parameters.AddWithValue("@otheramount", objcreditnotes.otheramount); ConnectionString.Open(); cmd.ExecuteNonQuery(); result = Convert.ToInt64(param.Value); } catch (Exception ex) { ErrHandler.writeError(ex.Message, ex.StackTrace); return(result); } finally { ConnectionString.Close(); } return(result); }