User talk:Jyosana

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using CRUD_EntityModel; using System.Linq.Expressions;

namespace CRUD_DAL {   public class ProductDAL {

public bool Save(List objSave, CustomerMasterTemp objCust) {           using (CRUDDataContext objContext = new CRUDDataContext) {

if (objCust.CustomerPK == 0) objContext.CustomerMasterTemps.InsertOnSubmit(objCust); else objContext.CustomerMasterTemps.Attach(objCust, true);

objContext.SubmitChanges;

foreach (ProductMaster objDetail in objSave) {                   ProductMaster objDel = (from objSQL in objContext.ProductMasters.Where(t => t.ProductID == objDetail.ProductID)                                              select objSQL).FirstOrDefault; if (objDel != null) {                       objContext.ProductMasters.DeleteOnSubmit(objDel); objContext.SubmitChanges; }

objDetail.CustomerMasterFK = objCust.CustomerMasterID;

if (objDetail.ProductID == 0) objContext.ProductMasters.InsertOnSubmit(objDetail); else objContext.ProductMasters.Attach(objDetail, true);

objContext.SubmitChanges; }           }            return true; }   } }

=
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using CRUD_DAL; using CRUD_EntityModel; using System.Transactions;

namespace CRUD_BAL {  public class ProductBAL {      public bool Save(List objsave, CustomerMasterTemp objCust) {          try{

bool blreturn= true; using (TransactionScope objTrans = new TransactionScope) {                  ProductDAL objDAL = new ProductDAL; blreturn = objDAL.Save(objsave, objCust); objTrans.Complete; }              if (blreturn == true) return true; else return false; }          catch(Exception ex) {              throw ex; }      }   } }

=
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Home.aspx.cs" Inherits="CrudWeb.Home" %>

<!DOCTYPE html>

  function CalculateTotal { var total = 0.00; var qty = parseFloat(document.getElementById("txtQty").value); var price = parseFloat(document.getElementById("txtPrice").value); var total = isNaN(parseFloat(qty * price)) ? 0 : (qty * price); document.getElementById("txtTotal").value = total; }     

