コード例 #1
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        #region server side validation
        String strErrorMessage = "";

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

        #region Collect Form Data
        CityENT entCity = new CityENT();

        if (txtCity.Text.Trim() != "")
        {
            entCity.CityName = txtCity.Text.Trim();
        }
        #endregion Collect Form Data

        CityBAL balCity = new CityBAL();

        if (Convert.ToBoolean(ViewState["CityEditActive"]) == false)
        {
            if (balCity.Insert(entCity))
            {
                fillCityGridview();
                ClientScript.RegisterStartupScript(GetType(), "SweetAlert", "swal({ type: 'success', title: 'City Inserted Successfully', showConfirmButton: false, timer: 2000});", true);
                ClearControls();
            }
            else
            {
                lblErrorMessage.Text = balCity.Message;
            }
        }
        else
        {
            entCity.CityID = Convert.ToInt32(ViewState["CityID"]);
            if (balCity.Update(entCity))
            {
                fillCityGridview();
                ClientScript.RegisterStartupScript(GetType(), "SweetAlert", "swal({ type: 'success', title: 'City Edited Successfully', showConfirmButton: false, timer: 2000});", true);
                ClearControls();
                ViewState["CityEditActive"] = false;
                lblModalTitle.Text          = "City Add";
            }
            else
            {
                lblErrorMessage.Text = balCity.Message;
            }
        }
    }
コード例 #2
0
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        #region ServerSide Validation
        String strErrorMessage = "";

        if (ddlStateID.SelectedIndex == 0)
        {
            strErrorMessage += "Select State<br/>";
        }

        if (txtCityName.Text == "")
        {
            strErrorMessage += "Enter City Name<br/>";
        }

        if (strErrorMessage != "")
        {
            lblMessage.Text    = strErrorMessage;
            divMessage.Visible = true;
            return;
        }

        #endregion ServerSide Validation

        #region Collect FormData
        CityENT entCity = new CityENT();

        if (ddlStateID.SelectedIndex != 0)
        {
            entCity.StateID = Convert.ToInt32(ddlStateID.SelectedValue);
        }

        if (txtCityName.Text != "")
        {
            entCity.CityName = txtCityName.Text.Trim();
        }

        if (Session["UserID"] != null)
        {
            entCity.UserID = Convert.ToInt32(Session["UserID"]);
        }

        #endregion Collect FormData

        CityBAL balCity = new CityBAL();

        if (Request.QueryString["CityID"] == null)
        {
            if (balCity.Insert(entCity))
            {
                ClearControls();
                lblMessage.Text    = "Add Successfully";
                divMessage.Visible = true;
            }
            else
            {
                lblMessage.Text    = balCity.Message;
                divMessage.Visible = true;
            }
        }
        else
        {
            entCity.CityID = Convert.ToInt32(Request.QueryString["CityID"]);

            if (balCity.Update(entCity))
            {
                ClearControls();
                Response.Redirect("~/AdminPanel/City/CityList.aspx");
            }
            else
            {
                lblMessage.Text    = balCity.Message;
                divMessage.Visible = true;
            }
        }
    }