Ejemplo n.º 1
0
 public ActionResult Edit(int id)
 {
     User user;
     using (IUnitOfWork unitOfWork = new TskDataDataContext(DbUtil.ConnectionString))
     {
         IUserRep userRep = new UserRep(unitOfWork);
         user = userRep.FindById(id);
         if (user != null)
         {
             if (Brilliantech.Tsk.Manage.WebApp.Util.CustomMembershipProvider.CanEdit(user.Name))
             {
                 ViewData["Role"] = new SelectList(UserRoleModel.UserRoleList(), "Key", "Name", user.Role);
                 return View(user);
             }
             else
             {
                 TempData["Message"] = "初始管理员,不可以编辑";
                 return RedirectToAction("Index");
             }
         }
         else {
             return RedirectToAction("Index");
         }
     }
 }
Ejemplo n.º 2
0
 public BaseRep(IUnitOfWork _unit)
 {
     if (_unit == null)
     {
         throw new ArgumentNullException("Data context is null");
     }
     else {
         this.context = _unit as TskDataDataContext;
     }
 }
 //
 // GET: /Inspect/Details/5
 public ActionResult Details(string id)
 {
     InspectOrigin inspect;
     using (IUnitOfWork unitOfWork = new TskDataDataContext(DbUtil.ConnectionString))
     {
         IInspectOriginRep inspectRep = new InspectOriginRep(unitOfWork);
         inspect = inspectRep.FindById(id);
     }
     return View(inspect);
 }
Ejemplo n.º 4
0
 //
 // GET: /UserTsk/Delete/5
 public ActionResult Delete(int id)
 {
     UserTsk userTsk;
     using (IUnitOfWork unitOfWork = new TskDataDataContext(DbUtil.ConnectionString))
     {
         IUserTskRep userTskRep = new UserTskRep(unitOfWork);
         userTsk = userTskRep.FindById(id);
         if (userTsk != null)
         {
             return View(userTsk);
         }
         else
         {
             return RedirectToAction("Index", new { userId = Session["UserTsk_UserId"] });
         }
     }
 }
Ejemplo n.º 5
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();
     }
 }
