Example #1
0
 public ActionResult Create(FormCollection collection)
 {
     try
     {
         if (Session["UserTsk_UserId"] == null)
         {
             return(RedirectToAction("Index", "User"));
         }
         else
         {
             if (collection.Get("TskNo").Trim().Length > 0)
             {
                 UserTsk userTsk;
                 using (IUnitOfWork unitOfWork = new TskDataDataContext(DbUtil.ConnectionString))
                 {
                     IUserTskRep userTskRep = new UserTskRep(unitOfWork);
                     UserTsk     ut         = userTskRep.FindByUserId((int)Session["UserTsk_UserId"], collection.Get("TskNo"));
                     if (ut == null)
                     {
                         userTsk = new UserTsk()
                         {
                             UserId = (int)Session["UserTsk_UserId"], TskNo = collection.Get("TskNo")
                         };
                         userTskRep.Create(userTsk);
                         unitOfWork.Submit();
                     }
                     else
                     {
                         TempData["Message"] = "此用户已配置TSK:" + collection.Get("TskNo");
                         return(View());
                     }
                 }
             }
             else
             {
                 TempData["Message"] = "TskNo长度需大于0";
                 return(View());
             }
         }
         return(RedirectToAction("Index", new { userId = Session["UserTsk_UserId"] }));
     }
     catch
     {
         return(View());
     }
 }
Example #2
0
 public bool ValidateUser(string username, string password = null)
 {
     using (IUnitOfWork unitOfWork = new TskDataDataContext(DbUtil.ConnectionString))
     {
         IUserRep userRep = new UserRep(unitOfWork);
         User     user    = userRep.Find(username, password);
         if (user == null)
         {
             return(false);
         }
         else
         {
             user.LastLoginTime = DateTime.Now;
             unitOfWork.Submit();
             return(true);
         }
     }
 }
