/// <summary> /// 得到一个对象实体 /// </summary> public Leadin.Model.Purchase DataRowToModel(DataRow row) { Leadin.Model.Purchase model = new Leadin.Model.Purchase(); if (row != null) { if (row["Id"] != null && row["Id"].ToString() != "") { model.Id = int.Parse(row["Id"].ToString()); } if (row["NumId"] != null) { model.NumId = row["NumId"].ToString(); } if (row["PaperId"] != null && row["PaperId"].ToString() != "") { model.PaperId = int.Parse(row["PaperId"].ToString()); } if (row["SupplierId"] != null && row["SupplierId"].ToString() != "") { model.SupplierId = int.Parse(row["SupplierId"].ToString()); } if (row["Num"] != null && row["Num"].ToString() != "") { model.Num = int.Parse(row["Num"].ToString()); } if (row["PurchasePrice"] != null && row["PurchasePrice"].ToString() != "") { model.PurchasePrice = decimal.Parse(row["PurchasePrice"].ToString()); } if (row["SellingPrice"] != null && row["SellingPrice"].ToString() != "") { model.SellingPrice = decimal.Parse(row["SellingPrice"].ToString()); } if (row["Freight"] != null && row["Freight"].ToString() != "") { model.Freight = decimal.Parse(row["Freight"].ToString()); } if (row["WorkersId"] != null && row["WorkersId"].ToString() != "") { model.WorkersId = int.Parse(row["WorkersId"].ToString()); } if (row["Explain"] != null) { model.Explain = row["Explain"].ToString(); } if (row["StateInfo"] != null && row["StateInfo"].ToString() != "") { model.StateInfo = int.Parse(row["StateInfo"].ToString()); } if (row["Remark"] != null && row["Remark"].ToString() != "") { model.Remark = int.Parse(row["Remark"].ToString()); } if (row["AddTime"] != null && row["AddTime"].ToString() != "") { model.AddTime = DateTime.Parse(row["AddTime"].ToString()); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Leadin.Model.Purchase model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tb_Purchase set "); strSql.Append("NumId=@NumId,"); strSql.Append("PaperId=@PaperId,"); strSql.Append("SupplierId=@SupplierId,"); strSql.Append("Num=@Num,"); strSql.Append("PurchasePrice=@PurchasePrice,"); strSql.Append("SellingPrice=@SellingPrice,"); strSql.Append("Freight=@Freight,"); strSql.Append("WorkersId=@WorkersId,"); strSql.Append("Explain=@Explain,"); strSql.Append("StateInfo=@StateInfo,"); strSql.Append("Remark=@Remark,"); strSql.Append("AddTime=@AddTime"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@NumId", SqlDbType.NVarChar, 100), new SqlParameter("@PaperId", SqlDbType.Int, 4), new SqlParameter("@SupplierId", SqlDbType.Int, 4), new SqlParameter("@Num", SqlDbType.Int, 4), new SqlParameter("@PurchasePrice", SqlDbType.Decimal, 9), new SqlParameter("@SellingPrice", SqlDbType.Decimal, 9), new SqlParameter("@Freight", SqlDbType.Decimal, 9), new SqlParameter("@WorkersId", SqlDbType.Int, 4), new SqlParameter("@Explain", SqlDbType.NText), new SqlParameter("@StateInfo", SqlDbType.Int, 4), new SqlParameter("@Remark", SqlDbType.Int, 4), new SqlParameter("@AddTime", SqlDbType.DateTime), new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = model.NumId; parameters[1].Value = model.PaperId; parameters[2].Value = model.SupplierId; parameters[3].Value = model.Num; parameters[4].Value = model.PurchasePrice; parameters[5].Value = model.SellingPrice; parameters[6].Value = model.Freight; parameters[7].Value = model.WorkersId; parameters[8].Value = model.Explain; parameters[9].Value = model.StateInfo; parameters[10].Value = model.Remark; parameters[11].Value = model.AddTime; parameters[12].Value = model.Id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Leadin.Model.Purchase model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tb_Purchase("); strSql.Append("NumId,PaperId,SupplierId,Num,PurchasePrice,SellingPrice,Freight,WorkersId,Explain,StateInfo,Remark,AddTime)"); strSql.Append(" values ("); strSql.Append("@NumId,@PaperId,@SupplierId,@Num,@PurchasePrice,@SellingPrice,@Freight,@WorkersId,@Explain,@StateInfo,@Remark,@AddTime)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@NumId", SqlDbType.NVarChar, 100), new SqlParameter("@PaperId", SqlDbType.Int, 4), new SqlParameter("@SupplierId", SqlDbType.Int, 4), new SqlParameter("@Num", SqlDbType.Int, 4), new SqlParameter("@PurchasePrice", SqlDbType.Decimal, 9), new SqlParameter("@SellingPrice", SqlDbType.Decimal, 9), new SqlParameter("@Freight", SqlDbType.Decimal, 9), new SqlParameter("@WorkersId", SqlDbType.Int, 4), new SqlParameter("@Explain", SqlDbType.NText), new SqlParameter("@StateInfo", SqlDbType.Int, 4), new SqlParameter("@Remark", SqlDbType.Int, 4), new SqlParameter("@AddTime", SqlDbType.DateTime) }; parameters[0].Value = model.NumId; parameters[1].Value = model.PaperId; parameters[2].Value = model.SupplierId; parameters[3].Value = model.Num; parameters[4].Value = model.PurchasePrice; parameters[5].Value = model.SellingPrice; parameters[6].Value = model.Freight; parameters[7].Value = model.WorkersId; parameters[8].Value = model.Explain; parameters[9].Value = model.StateInfo; parameters[10].Value = model.Remark; parameters[11].Value = model.AddTime; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Leadin.Model.Purchase GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,NumId,PaperId,SupplierId,Num,PurchasePrice,SellingPrice,Freight,WorkersId,Explain,StateInfo,Remark,AddTime from tb_Purchase "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; Leadin.Model.Purchase model = new Leadin.Model.Purchase(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }