コード例 #1
0
        public void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            if (!PageValidate.IsNumber(txtParentID.Text))
            {
                strErr += "ParentID格式错误!\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int MeterID  = int.Parse(this.lblMeterID.Text);
            int ParentID = int.Parse(this.txtParentID.Text);


            WebDemo.Model.WebDemo.ParentMeter model = new WebDemo.Model.WebDemo.ParentMeter();
            model.MeterID  = MeterID;
            model.ParentID = ParentID;

            WebDemo.BLL.WebDemo.ParentMeter bll = new WebDemo.BLL.WebDemo.ParentMeter();
            bll.Update(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx");
        }
コード例 #2
0
 private void ShowInfo(int MeterID)
 {
     WebDemo.BLL.WebDemo.ParentMeter   bll   = new WebDemo.BLL.WebDemo.ParentMeter();
     WebDemo.Model.WebDemo.ParentMeter model = bll.GetModel(MeterID);
     this.lblMeterID.Text  = model.MeterID.ToString();
     this.txtParentID.Text = model.ParentID.ToString();
 }
コード例 #3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(WebDemo.Model.WebDemo.ParentMeter model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update ParentMeter set ");
            strSql.Append("ParentID=@ParentID");
            strSql.Append(" where MeterID=@MeterID ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ParentID", SqlDbType.Int, 4),
                new SqlParameter("@MeterID",  SqlDbType.Int, 4)
            };
            parameters[0].Value = model.ParentID;
            parameters[1].Value = model.MeterID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #4
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(WebDemo.Model.WebDemo.ParentMeter model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into ParentMeter(");
            strSql.Append("MeterID,ParentID)");
            strSql.Append(" values (");
            strSql.Append("@MeterID,@ParentID)");
            SqlParameter[] parameters =
            {
                new SqlParameter("@MeterID",  SqlDbType.Int, 4),
                new SqlParameter("@ParentID", SqlDbType.Int, 4)
            };
            parameters[0].Value = model.MeterID;
            parameters[1].Value = model.ParentID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #5
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public WebDemo.Model.WebDemo.ParentMeter DataRowToModel(DataRow row)
 {
     WebDemo.Model.WebDemo.ParentMeter model = new WebDemo.Model.WebDemo.ParentMeter();
     if (row != null)
     {
         if (row["MeterID"] != null && row["MeterID"].ToString() != "")
         {
             model.MeterID = int.Parse(row["MeterID"].ToString());
         }
         if (row["ParentID"] != null && row["ParentID"].ToString() != "")
         {
             model.ParentID = int.Parse(row["ParentID"].ToString());
         }
     }
     return(model);
 }
コード例 #6
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public WebDemo.Model.WebDemo.ParentMeter GetModel(int MeterID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 MeterID,ParentID from ParentMeter ");
            strSql.Append(" where MeterID=@MeterID ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@MeterID", SqlDbType.Int, 4)
            };
            parameters[0].Value = MeterID;

            WebDemo.Model.WebDemo.ParentMeter model = new WebDemo.Model.WebDemo.ParentMeter();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }