using System; using System.Data; using System.Text; using System.Data.SqlClient; namespace Mtxfw.DAL { /// /// 数据访问类:P_Guige /// public partial class P_Guige : Mtxfw.Utility.Myabstract { public P_Guige() : base("P_Guige") { } /// /// 增加一条数据 /// public int Add(Mtxfw.Model.P_Guige model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into P_Guige("); strSql.Append("G_PID,G_Name,G_JG,G_JG0,G_JG1,G_JG2,G_JG3,G_JG4,G_JG5,G_JG6,G_JG7,G_JG8,G_JF,G_ZL,G_KC,G_Color,G_tihuodian,G_Images,ttype,MemberId)"); strSql.Append(" values ("); strSql.Append("@G_PID,@G_Name,@G_JG,@G_JG0,@G_JG1,@G_JG2,@G_JG3,@G_JG4,@G_JG5,@G_JG6,@G_JG7,@G_JG8,@G_JF,@G_ZL,@G_KC,@G_Color,@G_tihuodian,@G_Images,@ttype,@MemberId)"); strSql.Append(";select SCOPE_IDENTITY()"); SqlParameter[] parameters = { new SqlParameter("@G_PID", SqlDbType.Int), new SqlParameter("@G_Name", SqlDbType.VarChar,200), new SqlParameter("@G_JG", SqlDbType.Money), new SqlParameter("@G_JG0", SqlDbType.Money), new SqlParameter("@G_JG1", SqlDbType.Money), new SqlParameter("@G_JG2", SqlDbType.Money), new SqlParameter("@G_JG3", SqlDbType.Money), new SqlParameter("@G_JG4", SqlDbType.Money), new SqlParameter("@G_JG5", SqlDbType.Money), new SqlParameter("@G_JG6", SqlDbType.Money), new SqlParameter("@G_JG7", SqlDbType.Money), new SqlParameter("@G_JG8", SqlDbType.Money), new SqlParameter("@G_JF", SqlDbType.Money), new SqlParameter("@G_ZL", SqlDbType.Money), new SqlParameter("@G_KC", SqlDbType.Int), new SqlParameter("@G_Color", SqlDbType.VarChar,8000), new SqlParameter("@G_tihuodian", SqlDbType.VarChar,8000), new SqlParameter("@G_Images", SqlDbType.VarChar,8000), new SqlParameter("@ttype", SqlDbType.Int), new SqlParameter("@MemberId", SqlDbType.Int)}; parameters[0].Value = model.G_PID; parameters[1].Value = model.G_Name; parameters[2].Value = model.G_JG; parameters[3].Value = model.G_JG0; parameters[4].Value = model.G_JG1; parameters[5].Value = model.G_JG2; parameters[6].Value = model.G_JG3; parameters[7].Value = model.G_JG4; parameters[8].Value = model.G_JG5; parameters[9].Value = model.G_JG6; parameters[10].Value = model.G_JG7; parameters[11].Value = model.G_JG8; parameters[12].Value = model.G_JF; parameters[13].Value = model.G_ZL; parameters[14].Value = model.G_KC; parameters[15].Value = model.G_Color; parameters[16].Value = model.G_tihuodian; parameters[17].Value = model.G_Images; parameters[18].Value = model.ttype; parameters[19].Value = model.MemberId; string obj = Mtxfw.Utility.SqlDbHelper_U.GetObject(strSql.ToString(), parameters).ToString(); if (obj == "") { return 0; } else { return Convert.ToInt32(obj); } } /// /// 更新一条数据 /// public int Update(Mtxfw.Model.P_Guige model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update P_Guige set "); strSql.Append("G_Name=@G_Name,"); strSql.Append("G_JG=@G_JG,"); strSql.Append("G_JG0=@G_JG0,"); strSql.Append("G_JG1=@G_JG1,"); strSql.Append("G_JG2=@G_JG2,"); strSql.Append("G_JG3=@G_JG3,"); strSql.Append("G_JG4=@G_JG4,"); strSql.Append("G_JG5=@G_JG5,"); strSql.Append("G_JG6=@G_JG6,"); strSql.Append("G_JG7=@G_JG7,"); strSql.Append("G_JG8=@G_JG8,"); strSql.Append("G_JF=@G_JF,"); strSql.Append("G_ZL=@G_ZL,"); strSql.Append("G_KC=@G_KC,"); strSql.Append("G_Color=@G_Color,"); strSql.Append("G_tihuodian=@G_tihuodian,"); strSql.Append("G_Images=@G_Images"); strSql.Append(" where G_ID=@G_ID"); SqlParameter[] parameters = { new SqlParameter("@G_Name", SqlDbType.VarChar,200), new SqlParameter("@G_JG", SqlDbType.Money), new SqlParameter("@G_JG0", SqlDbType.Money), new SqlParameter("@G_JG1", SqlDbType.Money), new SqlParameter("@G_JG2", SqlDbType.Money), new SqlParameter("@G_JG3", SqlDbType.Money), new SqlParameter("@G_JG4", SqlDbType.Money), new SqlParameter("@G_JG5", SqlDbType.Money), new SqlParameter("@G_JG6", SqlDbType.Money), new SqlParameter("@G_JG7", SqlDbType.Money), new SqlParameter("@G_JG8", SqlDbType.Money), new SqlParameter("@G_JF", SqlDbType.Money), new SqlParameter("@G_ZL", SqlDbType.Money), new SqlParameter("@G_KC", SqlDbType.Int), new SqlParameter("@G_Color", SqlDbType.VarChar,8000), new SqlParameter("@G_tihuodian", SqlDbType.VarChar,8000), new SqlParameter("@G_Images", SqlDbType.VarChar,8000), new SqlParameter("@G_ID", SqlDbType.Int)}; parameters[0].Value = model.G_Name; parameters[1].Value = model.G_JG; parameters[2].Value = model.G_JG0; parameters[3].Value = model.G_JG1; parameters[4].Value = model.G_JG2; parameters[5].Value = model.G_JG3; parameters[6].Value = model.G_JG4; parameters[7].Value = model.G_JG5; parameters[8].Value = model.G_JG6; parameters[9].Value = model.G_JG7; parameters[10].Value = model.G_JG8; parameters[11].Value = model.G_JF; parameters[12].Value = model.G_ZL; parameters[13].Value = model.G_KC; parameters[14].Value = model.G_Color; parameters[15].Value = model.G_tihuodian; parameters[16].Value = model.G_Images; parameters[17].Value = model.G_ID; return Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters); } /// /// 更新一条数据 /// public int Update(int G_PID) { StringBuilder strSql = new StringBuilder(); strSql.Append("update P_Guige set "); strSql.Append("G_PID=@G_PID"); strSql.Append(" where G_PID=0"); SqlParameter[] parameters = { new SqlParameter("@G_PID", SqlDbType.Int)}; parameters[0].Value = G_PID; return Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters); } /// /// 删除一条数据 /// public bool Delete(int G_ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete from P_Guige "); strSql.Append(" where G_ID=@G_ID"); SqlParameter[] parameters = { new SqlParameter("@G_ID", SqlDbType.Int,4) }; parameters[0].Value = G_ID; int rows = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } } /// /// 删除一条数据 /// public bool Delete2(int G_PID) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete from P_Guige "); strSql.Append(" where G_PID=@G_PID"); SqlParameter[] parameters = { new SqlParameter("@G_PID", SqlDbType.Int,4) }; parameters[0].Value = G_PID; int rows = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } } /// /// 得到一个对象实体 /// public Mtxfw.Model.P_Guige GetModel(int G_ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 a.* from P_Guige a"); strSql.Append(" where G_ID=@G_ID"); SqlParameter[] parameters = { new SqlParameter("@G_ID", SqlDbType.Int,4) }; parameters[0].Value = G_ID; Mtxfw.Model.P_Guige model = new Mtxfw.Model.P_Guige(); DataSet ds = Mtxfw.Utility.SqlDbHelper_U.GetDataSet(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["G_ID"].ToString() != "") { model.G_ID = int.Parse(ds.Tables[0].Rows[0]["G_ID"].ToString()); } if (ds.Tables[0].Rows[0]["G_PID"].ToString() != "") { model.G_PID = int.Parse(ds.Tables[0].Rows[0]["G_PID"].ToString()); } else { model.G_PID = 0; } model.G_Name = ds.Tables[0].Rows[0]["G_Name"].ToString(); if (ds.Tables[0].Rows[0]["G_JG"].ToString() != "") { model.G_JG = Double.Parse(ds.Tables[0].Rows[0]["G_JG"].ToString()); } else { model.G_JG = 0; } if (ds.Tables[0].Rows[0]["G_JG0"].ToString() != "") { model.G_JG0 = Double.Parse(ds.Tables[0].Rows[0]["G_JG0"].ToString()); } else { model.G_JG0 = 0; } if (ds.Tables[0].Rows[0]["G_JG1"].ToString() != "") { model.G_JG1 = Double.Parse(ds.Tables[0].Rows[0]["G_JG1"].ToString()); } else { model.G_JG1 = 0; } if (ds.Tables[0].Rows[0]["G_JG2"].ToString() != "") { model.G_JG2 = Double.Parse(ds.Tables[0].Rows[0]["G_JG2"].ToString()); } else { model.G_JG2 = 0; } if (ds.Tables[0].Rows[0]["G_JG3"].ToString() != "") { model.G_JG3 = Double.Parse(ds.Tables[0].Rows[0]["G_JG3"].ToString()); } else { model.G_JG3 = 0; } model.G_JG4 = Double.Parse(ds.Tables[0].Rows[0]["G_JG4"].ToString()); model.G_JG5 = Double.Parse(ds.Tables[0].Rows[0]["G_JG5"].ToString()); model.G_JG6 = Double.Parse(ds.Tables[0].Rows[0]["G_JG6"].ToString()); model.G_JG7 = Double.Parse(ds.Tables[0].Rows[0]["G_JG7"].ToString()); model.G_JG8 = Double.Parse(ds.Tables[0].Rows[0]["G_JG8"].ToString()); model.G_JF = Double.Parse(ds.Tables[0].Rows[0]["G_JF"].ToString()); model.G_ZL = Double.Parse(ds.Tables[0].Rows[0]["G_ZL"].ToString()); if (ds.Tables[0].Rows[0]["G_KC"].ToString() != "") { model.G_KC = int.Parse(ds.Tables[0].Rows[0]["G_KC"].ToString()); } else { model.G_KC = 0; } model.G_Color = ds.Tables[0].Rows[0]["G_Color"].ToString(); model.G_tihuodian = ds.Tables[0].Rows[0]["G_tihuodian"].ToString(); model.G_Images = ds.Tables[0].Rows[0]["G_Images"].ToString(); if (ds.Tables[0].Rows[0]["ttype"].ToString() != "") { model.ttype = int.Parse(ds.Tables[0].Rows[0]["ttype"].ToString()); } else { model.ttype = 0; } model.MemberId = int.Parse(ds.Tables[0].Rows[0]["MemberId"].ToString()); return model; } else { return null; } } /// /// 得到一个对象实体 /// public Mtxfw.Model.P_Guige GetModelByProductId(int ProductId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 a.* from P_Guige a"); strSql.Append(" where G_PID=@ProductId order by G_ID desc"); SqlParameter[] parameters = { new SqlParameter("@ProductId", SqlDbType.Int,4) }; parameters[0].Value = ProductId; Mtxfw.Model.P_Guige model = new Mtxfw.Model.P_Guige(); DataSet ds = Mtxfw.Utility.SqlDbHelper_U.GetDataSet(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["G_ID"].ToString() != "") { model.G_ID = int.Parse(ds.Tables[0].Rows[0]["G_ID"].ToString()); } if (ds.Tables[0].Rows[0]["G_PID"].ToString() != "") { model.G_PID = int.Parse(ds.Tables[0].Rows[0]["G_PID"].ToString()); } else { model.G_PID = 0; } model.G_Name = ds.Tables[0].Rows[0]["G_Name"].ToString(); if (ds.Tables[0].Rows[0]["G_JG"].ToString() != "") { model.G_JG = Double.Parse(ds.Tables[0].Rows[0]["G_JG"].ToString()); } else { model.G_JG = 0; } if (ds.Tables[0].Rows[0]["G_JG0"].ToString() != "") { model.G_JG0 = Double.Parse(ds.Tables[0].Rows[0]["G_JG0"].ToString()); } else { model.G_JG0 = 0; } if (ds.Tables[0].Rows[0]["G_JG1"].ToString() != "") { model.G_JG1 = Double.Parse(ds.Tables[0].Rows[0]["G_JG1"].ToString()); } else { model.G_JG1 = 0; } if (ds.Tables[0].Rows[0]["G_JG2"].ToString() != "") { model.G_JG2 = Double.Parse(ds.Tables[0].Rows[0]["G_JG2"].ToString()); } else { model.G_JG2 = 0; } if (ds.Tables[0].Rows[0]["G_JG3"].ToString() != "") { model.G_JG3 = Double.Parse(ds.Tables[0].Rows[0]["G_JG3"].ToString()); } else { model.G_JG3 = 0; } model.G_JG4 = Double.Parse(ds.Tables[0].Rows[0]["G_JG4"].ToString()); model.G_JG5 = Double.Parse(ds.Tables[0].Rows[0]["G_JG5"].ToString()); model.G_JG6 = Double.Parse(ds.Tables[0].Rows[0]["G_JG6"].ToString()); model.G_JG7 = Double.Parse(ds.Tables[0].Rows[0]["G_JG7"].ToString()); model.G_JG8 = Double.Parse(ds.Tables[0].Rows[0]["G_JG8"].ToString()); model.G_JF = Double.Parse(ds.Tables[0].Rows[0]["G_JF"].ToString()); model.G_ZL = Double.Parse(ds.Tables[0].Rows[0]["G_ZL"].ToString()); if (ds.Tables[0].Rows[0]["G_KC"].ToString() != "") { model.G_KC = int.Parse(ds.Tables[0].Rows[0]["G_KC"].ToString()); } else { model.G_KC = 0; } model.G_Color = ds.Tables[0].Rows[0]["G_Color"].ToString(); model.G_Images = ds.Tables[0].Rows[0]["G_Images"].ToString(); if (ds.Tables[0].Rows[0]["ttype"].ToString() != "") { model.ttype = int.Parse(ds.Tables[0].Rows[0]["ttype"].ToString()); } else { model.ttype = 0; } model.MemberId = int.Parse(ds.Tables[0].Rows[0]["MemberId"].ToString()); return model; } else { return null; } } /// /// 获得数据列表 /// public DataSet GetList(string strWhere) { StringBuilder strSql = new StringBuilder(); strSql.Append("select a.*"); strSql.Append(" FROM P_Guige a"); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } return Mtxfw.Utility.SqlDbHelper_U.GetDataSet(strSql.ToString()); } /// /// 获得前几行数据 /// public DataSet GetList(int Top, string strWhere, string filedOrder) { StringBuilder strSql = new StringBuilder(); strSql.Append("select "); if (Top > 0) { strSql.Append(" top " + Top.ToString()); } strSql.Append(" a.*"); strSql.Append(" FROM P_Guige a"); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } strSql.Append(" order by " + filedOrder); return Mtxfw.Utility.SqlDbHelper_U.GetDataSet(strSql.ToString()); } public new int GetCount(string where) { StringBuilder sb = new StringBuilder(); sb.Append("select count(G_ID) from " + TABLE_NAME + " a"); if (!String.IsNullOrEmpty(where)) sb.Append(" where " + where); return Mtxfw.Utility.SqlDbHelper_U.ExecuteScalar(sb.ToString()); } } }