public static bool AddWord(Model.Book book) { string sql = "insert into U_Word(U_Word,U_Chinese,U_Pronounce,U_Note) values(@U_Word,@U_Chinese,@U_Pronounce,@U_Note)"; /*构建sql参数*/ SqlParameter[] parm = new SqlParameter[] { new SqlParameter("@U_Word", SqlDbType.VarChar), new SqlParameter("@U_Chinese", SqlDbType.VarChar), new SqlParameter("@U_Pronounce", SqlDbType.VarChar), new SqlParameter("@U_Note", SqlDbType.VarChar) }; /*给参数赋值*/ parm[0].Value = book.bookName; parm[1].Value = book.Name; parm[2].Value = book.move; parm[3].Value = book.address; /*执行sql进行添加*/ return((DBHelp.ExecuteNonQuery(sql, parm) > 0) ? true : false); }
public static Model.Book getSomeFile(string barcode, string Sqlname) { /*构建查询sql*/ string sql = "select * from " + Sqlname + " where U_id='" + barcode + "'"; SqlDataReader DataRead = DBHelp.ExecuteReader(sql, null); Model.Book book = new Model.Book(); /*如果查询存在记录,就包装到对象中返回*/ if (DataRead.Read()) { book.barcode = Convert.ToInt32(DataRead["U_Id"]); book.bookName = DataRead["U_Name"].ToString(); book.bookType = Convert.ToInt32(DataRead["U_PsdType"]); book.note = DataRead["U_Note"].ToString(); book.bookPhoto = (byte[])DataRead["U_Image"]; book.publishDate = Convert.ToDateTime(DataRead["U_LoginTime"].ToString()); } DataRead.Close(); return(book); }
public static bool AddFile(Model.Book book, string Sqlname) { string sql = "insert into " + Sqlname + "(U_Name,U_PsdType,U_Note,U_Image,U_LoginTime) values(@U_Name,@U_PsdType,@U_Note,@U_Image,@U_LoginTime)"; /*构建sql参数*/ SqlParameter[] parm = new SqlParameter[] { new SqlParameter("@U_Name", SqlDbType.VarChar), new SqlParameter("@U_PsdType", SqlDbType.Int), new SqlParameter("@U_Note", SqlDbType.VarChar), new SqlParameter("@U_Image", SqlDbType.Image), new SqlParameter("@U_LoginTime", SqlDbType.DateTime) }; /*给参数赋值*/ parm[0].Value = book.bookName; parm[1].Value = book.bookType; parm[2].Value = book.note; parm[3].Value = book.bookPhoto; parm[4].Value = book.publishDate; /*执行sql进行添加*/ return((DBHelp.ExecuteNonQuery(sql, parm) > 0) ? true : false); }
/*更新图书实现*/ public static bool EditWord(Model.Book book) { string sql = "update U_Word set U_Word=@U_Word,U_Chinese=@U_Chinese,U_Pronounce=@U_Pronounce,U_Note=@U_Note where U_Id=@U_Id"; /*构建sql参数信息*/ SqlParameter[] parm = new SqlParameter[] { new SqlParameter("@U_Id", SqlDbType.Int), new SqlParameter("@U_Word", SqlDbType.VarChar), new SqlParameter("@U_Chinese", SqlDbType.Int), new SqlParameter("@U_Pronounce", SqlDbType.VarChar), new SqlParameter("@U_Note", SqlDbType.Image) }; /*为参数赋值*/ parm[0].Value = book.barcode; parm[1].Value = book.bookName; parm[2].Value = book.Name; parm[3].Value = book.move; parm[4].Value = book.address; /*执行更新*/ return((DBHelp.ExecuteNonQuery(sql, parm) > 0) ? true : false); }
/*更新图书实现*/ public static bool EditFile(Model.Book book, string Sqlname) { string sql = "update " + Sqlname + " set U_Name=@U_Name,U_PsdType=@U_PsdType,U_Note=@U_Note,U_Image=@U_Image,U_LoginTime=@U_LoginTime where U_Id=@U_Id"; /*构建sql参数信息*/ SqlParameter[] parm = new SqlParameter[] { new SqlParameter("@U_Id", SqlDbType.Int), new SqlParameter("@U_Name", SqlDbType.VarChar), new SqlParameter("@U_PsdType", SqlDbType.Int), new SqlParameter("@U_Note", SqlDbType.VarChar), new SqlParameter("@U_Image", SqlDbType.Image), new SqlParameter("@U_LoginTime", SqlDbType.DateTime) }; /*为参数赋值*/ parm[0].Value = book.barcode; parm[1].Value = book.bookName; parm[2].Value = book.bookType; parm[3].Value = book.note; parm[4].Value = book.bookPhoto; parm[5].Value = book.publishDate; /*执行更新*/ return((DBHelp.ExecuteNonQuery(sql, parm) > 0) ? true : false); }
public static List <Model.Book> GetBImage(int pagenum, int pageindex, out int pageCount) { List <Model.Book> books = new List <Model.Book>(); SqlParameter[] P = { new SqlParameter("@pageIndex", pageindex), new SqlParameter("@pageCount", pagenum), new SqlParameter("@pageTotalCount", SqlDbType.Int), }; P[2].Direction = ParameterDirection.Output; DataSet ds = DbHepler.GetDataSet("WY", System.Data.CommandType.StoredProcedure, P); pageCount = Convert.ToInt32(P[2].Value); foreach (DataRow dr in ds.Tables[0].Rows) { Model.Book book = new Model.Book(); book.Author = dr["Author"].ToString(); book.AuthorDesc = dr["AuthorDesc"].ToString(); book.CategoryID = (int)dr["CategoryID"]; book.Clicks = (int)dr["Clicks"]; book.ContentDesc = dr["ContentDesc"].ToString(); book.EditorComment = dr["EditorComment"].ToString(); book.ID = dr["ID"].ToString(); book.ISBN = dr["ISBN"].ToString(); book.Price = (decimal)dr["Price"]; book.PublishDate = (DateTime)dr["PublishDate"]; book.PublisherID = (int)dr["PublisherID"]; book.State = (int)dr["State"]; book.Title = dr["Title"].ToString(); book.TOC = dr["TOC"].ToString(); book.WordsCount = (int)dr["WordsCount"]; books.Add(book); } return(books); }
//更新一本书 //0:更新失败 //1:更新成功 //2:连接出错,更新失败 //3:图片为空,更新失败 //4:ID为空,更新失败 // public int update(Model.Book book) { string id = book.Id; string name = book.Name; string author = book.Author; string publisher = book.Publisher; string pubtime = book.Pubtime; string pritime = book.Pritime; string edition = book.Edition; string impression = book.Impression; string pages = book.Pages; string words = book.Words; string format = book.Format; string paper = book.Paper; string packaging = book.Packaging; string isbn = book.Isbn; byte[] picture = book.Picture; string price = book.Price; string sort = book.Sort; string inventory = book.Inventory; //判断连接 if (DbHelper.checkConnection() == false) { return(2); } if (picture == null) { return(3); } if (id == null || id == "") { return(4); } string cmdText = "update book set b_name='" + name + "',b_author='" + author + "',b_publisher='" + publisher + "',b_pubtime='" + pubtime + "',b_pritime='" + pritime + "',b_edition='" + edition + "',b_impression='" + impression + "',b_pages='" + pages + "',b_words='" + words + "',b_format='" + format + "',b_paper='" + paper + "',b_packaging='" + packaging + "',b_isbn='" + isbn + "',b_picture=@picture,b_price='" + price + "',b_sort='" + sort + "',b_inventory='" + inventory + "' where b_id='" + id + "'"; SqlParameter[] parameters = { new SqlParameter("@picture", SqlDbType.Binary) }; parameters[0].Value = picture; int i = DbHelper.ExecuteNonQuery(cmdText, parameters); if (i == 1) { return(1); } else { Console.WriteLine("更新失败"); return(0); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.Book GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,Title,Author,PublisherId,PublishDate,ISBN,WordsCount,UnitPrice,ContentDescription,AurhorDescription,EditorComment,TOC,CategoryId,Clicks from Books "); strSql.Append(" where Id=@Id "); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; Model.Book model = new Model.Book(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Id"].ToString() != "") { model.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString()); } model.Title = ds.Tables[0].Rows[0]["Title"].ToString(); model.Author = ds.Tables[0].Rows[0]["Author"].ToString(); if (ds.Tables[0].Rows[0]["PublisherId"].ToString() != "") { // model.PublisherId = int.Parse(ds.Tables[0].Rows[0]["PublisherId"].ToString()); int PublisherId = int.Parse(ds.Tables[0].Rows[0]["PublisherId"].ToString()); model.Publisher = publisherServices.GetModel(PublisherId); } if (ds.Tables[0].Rows[0]["PublishDate"].ToString() != "") { model.PublishDate = DateTime.Parse(ds.Tables[0].Rows[0]["PublishDate"].ToString()); } model.ISBN = ds.Tables[0].Rows[0]["ISBN"].ToString(); if (ds.Tables[0].Rows[0]["WordsCount"].ToString() != "") { model.WordsCount = int.Parse(ds.Tables[0].Rows[0]["WordsCount"].ToString()); } if (ds.Tables[0].Rows[0]["UnitPrice"].ToString() != "") { model.UnitPrice = decimal.Parse(ds.Tables[0].Rows[0]["UnitPrice"].ToString()); } model.ContentDescription = ds.Tables[0].Rows[0]["ContentDescription"].ToString(); model.AurhorDescription = ds.Tables[0].Rows[0]["AurhorDescription"].ToString(); model.EditorComment = ds.Tables[0].Rows[0]["EditorComment"].ToString(); model.TOC = ds.Tables[0].Rows[0]["TOC"].ToString(); if (ds.Tables[0].Rows[0]["CategoryId"].ToString() != "") { int CategoryId = int.Parse(ds.Tables[0].Rows[0]["CategoryId"].ToString()); model.Category = categoryServices.GetModel(CategoryId); } if (ds.Tables[0].Rows[0]["Clicks"].ToString() != "") { model.Clicks = int.Parse(ds.Tables[0].Rows[0]["Clicks"].ToString()); } return(model); } else { return(null); } }