Пример #1
0
        public ActionResult Create(MemberViewModel model)
        {
            ServiceResult result = new ServiceResult();
            TempData["Service_Result"] = result;
            if (ModelState.IsValid)
            {
                try
                {
                    MemberService.Create(model);
                    result.Message = "添加会员信息成功!";
                    LogHelper.WriteLog("添加会员信息成功");
                    return RedirectToAction("index");
                }
                catch (Exception ex)
                {
                    result.Message = Utilities.GetInnerMostException(ex);
                    result.AddServiceError(result.Message);
                    LogHelper.WriteLog("添加会员信息错误", ex);
                }
            }
            else
            {
                result.Message = "请检查表单是否填写完整!";
                result.AddServiceError("请检查表单是否填写完整!");

            }
            ViewBag.Data_GroupID = Utilities.GetSelectListData(GroupService.GetALL()
              , x => x.ID, x => x.Name, true);
            ViewBag.Data_DepartmentID = Utilities.GetSelectListData(DepartmentService.GetALL()
                , x => x.ID, x => x.Name, true);
            ViewBag.Data_JobTitleID = Utilities.GetSelectListData(
               JobTitleCateService.GetALL()
              , x => x.ID, x => x.CateName, true);
            return View(model);
        }
Пример #2
0
        public ActionResult Create(MemberClerkViewModel model)
        {
            ServiceResult result = new ServiceResult();
            TempData["Service_Result"] = result;
            if (ModelState.IsValid)
            {
                try
                {

                    //groupID 6  指的是基本业务功能的会员群组
                    var entity = new MemberViewModel()
                    {
                        Address = model.Address,
                        BirthDay = model.BirthDay,
                        DepartmentID = model.DepartmentID,
                        Description = model.Description,
                        Email = model.Email,
                        IsLeader = model.IsLeader,
                        IsLeap = model.IsLeap,
                        Mobile = model.Mobile,
                        Mobile1 = model.Mobile1,
                        NickName = model.NickName,
                        Password = model.Password,
                        QQ = model.QQ,
                        Sex = model.Sex,
                        GroupID = 6,
                        FamilySituation = model.FamilySituation,
                        IDNumber = model.IDNumber,
                        JobExp = model.JobExp,
                        AvtarUrl = model.AvtarUrl,
                        StudyExp = model.StudyExp
                    };
                    MemberService.Create(entity);
                    result.Message = "添加业务人员成功!";
                    LogHelper.WriteLog("添加业务人员成功");
                    return RedirectToAction("index");
                }
                catch (Exception ex)
                {
                    result.Message = Utilities.GetInnerMostException(ex);
                    result.AddServiceError(result.Message);
                    LogHelper.WriteLog("添加业务人员错误", ex);
                }
            }
            else
            {
                result.Message = "请检查表单是否填写完整!";
                result.AddServiceError("请检查表单是否填写完整!");

            }
            var member = MemberService.GetALL().Include(x => x.Department)
                 .Single(x => x.MemberID == CookieHelper.MemberID);
            var departCode = member.Department.Code;
            var maxCode = Utilities.GetMaxCode(departCode, member.Department.Level);
            ViewBag.Data_DepartmentID = Utilities.GetSelectListData(
                DepartmentService.GetALL().Where(x => x.Code >= departCode && x.Code <= maxCode)
                , x => x.ID, x => x.Name, true);
            return View(model);
        }
Пример #3
0
        public ActionResult Import(ImportViewModel model)
        {
            ServiceResult result = new ServiceResult();
            TempData["Service_Result"] = result;
            var savePath = Server.MapPath("~/" + model.FilePath);
            string strConn;
            strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + savePath + ";" + "Extended Properties=Excel 8.0";
            OleDbConnection conn = new OleDbConnection(strConn);
            conn.Open();
            OleDbDataAdapter myCommand = new OleDbDataAdapter("select * from [Sheet1$]", strConn);
            DataSet myDataSet = new DataSet();
            try
            {
                myCommand.Fill(myDataSet, "ExcelInfo");
            }
            catch (Exception ex)
            {
                result.Message = Utilities.GetInnerMostException(ex);
                result.AddServiceError(result.Message);
                LogHelper.WriteLog("上传会员信息错误", ex);
                return View();
            }
            DataTable table = myDataSet.Tables["ExcelInfo"].DefaultView.ToTable();

            var departlist = DepartmentService.GetALL().ToList();
            var jobtitlelist = JobTitleCateService.GetALL().ToList();
            using (TransactionScope transaction = new TransactionScope())
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    var row = table.Rows[i];
                    var member = new MemberViewModel();
                    if (string.IsNullOrEmpty(row[1].ToString())
                        || string.IsNullOrEmpty(row[2].ToString())
                          || string.IsNullOrEmpty(row[3].ToString())
                          || string.IsNullOrEmpty(row[4].ToString())
                          || string.IsNullOrEmpty(row[6].ToString())
                          || string.IsNullOrEmpty(row[7].ToString())
                        )
                    {

                        continue;
                    }

                    if (departlist.Count(x => x.Name == row[2].ToString()) == 0)
                    {
                        result.Message = "上传数据部门格式错误";
                        result.AddServiceError(result.Message);
                    }
                    else
                    {
                        member.DepartmentID = departlist.Single(x => x.Name == row[2].ToString()).ID;
                    }
                    if (jobtitlelist.Count(x => x.CateName == row[3].ToString()) == 0)
                    {
                        result.Message = "上传数据职称类别格式错误";
                        result.AddServiceError(result.Message);
                    }
                    else
                    {
                        member.JobTitleID = jobtitlelist.Single(x => x.CateName == row[3].ToString()).ID;
                    }
                    member.NickName = row[1].ToString().Replace(" ", "");
                    member.Mobile = row[4].ToString();
                    member.QQ = row[5].ToString();
                    member.Email = row[6].ToString();
                    member.Password = "******";
                    member.GroupID = 6;
                    if (row[7].ToString() == "是")
                    {
                        member.IsLeader = true;
                    }
                    else
                    {
                        member.IsLeader = false;
                    }
                    if (row[8].ToString() == "男")
                    {
                        member.Sex = false;
                    }
                    else
                    {
                        member.Sex = true;
                    }

                    MemberService.Create(member);
                }
                transaction.Complete();
            }
            System.Threading.Thread.Sleep(2000);
            result.Message = "批量导入用户数据成功!";
            LogHelper.WriteLog("批量导入用户数据成功!");
            return RedirectToAction("Index");
        }