/// <summary> /// 更新一条数据 /// </summary> public bool Update(batteryModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update battery set "); strSql.Append("productCata=@productCata,"); strSql.Append("batchName=@batchName,"); strSql.Append("palletID=@palletID,"); strSql.Append("onlineTime=@onlineTime,"); strSql.Append("channel=@channel,"); strSql.Append("palletBinded=@palletBinded,"); strSql.Append("tag1=@tag1,"); strSql.Append("tag2=@tag2,"); strSql.Append("tag3=@tag3,"); strSql.Append("tag4=@tag4,"); strSql.Append("tag5=@tag5"); strSql.Append(" where batteryID=@batteryID "); SqlParameter[] parameters = { new SqlParameter("@productCata", SqlDbType.NChar, 10), new SqlParameter("@batchName", SqlDbType.NVarChar, 50), new SqlParameter("@palletID", SqlDbType.NVarChar, 50), new SqlParameter("@onlineTime", SqlDbType.DateTime), new SqlParameter("@channel", SqlDbType.Int, 4), new SqlParameter("@palletBinded", SqlDbType.Bit, 1), new SqlParameter("@tag1", SqlDbType.NChar, 10), new SqlParameter("@tag2", SqlDbType.NChar, 10), new SqlParameter("@tag3", SqlDbType.NChar, 10), new SqlParameter("@tag4", SqlDbType.NChar, 10), new SqlParameter("@tag5", SqlDbType.NChar, 10), new SqlParameter("@batteryID", SqlDbType.NVarChar, 50) }; parameters[0].Value = model.productCata; parameters[1].Value = model.batchName; parameters[2].Value = model.palletID; parameters[3].Value = model.onlineTime; parameters[4].Value = model.channel; parameters[5].Value = model.palletBinded; parameters[6].Value = model.tag1; parameters[7].Value = model.tag2; parameters[8].Value = model.tag3; parameters[9].Value = model.tag4; parameters[10].Value = model.tag5; parameters[11].Value = model.batteryID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(batteryModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into battery("); strSql.Append("batteryID,productCata,batchName,palletID,onlineTime,channel,palletBinded,tag1,tag2,tag3,tag4,tag5)"); strSql.Append(" values ("); strSql.Append("@batteryID,@productCata,@batchName,@palletID,@onlineTime,@channel,@palletBinded,@tag1,@tag2,@tag3,@tag4,@tag5)"); SqlParameter[] parameters = { new SqlParameter("@batteryID", SqlDbType.NVarChar, 50), new SqlParameter("@productCata", SqlDbType.NChar, 10), new SqlParameter("@batchName", SqlDbType.NVarChar, 50), new SqlParameter("@palletID", SqlDbType.NVarChar, 50), new SqlParameter("@onlineTime", SqlDbType.DateTime), new SqlParameter("@channel", SqlDbType.Int, 4), new SqlParameter("@palletBinded", SqlDbType.Bit, 1), new SqlParameter("@tag1", SqlDbType.NChar, 10), new SqlParameter("@tag2", SqlDbType.NChar, 10), new SqlParameter("@tag3", SqlDbType.NChar, 10), new SqlParameter("@tag4", SqlDbType.NChar, 10), new SqlParameter("@tag5", SqlDbType.NChar, 10) }; parameters[0].Value = model.batteryID; parameters[1].Value = model.productCata; parameters[2].Value = model.batchName; parameters[3].Value = model.palletID; parameters[4].Value = model.onlineTime; parameters[5].Value = model.channel; parameters[6].Value = model.palletBinded; parameters[7].Value = model.tag1; parameters[8].Value = model.tag2; parameters[9].Value = model.tag3; parameters[10].Value = model.tag4; parameters[11].Value = model.tag5; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public batteryModel GetModel(string batteryID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 batteryID,productCata,batchName,palletID,onlineTime,channel,palletBinded,tag1,tag2,tag3,tag4,tag5 from battery "); strSql.Append(" where batteryID=@batteryID "); SqlParameter[] parameters = { new SqlParameter("@batteryID", SqlDbType.NVarChar, 50) }; parameters[0].Value = batteryID; batteryModel model = new batteryModel(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 得到一个对象实体 /// </summary> public batteryModel DataRowToModel(DataRow row) { batteryModel model = new batteryModel(); if (row != null) { if (row["batteryID"] != null) { model.batteryID = row["batteryID"].ToString(); } if (row["productCata"] != null) { model.productCata = row["productCata"].ToString(); } if (row["batchName"] != null) { model.batchName = row["batchName"].ToString(); } if (row["palletID"] != null) { model.palletID = row["palletID"].ToString(); } if (row["onlineTime"] != null && row["onlineTime"].ToString() != "") { model.onlineTime = DateTime.Parse(row["onlineTime"].ToString()); } if (row["channel"] != null && row["channel"].ToString() != "") { model.channel = int.Parse(row["channel"].ToString()); } if (row["palletBinded"] != null && row["palletBinded"].ToString() != "") { if ((row["palletBinded"].ToString() == "1") || (row["palletBinded"].ToString().ToLower() == "true")) { model.palletBinded = true; } else { model.palletBinded = false; } } if (row["tag1"] != null) { model.tag1 = row["tag1"].ToString(); } if (row["tag2"] != null) { model.tag2 = row["tag2"].ToString(); } if (row["tag3"] != null) { model.tag3 = row["tag3"].ToString(); } if (row["tag4"] != null) { model.tag4 = row["tag4"].ToString(); } if (row["tag5"] != null) { model.tag5 = row["tag5"].ToString(); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(batteryModel model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(batteryModel model) { return(dal.Add(model)); }