Exemplo n.º 1
0
    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();
    }