=
=== using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using CRUD_BAL; using CRUD_EntityModel; namespace CrudWeb {   public partial class Home : System.Web.UI.Page {       #region Page Events ///        /// Handle page Load Event ///        ///          ///

protected void Page_Load(object sender, EventArgs e)       { txtQty.Attributes.Add("onblur", "CalculateTotal('txtQty','txtPrice')"); txtPrice.Attributes.Add("onblur", "CalculateTotal('txtQty','txtPrice')"); if (!Page.IsPostBack) {               DataTable dtCRUD = new DataTable; dtCRUD.Columns.AddRange(new DataColumn[5] { new DataColumn("ProductName"), new DataColumn("ProductDescription"), new DataColumn("Price"), new DataColumn("Qty"), new DataColumn("Total") }); ViewState["CRUDLIST"] = dtCRUD; this.BindGrid; }       }        #endregion

#region Methods ///        /// Bing Grid Detail With Record ///        private void BindGrid {           DataTable dt = (DataTable)ViewState["CRUDLIST"]; gvCRUD.DataSource = dt; gvCRUD.DataBind; if (gvCRUD.Rows.Count > 0) {               decimal d = 0; decimal total = dt.AsEnumerable.Where(r => decimal.TryParse(r.Field ("Total"), out d)).Sum(r => d); gvCRUD.FooterRow.Cells[3].Text = "Total"; gvCRUD.FooterRow.HorizontalAlign = HorizontalAlign.Right; gvCRUD.FooterRow.Cells[4].Text = total.ToString("N2"); // decimal total = dt.AsEnumerable.Sum(row => row.Field("Total") ?? 0); }           btnSave.Visible = gvCRUD.Rows.Count > 0 ? true : false; }       ///         /// Clear TextBox Value ///        private void ClearCRUD {           txtDescription.Text = txtPrice.Text = txtProductName.Text = txtQty.Text = txtTotal.Text = ""; btnAdd.Text = "ADD"; btnSave.Visible = gvCRUD.Rows.Count > 0 ? true : false; }       #endregion #region Control Events ///        /// Handle Add Button Event When Add New Record in Gridview ///        ///          ///          protected void btnAdd_Click(object sender, EventArgs e)        { DataTable dtOrder = (DataTable)ViewState["CRUDLIST"]; if (btnAdd.Text == "ADD") {               dtOrder.Rows.Add(txtProductName.Text, txtDescription.Text, txtPrice.Text, txtQty.Text, txtTotal.Text); }           else if (btnAdd.Text == "Update") {               if (dtOrder.Rows.Count > 0) {                   dtOrder.Rows[Convert.ToInt32(ViewState["Row"])]["ProductName"] = txtProductName.Text; dtOrder.Rows[Convert.ToInt32(ViewState["Row"])]["ProductDescription"] = txtDescription.Text; dtOrder.Rows[Convert.ToInt32(ViewState["Row"])]["Price"] = txtPrice.Text; dtOrder.Rows[Convert.ToInt32(ViewState["Row"])]["Qty"] = txtQty.Text; dtOrder.Rows[Convert.ToInt32(ViewState["Row"])]["Total"] = txtTotal.Text; }           }            ClearCRUD; ViewState["CRUDLIST"] = dtOrder; this.BindGrid; }       ///         /// Handle Clear Button Click ///        ///          ///          protected void btnClear_Click(object sender, EventArgs e)        { ClearCRUD; }       ///         /// Product Detail in Edit Mode ///        ///          ///          protected void btnEdit_Click(object sender, EventArgs e)        { Button btnEdit = (Button)sender; DataTable dtProduct = (DataTable)ViewState["CRUDLIST"]; if (dtProduct.Rows.Count > 0) {               btnAdd.Text = "Update"; ViewState["Row"] = btnEdit.CommandArgument; txtProductName.Text = Convert.ToString(dtProduct.Rows[Convert.ToInt32(btnEdit.CommandArgument)]["ProductName"]); txtDescription.Text = Convert.ToString(dtProduct.Rows[Convert.ToInt32(btnEdit.CommandArgument)]["ProductDescription"]); txtPrice.Text = Convert.ToString(dtProduct.Rows[Convert.ToInt32(btnEdit.CommandArgument)]["Price"]); txtQty.Text = Convert.ToString(dtProduct.Rows[Convert.ToInt32(btnEdit.CommandArgument)]["Qty"]); txtTotal.Text = Convert.ToString(dtProduct.Rows[Convert.ToInt32(btnEdit.CommandArgument)]["Total"]); }       }        ///         /// Product Detail in Delete Mode ///        ///          ///          protected void btnDelete_Click(object sender, EventArgs e)        { Button btnDelete = (Button)sender; DataTable dtProduct = (DataTable)ViewState["CRUDLIST"]; if (dtProduct.Rows.Count > 0) {               dtProduct.Rows.RemoveAt(Convert.ToInt32(btnDelete.CommandArgument)); ViewState["CRUDLIST"] = dtProduct; this.BindGrid; }       }        ///         /// Save Product Record ///        ///          ///          protected void btnSave_Click(object sender, EventArgs e)        { if (gvCRUD.Rows.Count > 0) {

CustomerMasterTemp objCust = new CustomerMasterTemp; objCust.CustomerMasterID = Convert.ToInt32(txtCustomerID.Text); objCust.CustomerName = txtCustomerName.Text;

List objProductList = new List; foreach (GridViewRow row in gvCRUD.Rows) {                   if (row.RowType == DataControlRowType.DataRow) {                       ProductMaster objProduct = new ProductMaster; objProduct.ProductID = 0; objProduct.ProductName = row.Cells[0].Text; objProduct.ProductDescription = row.Cells[1].Text; objProduct.Price = Convert.ToDecimal(row.Cells[2].Text); objProduct.Qty = Convert.ToDecimal(row.Cells[3].Text); objProduct.Total = Convert.ToDecimal(row.Cells[4].Text); objProductList.Add(objProduct); }               }

ProductBAL objProductBAL = new ProductBAL; objProductBAL.Save(objProductList, objCust); }       }        #endregion } }