private void ShowInfo(string MaterialID) { Maticsoft.BLL.MaterialInfo bll = new Maticsoft.BLL.MaterialInfo(); Maticsoft.Model.MaterialInfo model = bll.GetModel(MaterialID); this.lblMaterialID.Text = model.MaterialID; this.txtAliasName.Text = model.AliasName; this.txtProductName.Text = model.ProductName; this.txtModel.Text = model.Model; this.txtMaterialPhoto.Text = model.MaterialPhoto.ToString(); this.txtType.Text = model.Type; }
protected void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtMaterialID.Text.Trim().Length == 0) { strErr += "MaterialID不能为空!\\n"; } if (this.txtAliasName.Text.Trim().Length == 0) { strErr += "AliasName不能为空!\\n"; } if (this.txtProductName.Text.Trim().Length == 0) { strErr += "ProductName不能为空!\\n"; } if (this.txtModel.Text.Trim().Length == 0) { strErr += "Model不能为空!\\n"; } if (this.txtType.Text.Trim().Length == 0) { strErr += "Type不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } string MaterialID = this.txtMaterialID.Text; string AliasName = this.txtAliasName.Text; string ProductName = this.txtProductName.Text; string Model = this.txtModel.Text; byte[] MaterialPhoto = new UnicodeEncoding().GetBytes(this.txtMaterialPhoto.Text); string Type = this.txtType.Text; Maticsoft.Model.MaterialInfo model = new Maticsoft.Model.MaterialInfo(); model.MaterialID = MaterialID; model.AliasName = AliasName; model.ProductName = ProductName; model.Model = Model; model.MaterialPhoto = MaterialPhoto; model.Type = Type; Maticsoft.BLL.MaterialInfo bll = new Maticsoft.BLL.MaterialInfo(); bll.Add(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx"); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.MaterialInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tb_MaterialInfo set "); strSql.Append("AliasName=@AliasName,"); strSql.Append("ProductName=@ProductName,"); strSql.Append("Model=@Model,"); strSql.Append("MaterialPhoto=@MaterialPhoto,"); strSql.Append("Type=@Type,"); strSql.Append("Unit=@Unit"); strSql.Append(" where MaterialID=@MaterialID "); SqlParameter[] parameters = { new SqlParameter("@AliasName", SqlDbType.VarChar, 20), new SqlParameter("@ProductName", SqlDbType.VarChar, 30), new SqlParameter("@Model", SqlDbType.VarChar, 50), new SqlParameter("@MaterialPhoto", SqlDbType.Image), new SqlParameter("@Type", SqlDbType.VarChar, 20), new SqlParameter("@Unit", SqlDbType.VarChar, 20), new SqlParameter("@MaterialID", SqlDbType.VarChar, 30) }; parameters[0].Value = model.AliasName; parameters[1].Value = model.ProductName; parameters[2].Value = model.Model; parameters[3].Value = model.MaterialPhoto; parameters[4].Value = model.Type; parameters[5].Value = model.Unit; parameters[6].Value = model.MaterialID; int rows = dbs.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
// //设置物料别名 // private void btn_Save_AliasName_Click(object sender, RoutedEventArgs e) { Maticsoft.BLL.MaterialInfo _M_MaterialInfo = new Maticsoft.BLL.MaterialInfo(); Maticsoft.Model.MaterialInfo _MaterialInfo = new Maticsoft.Model.MaterialInfo() { AliasName = txb_AliasName.Text, MaterialID = txb_MaterialNum.Text, Model = txb_Model.Text, ProductName = txb_ProductName.Text, Type = "", Unit = lab_Unit.Content.ToString() }; if (_M_MaterialInfo.Update(_MaterialInfo)) { My_MessageBox.My_MessageBox_Message("添加成功!"); } else { My_MessageBox.My_MessageBox_Message("添加失败!"); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(Maticsoft.Model.MaterialInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tb_MaterialInfo("); strSql.Append("MaterialID,AliasName,ProductName,Model,MaterialPhoto,Type,Unit)"); strSql.Append(" values ("); strSql.Append("@MaterialID,@AliasName,@ProductName,@Model,@MaterialPhoto,@Type,@Unit)"); SqlParameter[] parameters = { new SqlParameter("@MaterialID", SqlDbType.VarChar, 30), new SqlParameter("@AliasName", SqlDbType.VarChar, 20), new SqlParameter("@ProductName", SqlDbType.VarChar, 30), new SqlParameter("@Model", SqlDbType.VarChar, 50), new SqlParameter("@MaterialPhoto", SqlDbType.Image), new SqlParameter("@Type", SqlDbType.VarChar, 20), new SqlParameter("@Unit", SqlDbType.VarChar, 20) }; parameters[0].Value = model.MaterialID; parameters[1].Value = model.AliasName; parameters[2].Value = model.ProductName; parameters[3].Value = model.Model; parameters[4].Value = model.MaterialPhoto; parameters[5].Value = model.Type; parameters[6].Value = model.Unit; int rows = dbs.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.MaterialInfo DataRowToModel(DataRow row) { Maticsoft.Model.MaterialInfo model = new Maticsoft.Model.MaterialInfo(); if (row != null) { if (row["MaterialID"] != null) { model.MaterialID = row["MaterialID"].ToString(); } if (row["AliasName"] != null) { model.AliasName = row["AliasName"].ToString(); } if (row["ProductName"] != null) { model.ProductName = row["ProductName"].ToString(); } if (row["Model"] != null) { model.Model = row["Model"].ToString(); } if (row["MaterialPhoto"] != null && row["MaterialPhoto"].ToString() != "") { model.MaterialPhoto = (byte[])row["MaterialPhoto"]; } if (row["Type"] != null) { model.Type = row["Type"].ToString(); } if (row["Unit"] != null) { model.Unit = row["Unit"].ToString(); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.MaterialInfo GetModel(string MaterialID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 MaterialID,AliasName,ProductName,Model,MaterialPhoto,Type,Unit from tb_MaterialInfo "); strSql.Append(" where MaterialID=@MaterialID "); SqlParameter[] parameters = { new SqlParameter("@MaterialID", SqlDbType.VarChar, 30) }; parameters[0].Value = MaterialID; Maticsoft.Model.MaterialInfo model = new Maticsoft.Model.MaterialInfo(); DataSet ds = dbs.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }