Exemple #1
0
        public ContactCategoryENT SelectByPK(SqlInt32 ContactCategoryID)
        {
            using (SqlConnection objConn = new SqlConnection(ConnectionString))
            {
                objConn.Open();
                using (SqlCommand objCmd = objConn.CreateCommand())
                {
                    try
                    {
                        #region Prepare Command
                        objCmd.CommandType = CommandType.StoredProcedure;
                        objCmd.CommandText = "PR_ContactCategory_SelectByPK";
                        objCmd.Parameters.AddWithValue("@ContactCategoryID", ContactCategoryID);
                        #endregion Prepare Command

                        #region ReadData and Set Controls
                        ContactCategoryENT entContactCategory = new ContactCategoryENT();
                        using (SqlDataReader objSDR = objCmd.ExecuteReader())
                        {
                            while (objSDR.Read())
                            {
                                if (!objSDR["ContactCategoryID"].Equals(DBNull.Value))
                                {
                                    entContactCategory.ContactCategoryID = Convert.ToInt32(objSDR["ContactCategoryID"]);
                                }
                                if (!objSDR["ContactCategoryName"].Equals(DBNull.Value))
                                {
                                    entContactCategory.ContactCategoryName = Convert.ToString(objSDR["ContactCategoryName"]);
                                }
                            }
                        }

                        return(entContactCategory);

                        #endregion ReadData and Set Controls
                    }
                    catch (SqlException sqlex)
                    {
                        Message = sqlex.InnerException.Message.ToString();
                        return(null);
                    }
                    catch (Exception ex)
                    {
                        Message = ex.InnerException.Message.ToString();
                        return(null);
                    }
                    finally
                    {
                        if (objConn.State == ConnectionState.Open)
                        {
                            objConn.Close();
                        }
                    }
                }
            }
        }
Exemple #2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            #region Server Side Validation

            lblError.Text = "";
            if (txtContactCategoryName.Text.Trim().ToUpper() == "")
            {
                lblError.Text += "Enter ContactCategory Name <br/>";
            }

            if (lblError.Text != "")
            {
                return;
            }
            #endregion Server Side Validation

            #region Collecting Data
            ContactCategoryENT entContactCategory = new ContactCategoryENT();
            if (txtContactCategoryName.Text.Trim().ToUpper() != "")
            {
                entContactCategory.ContactCategoryName = txtContactCategoryName.Text.Trim().ToUpper();
            }
            ContactCategoryBAL balContactCategory = new ContactCategoryBAL();
            #endregion Collecting Data
            if (Request.QueryString["ContactCategoryID"] == null)
            {
                #region insertingData
                if (balContactCategory.Insert(entContactCategory))
                {
                    Response.Redirect("~/AdminPanel/ContactCategory/ContactCategoryList.aspx");
                }
                else
                {
                    lblError.Text = balContactCategory.Message;
                }
                #endregion insertingData
            }
            else
            {
                #region updatingData
                entContactCategory.ContactCategoryID = Convert.ToInt32(Request.QueryString["ContactCategoryID"]);
                if (balContactCategory.Update(entContactCategory))
                {
                    Response.Redirect("~/AdminPanel/ContactCategory/ContactCategoryList.aspx");
                }
                else
                {
                    lblError.Text = balContactCategory.Message;
                }
                #endregion updatingData
            }
        }
        public Boolean Update(ContactCategoryENT entContactCategory)
        {
            ContactCategoryDAL dalContactCategory = new ContactCategoryDAL();

            if (dalContactCategory.Update(entContactCategory))
            {
                return(true);
            }
            else
            {
                Message = dalContactCategory.Message;
                return(false);
            }
        }
Exemple #4
0
        public Boolean Insert(ContactCategoryENT entContactCategory)
        {
            using (SqlConnection objConn = new SqlConnection(ConnectionString))
            {
                objConn.Open();
                using (SqlCommand objCmd = objConn.CreateCommand())
                {
                    try
                    {
                        #region Prepare Command
                        objCmd.CommandType = CommandType.StoredProcedure;
                        objCmd.CommandText = "PR_ContactCategory_Insert";
                        objCmd.Parameters.Add("@ContactCategoryID", SqlDbType.Int).Direction            = ParameterDirection.Output;
                        objCmd.Parameters.AddWithValue("@ContactCategoryName", SqlDbType.VarChar).Value = entContactCategory.ContactCategoryName;
                        #endregion Prepare Command

                        objCmd.ExecuteNonQuery();

                        if (objCmd.Parameters["@ContactCategoryID"] != null)
                        {
                            entContactCategory.ContactCategoryID = Convert.ToInt32(objCmd.Parameters["@ContactCategoryID"].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();
                        }
                    }
                }
            }
        }
Exemple #5
0
        private void fillControls(SqlInt32 ContactCategoryID)
        {
            ContactCategoryENT entContactCategory = new ContactCategoryENT();
            ContactCategoryBAL balContactCategory = new ContactCategoryBAL();

            entContactCategory = balContactCategory.SelectByPK(ContactCategoryID);
            if (entContactCategory != null)
            {
                if (!entContactCategory.ContactCategoryName.IsNull)
                {
                    txtContactCategoryName.Text = entContactCategory.ContactCategoryName.Value.ToString();
                }
            }
            else
            {
                lblError.Text = balContactCategory.Message;
            }
        }
Exemple #6
0
        public Boolean Update(ContactCategoryENT entContactCategory)
        {
            using (SqlConnection objConn = new SqlConnection(ConnectionString))
            {
                objConn.Open();
                using (SqlCommand objCmd = objConn.CreateCommand())
                {
                    try
                    {
                        #region Prepare Command
                        objCmd.CommandType = CommandType.StoredProcedure;
                        objCmd.CommandText = "PR_ContactCategory_UpdateByPK";
                        objCmd.Parameters.AddWithValue("@ContactCategoryID", entContactCategory.ContactCategoryID);
                        objCmd.Parameters.AddWithValue("@ContactCategoryName", entContactCategory.ContactCategoryName);
                        #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();
                        }
                    }
                }
            }
        }