Example #1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(WebDemo.Model.WebDemo.BlockUpInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into BlockUpInfo(");
            strSql.Append("MeterID,StopYear,OperDate,StopReason,OperatorID)");
            strSql.Append(" values (");
            strSql.Append("@MeterID,@StopYear,@OperDate,@StopReason,@OperatorID)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@MeterID",    SqlDbType.Int,         4),
                new SqlParameter("@StopYear",   SqlDbType.Int,         4),
                new SqlParameter("@OperDate",   SqlDbType.DateTime),
                new SqlParameter("@StopReason", SqlDbType.VarChar,   200),
                new SqlParameter("@OperatorID", SqlDbType.Int, 4)
            };
            parameters[0].Value = model.MeterID;
            parameters[1].Value = model.StopYear;
            parameters[2].Value = model.OperDate;
            parameters[3].Value = model.StopReason;
            parameters[4].Value = model.OperatorID;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Example #2
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public WebDemo.Model.WebDemo.BlockUpInfo DataRowToModel(DataRow row)
 {
     WebDemo.Model.WebDemo.BlockUpInfo model = new WebDemo.Model.WebDemo.BlockUpInfo();
     if (row != null)
     {
         if (row["ID"] != null && row["ID"].ToString() != "")
         {
             model.ID = int.Parse(row["ID"].ToString());
         }
         if (row["MeterID"] != null && row["MeterID"].ToString() != "")
         {
             model.MeterID = int.Parse(row["MeterID"].ToString());
         }
         if (row["StopYear"] != null && row["StopYear"].ToString() != "")
         {
             model.StopYear = int.Parse(row["StopYear"].ToString());
         }
         if (row["OperDate"] != null && row["OperDate"].ToString() != "")
         {
             model.OperDate = DateTime.Parse(row["OperDate"].ToString());
         }
         if (row["StopReason"] != null)
         {
             model.StopReason = row["StopReason"].ToString();
         }
         if (row["OperatorID"] != null && row["OperatorID"].ToString() != "")
         {
             model.OperatorID = int.Parse(row["OperatorID"].ToString());
         }
     }
     return(model);
 }
Example #3
0
 private void ShowInfo(int ID)
 {
     WebDemo.BLL.WebDemo.BlockUpInfo   bll   = new WebDemo.BLL.WebDemo.BlockUpInfo();
     WebDemo.Model.WebDemo.BlockUpInfo model = bll.GetModel(ID);
     this.lblID.Text         = model.ID.ToString();
     this.lblMeterID.Text    = model.MeterID.ToString();
     this.lblStopYear.Text   = model.StopYear.ToString();
     this.lblOperDate.Text   = model.OperDate.ToString();
     this.lblStopReason.Text = model.StopReason;
     this.lblOperatorID.Text = model.OperatorID.ToString();
 }
Example #4
0
        public void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            if (!PageValidate.IsNumber(txtMeterID.Text))
            {
                strErr += "MeterID格式错误!\\n";
            }
            if (!PageValidate.IsNumber(txtStopYear.Text))
            {
                strErr += "StopYear格式错误!\\n";
            }
            if (!PageValidate.IsDateTime(txtOperDate.Text))
            {
                strErr += "OperDate格式错误!\\n";
            }
            if (this.txtStopReason.Text.Trim().Length == 0)
            {
                strErr += "StopReason不能为空!\\n";
            }
            if (!PageValidate.IsNumber(txtOperatorID.Text))
            {
                strErr += "OperatorID格式错误!\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int      ID         = int.Parse(this.lblID.Text);
            int      MeterID    = int.Parse(this.txtMeterID.Text);
            int      StopYear   = int.Parse(this.txtStopYear.Text);
            DateTime OperDate   = DateTime.Parse(this.txtOperDate.Text);
            string   StopReason = this.txtStopReason.Text;
            int      OperatorID = int.Parse(this.txtOperatorID.Text);


            WebDemo.Model.WebDemo.BlockUpInfo model = new WebDemo.Model.WebDemo.BlockUpInfo();
            model.ID         = ID;
            model.MeterID    = MeterID;
            model.StopYear   = StopYear;
            model.OperDate   = OperDate;
            model.StopReason = StopReason;
            model.OperatorID = OperatorID;

            WebDemo.BLL.WebDemo.BlockUpInfo bll = new WebDemo.BLL.WebDemo.BlockUpInfo();
            bll.Update(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx");
        }
Example #5
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(WebDemo.Model.WebDemo.BlockUpInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update BlockUpInfo set ");
            strSql.Append("MeterID=@MeterID,");
            strSql.Append("StopYear=@StopYear,");
            strSql.Append("OperDate=@OperDate,");
            strSql.Append("StopReason=@StopReason,");
            strSql.Append("OperatorID=@OperatorID");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@MeterID",    SqlDbType.Int,         4),
                new SqlParameter("@StopYear",   SqlDbType.Int,         4),
                new SqlParameter("@OperDate",   SqlDbType.DateTime),
                new SqlParameter("@StopReason", SqlDbType.VarChar,   200),
                new SqlParameter("@OperatorID", SqlDbType.Int,         4),
                new SqlParameter("@ID",         SqlDbType.Int, 4)
            };
            parameters[0].Value = model.MeterID;
            parameters[1].Value = model.StopYear;
            parameters[2].Value = model.OperDate;
            parameters[3].Value = model.StopReason;
            parameters[4].Value = model.OperatorID;
            parameters[5].Value = model.ID;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #6
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public WebDemo.Model.WebDemo.BlockUpInfo GetModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 ID,MeterID,StopYear,OperDate,StopReason,OperatorID from BlockUpInfo ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID", SqlDbType.Int, 4)
            };
            parameters[0].Value = ID;

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

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