/// <summary> /// 增加一条数据 /// </summary> public int Add(WebDemo.Model.WebDemo.FailureInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into FailureInfo("); strSql.Append("MeterID,FailurePhone,FailureMan,FailureMemo,FailureType,FailureRegTime,FailureRegType,DisposeMan,DisposeMemo,DisposeStatus,DisposeTime,sel,FailureCode,AppointMan,AppointManPhone,FailureSort,UsersID,UserCode)"); strSql.Append(" values ("); strSql.Append("@MeterID,@FailurePhone,@FailureMan,@FailureMemo,@FailureType,@FailureRegTime,@FailureRegType,@DisposeMan,@DisposeMemo,@DisposeStatus,@DisposeTime,@sel,@FailureCode,@AppointMan,@AppointManPhone,@FailureSort,@UsersID,@UserCode)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@MeterID", SqlDbType.Int, 4), new SqlParameter("@FailurePhone", SqlDbType.VarChar, 50), new SqlParameter("@FailureMan", SqlDbType.VarChar, 50), new SqlParameter("@FailureMemo", SqlDbType.VarChar, 500), new SqlParameter("@FailureType", SqlDbType.Int, 4), new SqlParameter("@FailureRegTime", SqlDbType.DateTime), new SqlParameter("@FailureRegType", SqlDbType.Int, 4), new SqlParameter("@DisposeMan", SqlDbType.VarChar, 50), new SqlParameter("@DisposeMemo", SqlDbType.VarChar, 500), new SqlParameter("@DisposeStatus", SqlDbType.Int, 4), new SqlParameter("@DisposeTime", SqlDbType.DateTime), new SqlParameter("@sel", SqlDbType.Bit, 1), new SqlParameter("@FailureCode", SqlDbType.VarChar, 20), new SqlParameter("@AppointMan", SqlDbType.VarChar, 50), new SqlParameter("@AppointManPhone", SqlDbType.VarChar, 50), new SqlParameter("@FailureSort", SqlDbType.Int, 4), new SqlParameter("@UsersID", SqlDbType.Int, 4), new SqlParameter("@UserCode", SqlDbType.VarChar, 50) }; parameters[0].Value = model.MeterID; parameters[1].Value = model.FailurePhone; parameters[2].Value = model.FailureMan; parameters[3].Value = model.FailureMemo; parameters[4].Value = model.FailureType; parameters[5].Value = model.FailureRegTime; parameters[6].Value = model.FailureRegType; parameters[7].Value = model.DisposeMan; parameters[8].Value = model.DisposeMemo; parameters[9].Value = model.DisposeStatus; parameters[10].Value = model.DisposeTime; parameters[11].Value = model.sel; parameters[12].Value = model.FailureCode; parameters[13].Value = model.AppointMan; parameters[14].Value = model.AppointManPhone; parameters[15].Value = model.FailureSort; parameters[16].Value = model.UsersID; parameters[17].Value = model.UserCode; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WebDemo.Model.WebDemo.FailureInfo GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,MeterID,FailurePhone,FailureMan,FailureMemo,FailureType,FailureRegTime,FailureRegType,DisposeMan,DisposeMemo,DisposeStatus,DisposeTime,sel,FailureCode,AppointMan,AppointManPhone,FailureSort,UsersID,UserCode from FailureInfo "); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; WebDemo.Model.WebDemo.FailureInfo model = new WebDemo.Model.WebDemo.FailureInfo(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
private void ShowInfo(int ID) { WebDemo.BLL.WebDemo.FailureInfo bll = new WebDemo.BLL.WebDemo.FailureInfo(); WebDemo.Model.WebDemo.FailureInfo model = bll.GetModel(ID); this.lblID.Text = model.ID.ToString(); this.lblMeterID.Text = model.MeterID.ToString(); this.lblFailurePhone.Text = model.FailurePhone; this.lblFailureMan.Text = model.FailureMan; this.lblFailureMemo.Text = model.FailureMemo; this.lblFailureType.Text = model.FailureType.ToString(); this.lblFailureRegTime.Text = model.FailureRegTime.ToString(); this.lblFailureRegType.Text = model.FailureRegType.ToString(); this.lblDisposeMan.Text = model.DisposeMan; this.lblDisposeMemo.Text = model.DisposeMemo; this.lblDisposeStatus.Text = model.DisposeStatus.ToString(); this.lblDisposeTime.Text = model.DisposeTime.ToString(); this.lblsel.Text = model.sel?"是":"否"; this.lblFailureCode.Text = model.FailureCode; this.lblAppointMan.Text = model.AppointMan; this.lblAppointManPhone.Text = model.AppointManPhone; this.lblFailureSort.Text = model.FailureSort.ToString(); this.lblUsersID.Text = model.UsersID.ToString(); this.lblUserCode.Text = model.UserCode; }
/// <summary> /// 得到一个对象实体 /// </summary> public WebDemo.Model.WebDemo.FailureInfo DataRowToModel(DataRow row) { WebDemo.Model.WebDemo.FailureInfo model = new WebDemo.Model.WebDemo.FailureInfo(); 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["FailurePhone"] != null) { model.FailurePhone = row["FailurePhone"].ToString(); } if (row["FailureMan"] != null) { model.FailureMan = row["FailureMan"].ToString(); } if (row["FailureMemo"] != null) { model.FailureMemo = row["FailureMemo"].ToString(); } if (row["FailureType"] != null && row["FailureType"].ToString() != "") { model.FailureType = int.Parse(row["FailureType"].ToString()); } if (row["FailureRegTime"] != null && row["FailureRegTime"].ToString() != "") { model.FailureRegTime = DateTime.Parse(row["FailureRegTime"].ToString()); } if (row["FailureRegType"] != null && row["FailureRegType"].ToString() != "") { model.FailureRegType = int.Parse(row["FailureRegType"].ToString()); } if (row["DisposeMan"] != null) { model.DisposeMan = row["DisposeMan"].ToString(); } if (row["DisposeMemo"] != null) { model.DisposeMemo = row["DisposeMemo"].ToString(); } if (row["DisposeStatus"] != null && row["DisposeStatus"].ToString() != "") { model.DisposeStatus = int.Parse(row["DisposeStatus"].ToString()); } if (row["DisposeTime"] != null && row["DisposeTime"].ToString() != "") { model.DisposeTime = DateTime.Parse(row["DisposeTime"].ToString()); } if (row["sel"] != null && row["sel"].ToString() != "") { if ((row["sel"].ToString() == "1") || (row["sel"].ToString().ToLower() == "true")) { model.sel = true; } else { model.sel = false; } } if (row["FailureCode"] != null) { model.FailureCode = row["FailureCode"].ToString(); } if (row["AppointMan"] != null) { model.AppointMan = row["AppointMan"].ToString(); } if (row["AppointManPhone"] != null) { model.AppointManPhone = row["AppointManPhone"].ToString(); } if (row["FailureSort"] != null && row["FailureSort"].ToString() != "") { model.FailureSort = int.Parse(row["FailureSort"].ToString()); } if (row["UsersID"] != null && row["UsersID"].ToString() != "") { model.UsersID = int.Parse(row["UsersID"].ToString()); } if (row["UserCode"] != null) { model.UserCode = row["UserCode"].ToString(); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(WebDemo.Model.WebDemo.FailureInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update FailureInfo set "); strSql.Append("MeterID=@MeterID,"); strSql.Append("FailurePhone=@FailurePhone,"); strSql.Append("FailureMan=@FailureMan,"); strSql.Append("FailureMemo=@FailureMemo,"); strSql.Append("FailureType=@FailureType,"); strSql.Append("FailureRegTime=@FailureRegTime,"); strSql.Append("FailureRegType=@FailureRegType,"); strSql.Append("DisposeMan=@DisposeMan,"); strSql.Append("DisposeMemo=@DisposeMemo,"); strSql.Append("DisposeStatus=@DisposeStatus,"); strSql.Append("DisposeTime=@DisposeTime,"); strSql.Append("sel=@sel,"); strSql.Append("FailureCode=@FailureCode,"); strSql.Append("AppointMan=@AppointMan,"); strSql.Append("AppointManPhone=@AppointManPhone,"); strSql.Append("FailureSort=@FailureSort,"); strSql.Append("UsersID=@UsersID,"); strSql.Append("UserCode=@UserCode"); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@MeterID", SqlDbType.Int, 4), new SqlParameter("@FailurePhone", SqlDbType.VarChar, 50), new SqlParameter("@FailureMan", SqlDbType.VarChar, 50), new SqlParameter("@FailureMemo", SqlDbType.VarChar, 500), new SqlParameter("@FailureType", SqlDbType.Int, 4), new SqlParameter("@FailureRegTime", SqlDbType.DateTime), new SqlParameter("@FailureRegType", SqlDbType.Int, 4), new SqlParameter("@DisposeMan", SqlDbType.VarChar, 50), new SqlParameter("@DisposeMemo", SqlDbType.VarChar, 500), new SqlParameter("@DisposeStatus", SqlDbType.Int, 4), new SqlParameter("@DisposeTime", SqlDbType.DateTime), new SqlParameter("@sel", SqlDbType.Bit, 1), new SqlParameter("@FailureCode", SqlDbType.VarChar, 20), new SqlParameter("@AppointMan", SqlDbType.VarChar, 50), new SqlParameter("@AppointManPhone", SqlDbType.VarChar, 50), new SqlParameter("@FailureSort", SqlDbType.Int, 4), new SqlParameter("@UsersID", SqlDbType.Int, 4), new SqlParameter("@UserCode", SqlDbType.VarChar, 50), new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = model.MeterID; parameters[1].Value = model.FailurePhone; parameters[2].Value = model.FailureMan; parameters[3].Value = model.FailureMemo; parameters[4].Value = model.FailureType; parameters[5].Value = model.FailureRegTime; parameters[6].Value = model.FailureRegType; parameters[7].Value = model.DisposeMan; parameters[8].Value = model.DisposeMemo; parameters[9].Value = model.DisposeStatus; parameters[10].Value = model.DisposeTime; parameters[11].Value = model.sel; parameters[12].Value = model.FailureCode; parameters[13].Value = model.AppointMan; parameters[14].Value = model.AppointManPhone; parameters[15].Value = model.FailureSort; parameters[16].Value = model.UsersID; parameters[17].Value = model.UserCode; parameters[18].Value = model.ID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
protected void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (!PageValidate.IsNumber(txtMeterID.Text)) { strErr += "MeterID格式错误!\\n"; } if (this.txtFailurePhone.Text.Trim().Length == 0) { strErr += "FailurePhone不能为空!\\n"; } if (this.txtFailureMan.Text.Trim().Length == 0) { strErr += "FailureMan不能为空!\\n"; } if (this.txtFailureMemo.Text.Trim().Length == 0) { strErr += "FailureMemo不能为空!\\n"; } if (!PageValidate.IsNumber(txtFailureType.Text)) { strErr += "FailureType格式错误!\\n"; } if (!PageValidate.IsDateTime(txtFailureRegTime.Text)) { strErr += "FailureRegTime格式错误!\\n"; } if (!PageValidate.IsNumber(txtFailureRegType.Text)) { strErr += "FailureRegType格式错误!\\n"; } if (this.txtDisposeMan.Text.Trim().Length == 0) { strErr += "DisposeMan不能为空!\\n"; } if (this.txtDisposeMemo.Text.Trim().Length == 0) { strErr += "DisposeMemo不能为空!\\n"; } if (!PageValidate.IsNumber(txtDisposeStatus.Text)) { strErr += "DisposeStatus格式错误!\\n"; } if (!PageValidate.IsDateTime(txtDisposeTime.Text)) { strErr += "DisposeTime格式错误!\\n"; } if (this.txtFailureCode.Text.Trim().Length == 0) { strErr += "FailureCode不能为空!\\n"; } if (this.txtAppointMan.Text.Trim().Length == 0) { strErr += "AppointMan不能为空!\\n"; } if (this.txtAppointManPhone.Text.Trim().Length == 0) { strErr += "AppointManPhone不能为空!\\n"; } if (!PageValidate.IsNumber(txtFailureSort.Text)) { strErr += "FailureSort格式错误!\\n"; } if (!PageValidate.IsNumber(txtUsersID.Text)) { strErr += "UsersID格式错误!\\n"; } if (this.txtUserCode.Text.Trim().Length == 0) { strErr += "UserCode不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int MeterID = int.Parse(this.txtMeterID.Text); string FailurePhone = this.txtFailurePhone.Text; string FailureMan = this.txtFailureMan.Text; string FailureMemo = this.txtFailureMemo.Text; int FailureType = int.Parse(this.txtFailureType.Text); DateTime FailureRegTime = DateTime.Parse(this.txtFailureRegTime.Text); int FailureRegType = int.Parse(this.txtFailureRegType.Text); string DisposeMan = this.txtDisposeMan.Text; string DisposeMemo = this.txtDisposeMemo.Text; int DisposeStatus = int.Parse(this.txtDisposeStatus.Text); DateTime DisposeTime = DateTime.Parse(this.txtDisposeTime.Text); bool sel = this.chksel.Checked; string FailureCode = this.txtFailureCode.Text; string AppointMan = this.txtAppointMan.Text; string AppointManPhone = this.txtAppointManPhone.Text; int FailureSort = int.Parse(this.txtFailureSort.Text); int UsersID = int.Parse(this.txtUsersID.Text); string UserCode = this.txtUserCode.Text; WebDemo.Model.WebDemo.FailureInfo model = new WebDemo.Model.WebDemo.FailureInfo(); model.MeterID = MeterID; model.FailurePhone = FailurePhone; model.FailureMan = FailureMan; model.FailureMemo = FailureMemo; model.FailureType = FailureType; model.FailureRegTime = FailureRegTime; model.FailureRegType = FailureRegType; model.DisposeMan = DisposeMan; model.DisposeMemo = DisposeMemo; model.DisposeStatus = DisposeStatus; model.DisposeTime = DisposeTime; model.sel = sel; model.FailureCode = FailureCode; model.AppointMan = AppointMan; model.AppointManPhone = AppointManPhone; model.FailureSort = FailureSort; model.UsersID = UsersID; model.UserCode = UserCode; WebDemo.BLL.WebDemo.FailureInfo bll = new WebDemo.BLL.WebDemo.FailureInfo(); bll.Add(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx"); }