/// <summary> /// 得到一个对象实体 /// </summary> public VAN_OA.Model.BaseInfo.TB_Good GetModel(int GoodId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select "); strSql.Append(" GoodArea,GoodNumber,GoodRow,GoodCol,GoodAreaNumber, Product,GoodProNo,GoodStatus,GoodBrand,GoodId,GoodNo,GoodName,ZhuJi,GoodSpec,GoodModel,GoodUnit,CreateUserId,CreateTime,tb_User.loginName,GoodTypeSmName,GoodTypeName,IfSpec "); strSql.Append(" from TB_Good left join tb_User on tb_User.ID=TB_Good.CreateUserId"); strSql.Append(" where GoodId=" + GoodId + ""); VAN_OA.Model.BaseInfo.TB_Good model = null; using (SqlConnection conn = DBHelp.getConn()) { conn.Open(); SqlCommand objCommand = new SqlCommand(strSql.ToString(), conn); using (SqlDataReader objReader = objCommand.ExecuteReader()) { if (objReader.Read()) { model = ReaderBind(objReader); } } } return(model); }
public TB_Good getModel() { VAN_OA.Model.BaseInfo.TB_Good model = new VAN_OA.Model.BaseInfo.TB_Good(); model.CreateUserId = Convert.ToInt32(Session["currentUserId"]); model.GoodModel = txtModel.Text; model.GoodName = txtGoodName.Text; model.GoodTypeSmName = ddlGoodSmType.Text; model.GoodSpec = txtSpec.Text; model.GoodTypeName = ddlGoodType.SelectedItem.Value; model.GoodUnit = txtUnit.Text; model.ZhuJi = txtZhuJi.Text; model.GoodBrand = txtGoodBrand.Text; model.GoodNumber = ddlNumber.Text; model.GoodCol = ddlCol.Text; model.GoodRow = ddlRow.Text; model.GoodArea = ddlArea.Text; model.GoodAreaNumber = model.GoodArea + model.GoodNumber + "-" + model.GoodRow + "-" + model.GoodCol; if (Request["allE_id"] != null) { model.GoodId = Convert.ToInt32(Request["allE_id"]); } model.IfSpec = cbSpec.Checked; model.Product = txtProduct.Text; return(model); }
/// <summary> /// 获得数据列表(比DataSet效率高,推荐使用) /// </summary> public List <VAN_OA.Model.BaseInfo.TB_Good> GetListToQuery_WebSer(string strWhere, int count) { StringBuilder strSql = new StringBuilder(); strSql.Append("select "); strSql.Append(" TB_Good.GoodNo,GoodName,GoodSpec,GoodModel,GoodUnit,GoodTypeSmName,isnull(GoodNum,0) as GoodNum "); strSql.Append(" from TB_Good left join TB_HouseGoods on TB_Good.GoodId=TB_HouseGoods.GoodId"); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } //strSql.Append(" order by GoodName,GoodSpec,GoodModel "); List <VAN_OA.Model.BaseInfo.TB_Good> list = new List <VAN_OA.Model.BaseInfo.TB_Good>(); using (SqlConnection conn = DBHelp.getConn()) { conn.Open(); SqlCommand objCommand = new SqlCommand(strSql.ToString(), conn); using (SqlDataReader dataReader = objCommand.ExecuteReader()) { while (dataReader.Read()) { VAN_OA.Model.BaseInfo.TB_Good model = new VAN_OA.Model.BaseInfo.TB_Good(); object ojb; model.GoodNo = dataReader["GoodNo"].ToString(); model.GoodName = dataReader["GoodName"].ToString(); model.GoodSpec = dataReader["GoodSpec"].ToString(); model.GoodModel = dataReader["GoodModel"].ToString(); model.GoodUnit = dataReader["GoodUnit"].ToString(); ojb = dataReader["GoodTypeSmName"]; if (ojb != null && ojb != DBNull.Value) { model.GoodTypeSmName = ojb.ToString(); } model.HouseNum = Convert.ToDecimal(dataReader["GoodNum"]); list.Add(model); } } } return(list); }
/// <summary> /// 对象实体绑定数据 /// </summary> public VAN_OA.Model.BaseInfo.TB_Good ReaderBind(IDataReader dataReader) { VAN_OA.Model.BaseInfo.TB_Good model = new VAN_OA.Model.BaseInfo.TB_Good(); object ojb; ojb = dataReader["GoodId"]; if (ojb != null && ojb != DBNull.Value) { model.GoodId = (int)ojb; } model.GoodNo = dataReader["GoodNo"].ToString(); model.GoodName = dataReader["GoodName"].ToString(); model.ZhuJi = dataReader["ZhuJi"].ToString(); ojb = dataReader["GoodTypeName"]; if (ojb != null && ojb != DBNull.Value) { model.GoodTypeName = ojb.ToString(); } ojb = dataReader["GoodTypeSmName"]; if (ojb != null && ojb != DBNull.Value) { model.GoodTypeSmName = ojb.ToString(); } model.GoodSpec = dataReader["GoodSpec"].ToString(); model.GoodModel = dataReader["GoodModel"].ToString(); model.GoodUnit = dataReader["GoodUnit"].ToString(); ojb = dataReader["CreateUserId"]; if (ojb != null && ojb != DBNull.Value) { model.CreateUserId = (int)ojb; } ojb = dataReader["CreateTime"]; if (ojb != null && ojb != DBNull.Value) { model.CreateTime = (DateTime)ojb; } ojb = dataReader["loginName"]; if (ojb != null && ojb != DBNull.Value) { model.CreateUserName = ojb.ToString(); } ojb = dataReader["GoodTypeSmName"]; if (ojb != null && ojb != DBNull.Value) { model.GoodTypeSmName = ojb.ToString(); } ojb = dataReader["GoodTypeName"]; if (ojb != null && ojb != DBNull.Value) { model.GoodTypeName = ojb.ToString(); } model.IfSpec = Convert.ToBoolean(dataReader["IfSpec"]); ojb = dataReader["GoodBrand"]; if (ojb != null && ojb != DBNull.Value) { model.GoodBrand = ojb.ToString(); } model.ProNo = Convert.ToString(dataReader["GoodProNo"]); model.Status = Convert.ToString(dataReader["GoodStatus"]); model.Product = Convert.ToString(dataReader["Product"]); model.GoodArea = Convert.ToString(dataReader["GoodArea"]); model.GoodNumber = Convert.ToString(dataReader["GoodNumber"]); model.GoodRow = Convert.ToString(dataReader["GoodRow"]); model.GoodCol = Convert.ToString(dataReader["GoodCol"]); model.GoodAreaNumber = Convert.ToString(dataReader["GoodAreaNumber"]); return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(VAN_OA.Model.BaseInfo.TB_Good model) { string sql = string.Format("select right('0000000000'+(convert(varchar,(convert(int,right(max(GoodNo),5))+1))),5) FROM TB_Good"); string MaxNo = ""; object objMax = DBHelp.ExeScalar(sql); if (objMax != null && objMax.ToString() != "") { MaxNo = objMax.ToString(); } else { MaxNo = "10001"; } StringBuilder strSql = new StringBuilder(); StringBuilder strSql1 = new StringBuilder(); StringBuilder strSql2 = new StringBuilder(); strSql1.Append("GoodNo,"); strSql2.Append("'" + MaxNo + "',"); if (model.GoodName != null) { strSql1.Append("GoodName,"); strSql2.Append("'" + model.GoodName + "',"); } if (model.ZhuJi != null) { strSql1.Append("ZhuJi,"); strSql2.Append("'" + model.ZhuJi + "',"); } if (model.GoodTypeName != null) { strSql1.Append("GoodTypeName,"); strSql2.Append("'" + model.GoodTypeName + "',"); } if (model.GoodTypeSmName != null) { strSql1.Append("GoodTypeSmName,"); strSql2.Append("'" + model.GoodTypeSmName + "',"); } if (model.GoodSpec != null) { strSql1.Append("GoodSpec,"); strSql2.Append("'" + model.GoodSpec + "',"); } if (model.GoodModel != null) { strSql1.Append("GoodModel,"); strSql2.Append("'" + model.GoodModel + "',"); } if (model.GoodUnit != null) { strSql1.Append("GoodUnit,"); strSql2.Append("'" + model.GoodUnit + "',"); } if (model.CreateUserId != null) { strSql1.Append("CreateUserId,"); strSql2.Append("" + model.CreateUserId + ","); } if (model.CreateTime != null) { strSql1.Append("CreateTime,"); strSql2.Append("getdate(),"); } if (model.IfSpec != null) { strSql1.Append("IfSpec,"); strSql2.Append("" + (model.IfSpec ? 1 : 0) + ","); } if (model.GoodBrand != null) { strSql1.Append("GoodBrand,"); strSql2.Append("'" + model.GoodBrand + "',"); } if (model.Product != null) { strSql1.Append("Product,"); strSql2.Append("'" + model.Product + "',"); } if (model.GoodCol != null) { strSql1.Append("GoodCol,"); strSql2.Append("'" + model.GoodCol + "',"); } if (model.GoodRow != null) { strSql1.Append("GoodRow,"); strSql2.Append("'" + model.GoodRow + "',"); } if (model.GoodNumber != null) { strSql1.Append("GoodNumber,"); strSql2.Append("'" + model.GoodNumber + "',"); } if (model.GoodArea != null) { strSql1.Append("GoodArea,"); strSql2.Append("'" + model.GoodArea + "',"); } if (model.GoodAreaNumber != null) { strSql1.Append("GoodAreaNumber,"); strSql2.Append("'" + model.GoodAreaNumber + "',"); } strSql.Append("insert into TB_Good("); strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1)); strSql.Append(")"); strSql.Append(" values ("); strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1)); strSql.Append(")"); strSql.Append(";select @@IDENTITY"); object obj = DBHelp.ExeScalar(strSql.ToString()); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
public bool Update(VAN_OA.Model.BaseInfo.TB_Good model, SqlCommand objCommand) { StringBuilder strSql = new StringBuilder(); strSql.Append("update TB_Good set "); if (model.GoodName != null) { strSql.Append("GoodName='" + model.GoodName + "',"); } if (model.ZhuJi != null) { strSql.Append("ZhuJi='" + model.ZhuJi + "',"); } else { strSql.Append("ZhuJi= null ,"); } if (model.GoodTypeName != null) { strSql.Append("GoodTypeName='" + model.GoodTypeName + "',"); } else { strSql.Append("GoodTypeId= null ,"); } if (model.GoodTypeSmName != null) { strSql.Append("GoodTypeSmName='" + model.GoodTypeSmName + "',"); } else { strSql.Append("GoodTypeSmName= null ,"); } if (model.GoodSpec != null) { strSql.Append("GoodSpec='" + model.GoodSpec + "',"); } else { strSql.Append("GoodSpec= null ,"); } if (model.GoodModel != null) { strSql.Append("GoodModel='" + model.GoodModel + "',"); } else { strSql.Append("GoodModel= null ,"); } if (model.GoodUnit != null) { strSql.Append("GoodUnit='" + model.GoodUnit + "',"); } else { strSql.Append("GoodUnit= null ,"); } if (model.CreateUserId != null) { strSql.Append("CreateUserId=" + model.CreateUserId + ","); } if (model.CreateTime != null) { strSql.Append("CreateTime=getdate(),"); } if (model.IfSpec != null) { strSql.Append("IfSpec=" + (model.IfSpec ? 1 : 0) + ","); } if (model.GoodBrand != null) { strSql.Append("GoodBrand='" + model.GoodBrand + "',"); } if (model.Product != null) { strSql.Append("Product='" + model.Product + "',"); } if (model.GoodAreaNumber != null) { strSql.Append("GoodAreaNumber='" + model.GoodAreaNumber + "',"); } if (model.GoodArea != null) { strSql.Append("GoodArea='" + model.GoodArea + "',"); } if (model.GoodNumber != null) { strSql.Append("GoodNumber='" + model.GoodNumber + "',"); } if (model.GoodRow != null) { strSql.Append("GoodRow='" + model.GoodRow + "',"); } if (model.GoodCol != null) { strSql.Append("GoodCol='" + model.GoodCol + "',"); } strSql.Append("GoodStatus='" + model.Status + "',"); int n = strSql.ToString().LastIndexOf(","); strSql.Remove(n, 1); strSql.Append(" where GoodId=" + model.GoodId + ""); objCommand.CommandText = strSql.ToString(); return(objCommand.ExecuteNonQuery() > 0 ? true : false); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(VAN_OA.Model.BaseInfo.TB_Good model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update TB_Good set "); if (model.GoodName != null) { strSql.Append("GoodName='" + model.GoodName + "',"); } if (model.ZhuJi != null) { strSql.Append("ZhuJi='" + model.ZhuJi + "',"); } else { strSql.Append("ZhuJi= null ,"); } if (model.GoodTypeName != null) { strSql.Append("GoodTypeName='" + model.GoodTypeName + "',"); } else { strSql.Append("GoodTypeId= null ,"); } if (model.GoodTypeSmName != null) { strSql.Append("GoodTypeSmName='" + model.GoodTypeSmName + "',"); } else { strSql.Append("GoodTypeSmName= null ,"); } if (model.GoodSpec != null) { strSql.Append("GoodSpec='" + model.GoodSpec + "',"); } else { strSql.Append("GoodSpec= null ,"); } if (model.GoodModel != null) { strSql.Append("GoodModel='" + model.GoodModel + "',"); } else { strSql.Append("GoodModel= null ,"); } if (model.GoodUnit != null) { strSql.Append("GoodUnit='" + model.GoodUnit + "',"); } else { strSql.Append("GoodUnit= null ,"); } if (model.CreateUserId != null) { strSql.Append("CreateUserId=" + model.CreateUserId + ","); } if (model.CreateTime != null) { strSql.Append("CreateTime=getdate(),"); } if (model.IfSpec != null) { strSql.Append("IfSpec=" + (model.IfSpec ? 1 : 0) + ","); } if (model.GoodBrand != null) { strSql.Append("GoodBrand='" + model.GoodBrand + "',"); } if (model.Product != null) { strSql.Append("Product='" + model.Product + "',"); } if (model.GoodAreaNumber != null) { strSql.Append("GoodAreaNumber='" + model.GoodAreaNumber + "',"); } if (model.GoodArea != null) { strSql.Append("GoodArea='" + model.GoodArea + "',"); } if (model.GoodNumber != null) { strSql.Append("GoodNumber='" + model.GoodNumber + "',"); } if (model.GoodRow != null) { strSql.Append("GoodRow='" + model.GoodRow + "',"); } if (model.GoodCol != null) { strSql.Append("GoodCol='" + model.GoodCol + "',"); } int n = strSql.ToString().LastIndexOf(","); strSql.Remove(n, 1); strSql.Append(" where GoodId=" + model.GoodId + ""); bool rowsAffected = DBHelp.ExeCommand(strSql.ToString()); return(rowsAffected); }