Example #3
0
        public bool ChangePassword(string username, string oldPassword, string newPassword)
        {
            using (IUnitOfWork unitOfWork = new TskDataDataContext(DbUtil.ConnectionString))
            {
                IUserRep userRep = new UserRep(unitOfWork);
                User     user    = userRep.Find(username, oldPassword);
                if (user != null)
                {
                    user.Password = newPassword;

                    unitOfWork.Submit();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Example #4
0
        public ActionResult Delete(int id, FormCollection collection)
        {
            UserTsk userTsk = null;

            try
            {
                using (IUnitOfWork unitOfWork = new TskDataDataContext(DbUtil.ConnectionString))
                {
                    IUserTskRep userTskRep = new UserTskRep(unitOfWork);
                    userTsk = userTskRep.FindById(id);
                    userTskRep.Delete(userTsk);
                    unitOfWork.Submit();
                }
                return(RedirectToAction("Index", new { userId = Session["UserTsk_UserId"] }));
            }
            catch
            {
                return(View(userTsk));
            }
        }
Example #5
0
        public void CreateUser(string username, string password, string role, string email, out MembershipCreateStatus status)
        {
            status = MembershipCreateStatus.Success;
            using (IUnitOfWork unitOfWork = new TskDataDataContext(DbUtil.ConnectionString))
            {
                IUserRep userRep = new UserRep(unitOfWork);

                if (userRep.Find(username) != null)
                {
                    status = MembershipCreateStatus.DuplicateUserName;
                }
                else
                {
                    userRep.Create(new User()
                    {
                        Name = username, Password = password, Role = role, Email = email
                    });
                }
                unitOfWork.Submit();
            }
        }
Example #6
0
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                User user;

                using (IUnitOfWork unitOfWork = new TskDataDataContext(DbUtil.ConnectionString))
                {
                    IUserRep userRep = new UserRep(unitOfWork);
                    user = userRep.FindById(id);

                    if (Brilliantech.Tsk.Manage.WebApp.Util.CustomMembershipProvider.CanEdit(user.Name))
                    {
                        ViewData["Role"] = new SelectList(UserRoleModel.UserRoleList(), "Key", "Name", user.Role);
                        if (collection.Get("Password").Trim().Length < CustomMembershipProvider.MinRequiredPasswordLength)
                        {
                            ViewBag.Message = "密码长度小于" + CustomMembershipProvider.MinRequiredPasswordLength;
                            return(View(user));
                        }
                        else
                        {
                            user.Password = collection.Get("Password").Trim();
                            user.Role     = collection.Get("Role");
                            user.Email    = collection.Get("Email");
                            unitOfWork.Submit();
                            return(RedirectToAction("Index"));
                        }
                    }
                    else
                    {
                        TempData["Message"] = "初始管理员,不可以编辑";
                        return(RedirectToAction("Index"));
                    }
                }
            }
            catch
            {
                return(View());
            }
        }
Example #7
0
        public ProcessMessage CreateInspect(string text)
        {
            ProcessMessage message = new ProcessMessage();

            try
            {
                using (IUnitOfWork unitOfWork = new TskDataDataContext(MSSqlConfig.ConnectionString))
                {
                    IInspectOriginRep inspectOriginRep = new InspectOriginRep(unitOfWork);
                    InspectOrigin     inspectOrigin    = new InspectOrigin()
                    {
                        Id        = Guid.NewGuid(),
                        Text      = text,
                        CreatedAt = DateTime.Now
                    };

                    if (text == null || text.Length == 0 || text.Split(TskConfig.DataSpliter).Length != TskConfig.DataCount)
                    {
                        message.Result = false;
                        message.Messages.Add("数据为空或数据格式不存在");
                        if (!string.IsNullOrEmpty(text))
                        {
                            message.Messages.Add("数据属性长度为:" + text.Split(TskConfig.DataSpliter).Length.ToString());
                            message.Messages.Add("分隔符为:" + TskConfig.DataSpliter.ToString());
                        }
                        LogUtil.Logger.Error(message.GetMessageContent());
                    }
                    else
                    {
                        IInspectRep inspectRep = new InspectRep(unitOfWork);
                        string[]    data       = text.Split(TskConfig.DataSpliter);
                        Inspect     inspect    = new Inspect()
                        {
                            Id         = Guid.NewGuid(),
                            TskNo      = data[0],
                            LeoniNo    = data[1],
                            CusNo      = data[2],
                            ClipScanNo = data[3],
                            //  ClipScanTime1 = data[4],
                            // ClipScanTime2 = data[6],
                            TskScanNo = data[7],
                            // TskScanTime3 = data[8],
                            // Time3MinTime2 = data[9],
                            OkOrNot   = data[10],
                            CreatedAt = DateTime.Now,
                            OriginId  = inspectOrigin.Id
                        };
                        DateTime clipScanTime1 = DateTime.Now;
                        if (DateTime.TryParse(data[4], out clipScanTime1))
                        {
                            inspect.ClipScanTime1 = clipScanTime1;
                        }

                        DateTime clipScanTime2 = DateTime.Now;
                        if (DateTime.TryParse(data[6], out clipScanTime2))
                        {
                            inspect.ClipScanTime2 = clipScanTime2;
                        }

                        DateTime tskScanTime3 = DateTime.Now;
                        if (DateTime.TryParse(data[8], out tskScanTime3))
                        {
                            inspect.TskScanTime3 = tskScanTime3;
                        }

                        float time3MinTime2 = 0;
                        if (float.TryParse(data[9], out time3MinTime2))
                        {
                            inspect.Time3MinTime2 = time3MinTime2;
                        }

                        inspectRep.Create(inspect);
                        message.Messages.Add("数据处理成功");
                        message.Result = true;
                    }

                    inspectOrigin.ProcessResult  = message.Result;
                    inspectOrigin.ProcessMessage = message.GetMessageContent();
                    inspectOriginRep.Create(inspectOrigin);

                    unitOfWork.Submit();
                }
                return(message);
            }
            catch (Exception e)
            {
                LogUtil.Logger.Error(e.Message);
                throw e;
            }
        }