Exemplo n.º 1
0
        //新增一个用户
        //void AddUser(UserBasicInfo basicInfo)
        void AddUser(object basicInfo1)
        {
            User user;

            panelUsers.VerticalScroll.Value = 0;

            UserBasicInfo basicInfo = (UserBasicInfo)basicInfo1;

            //先加入一个用户
            user = new User(users.Count, panelUsers);
            autosize.setControlsTag(user.PUserView.UserPanel);                               //将控件加入 自动调节大小的控制类中
            autosize.resizeControl(this);                                                    //在resize消息里调用此函数以自动设置窗口控件大小和位置

            user.PUserView.BtnName.Click         += new EventHandler(UserNameButtons_Click); //设置姓名按钮的点击事件
            user.PUserView.BtnName.MouseEnter    += new EventHandler(UserNameButtons_MouseEnter);
            user.PUserView.BtnName.MouseLeave    += new EventHandler(UserNameButtons_MouseLeave);
            user.PUserView.BtnDetails.Click      += new EventHandler(DetailsButtons_Click);                             //设置姓名按钮的点击事件
            user.PUserView.BtnDetails.MouseEnter += new EventHandler(UserDetailsButtons_MouseEnter);
            user.PUserView.BtnDetails.MouseLeave += new EventHandler(UserDetailsButtons_MouseLeave);
            user.BasicInfo = basicInfo;
            users.Add(user);

            //再重新调整"空用户"
            AdjustUser();

            UserTableAddUser(user);                     //向用户信息列表中添加一个用户
        }
Exemplo n.º 2
0
        //读取默认的用户配置文件
        public bool ReadDefaultUserFile()
        {
            userInfoList = new List <UserBasicInfo>();

            IEnumerator rows = ReadExcelFile(DefaultUserFileName);

            try
            {
                if (rows != null)
                {
                    rows.MoveNext();                            //跳过第一行
                    //向下移动
                    while (rows.MoveNext())
                    {
                        //获得当前行
                        XSSFRow row = rows.Current as XSSFRow;
                        if (row.Cells.Count >= 11)                                      //每行至少有11列
                        {
                            UserBasicInfo userInfo = new UserBasicInfo();
                            userInfo.userNO          = getCellString(row, 0);                                                   //读取用户编号
                            userInfo.name            = getCellString(row, 1);                                                   //读取姓名
                            userInfo.birthDate       = getCellString(row, 2);                                                   //读取出生年月
                            userInfo.uAffiliatedUnit = getCellString(row, 3);                                                   //读取单位
                            userInfo.userPhoto       = getCellString(row, 4);                                                   //读取照片
                            userInfo.duty            = getCellString(row, 5);                                                   //读取职务
                            int      result;
                            string[] SerialNo = getCellString(row, 6).Split('-');
                            if (int.TryParse(SerialNo[0], out result))                                                                  //读取组号
                            {
                                userInfo.terminalGrpNO = result;
                            }
                            else
                            {
                                return(false);
                            }
                            if (int.TryParse(SerialNo[1], out result))                                                                  //读取终端号
                            {
                                userInfo.terminalNO = result;
                            }
                            else
                            {
                                return(false);
                            }
                            userInfo.terminalCapSpec = getCellString(row, 7);                                           //读取气瓶容量
                            userInfo.BlueToothMac    = getCellString(row, 8);                                           //读取蓝牙MAC地址
                            userInfo.WirelessSN      = getCellString(row, 9);                                           //读取无线SN号
                            userInfo.Sex             = getCellString(row, 10);                                          //性别

                            //解析年龄
                            try
                            {
                                DateTime birthDate = DateTime.ParseExact(userInfo.birthDate, "yyyy-MM-dd", CultureInfo.CurrentCulture);                                 //获取记录的时间
                                userInfo.Age = ((DateTime.Now.Year - birthDate.Year) >= 0) ? ("" + (DateTime.Now.Year - birthDate.Year)) : "";
                            }
                            catch (Exception ex) { Console.WriteLine(ex.Message); log.Info(AppUtil.getExceptionInfo(ex)); }

                            userInfoList.Add(userInfo);
                        }
                    }
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                log.Info(AppUtil.getExceptionInfo(ex));
                MessageBox.Show("读取用户配置文件失败");
            }


            return(true);
        }