コード例 #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
        public CityENT SelectByPK(SqlInt32 CityID)
        {
            using (SqlConnection objConn = new SqlConnection(ConnectionString))
            {
                objConn.Open();
                using (SqlCommand objCmd = objConn.CreateCommand())
                {
                    try
                    {
                        #region Prepare Command
                        objCmd.CommandType = CommandType.StoredProcedure;
                        objCmd.CommandText = "PR_City_SelectByPK";
                        objCmd.Parameters.Add("@CityID", SqlDbType.Int).Value = CityID;
                        #endregion Prepare Command

                        #region ReadData and Set Controls
                        CityENT entCity = new CityENT();
                        using (SqlDataReader objSDR = objCmd.ExecuteReader())
                        {
                            while (objSDR.Read())
                            {
                                if (!objSDR["CityID"].Equals(DBNull.Value))
                                {
                                    entCity.CityID = Convert.ToInt32(objSDR["CityID"]);
                                }
                                if (!objSDR["CityName"].Equals(DBNull.Value))
                                {
                                    entCity.CityName = Convert.ToString(objSDR["CityName"]);
                                }
                            }
                        }
                        return(entCity);

                        #endregion ReadData and Set Controls
                    }
                    catch (SqlException sqlEx)
                    {
                        Message = sqlEx.InnerException.Message;
                        return(null);
                    }
                    catch (Exception ex)
                    {
                        Message = ex.InnerException.Message;
                        return(null);
                    }
                    finally
                    {
                        if (objConn.State == ConnectionState.Open)
                        {
                            objConn.Close();
                        }
                    }
                }
            }
        }
コード例 #3
0
    private void FillControls(SqlInt32 CityID)
    {
        CityBAL balCity = new CityBAL();
        CityENT entCity = new CityENT();

        entCity = balCity.SelectByPK(CityID);

        if (!entCity.CityName.IsNull)
        {
            txtCity.Text = entCity.CityName.Value.ToString();
        }
    }
コード例 #4
0
        public Boolean Update(CityENT entCity)
        {
            CityDAL dalCity = new CityDAL();

            if (dalCity.Update(entCity))
            {
                return(true);
            }
            else
            {
                Message = dalCity.Message;
                return(false);
            }
        }
コード例 #5
0
ファイル: CityDAL.cs プロジェクト: yuvrajkanakiya/paramdecor
        public Boolean Insert(CityENT entCity)
        {
            using (SqlConnection objConn = new SqlConnection(ConnectionString))
            {
                objConn.Open();

                using (SqlCommand objCmd = objConn.CreateCommand())
                {
                    try
                    {
                        #region Prepare Command
                        objCmd.CommandType = CommandType.StoredProcedure;
                        objCmd.CommandText = "PR_City_Insert";
                        objCmd.Parameters.Add("@CityID", SqlDbType.Int, 4).Direction = ParameterDirection.Output;
                        objCmd.Parameters.Add("@StateID", SqlDbType.Int).Value       = entCity.StateID;
                        objCmd.Parameters.Add("@CityName", SqlDbType.VarChar).Value  = entCity.CityName;
                        objCmd.Parameters.Add("@UserID", SqlDbType.Int).Value        = entCity.UserID;
                        #endregion Prepare Command

                        objCmd.ExecuteNonQuery();

                        if (objCmd.Parameters["@CityID"] != null)
                        {
                            entCity.CityID = Convert.ToInt32(objCmd.Parameters["@CityID"].Value);
                        }

                        return(true);
                    }
                    catch (SqlException sqlex)
                    {
                        Message = sqlex.InnerException.Message.ToString();
                        return(false);
                    }
                    catch (Exception ex)
                    {
                        Message = ex.InnerException.Message.ToString();
                        return(false);
                    }
                    finally
                    {
                        if (objConn.State == ConnectionState.Open)
                        {
                            objConn.Close();
                        }
                    }
                }
            }
        }
コード例 #6
0
ファイル: CityDAL.cs プロジェクト: yuvrajkanakiya/paramdecor
        public Boolean Update(CityENT entCity)
        {
            using (SqlConnection objConn = new SqlConnection(ConnectionString))
            {
                objConn.Open();

                using (SqlCommand objCmd = objConn.CreateCommand())
                {
                    try
                    {
                        #region Prepare Command
                        objCmd.CommandType = CommandType.StoredProcedure;
                        objCmd.CommandText = "PR_City_Update";
                        objCmd.Parameters.AddWithValue("@cityID", entCity.StateID);
                        objCmd.Parameters.AddWithValue("@CityName", entCity.CityName);
                        objCmd.Parameters.AddWithValue("@StateID", entCity.StateID);
                        #endregion Prepare Command

                        objCmd.ExecuteNonQuery();

                        return(true);
                    }
                    catch (SqlException sqlex)
                    {
                        Message = sqlex.InnerException.Message.ToString();
                        return(false);
                    }
                    catch (Exception ex)
                    {
                        Message = ex.InnerException.Message.ToString();
                        return(false);
                    }
                    finally
                    {
                        if (objConn.State == ConnectionState.Open)
                        {
                            objConn.Close();
                        }
                    }
                }
            }
        }
コード例 #7
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;
            }
        }
    }