예제 #1
0
        /// <summary>
        /// 新增或修改职员(type->1:新增,2:修改)
        /// </summary>
        public string AddOrModifyStaff(byte type, string entity, string cardNo)
        {
            var res           = "";
            var repeatCardStr = "";

            if (entity.Length > 6)
            {
                SYS_Staff obj = JsonHelper.JsonToT <SYS_Staff>(entity);
                if (null != obj)
                {
                    var role = UnitOfWork.Repository <SYS_StaffRole>().GetEntitiesAsync(x => x.ID == obj.RoleId).Result.FirstOrDefault();
                    if (null != role)
                    {
                        obj.RoleLevel = role.RoleLevel;
                    }

                    if (type == 1)
                    {
                        obj.SchoolId   = mlUser.School.ID;
                        obj.OpenId     = Guid.NewGuid().ToString();
                        obj.Status     = (byte)StaffStatus.在职;
                        obj.CreateTime = DateTime.Now;

                        var oldStaff = UnitOfWork.Repository <SYS_Staff>().GetEntitiesAsync(x => x.StaffName == obj.StaffName && x.Phone == obj.Phone && x.SchoolId == obj.SchoolId && x.Status == (byte)StaffStatus.在职).Result.FirstOrDefault();
                        var isOk     = 0;
                        if (oldStaff == null)
                        {
                            UnitOfWork.Repository <SYS_Staff>().AddEntity(obj);
                            isOk = UnitOfWork.CommitAsync().Result;
                            if (isOk > 0)
                            {
                                res = "OK,职员添加成功";
                            }
                        }
                        else
                        {
                            res = "职员信息重复,无法添加";
                        }

                        //添加卡
                        if (isOk > 0)
                        {
                            //检测卡是否已存在
                            var oldCard = UnitOfWork.Repository <SYS_Card>().GetEntitiesAsync(x => x.CardNo == cardNo && x.SchoolId == mlUser.School.ID).Result.FirstOrDefault();
                            if (oldCard == null)
                            {
                                var card = new SYS_Card
                                {
                                    CardNo       = cardNo,
                                    CardMasterId = obj.ID,
                                    SchoolId     = mlUser.School.ID,
                                    CardType     = (byte)CardType.职员卡,
                                    CreateTime   = DateTime.Now,
                                    Status       = (byte)CardStatus.正常
                                };
                                UnitOfWork.Repository <SYS_Card>().AddEntity(card);
                                isOk = UnitOfWork.CommitAsync().Result;
                                if (isOk > 0)
                                {
                                    res = "OK";
                                }
                            }
                            else
                            {
                                repeatCardStr = cardNo;
                            }
                            if (repeatCardStr.Length > 0)
                            {
                                res = "警告:职员添加成功,但是卡" + repeatCardStr + "已存在,无法添加";
                            }
                        }
                    }
                    //修改职员
                    else
                    {
                        UnitOfWork.Repository <SYS_Staff>().UpdateEntity(obj);
                        res = "OK,修改成功";
                        //添加卡
                        if (cardNo != null && cardNo.Length > 0)
                        {
                            //检测该卡号是否已存在
                            var oldCard = UnitOfWork.Repository <SYS_Card>().GetEntitiesAsync(x => x.CardNo == cardNo && x.SchoolId == mlUser.School.ID).Result.FirstOrDefault();
                            if (oldCard == null)
                            {
                                //该用户是否有老卡,有则先注销
                                //var staffOldCard = UnitOfWork.Repository<SYS_Card>().GetEntities(x => x.CardMasterId == obj.ID && x.CardType == (byte)CardType.职员卡).FirstOrDefault();
                                //if (staffOldCard != null)
                                //{
                                //    staffOldCard.Status = (byte)CardStatus.注销;
                                //    UnitOfWork.Repository<SYS_Card>().UpdateEntity(staffOldCard);
                                //}
                                var card = new SYS_Card
                                {
                                    CardNo       = cardNo,
                                    CardMasterId = obj.ID,
                                    SchoolId     = mlUser.School.ID,
                                    CardType     = (byte)CardType.职员卡,
                                    CreateTime   = DateTime.Now,
                                    Status       = (byte)CardStatus.正常
                                };
                                UnitOfWork.Repository <SYS_Card>().AddEntity(card);
                            }
                            else
                            {
                                repeatCardStr = cardNo;
                            }
                            if (repeatCardStr.Length > 0)
                            {
                                res = "警告:卡" + repeatCardStr + "已存在,无法添加";
                            }
                        }
                        var isOk = UnitOfWork.CommitAsync().Result;
                        if (isOk > 0)
                        {
                            res = "OK";
                        }
                    }
                }
                UnitOfWork.Commit();
            }
            return(res);
        }
