protected void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (!PageValidate.IsNumber(txtMeterId.Text)) { strErr += "MeterId格式错误!\\n"; } if (!PageValidate.IsNumber(txtCameraNo.Text)) { strErr += "CameraNo格式错误!\\n"; } if (!PageValidate.IsNumber(txtCutLocationX.Text)) { strErr += "CutLocationX格式错误!\\n"; } if (!PageValidate.IsNumber(txtCutLocationY.Text)) { strErr += "CutLocationY格式错误!\\n"; } if (!PageValidate.IsNumber(txtCutWidth.Text)) { strErr += "CutWidth格式错误!\\n"; } if (!PageValidate.IsNumber(txtCutHeight.Text)) { strErr += "CutHeight格式错误!\\n"; } if (!PageValidate.IsDateTime(txtLastOperDate.Text)) { strErr += "LastOperDate格式错误!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int MeterId = int.Parse(this.txtMeterId.Text); int CameraNo = int.Parse(this.txtCameraNo.Text); int CutLocationX = int.Parse(this.txtCutLocationX.Text); int CutLocationY = int.Parse(this.txtCutLocationY.Text); int CutWidth = int.Parse(this.txtCutWidth.Text); int CutHeight = int.Parse(this.txtCutHeight.Text); DateTime LastOperDate = DateTime.Parse(this.txtLastOperDate.Text); WebDemo.Model.WebDemo.MeterImageCutArea model = new WebDemo.Model.WebDemo.MeterImageCutArea(); model.MeterId = MeterId; model.CameraNo = CameraNo; model.CutLocationX = CutLocationX; model.CutLocationY = CutLocationY; model.CutWidth = CutWidth; model.CutHeight = CutHeight; model.LastOperDate = LastOperDate; WebDemo.BLL.WebDemo.MeterImageCutArea bll = new WebDemo.BLL.WebDemo.MeterImageCutArea(); bll.Add(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx"); }
private void ShowInfo(int Id) { WebDemo.BLL.WebDemo.MeterImageCutArea bll = new WebDemo.BLL.WebDemo.MeterImageCutArea(); WebDemo.Model.WebDemo.MeterImageCutArea model = bll.GetModel(Id); this.lblId.Text = model.Id.ToString(); this.lblMeterId.Text = model.MeterId.ToString(); this.lblCameraNo.Text = model.CameraNo.ToString(); this.txtCutLocationX.Text = model.CutLocationX.ToString(); this.txtCutLocationY.Text = model.CutLocationY.ToString(); this.txtCutWidth.Text = model.CutWidth.ToString(); this.txtCutHeight.Text = model.CutHeight.ToString(); this.txtLastOperDate.Text = model.LastOperDate.ToString(); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(WebDemo.Model.WebDemo.MeterImageCutArea model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update MeterImageCutArea set "); strSql.Append("CutLocationX=@CutLocationX,"); strSql.Append("CutLocationY=@CutLocationY,"); strSql.Append("CutWidth=@CutWidth,"); strSql.Append("CutHeight=@CutHeight,"); strSql.Append("LastOperDate=@LastOperDate"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@CutLocationX", SqlDbType.Int, 4), new SqlParameter("@CutLocationY", SqlDbType.Int, 4), new SqlParameter("@CutWidth", SqlDbType.Int, 4), new SqlParameter("@CutHeight", SqlDbType.Int, 4), new SqlParameter("@LastOperDate", SqlDbType.DateTime), new SqlParameter("@Id", SqlDbType.Int, 4), new SqlParameter("@MeterId", SqlDbType.Int, 4), new SqlParameter("@CameraNo", SqlDbType.Int, 4) }; parameters[0].Value = model.CutLocationX; parameters[1].Value = model.CutLocationY; parameters[2].Value = model.CutWidth; parameters[3].Value = model.CutHeight; parameters[4].Value = model.LastOperDate; parameters[5].Value = model.Id; parameters[6].Value = model.MeterId; parameters[7].Value = model.CameraNo; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WebDemo.Model.WebDemo.MeterImageCutArea DataRowToModel(DataRow row) { WebDemo.Model.WebDemo.MeterImageCutArea model = new WebDemo.Model.WebDemo.MeterImageCutArea(); 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["CameraNo"] != null && row["CameraNo"].ToString() != "") { model.CameraNo = int.Parse(row["CameraNo"].ToString()); } if (row["CutLocationX"] != null && row["CutLocationX"].ToString() != "") { model.CutLocationX = int.Parse(row["CutLocationX"].ToString()); } if (row["CutLocationY"] != null && row["CutLocationY"].ToString() != "") { model.CutLocationY = int.Parse(row["CutLocationY"].ToString()); } if (row["CutWidth"] != null && row["CutWidth"].ToString() != "") { model.CutWidth = int.Parse(row["CutWidth"].ToString()); } if (row["CutHeight"] != null && row["CutHeight"].ToString() != "") { model.CutHeight = int.Parse(row["CutHeight"].ToString()); } if (row["LastOperDate"] != null && row["LastOperDate"].ToString() != "") { model.LastOperDate = DateTime.Parse(row["LastOperDate"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(WebDemo.Model.WebDemo.MeterImageCutArea model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into MeterImageCutArea("); strSql.Append("MeterId,CameraNo,CutLocationX,CutLocationY,CutWidth,CutHeight,LastOperDate)"); strSql.Append(" values ("); strSql.Append("@MeterId,@CameraNo,@CutLocationX,@CutLocationY,@CutWidth,@CutHeight,@LastOperDate)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@MeterId", SqlDbType.Int, 4), new SqlParameter("@CameraNo", SqlDbType.Int, 4), new SqlParameter("@CutLocationX", SqlDbType.Int, 4), new SqlParameter("@CutLocationY", SqlDbType.Int, 4), new SqlParameter("@CutWidth", SqlDbType.Int, 4), new SqlParameter("@CutHeight", SqlDbType.Int, 4), new SqlParameter("@LastOperDate", SqlDbType.DateTime) }; parameters[0].Value = model.MeterId; parameters[1].Value = model.CameraNo; parameters[2].Value = model.CutLocationX; parameters[3].Value = model.CutLocationY; parameters[4].Value = model.CutWidth; parameters[5].Value = model.CutHeight; parameters[6].Value = model.LastOperDate; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WebDemo.Model.WebDemo.MeterImageCutArea GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,MeterId,CameraNo,CutLocationX,CutLocationY,CutWidth,CutHeight,LastOperDate from MeterImageCutArea "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; WebDemo.Model.WebDemo.MeterImageCutArea model = new WebDemo.Model.WebDemo.MeterImageCutArea(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }