Exemple #1
0
 protected void btn_modify_Click(object sender, EventArgs e)
 {
     if (Context.Request["ddId"] != null)
     {
         bool b;
         datadic.DdId     = Convert.ToInt32(Context.Request["ddId"]);
         datadic.DdTypeId = Convert.ToInt32(ddlDatadicType.SelectedItem.Value);
         datadic.DdValue  = tb_ddValue.Text;
         datadic.DdDesc   = tb_ddDesc.Text;
         b = datadicDao.datadicUpdate(datadic);
         if (b)
         {
             Session["flag"] = "modifySuccess";
             Response.Redirect("datadicList.aspx");
         }
     }
     else
     {
         datadic          = new Datadic();
         datadic.DdTypeId = Convert.ToInt32(ddlDatadicType.SelectedItem.Value);
         datadic.DdValue  = tb_ddValue.Text;
         datadic.DdDesc   = tb_ddDesc.Text;
         datadicDao.datadicAdd(datadic);
         bool b = datadicDao.datadicUpdate(datadic);
         if (b)
         {
             Session["flag"] = "addSuccess";
             Response.Redirect("datadicList.aspx");
         }
     }
 }
 protected void deleteBtn_Click(object sender, EventArgs e)
 {
     Datadic datadic = datadicDao.findById(Convert.ToInt32(ddIdTxt.Text));
     bool b=datadicDao.datadicDelete(datadic);
     if(b){
         Session["flag"] = "delSuccess";
         Response.Redirect("datadicList.aspx");
     }
     else {
         Session["flag"] = "delFailure";
         Response.Redirect("datadicList.aspx");
     };
 }
Exemple #3
0
        //根据传入对象的datadic的ddId进行更新查询,更新成功返回true,否则返回false
        public bool datadicUpdate(Datadic datadic)
        {
            con = dbUtil.getCon();
            string     cmdText = "update t_datadic set ddTypeId=" + datadic.DdTypeId + ",ddValue='" + datadic.DdValue + "',ddDesc='" + datadic.DdDesc + "' where ddId=" + datadic.DdId;
            SqlCommand sqlcom  = new SqlCommand(cmdText, con);
            int        n       = sqlcom.ExecuteNonQuery();//返回受影响的行数

            if (n == 1)
            {
                dbUtil.close(con);
                return(true);
            }
            else
            {
                dbUtil.close(con);
                return(false);
            }
        }
Exemple #4
0
        //根据传入对象的datadic的ddId进行删除查询,删除成功返回true,否则返回false
        public bool datadicDelete(Datadic datadic)
        {
            con = dbUtil.getCon();
            string     cmdText = "delete from t_datadic where ddId=" + datadic.DdId;
            SqlCommand sqlcom  = new SqlCommand(cmdText, con);
            int        n       = sqlcom.ExecuteNonQuery();//返回受影响的行数

            if (n == 1)
            {
                dbUtil.close(con);
                return(true);
            }
            else
            {
                dbUtil.close(con);
                return(false);
            }
        }
Exemple #5
0
        //添加数据
        public bool datadicAdd(Datadic datadic)
        {
            con = dbUtil.getCon();
            string     comText = "insert into t_datadic(ddTypeId,ddValue,ddDesc)values(" + datadic.DdTypeId + ",'" + datadic.DdValue + "','" + datadic.DdDesc + "') ";
            SqlCommand sqlcom  = new SqlCommand(comText, con);
            int        n       = sqlcom.ExecuteNonQuery();//返回受影响的行数

            if (n == 1)
            {
                dbUtil.close(con);
                return(true);
            }
            else
            {
                dbUtil.close(con);
                return(false);
            }
        }
Exemple #6
0
        //根据主键查询某一个Datadic
        public Datadic findById(int ddId)
        {
            con = dbUtil.getCon();
            Datadic       resultDatadic = null;
            string        cmdText       = "select * from t_datadic where ddId=" + ddId; //查询用户字符串
            SqlCommand    sqlCmd        = new SqlCommand(cmdText, con);                 //查询对象
            SqlDataReader sqlDr         = sqlCmd.ExecuteReader();                       //创建逐行数据读取器对象

            if (sqlDr.Read())
            {
                resultDatadic          = new Datadic();
                resultDatadic.DdId     = (int)sqlDr["ddId"];
                resultDatadic.DdTypeId = (int)sqlDr["ddTypeId"];
                resultDatadic.DdValue  = (string)sqlDr["ddValue"];
                resultDatadic.DdDesc   = (string)sqlDr["ddDesc"];
            }
            sqlDr.Close();
            dbUtil.close(con);
            return(resultDatadic);
        }
Exemple #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int ddId = Convert.ToInt32(Context.Request["ddId"]);

            //根据datadicList页面传过来的datadicId从数据库中获取datadic对象
            datadic = datadicDao.findById(ddId);
            if (!IsPostBack)
            {
                if (Context.Request["ddId"] == null)
                {
                    tb_ddDesc.Text  = "";
                    tb_ddValue.Text = "";
                }
                else
                {
                    // ddlDatadicType.SelectedItem.Value = datadic.DdTypeId.ToString();
                    ddlDatadicType.SelectedValue = datadic.DdTypeId.ToString();
                    tb_ddValue.Text = datadic.DdValue;
                    tb_ddDesc.Text  = datadic.DdDesc;
                }
            }
        }