Esempio n. 1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public List <A_PASection> GetModelList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select A_PASectionID,A_PASectionName ");
            strSql.Append(" FROM A_PASection ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List <A_PASection> PASection = new List <A_PASection>();

            using (SqlConnection conn = DBHelp.getConn())
            {
                conn.Open();
                SqlCommand objCommand = new SqlCommand(strSql.ToString(), conn);
                using (SqlDataReader dataReader = objCommand.ExecuteReader())
                {
                    while (dataReader.Read())
                    {
                        A_PASection model = new A_PASection();
                        object      ojb;
                        ojb = dataReader["A_PASectionId"];
                        if (ojb != null && ojb != DBNull.Value)
                        {
                            model.A_PASectionID = (int)ojb;
                        }
                        model.A_PASectionName = dataReader["A_PASectionName"].ToString();
                        PASection.Add(model);
                    }
                }
            }
            return(PASection);
        }
Esempio n. 2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(A_PASection model)
        {
            StringBuilder strSql  = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();

            if (model.A_PASectionName != null)
            {
                strSql1.Append("A_PASectionName,");
                strSql2.Append("'" + model.A_PASectionName + "',");
            }
            strSql.Append("insert into A_PASection(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            strSql.Append(";select @@IDENTITY");
            object obj = DBHelp.ExeScalar(strSql.ToString());

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Esempio n. 3
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (this.FormCheck())
            {
                try
                {
                    A_PASection PASection = new A_PASection();
                    PASection.A_PASectionName = this.txtPASectionName.Text.Trim();
                    if (this.PASectionSer.Add(PASection) > 0)
                    {
                        base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('添加成功!');</script>");

                        this.txtPASectionName.Text = "";
                    }
                    else
                    {
                        base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('添加失败!');</script>");
                    }
                }
                catch (Exception ex)
                {
                    base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('" + ex.Message + "!');</script>");
                }
            }
        }
Esempio n. 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                if (base.Request["PASectionId"] != null)
                {
                    this.btnAdd.Visible = false;
                    A_PASection PASection = this.PASectionSer.GetModelList("A_PASectionId=" + base.Request["PASectionId"])[0];

                    this.txtPASectionName.Text = PASection.A_PASectionName;
                }
                else
                {
                    this.btnUpdate.Visible = false;
                }
            }
        }
Esempio n. 5
0
 protected void btnUpdate_Click(object sender, EventArgs e)
 {
     if (this.FormCheck())
     {
         try
         {
             A_PASection PASection = new A_PASection();
             PASection.A_PASectionName = this.txtPASectionName.Text.Trim();
             PASection.A_PASectionID   = Convert.ToInt32(base.Request["PASectionId"]);
             PASectionSer.Update(PASection);
             base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('修改成功!');</script>");
         }
         catch (Exception ex)
         {
             base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('" + ex.Message + "!');</script>");
         }
     }
 }
Esempio n. 6
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(A_PASection model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update A_PASection set ");
            if (model.A_PASectionName != null)
            {
                strSql.Append("A_PASectionName='" + model.A_PASectionName + "',");
            }
            else
            {
                strSql.Append("A_PASectionName= null ,");
            }
            int n = strSql.ToString().LastIndexOf(",");

            strSql.Remove(n, 1);
            strSql.Append(" where A_PASectionID=" + model.A_PASectionID + "");
            DBHelp.ExeCommand(strSql.ToString());
        }