private void ShowInfo() { ZhangWei.BLL.Dept_Customer bll = new ZhangWei.BLL.Dept_Customer(); ZhangWei.Model.Dept_Customer model = bll.GetModel(); this.lblDept_ID.Text = model.Dept_ID.ToString(); this.lblCustomer_ID.Text = model.Customer_ID.ToString(); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(ZhangWei.Model.Dept_Customer model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Dept_Customer set "); strSql.Append("Dept_ID=@Dept_ID,"); strSql.Append("Customer_ID=@Customer_ID"); strSql.Append(" where "); SqlParameter[] parameters = { new SqlParameter("@Dept_ID", SqlDbType.Int, 4), new SqlParameter("@Customer_ID", SqlDbType.Int, 4) }; parameters[0].Value = model.Dept_ID; parameters[1].Value = model.Customer_ID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public ZhangWei.Model.Dept_Customer GetModel() { //该表无主键信息,请自定义主键/条件字段 StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Dept_ID,Customer_ID from Dept_Customer "); strSql.Append(" where "); SqlParameter[] parameters = { }; ZhangWei.Model.Dept_Customer model = new ZhangWei.Model.Dept_Customer(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Dept_ID"] != null && ds.Tables[0].Rows[0]["Dept_ID"].ToString() != "") { model.Dept_ID = int.Parse(ds.Tables[0].Rows[0]["Dept_ID"].ToString()); } if (ds.Tables[0].Rows[0]["Customer_ID"] != null && ds.Tables[0].Rows[0]["Customer_ID"].ToString() != "") { model.Customer_ID = int.Parse(ds.Tables[0].Rows[0]["Customer_ID"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(ZhangWei.Model.Dept_Customer model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Dept_Customer("); strSql.Append("Dept_ID,Customer_ID)"); strSql.Append(" values ("); strSql.Append("@Dept_ID,@Customer_ID)"); SqlParameter[] parameters = { new SqlParameter("@Dept_ID", SqlDbType.Int, 4), new SqlParameter("@Customer_ID", SqlDbType.Int, 4) }; parameters[0].Value = model.Dept_ID; parameters[1].Value = model.Customer_ID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (!PageValidate.IsNumber(txtDept_ID.Text)) { strErr += "Dept_ID格式错误!\\n"; } if (!PageValidate.IsNumber(txtCustomer_ID.Text)) { strErr += "Customer_ID格式错误!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int Dept_ID = int.Parse(this.txtDept_ID.Text); int Customer_ID = int.Parse(this.txtCustomer_ID.Text); ZhangWei.Model.Dept_Customer model = new ZhangWei.Model.Dept_Customer(); model.Dept_ID = Dept_ID; model.Customer_ID = Customer_ID; ZhangWei.BLL.Dept_Customer bll = new ZhangWei.BLL.Dept_Customer(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }