private BookAppointLog GetBookAppointLog(ref List <string> error)
        {
            List <string> errorList = new List <string>();//错误列表
            string        bookId    = bookCodeTextBox.Text;

            if (string.IsNullOrEmpty(bookId))
            {
                errorList.Add("BookId Error");
            }
            string readerId = readerIdTextBox.Text;

            if (string.IsNullOrEmpty(readerId))
            {
                errorList.Add("ReaderId Error");
            }
            string expireDate = validityTermTextBox.Text;

            if (string.IsNullOrEmpty(expireDate))
            {
                errorList.Add("ExpireDate Error");
            }
            DateTime       date           = appointDatePicker.Value;
            DateTime       expireDateTime = date.AddDays(double.Parse(expireDate));
            BookAppointLog bookAppointLog = new BookAppointLog()
            {
                BookId          = int.Parse(bookId),
                ReaderId        = int.Parse(readerId),
                AppointmentTime = appointDatePicker.Value,
                ExpireDate      = expireDateTime,
                State           = "有效"
            };

            error = errorList;
            return(bookAppointLog);
        }
Esempio n. 2
0
 /// <summary>
 /// 增加记录
 /// </summary>
 private void AddLog_Click(object sender, EventArgs e)
 {
     try
     {
         List <string> errorList = new List <string>();//创建一个错误列表
         //获取根据当前页面内容生成的订单(若有错误会被添加到错误列表中)
         BookAppointLog log = GetBookAppointLog(ref errorList);
         //判断是否添加订单成功
         if (circulationBll.AddAppointLog(log, ref errorList))
         {
             MessageBox.Show("添加成功");
         }
         else
         {
             MessageBox.Show("添加失败");
             foreach (var i in errorList)
             {
                 MessageBox.Show(i);//逐条显示错误信息
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     DataBind();
 }
 private void btn_addCase_Click(object sender, EventArgs e)
 {
     try
     {
         List <string> errorList = new List <string>();//创建一个错误列表
         //获取根据当前页面内容生成的订单(若有错误会被添加到错误列表中)
         var list = new BookAppointLog[] { GetBookAppointLog(ref errorList) };
         if (errorList.Count == 0)
         {
             if (userCaseHandle.AddUserCases(list.ToList()))
             {
                 MessageBox.Show("添加成功");
             }
         }
         else
         {
             MessageBox.Show("添加失败");
             foreach (var i in errorList)
             {
                 MessageBox.Show(i);//逐条显示错误信息
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     DataBind();
 }
Esempio n. 4
0
        /// <summary>
        /// 预约图书
        /// </summary>
        /// <param name="log"></param>
        /// <returns></returns>
        public bool AddAppointLog(BookAppointLog log)
        {
            string sqlStr = "AddBookAppointLog";

            //储存Datatable
            MySqlParameter[] para = new MySqlParameter[]//存储相应参数的容器
            {
                new MySqlParameter("@returnValue", MySqlDbType.Int32, 1),
                new MySqlParameter("@readerId", log.ReaderId),
                new MySqlParameter("@bookId", log.BookId),
                new MySqlParameter("@appointTime", log.AppointmentTime),
                new MySqlParameter("@expireDate", log.ExpireDate),
            };
            para[0].Direction = ParameterDirection.Output;//将第一个变量设为输出变量
            int count = helper.ExecuteNonQuery(sqlStr, para, CommandType.StoredProcedure);

            if (para[0].Value.ToString() == "-2")
            {
                throw new Exception("存在未处理违约");
            }
            if (para[0].Value.ToString() == "-3")
            {
                throw new Exception("用户可预约数量不足");
            }
            return(para[0].Value.ToString() == "1");
        }
Esempio n. 5
0
        public void AddAppointLogTest()
        {
            Tools.UserCaseHandle userCaseHandle  = new Tools.UserCaseHandle(@"C:\Users\96464\Desktop\软件工程\测试用例\Add_BookAppointLog.xls");
            IEnumerable          bookAppointLogs = userCaseHandle.GetUserCases();
            List <string>        errorList       = new List <string>();

            foreach (var i in bookAppointLogs)
            {
                Assert.AreEqual(false, circulationBll.AddAppointLog((BookAppointLog)i, ref errorList));
            }
            int maxId = -1;

            foreach (Book i in circulationBll.GetAllBooksArray())
            {
                if (i.Id > maxId)
                {
                    maxId = i.Id;
                }
            }
            BookAppointLog log = new BookAppointLog()
            {
                Id              = 1,
                BookId          = maxId,
                AppointmentTime = DateTime.Now,
                ExpireDate      = DateTime.Now,
                ReaderId        = utilBll.GetUserIdFormNumber("201709001013"),
                State           = "有效"
            };

            Assert.AreEqual(true, circulationBll.AddAppointLog(log, ref errorList));
            maxId = -1;
            foreach (Book i in circulationBll.GetAllBooksArray())
            {
                if (i.Id > maxId)
                {
                    maxId = i.Id;
                }
            }
            log = new BookAppointLog()
            {
                Id              = 1,
                BookId          = maxId,
                AppointmentTime = DateTime.Now,
                ExpireDate      = DateTime.Now,
                ReaderId        = utilBll.GetUserIdFormNumber("201709001013"),
                State           = "有效"
            };
            Assert.AreEqual(true, circulationBll.AddAppointLog(log, ref errorList));
        }
Esempio n. 6
0
        private BookAppointLog GetBookAppointLog(ref List <string> error)
        {
            List <string> errorList           = new List <string>();//错误列表
            Match         matchAppointCardNum = Regex.Match(borrowCardNumTextBox.Text, @"(^\d{11}$)");

            if (!matchAppointCardNum.Success)
            {
                errorList.Add("AppointCardNum Error");
            }
            //通过借书证号获取id
            int readerId = circulationBll.GetReaderIdByNum(borrowCardNumTextBox.Text);

            if (readerId == -1)
            {
                errorList.Add("ReaderId Error");
            }
            string bookId = bookCodeTextBox.Text;

            if (string.IsNullOrEmpty(bookId))
            {
                errorList.Add("BookId Error");
            }
            string expireDate = validityTermTextBox.Text;

            if (string.IsNullOrEmpty(expireDate))
            {
                errorList.Add("ExpireDate Error");
            }
            DateTime       date           = appointDatePicker.Value;
            DateTime       expireDateTime = date.AddDays(double.Parse(expireDate));
            BookAppointLog bookAppointLog = new BookAppointLog()
            {
                BookId          = int.Parse(bookId),
                ReaderId        = readerId,
                AppointmentTime = appointDatePicker.Value,
                ExpireDate      = expireDateTime,
                State           = "有效"
            };

            error = errorList;
            return(bookAppointLog);
        }
Esempio n. 7
0
        /// <summary>
        /// 预约图书
        /// </summary>
        /// <param name="log"></param>
        /// <param name="errorMsg">错误</param>
        /// <returns>增加成功与否</returns>
        public bool AddAppointLog(BookAppointLog log, ref List <string> errorMsg)
        {
            bool result = false;

            try
            {
                if (!BookAppointLog.isNull(log))                       //是否有空项
                {
                    if (BookAppointLog.isNormative(log, ref errorMsg)) //是否符合规范
                    {
                        result = circulationDal.AddAppointLog(log);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw ex;
            }
            return(result);
        }