public static Boolean UpdateProductGrade(ProductCode_Grade_Map productGrade) { LinqToSqlDataContext db = null; try { db = new LinqToSqlDataContext(); ProductCode_Grade_Map objGrade = db.ProductCode_Grade_Maps.Single(i => i.ProductGradeID == productGrade.ProductGradeID); objGrade.ProductCode = productGrade.ProductCode; objGrade.Grade = productGrade.Grade; objGrade.CreatedOn = productGrade.CreatedOn; objGrade.CreatedBy = productGrade.CreatedBy; objGrade.IsDeleted = productGrade.IsDeleted; db.SubmitChanges(); db.Dispose(); return(true); } catch (Exception objException) { db = new CSLOrderingARCBAL.LinqToSqlDataContext(); db.USP_SaveErrorDetails("ProductBAL", "UpdateProductGrade", Convert.ToString(objException.Message), Convert.ToString(objException.InnerException), Convert.ToString(objException.StackTrace), "", null, false, null); return(false); } }
public static Boolean InsertProductGrade(ProductCode_Grade_Map productGrade) { LinqToSqlDataContext db = new LinqToSqlDataContext(); int count = (from gp in db.ProductCode_Grade_Maps where gp.ProductCode == productGrade.ProductCode select gp ).Count(); if (count > 0) { return(false); } else { ProductCode_Grade_Map objProductGrade = new ProductCode_Grade_Map(); objProductGrade.ProductCode = productGrade.ProductCode; objProductGrade.Grade = productGrade.Grade; objProductGrade.CreatedOn = productGrade.CreatedOn; objProductGrade.CreatedBy = productGrade.CreatedBy; objProductGrade.IsDeleted = productGrade.IsDeleted; db.ProductCode_Grade_Maps.InsertOnSubmit(objProductGrade); // insert db.SubmitChanges(); return(true); } }
protected void btnSave_Click(object sender, EventArgs e) { string productCode = ""; if (!String.IsNullOrEmpty(txtProductCode.Text.Trim())) { ProductCode_Grade_Map objGrade = new ProductCode_Grade_Map(); objGrade.ProductCode = txtProductCode.Text.Trim(); productCode = txtProductCode.Text.Trim(); objGrade.Grade = ddlGrade.SelectedValue.ToString(); objGrade.CreatedOn = DateTime.Now; objGrade.CreatedBy = Session[enumSessions.User_Name.ToString()].ToString(); objGrade.IsDeleted = false; Boolean flag = false; if (ViewState["ProductGradeID"] != null) { objGrade.ProductGradeID = Convert.ToInt32(ViewState["ProductGradeID"]); flag = ProductBAL.UpdateProductGrade(objGrade); } else { flag = ProductBAL.InsertProductGrade(objGrade); } if (flag == false) { string script = "alertify.alert('" + ltrDuplicate.Text + "');"; ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true); } else { string script = "alertify.alert('" + ltrSaved.Text + "');"; ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true); } LoadData(); ClearControl(); ViewState["ProductGradeID"] = null; } pnlGradeDetails.Visible = false; pnlGradeList.Visible = true; LinqToSqlDataContext db = new LinqToSqlDataContext(); Audit audit = new Audit(); audit.UserName = Session[enumSessions.User_Name.ToString()].ToString(); audit.ChangeID = Convert.ToInt32(enumAudit.Manage_Products_Grade); audit.CreatedOn = DateTime.Now; audit.Notes = "Grade: " + ddlGrade.SelectedValue.ToString() + ", Product Code: " + productCode; if (Request.ServerVariables["LOGON_USER"] != null) { audit.WindowsUser = Request.ServerVariables["LOGON_USER"]; } audit.IPAddress = Request.UserHostAddress; db.Audits.InsertOnSubmit(audit); db.SubmitChanges(); }
//Get Product Grade details by ID public static ProductCode_Grade_Map GetProductGradeById(int productGradeID) { LinqToSqlDataContext db = new LinqToSqlDataContext(); ProductCode_Grade_Map productGrade = (from pg in db.ProductCode_Grade_Maps where pg.IsDeleted == false && pg.ProductGradeID == productGradeID select pg ).SingleOrDefault(); db.Dispose(); return(productGrade); }
//Delete product's Grade public static Boolean DeleteProductGrade(int productGradeID) { LinqToSqlDataContext db = null; try { db = new LinqToSqlDataContext(); ProductCode_Grade_Map productGrade = db.ProductCode_Grade_Maps.Where(i => i.ProductGradeID == productGradeID).Single(); db.ProductCode_Grade_Maps.DeleteOnSubmit(productGrade); db.SubmitChanges(); db.Dispose(); return(true); } catch (Exception objException) { db = new CSLOrderingARCBAL.LinqToSqlDataContext(); db.USP_SaveErrorDetails("ProductBAL", "DeleteProductGrade", Convert.ToString(objException.Message), Convert.ToString(objException.InnerException), Convert.ToString(objException.StackTrace), "", null, false, null); return(false); } }