Ejemplo n.º 6
0
        public ActionResult Delete(int id, FormCollection collection)
        {
            User user = null;
            try
            {
                using (IUnitOfWork unitOfWork = new TskDataDataContext(DbUtil.ConnectionString))
                {
                    IUserRep userRep = new UserRep(unitOfWork);
                    user = userRep.FindById(id);
                    userRep.Delete(user);
                    unitOfWork.Submit();
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View(user);
            }
        }
Ejemplo n.º 7
0
 private IPagedList<Inspect> QueryInspect(InspectQueryModel query, int? currentPageIndex, int? pageSize)
 {
     IPagedList<Inspect> inspects;
     using (IUnitOfWork unitOfWork = new TskDataDataContext(DbUtil.ConnectionString))
     {
         IInspectRep inspectRep = new InspectRep(unitOfWork);
         inspects = GenerateQuery(unitOfWork, query).ToPagedList(currentPageIndex.Value, pageSize.Value);
     }
     return inspects;
 }
Ejemplo n.º 8
0
 private List<Inspect> ExportInspect(InspectQueryModel query)
 {
     List<Inspect> inspects = new List<Inspect>();
     using (IUnitOfWork unitOfWork = new TskDataDataContext(DbUtil.ConnectionString))
     {
         IInspectRep inspectRep = new InspectRep(unitOfWork);
         inspects = GenerateQuery(unitOfWork, query).ToList<Inspect>();
     }
     return inspects;
 }
Ejemplo n.º 9
0
        public ActionResult Index(int? page)
        {
            DateTime dt = DateTime.Now;
            DateTime endTime = dt.AddDays(1 - Convert.ToInt32(dt.DayOfWeek.ToString("d")));
            NameValueCollection q = new NameValueCollection();
            q.Add("ClipScanTime1Start", endTime.AddDays(-1).ToString("yyyy/MM/dd 10:00"));
            q.Add("ClipScanTime1End", DateTime.Now.AddHours(1).ToString("yyyy/MM/dd HH:00"));
            InspectQueryModel query = new InspectQueryModel(q);

            IPagedList<Inspect> inspects = null;
            using (IUnitOfWork unitOfWork = new TskDataDataContext(DbUtil.ConnectionString))
            {
                int currentPageIndex = page.HasValue ? (page.Value <= 0 ? 0 : page.Value - 1) : 0;
                IInspectRep inspectRep = new InspectRep(unitOfWork);
                inspects = inspectRep.Queryable(query.ClipScanTime1Start,query.ClipScanTime1End).ToPagedList(currentPageIndex, int.Parse(Resources.PageSize));
            }
            ViewBag.Query = query;
            return View(inspects);
        }
Ejemplo n.º 10
0
        public ActionResult Index(int userId)
        {
            List<UserTsk> userTsks = null;

            using (IUnitOfWork unitOfWork = new TskDataDataContext(DbUtil.ConnectionString))
            {
                Session["UserTsk_UserId"] = userId;
                IUserTskRep userTskRep = new UserTskRep(unitOfWork);
                userTsks = userTskRep.ListByUserId(userId);
            }
            return View(userTsks);
        }
        public ActionResult Index(int? page)
        {
            DateTime dt = DateTime.Now;
            DateTime endTime = dt.AddDays(1 - Convert.ToInt32(dt.DayOfWeek.ToString("d")));
            NameValueCollection q = new NameValueCollection();
            q.Add("CreatedAtStart", endTime.AddDays(-1).ToString("yyyy/MM/dd 10:00"));
            q.Add("CreatedAtEnd", DateTime.Now.AddHours(1).ToString("yyyy/MM/dd HH:00"));
            InspectOriginQueryModel query = new InspectOriginQueryModel(q);

            IPagedList<InspectOrigin> inspects = null;
            using (var txn = new System.Transactions.TransactionScope(TransactionScopeOption.Required,
               new TransactionOptions
               {
                   IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted
               }))
            {
                using (IUnitOfWork unitOfWork = new TskDataDataContext(DbUtil.ConnectionString))
                {
                    int currentPageIndex = page.HasValue ? (page.Value <= 0 ? 0 : page.Value - 1) : 0;
                    IInspectOriginRep inspectOriginRep = new InspectOriginRep(unitOfWork);
                    inspects = inspectOriginRep.Queryable(query.CreatedAtStart,query.CreatedAtEnd).ToPagedList(currentPageIndex, int.Parse(Resources.PageSize));
                }
            }
            ViewBag.Query = query;
            return View(inspects);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Called by the <see cref="IScheduler" /> when a
        /// <see cref="ITrigger" /> fires that is associated with the <see cref="IJob" />.
        /// </summary>
        public virtual void Execute(IJobExecutionContext context)
        {
            //TestFile(context);
            //return;
            try
            {
                JobDataMap job = context.JobDetail.JobDataMap;
                DateTime startQueryDate = (DateTime)job.Get("StartDate");
                DateTime endQueryDate = (DateTime)job.Get("EndDate");

                List<User> users = null;
                using (IUnitOfWork unitOfWork = new TskDataDataContext(DbUtil.ConnectionString))
                {
                    IUserRep userRep = new UserRep(unitOfWork);
                    users = userRep.ListWithEmail();
                }

                SmtpClient smtpServer = new SmtpClient(EmailServerSetting.SmtpHost);
                //smtpServer.Port = EmailServerSetting.SmtpPort;
                smtpServer.Credentials = new System.Net.NetworkCredential(EmailServerSetting.EmailUser, EmailServerSetting.EmailPwd);

                foreach (User user in users)
                {
                    try
                    {
                        List<UserInspect> inspects = new List<UserInspect>();
                        using (IUnitOfWork unitOfWork = new TskDataDataContext(DbUtil.ConnectionString))
                        {
                            IUserInspectRep userInspectRep = new UserInspectRep(unitOfWork);
                            inspects = userInspectRep.ListByUserId(user.Id, startQueryDate, endQueryDate);
                        }
                        if (inspects.Count > 0)
                        {
                            using (MailMessage mail = new MailMessage())
                            {
                                mail.From = new MailAddress(EmailServerSetting.EmailAddress);
                                mail.To.Add(user.Email);
                                mail.Subject = "电测台数据文件";

                                var filename = "Inspect" + DateTime.Now.ToString("yyyyMMddHHmm") + "_" + Guid.NewGuid().ToString("N");
                                var csvfilename = filename + ".csv";
                                //var zipfilename = filename + ".zip";

                                var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "InspectFileTmp");
                                if (!Directory.Exists(filePath))
                                {
                                    Directory.CreateDirectory(filePath);
                                }
                                var csvFilePath = Path.Combine(filePath, csvfilename);
                                //var zipFilePath = Path.Combine(filePath, zipfilename);

                                using (FileStream csv = new FileStream(csvFilePath, FileMode.Create, FileAccess.ReadWrite))
                                {
                                    using (MemoryStream ms = new MemoryStream())
                                    {
                                        using (StreamWriter sw = new StreamWriter(ms, Encoding.UTF8))
                                        {
                                            sw.WriteLine(string.Join(",", InspectQueryModel.CsvHead.ToArray()));
                                            foreach (UserInspect i in inspects)
                                            {
                                                List<string> ii = new List<string>();
                                                foreach (string field in InspectQueryModel.Fileds)
                                                {
                                                    var value = i.GetType().GetProperty(field).GetValue(i, null);
                                                    ii.Add(value == null ? "" : value.ToString());
                                                }
                                                sw.WriteLine(string.Join(",", ii.ToArray()));
                                            }

                                            csv.Write(ms.ToArray(), 0, (int)ms.Length);
                                        }
                                    }
                                }
                                //using (ZipFile zip = new ZipFile())
                                //{
                                //    zip.AddFile(csvFilePath);
                                //    zip.Save(zipfilename);
                                //}
                                Attachment att = new Attachment(csvFilePath);
                                mail.Attachments.Add(att);

                                smtpServer.Send(mail);
                                LogUtil.Logger.Info("Send Inspect Email to:" + user.Email + ", File: " + filename);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        LogUtil.Logger.Error(ex.Message);
                    }
                }
            }
            catch (Exception e)
            {
                LogUtil.Logger.Error(e.Message);
            }
        }
Ejemplo n.º 13
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;
            }
        }
Ejemplo n.º 14
0
 public ActionResult Index(int? page)
 {
     IPagedList<User> users = null;
     using (IUnitOfWork unitOfWork = new TskDataDataContext(DbUtil.ConnectionString))
     {
         int currentPageIndex = page.HasValue ? (page.Value <= 0 ? 0 : page.Value - 1) : 0;
         IUserRep userRep = new UserRep(unitOfWork);
         users = userRep.Queryable().ToPagedList(currentPageIndex, int.Parse(Resources.PageSize));
     }
     return View(users);
 }
Ejemplo n.º 15
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();
            }
        }