Esempio n. 1
0
        /// <summary>
        /// 添加一条读者记录
        /// </summary>
        /// <param name="info">读者信息</param>
        /// <returns>增加成功与否</returns>
        public bool addANewReader(UserManagementReaderInfo info)
        {
            string sqlStr = "AddNewReader";

            MySqlParameter[] paras = new MySqlParameter[]
            {
                new MySqlParameter("@returnValue", MySqlDbType.Int32, 1),
                new MySqlParameter("@_userName", info.UserName),
                new MySqlParameter("@_userNumber", info.UserNumber),
                new MySqlParameter("@_gender", info.Gender),
                new MySqlParameter("@_birthday", info.Birthday),
                new MySqlParameter("@_address", info.Address),
                new MySqlParameter("@_contact", info.Contact),
                new MySqlParameter("@_libraryCardNum", info.LibraryCardNum),
                new MySqlParameter("@_departmentName", info.DepartmentName),
                new MySqlParameter("@_password", helper.GetMD5(info.Contact.Substring(5, 6)))
            };
            paras[0].Direction = ParameterDirection.Output;//将第一个变量设置为输出变量
            int count = helper.ExecuteNonQuery(sqlStr, paras, CommandType.StoredProcedure);

            if (paras[0].Value.ToString() == "-2")
            {
                throw new Exception("获取 UserId 失败");
            }
            else if (paras[0].Value.ToString() == "-3")
            {
                throw new Exception("获取 DepartmentId 失败");
            }
            else if (paras[0].Value.ToString() == "-4")
            {
                throw new Exception("登陆表信息录入失败");
            }
            return(paras[0].Value.ToString() == "1");
        }
