Example #1
0
 private void button12_Click(object sender, EventArgs e)
 {
     if (textBox21.Text != "")
     {
         try
         {
             T_Books book = BLL.BLL_T_Books.GetOneInfo(textBox21.Text, -1);
             textBox19.Text   = book.BookName;
             textBox24.Text   = book.Nid.ToString();
             textBox9.Text    = book.GetBookClasses();
             textBox22.Text   = book.Author;
             textBox17.Text   = book.Press;
             textBox12.Text   = book.Price.ToString("F");
             textBox23.Text   = book.IsLeased ? "已被租借" : "可以租借";
             button11.Visible = !book.IsLeased;
         }
         catch (Exception ex)
         {
             MessageBox.Show("加载图书信息时出错:\n" + ex.Message);
         }
     }
     else
     {
         MessageBox.Show("请输入或选择要查询图书的名称!");
     }
 }
Example #2
0
 /// <summary>
 /// 查询单个图书信息
 /// </summary>
 public static T_Books GetOneInfo(string bookname, int id)
 {
     try
     {
         string sql = "select * from T_Books where ";
         if (bookname != null)
         {
             sql += "BookName='" + bookname + "'";
         }
         else
         {
             sql += "Nid=" + id;
         }
         DataTable dt = FS.SQLHelper.GetTable(sql, System.Data.CommandType.Text, null);
         if (dt.Rows.Count != 0)
         {
             T_Books book = new T_Books((int)dt.Rows[0]["Nid"], dt.Rows[0]["BookName"].ToString(), (int)dt.Rows[0]["BookClasses"], dt.Rows[0]["Author"].ToString(), dt.Rows[0]["Press"].ToString(), (decimal)dt.Rows[0]["Price"], (bool)dt.Rows[0]["IsLeased"], dt.Rows[0]["Leasee"].ToString(), dt.Rows[0]["LeaseTime"]);
             return(book);
         }
         else
         {
             return(null);
         }
     }
     catch
     {
         return(new T_Books()
         {
             Nid = -2
         });
     }
 }
        public static T_Books GetOneInfo(string bookname, int id)
        {
            T_Books book = DAL.DAL_T_Books.GetOneInfo(bookname, id);

            if (book == null)
            {
                throw new Exception("未找到该该书,请检查拼写是否正确!");
            }
            else if (book.Nid == -2)
            {
                throw new Exception("数据库连接失败!");
            }
            else
            {
                return(book);
            }
        }
Example #4
0
        /// <summary>
        /// 修改
        /// </summary>
        public static int Modify(T_Books book)
        {
            string sql;

            try
            {
                sql = "update T_Books set ";
                if (book.BookName != null)
                {
                    sql += "BookName='" + book.BookName + "',";
                }
                if (book.BookClasses != 0)
                {
                    sql += "BookClasses='" + book.BookClasses + "',";
                }
                if (book.Author != null)
                {
                    sql += "Author='" + book.Author + "',";
                }
                if (book.Press != null)
                {
                    sql += "Press='" + book.Press + "',";
                }
                if (book.Price != (decimal)0)
                {
                    sql += "Price='" + book.Price + "',";
                }
                if (book.Leasee != null)
                {
                    sql += "IsLeased='" + book.IsLeased + "',";
                    sql += "Leasee='" + book.Leasee + "',";
                    sql += "LeaseTime='" + book.LeaseTime + "',";
                }
                sql  = sql.Substring(0, sql.Length - 1);
                sql += " where Nid=" + book.Nid;
                return(FS.SQLHelper.ExecuteNonQuery(sql, CommandType.Text, null));
            }
            catch
            {
                return(-2);
            }
        }
Example #5
0
        /// <summary>
        /// 添加图书信息
        /// </summary>
        public static int AddBook(T_Books book)
        {
            string sql;

            try
            {
                sql = "select Count(*) from T_Books where BookName='" + book.BookName + "'";
                if (FS.SQLHelper.GetInt(sql) == 0)
                {
                    sql = "insert T_Books (BookName,BookClasses,Author,Press,Price) values ('" + book.BookName + "'," + book.BookClasses + ",'" + book.Author + "','" + book.Press + "'," + book.Price + ")";
                    return(FS.SQLHelper.ExecuteNonQuery(sql, System.Data.CommandType.Text, null));
                }
                else
                {
                    return(-1);
                }
            }
            catch
            {
                return(-2);
            }
        }
 public static int Modify(T_Books book)
 {
     return(DAL.DAL_T_Books.Modify(book));
 }