예제 #2
0
        /// <summary>
        /// 批量导入职员
        /// </summary>
        public string ImportStaffs(string fileName)
        {
            var res            = "数据格式有误";
            var totalRowCount  = 0;
            var staffCount     = 0;
            var repeatStaffStr = "";
            var repeatCardStr  = "";

            try
            {
                DataTable dt          = ExcelHelper.ImportExcel(fileName);
                var       nameCol     = 0;
                var       isNameColOk = false;
                if (dt.Rows.Count > 1)
                {
                    var staffs = (List <SYS_Staff>)GetSchoolEntities("staff");
                    totalRowCount = dt.Rows.Count - 1;
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        DataRow dr = dt.Rows[i];
                        if (!isNameColOk)
                        {
                            for (int j = 0; j < 10; j++)
                            {
                                //定位姓名所在列号
                                if (dr[j].ToString().Contains("姓名"))
                                {
                                    nameCol     = j;
                                    isNameColOk = true;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            //新建职员
                            var name     = dr[nameCol].ToString();
                            var phone    = dr[nameCol + 1].ToString();
                            var roleName = dr[nameCol + 2].ToString();
                            var role     = UnitOfWork.Repository <SYS_StaffRole>().GetEntitiesAsync(x => x.RoleName == roleName).Result.FirstOrDefault();
                            //检索是否重复
                            var oldStaff = staffs.Where(x => x.StaffName == name && x.Phone == phone && x.SchoolId == mlUser.School.ID && x.Status == (byte)StuStatus.正常).FirstOrDefault();
                            if (oldStaff == null)
                            {
                                var staff = new SYS_Staff
                                {
                                    StaffName  = name,
                                    SchoolId   = mlUser.School.ID,
                                    OpenId     = Guid.NewGuid().ToString(),
                                    WorkNo     = dr[nameCol + 3].ToString(),
                                    Phone      = phone,
                                    Status     = (byte)StaffStatus.在职,
                                    AttStatus  = (byte)CurrentAttStatus.未签到,
                                    CreateTime = DateTime.Now
                                };
                                if (role != null)
                                {
                                    staff.RoleId    = role.ID;
                                    staff.RoleLevel = role.RoleLevel;
                                }
                                UnitOfWork.Repository <SYS_Staff>().AddEntity(staff);
                                staffCount++;

                                //新建卡
                                var totalCol = dr.ItemArray.Count();
                                if (totalCol - nameCol > 4)
                                {
                                    int cardNo    = 0;
                                    var cardNoStr = dr[nameCol + 4].ToString();
                                    if (cardNoStr.Length > 3 && int.TryParse(cardNoStr, out cardNo))
                                    {
                                        //先提交学生到数据库-->得到学生ID
                                        var isOk = UnitOfWork.CommitAsync().Result;
                                        if (isOk > 0)
                                        {
                                            //开始建卡
                                            var oldCard = UnitOfWork.Repository <SYS_Card>().GetEntitiesAsync(x => x.CardNo == cardNoStr && x.SchoolId == mlUser.School.ID)
                                                          .Result.FirstOrDefault();
                                            if (oldCard == null)
                                            {
                                                var card = new SYS_Card
                                                {
                                                    SchoolId     = mlUser.School.ID,
                                                    CardMasterId = staff.ID,
                                                    CardNo       = cardNoStr,
                                                    CardType     = (byte)CardType.职员卡,
                                                    Status       = (byte)CardStatus.正常,
                                                    CreateTime   = DateTime.Now
                                                };
                                                UnitOfWork.Repository <SYS_Card>().AddEntity(card);
                                            }
                                            else
                                            {
                                                repeatCardStr += staff.StaffName + ":" + cardNoStr + "  ";
                                            }
                                            UnitOfWork.Commit();
                                        }
                                    }
                                }
                            }
                            else//同一个学校职员信息重复
                            {
                                repeatStaffStr += oldStaff.StaffName + "  ";
                            }
                        }
                    }
                    UnitOfWork.Commit();
                    if (repeatStaffStr.Length > 0)
                    {
                        repeatStaffStr = "<b class='text-danger'>" + repeatStaffStr + "</b>";
                    }
                    else
                    {
                        repeatStaffStr = "无";
                    }
                    if (repeatCardStr.Length > 0)
                    {
                        repeatCardStr = "<b class='text-danger'>" + repeatCardStr + "</b>";
                    }
                    else
                    {
                        repeatCardStr = "无";
                    }

                    res = "<div>操作OK,完成导入职员数:<b class='text-success'>" + staffCount +
                          "</b></div><div>重复导入失败:" + repeatStaffStr +
                          "</div><div>重复卡号建卡失败:" + repeatCardStr + "</div>";
                }
                dt.Dispose();
            }
            catch (Exception ex)
            {
                res = "错误:" + ex.Message;
            }

            GC.Collect();
            System.IO.File.Delete(fileName);
            return(res);
        }
예제 #3
0
        /// <summary>
        /// 批量导入学生
        /// </summary>
        public string ImportStus(int classId, string fileName)
        {
            var res           = "数据格式有误";
            var totalRowCount = 0;
            var stuCount      = 0;
            var repeatStuStr  = "";
            var repeatCardStr = "";

            try
            {
                DataTable dt          = ExcelHelper.ImportExcel(fileName);
                var       nameCol     = 0;
                var       isNameColOk = false;
                var       cls         = UnitOfWork.Repository <SYS_Class>().GetEntitiesAsync(x => x.ID == classId && x.SchoolId == mlUser.School.ID).Result.FirstOrDefault();
                if (null != cls && dt.Rows.Count > 1)
                {
                    var allStus = (List <SYS_Student>)GetSchoolEntities("stu");
                    totalRowCount = dt.Rows.Count - 1;
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        DataRow dr = dt.Rows[i];
                        if (!isNameColOk)
                        {
                            for (int j = 0; j < 10; j++)
                            {
                                //定位姓名所在列号
                                if (dr[j].ToString().Contains("姓名"))
                                {
                                    nameCol     = j;
                                    isNameColOk = true;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            //新建学生
                            byte sex    = 1;
                            var  name   = dr[nameCol].ToString();
                            var  phone  = dr[nameCol + 1].ToString();
                            var  oldStu = allStus.Where(x => x.StuName == name && x.Phone == phone && x.SchoolId == mlUser.School.ID && x.Status == (byte)StuStatus.正常).FirstOrDefault();
                            if (oldStu == null)
                            {
                                if (dr[nameCol + 2].ToString().Contains("女"))
                                {
                                    sex = 2;
                                }
                                var stu = new SYS_Student
                                {
                                    StuName    = name,
                                    SchoolId   = mlUser.School.ID,
                                    ClassId    = classId,
                                    Grade      = cls.Grade,
                                    Phone      = phone,
                                    Sex        = sex,
                                    StuNo      = dr[nameCol + 3].ToString(),
                                    Address    = dr[nameCol + 4].ToString(),
                                    Birthday   = DateTime.Parse(dr[nameCol + 5].ToString()),
                                    Status     = (byte)StuStatus.正常,
                                    AttStatus  = (byte)CurrentAttStatus.未签到,
                                    CreateTime = DateTime.Now
                                };
                                UnitOfWork.Repository <SYS_Student>().AddEntity(stu);
                                stuCount++;

                                //新建卡
                                var totalCol = dr.ItemArray.Count();
                                if (totalCol > 5)
                                {
                                    var cardNoList = new List <string>();

                                    for (var k = 1; k < totalCol - 5; k++)
                                    {
                                        int cardNo    = 0;
                                        var cardNoStr = dr[nameCol + 5 + k].ToString();
                                        if (cardNoStr.Length > 3 && int.TryParse(cardNoStr, out cardNo))
                                        {
                                            cardNoList.Add(cardNoStr);
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                    if (cardNoList.Count > 0)
                                    {
                                        //先提交学生到数据库-->得到学生ID
                                        var isOk = UnitOfWork.CommitAsync().Result;
                                        if (isOk > 0)
                                        {
                                            //开始建卡
                                            foreach (var cNo in cardNoList)
                                            {
                                                var oldCard = UnitOfWork.Repository <SYS_Card>().GetEntitiesAsync(x => x.CardNo == cNo && x.SchoolId == mlUser.School.ID).Result
                                                              .FirstOrDefault();
                                                if (oldCard == null)
                                                {
                                                    var card = new SYS_Card
                                                    {
                                                        SchoolId     = mlUser.School.ID,
                                                        CardMasterId = stu.ID,
                                                        CardNo       = cNo,
                                                        CardType     = (byte)CardType.学生卡,
                                                        Status       = (byte)CardStatus.正常,
                                                        CreateTime   = DateTime.Now
                                                    };
                                                    UnitOfWork.Repository <SYS_Card>().AddEntity(card);
                                                }
                                                else
                                                {
                                                    repeatCardStr += stu.StuName + ":" + cNo + "  ";
                                                }
                                            }
                                            UnitOfWork.Commit();
                                        }
                                    }
                                }
                            }
                            else//同一个学校学生信息重复
                            {
                                repeatStuStr += oldStu.StuName + "  ";
                            }
                        }
                    }
                    UnitOfWork.Commit();
                    if (repeatStuStr.Length > 0)
                    {
                        repeatStuStr = "<b class='text-danger'>" + repeatStuStr + "</b>";
                    }
                    else
                    {
                        repeatStuStr = "无";
                    }
                    if (repeatCardStr.Length > 0)
                    {
                        repeatCardStr = "<b class='text-danger'>" + repeatCardStr + "</b>";
                    }
                    else
                    {
                        repeatCardStr = "无";
                    }

                    res = "<div>操作OK,完成导入学生数:<b class='text-success'>" + stuCount +
                          "</b></div><div>重复学生导入失败:" + repeatStuStr +
                          "</div><div>重复卡号建卡失败:" + repeatCardStr + "</div>";
                }
                dt.Dispose();
            }
            catch (Exception ex)
            {
                res = "错误:" + ex.Message;
            }

            GC.Collect();
            System.IO.File.Delete(fileName);
            return(res);
        }
예제 #4
0
        /// <summary>
        /// 新增或修改学生(type->1:新增,2:修改)
        /// </summary>
        public string AddOrModifyStu(byte type, string entity)
        {
            var res = "操作失败";

            if (entity.Length > 6)
            {
                List <SYS_Class> classes = (List <SYS_Class>)GetSchoolEntities("class");
                SYS_Student      obj     = JsonHelper.JsonToTByKey <SYS_Student>(entity, "Student");
                List <string>    cardNos = JsonHelper.JsonToTByKey <List <string> >(entity, "Cards");

                if (null != obj)
                {
                    SYS_Class clas = classes.Where(x => x.ID == obj.ClassId).FirstOrDefault();
                    if (type == 1)//新增
                    {
                        obj.SchoolId   = mlUser.School.ID;
                        obj.Status     = (byte)StuStatus.正常;
                        obj.Grade      = clas.Grade;
                        obj.AttStatus  = (byte)CurrentAttStatus.未签到;
                        obj.CreateTime = DateTime.Now;

                        var oldStu = UnitOfWork.Repository <SYS_Student>().GetEntitiesAsync(x => x.StuName == obj.StuName && x.Phone == obj.Phone && x.SchoolId == obj.SchoolId && x.Status == (byte)StuStatus.正常).Result.FirstOrDefault();
                        var isOk   = 0;
                        if (oldStu == null)
                        {
                            UnitOfWork.Repository <SYS_Student>().AddEntity(obj);
                            isOk = UnitOfWork.CommitAsync().Result;
                            if (isOk > 0)
                            {
                                res = "OK,学生添加成功";
                            }
                        }
                        else
                        {
                            res = "学生信息重复,无法添加\r\n";
                        }
                        //建卡
                        var stuOldCards = UnitOfWork.Repository <SYS_Card>().GetEntitiesAsync(x => x.CardMasterId == obj.ID && x.CardType == (byte)CardType.学生卡).Result;//该学生已有卡
                        if (isOk > 0 && null != cardNos && cardNos.Count > 0)
                        {
                            var repeatCardStr = "";
                            foreach (var cNo in cardNos)
                            {
                                if (stuOldCards.FindIndex(delegate(SYS_Card card) { return(card.CardNo == cNo); }) < 0)
                                {
                                    var oldCard = UnitOfWork.Repository <SYS_Card>().GetEntitiesAsync(x => x.CardNo == cNo && x.SchoolId == mlUser.School.ID)
                                                  .Result.FirstOrDefault();
                                    if (oldCard == null)
                                    {
                                        SYS_Card newCard = new SYS_Card
                                        {
                                            CardNo       = cNo,
                                            CardMasterId = obj.ID,
                                            SchoolId     = mlUser.School.ID,
                                            CardType     = (byte)CardType.学生卡,
                                            Status       = (byte)CardStatus.正常,
                                            CreateTime   = DateTime.Now
                                        };
                                        UnitOfWork.Repository <SYS_Card>().AddEntity(newCard);
                                        isOk = UnitOfWork.CommitAsync().Result;
                                    }
                                    else
                                    {
                                        repeatCardStr += cNo + " ";
                                    }
                                }
                            }
                            if (repeatCardStr.Length > 0)
                            {
                                res = "警告:学生添加成功,但是卡" + repeatCardStr + "已存在,无法添加";
                            }
                        }
                    }
                    else//修改
                    {
                        UnitOfWork.Repository <SYS_Student>().UpdateEntity(obj);
                        var isOk = UnitOfWork.CommitAsync().Result;
                        if (isOk > 0)
                        {
                            res = "OK,学生修改成功";
                        }
                        else
                        {
                            res = "学生信息修改失败\r\n";
                        }
                        ///建卡
                        //检索该学生已有卡
                        var stuOldCards = UnitOfWork.Repository <SYS_Card>().GetEntitiesAsync(x => x.CardMasterId == obj.ID && x.CardType == (byte)CardType.学生卡).Result;
                        if (isOk > 0 && null != cardNos && cardNos.Count > 0)
                        {
                            var repeatCardStr = "";
                            foreach (var cNo in cardNos)
                            {
                                if (stuOldCards.FindIndex(delegate(SYS_Card card) { return(card.CardNo == cNo); }) < 0)
                                {
                                    var oldCard = UnitOfWork.Repository <SYS_Card>().GetEntitiesAsync(x => x.CardNo == cNo && x.SchoolId == mlUser.School.ID && x.Status == (byte)CardStatus.正常)
                                                  .Result.FirstOrDefault();
                                    if (oldCard == null)
                                    {
                                        SYS_Card newCard = new SYS_Card
                                        {
                                            CardNo       = cNo,
                                            CardMasterId = obj.ID,
                                            SchoolId     = mlUser.School.ID,
                                            CardType     = (byte)CardType.学生卡,
                                            Status       = (byte)CardStatus.正常,
                                            CreateTime   = DateTime.Now
                                        };
                                        UnitOfWork.Repository <SYS_Card>().AddEntity(newCard);
                                        isOk = UnitOfWork.CommitAsync().Result;
                                    }
                                    else
                                    {
                                        repeatCardStr += cNo + " ";
                                    }
                                }
                            }
                            if (repeatCardStr.Length > 0)
                            {
                                res = "警告:卡" + repeatCardStr + "已存在,无法添加";
                            }
                        }
                    }
                }
            }
            return(res);
        }