/// <summary> /// 增加一条数据 /// </summary> public int Add(tb_Base model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tb_Base("); strSql.Append("pId,baseName,temp1,temp2)"); strSql.Append(" values ("); strSql.Append("@pId,@baseName,@temp1,@temp2)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@pId", SqlDbType.Int, 4), new SqlParameter("@baseName", SqlDbType.NVarChar, 200), new SqlParameter("@temp1", SqlDbType.Text), new SqlParameter("@temp2", SqlDbType.Text) }; parameters[0].Value = model.pId; parameters[1].Value = model.baseName; parameters[2].Value = model.temp1; parameters[3].Value = model.temp2; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(tb_Base model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tb_Base set "); strSql.Append("pId=@pId,"); strSql.Append("baseName=@baseName,"); strSql.Append("temp1=@temp1,"); strSql.Append("temp2=@temp2"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@pId", SqlDbType.Int, 4), new SqlParameter("@baseName", SqlDbType.NVarChar, 200), new SqlParameter("@temp1", SqlDbType.Text), new SqlParameter("@temp2", SqlDbType.Text), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.pId; parameters[1].Value = model.baseName; parameters[2].Value = model.temp1; parameters[3].Value = model.temp2; parameters[4].Value = model.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public tb_Base DataRowToModel(DataRow row) { tb_Base model = new tb_Base(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["pId"] != null && row["pId"].ToString() != "") { model.pId = int.Parse(row["pId"].ToString()); } if (row["baseName"] != null) { model.baseName = row["baseName"].ToString(); } if (row["temp1"] != null) { model.temp1 = row["temp1"].ToString(); } if (row["temp2"] != null) { model.temp2 = row["temp2"].ToString(); } } return(model); }
public int tb_BaseAdd( tb_Base good ) { int intFalg = 0; try { /* if (ishaspics) * { * string str_Add = "insert into tb_BaseInfo(GoodId,GoodName,ItemNO,ModelNO,GoodMaterial,FCreater,FCreateDate,fImage) values( "; * str_Add += " '" + good.strGoodsId + "','" + good.strGoodsName + "',"; * str_Add += " '" + good.strItemNO + "',"; * str_Add += " '" + good.strModelNO + "','" + good.strGoodMaterial + "','" + good.strFCreater + "','" + good.dFCreateDate + "',@img )"; * intFalg = dbc.ExeInfochange(str_Add, "@img", good.image); * } * else * { */ string str_Add = "insert into tb_Base(FClass,FBaseID,FBaseName,FRemark) values( "; str_Add += " '" + good.strFClass + "','" + good.strFBaseID + "',"; str_Add += " '" + good.strFBaseName + "',"; str_Add += " '" + good.strFRemark + "')"; string sql = "select Count(1) from tb_Base where FBaseID='" + good.strFBaseID + "'"; //SqlCommand cmd1 = new SqlCommand(sql, conn); int count = dbc.ExecuteSelect(sql); if (count > 0) { MessageUtil.ShowError("编号已存在!"); return(0); } else { intFalg = dbc.ExeInfochange(str_Add); //} return(intFalg); } } catch (Exception ee) { MessageBox.Show(ee.ToString()); return(intFalg); } }
public int tb_goodUpdate(tb_Base good) { int intFalg = 0; try { string str_Update = "update tb_Base set "; str_Update += "FClass='" + good.strFClass + "', "; str_Update += "FBaseName='" + good.strFBaseName + "',"; str_Update += "FRemark= '" + good.strFRemark + "'"; str_Update += " where FBaseID='" + good.strFBaseID + "'"; intFalg = dbc.ExeInfochange(str_Update); return(intFalg); // conn.Dispose(); //return intFalg; } catch (Exception ee) { MessageBox.Show(ee.ToString()); return(intFalg); } }
/// <summary> /// 得到一个对象实体 /// </summary> public tb_Base GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,pId,baseName,temp1,temp2 from tb_Base "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; tb_Base model = new tb_Base(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
public tb_Base Find(string _baseid) { tb_Base goods = new tb_Base(); string sql = "select FClass,FBaseID,FBaseName,FRemark from tb_Base where FBaseID ='" + _baseid + "'"; DataSet ds = dbl.GetDataset(sql); if (ds != null) { if (ds.Tables.Count > 0) { if (ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { goods.strFClass = ds.Tables[0].Rows[i][0].ToString(); goods.strFBaseID = ds.Tables[0].Rows[i][1].ToString(); goods.strFBaseName = ds.Tables[0].Rows[i][2].ToString(); goods.strFRemark = ds.Tables[0].Rows[i][3].ToString(); } } } } return(goods); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(tb_Base model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(tb_Base model) { return(dal.Add(model)); }