示例#1
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        #region Server Side Validation
        String strError = "";

        if (txtDepartmentName.Text.Trim() == "")
        {
            strError += "Enter Department +</br>";
        }

        if (strError.Trim() != "")
        {
            PanelErrorMesseage.Visible = true;
            lblErrorMessage.Text       = strError;
            return;
        }
        #endregion Server Side Validation

        #region Collect Data
        DepartmentENT entDepartment = new DepartmentENT();

        if (txtDepartmentName.Text.Trim() != "")
        {
            entDepartment.DepartmentName = txtDepartmentName.Text.Trim();
        }

        #endregion Collect Data

        DepartmentBAL balDepartment = new DepartmentBAL();

        if (Request.QueryString["DepartmentID"] == null)
        {
            if (balDepartment.Insert(entDepartment))
            {
                clearSelection();
                PanelSuccess.Visible = true;
                lblSuccess.Text      = "Data Inserted Successfully";
            }
            else
            {
                PanelErrorMesseage.Visible = true;
                lblErrorMessage.Text       = balDepartment.Message;
            }
        }
        else
        {
            entDepartment.DepartmentID = Convert.ToInt32(Request.QueryString["DepartmentID"].ToString().Trim());

            if (balDepartment.Update(entDepartment))
            {
                Response.Redirect("~/Content/Department/DepartmentList.aspx");
            }
            else
            {
                PanelErrorMesseage.Visible = true;
                lblErrorMessage.Text       = balDepartment.Message;
            }
        }
    }
示例#2
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        #region server side validation
        String strErrorMessage = "";

        if (txtDepartment.Text.Trim() == "")
        {
            strErrorMessage += "- Enter Department <br/>";
        }
        if (strErrorMessage.Trim() != "")
        {
            lblErrorMessage.Text = strErrorMessage;
            return;
        }
        #endregion server side validation

        #region Collect Form Data
        DepartmentENT entDepartment = new DepartmentENT();

        if (txtDepartment.Text.Trim() != "")
        {
            entDepartment.DepartmentName = txtDepartment.Text.Trim();
        }
        #endregion Collect Form Data

        DepartmentBAL balDepartment = new DepartmentBAL();

        if (Convert.ToBoolean(ViewState["DepartmentEditActive"]) == false)
        {
            if (balDepartment.Insert(entDepartment))
            {
                fillDepartmentGridview();
                ClientScript.RegisterStartupScript(GetType(), "SweetAlert", "swal({ type: 'success', title: 'Department Inserted Successfully', showConfirmButton: false, timer: 2000});", true);
                ClearControls();
            }
            else
            {
                lblErrorMessage.Text = balDepartment.Message;
            }
        }
        else
        {
            entDepartment.DepartmentID = Convert.ToInt32(ViewState["DepartmentID"]);
            if (balDepartment.Update(entDepartment))
            {
                fillDepartmentGridview();
                ClientScript.RegisterStartupScript(GetType(), "SweetAlert", "swal({ type: 'success', title: 'Department Edited Successfully', showConfirmButton: false, timer: 2000});", true);
                ClearControls();
                ViewState["DepartmentEditActive"] = false;
                lblModalTitle.Text = "Department Add";
            }
            else
            {
                lblErrorMessage.Text = balDepartment.Message;
            }
        }
    }