Esempio n. 2
0
        /// <summary>
        /// 修改一条读者信息记录
        /// </summary>
        /// <param name="order">读者信息</param>
        /// <returns>修改成功与否</returns>
        public bool UpdateReaderInfo(UserManagementReaderInfo info, int id, ref List <string> errorMsg)
        {
            bool result = false;

            try
            {
                if (info.UserNumber == "")
                {
                    errorMsg.Add("UserNumber Error");
                    return(false);
                }
                if (!UserManagementReaderInfo.isNull(info))                       //是否有空项
                {
                    if (UserManagementReaderInfo.isNormative(info, ref errorMsg)) //是否符合规范
                    {
                        result = userManagementDal.UpdateReaderInfo(info, id);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw e;
            }
            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// 获取全部读者信息
        /// </summary>
        /// <returns>读者信息</returns>
        public IEnumerable GetAllReadersInfoArray()
        {
            List <UserManagementReaderInfo> result = new List <UserManagementReaderInfo>();

            try
            {
                DataTable datatable = userManagementDal.GetAllReadersInfo();
                foreach (DataRow dr in datatable.Rows)
                {
                    UserManagementReaderInfo userManagementReaderInfo = new UserManagementReaderInfo()
                    {
                        LibraryCardNum = dr["借书证号"].ToString(),
                        UserNumber     = dr["学号/职工号"].ToString(),
                        UserName       = dr["读者姓名"].ToString(),
                        Gender         = (int)dr["性别"],
                        Birthday       = (DateTime)dr["出生日期"],
                        Address        = dr["地址"].ToString(),
                        Contact        = dr["联系电话"].ToString(),
                        DepartmentName = dr["所在院系"].ToString()
                    };
                    result.Add(userManagementReaderInfo);
                }
                return(result);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw e;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 修改一条读者信息记录
        /// </summary>
        /// <param name="info">读者信息</param>
        /// <param name="id">读者编号</param>
        /// <returns>修改成功与否</returns>
        public bool UpdateReaderInfo(UserManagementReaderInfo info, int id)
        {
            string sqlStr = "UpdateReaderInfo";

            //储存Datatable
            MySqlParameter[] paras = new MySqlParameter[]//存储相应参数的容器
            {
                new MySqlParameter("@returnValue", MySqlDbType.Int32, 1),
                new MySqlParameter("@_userId", id),
                new MySqlParameter("@_userName", info.UserName),
                new MySqlParameter("@_userNumber", info.UserNumber),
                new MySqlParameter("@_gender", info.Gender),
                new MySqlParameter("@_birthday", info.Birthday),
                new MySqlParameter("@_address", info.Address),
                new MySqlParameter("@_contact", info.Contact),
                new MySqlParameter("@_libraryCardNum", info.LibraryCardNum),
                new MySqlParameter("@_departmentName", info.DepartmentName),
            };
            paras[0].Direction = ParameterDirection.Output;//将第一个变量设置为输出变量
            int count = helper.ExecuteNonQuery(sqlStr, paras, CommandType.StoredProcedure);

            if (paras[0].Value.ToString() == "-1")
            {
                throw new Exception("获取院系编号失败");
            }
            else if (paras[0].Value.ToString() == "-2")
            {
                throw new Exception("修改基本信息表失败");
            }
            else if (paras[0].Value.ToString() == "-3")
            {
                throw new Exception("修改读者信息表失败");
            }
            return(paras[0].Value.ToString() == "1");
        }
Esempio n. 5
0
 private void btn_addCase_Click(object sender, EventArgs e)
 {
     try
     {
         List <string> errorList = new List <string>();//创建一个错误列表
         //获取根据当前页面内容生成的订单(若有错误会被添加到错误列表中)
         var list = new UserManagementReaderInfo[] { GetReaderInfo(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();
 }
        /// <summary>
        /// 增加记录
        /// </summary>
        private void AddLog_Click(object sender, EventArgs e)
        {
            try
            {
                List <string> errorList = new List <string>();//创建一个错误列表

                //获取根据当前页面内容生成的读者信息(若有错误会被添加到错误列表中)
                UserManagementReaderInfo info = GetReaderInfo(ref errorList);

                //判断是否添加读者成功
                if (userManagementBll.addANewReader(info, ref errorList))
                {
                    MessageBox.Show("添加成功");
                }
                else
                {
                    MessageBox.Show("添加失败");
                    foreach (var i in errorList)
                    {
                        MessageBox.Show(i);//逐条显示错误信息
                    }
                }
                DataBind();//数据绑定
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 7
0
        private UserManagementReaderInfo GetReaderInfo(ref List <string> error)
        {
            List <string> errorList = new List <string>();

            UserManagementReaderInfo info = new UserManagementReaderInfo()
            {
                LibraryCardNum = txb_LibraryCardNum.Text,
                UserNumber     = txb_UserNumber.Text,
                UserName       = txb_UserName.Text,
                BitGender      = cbb_Gender.Text,
                Birthday       = dtp_Birthday.Value,
                Address        = cbb_BuildingNo.Text + "#" + txb_DormitoryNo.Text,
                Contact        = txb_Contact.Text,
                DepartmentName = cbb_Department.Text
            };

            error = errorList; //返回错误列表
            return(info);      //返回读者信息
        }
Esempio n. 8
0
        /// <summary>
        /// 增加一条读者记录
        /// </summary>
        /// <param name="info">读者信息</param>
        /// <returns>增加成功与否</returns>
        public bool addANewReader(UserManagementReaderInfo info, ref List <string> errorMsg)
        {
            bool result = false;

            try
            {
                if (!UserManagementReaderInfo.isNull(info))
                {
                    if (UserManagementReaderInfo.isNormative(info, ref errorMsg))
                    {
                        result = userManagementDal.addANewReader(info);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(false);
            }
            return(result);
        }
Esempio n. 9
0
        public void TestAddANewReader()
        {
            Tools.UserCaseHandle userCaseHandle           = new Tools.UserCaseHandle(@"C:\Users\96464\Desktop\软件工程\测试用例\Add_UserManagementReaderInfo.xls");
            IEnumerable          userManagementReaderInfo = userCaseHandle.GetUserCases();
            List <string>        errorList = new List <string>();

            foreach (var i in userManagementReaderInfo)
            {
                Assert.AreEqual(false, userManagementBll.addANewReader((UserManagementReaderInfo)i, ref errorList));
            }
            UserManagementReaderInfo info = new UserManagementReaderInfo()
            {
                LibraryCardNum = "10100621120",
                UserNumber     = "201709001039",
                UserName       = "******",
                BitGender      = "男",
                Birthday       = DateTime.Now,
                Address        = "14#324",
                Contact        = "15319991111",
                DepartmentName = "计算机系"
            };

            Assert.AreEqual(true, userManagementBll.addANewReader(info, ref errorList));
        }
 /// <summary>
 /// 保存记录
 /// </summary>
 private void SaveLog_Click(object sender, EventArgs e)
 {
     try
     {
         List <string> errorList = new List <string>();         //创建一个错误列表
         //获取根据当前页面内容生成的读者信息(若有错误会被添加到错误列表中)
         int    selectRow = dataGridView1.CurrentCell.RowIndex; //获取选中行的索引值
         string userId    = dataGridView1.Rows[selectRow].Cells[0].Value.ToString();
         int    id;
         if (!int.TryParse(userId, out id))//将其转换为数字失败
         {
             MessageBox.Show("用户编号错误");
             return;
         }
         UserManagementReaderInfo info = GetReaderInfo(ref errorList);
         //判断是否修改读者信息成功
         if (userManagementBll.UpdateReaderInfo(info, id, ref errorList))
         {
             MessageBox.Show("修改成功");
         }
         else
         {
             MessageBox.Show("修改失败");
             foreach (var i in errorList)
             {
                 MessageBox.Show(i);//逐条显示错误信息
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     DataBind();                 //数据绑定
     ChangeControlEnableState(); //改变菜单按钮启用状态
 }