Beispiel #1
0
        public ActionResult Upload(IEnumerable<HttpPostedFileBase> uploads, DocumentViewModel model)
        {
            int[] fileId;
            int docId;
            if (model.Id != 0)
            {
                dataManager.Documents.SaveDocument(new documents
                {
                    id = model.Id,
                    name = model.DocName,
                    docTypeID = model.DocTypeId,
                    dateS = model.DateS,
                    datePo = model.DatePo,
                    onBoard = model.OnBoard,
                    carID = model.CarId,
                    createUser = model.CreateUser,
                    createDate = model.CreateDate,
                    //updateUser =
                    updateDate = DateTime.Now
                });
                docId = model.Id;
            }
            else
            {
                docId = dataManager.Documents.CreateDocument(model.DocTypeId, model.DocName, model.DateS, model.DatePo, model.OnBoard, model.CarId, null, DateTime.Now, null, null);
            }
            List<int> fileIdList = new List<int>();
            if (uploads != null)
            {
                foreach (var file in uploads)
                {
                    if (file != null)
                    {
                        string rout = "~/Files/" + dataManager.DocumentTypes.GetDocumentTypeById(model.DocTypeId).name + "/" + DateTime.Today.Month + "." + DateTime.Today.Year + "/";
                        if (!Directory.Exists(Server.MapPath(rout)))
                        {
                            Directory.CreateDirectory(Server.MapPath(rout));
                        }

                        // получаем имя файла
                        string fileName = System.IO.Path.GetFileName(file.FileName);
                        //проверяем наличие файла с такимже именем
                        if (System.IO.File.Exists(Server.MapPath(rout + fileName)))
                        {
                            string ext = System.IO.Path.GetExtension(file.FileName);
                            string n = System.IO.Path.GetFileNameWithoutExtension(file.FileName);
                            fileName = n + "_" + ext;
                        }
                        // сохраняем файл в папку Files в проекте
                        file.SaveAs(Server.MapPath(rout + fileName));
                        fileIdList.Add(dataManager.Files.CreateFile(Server.MapPath(rout + fileName), fileName));
                    }
                }
                fileId = fileIdList.ToArray();
                dataManager.Documents.AddDocumentsToFile(fileId, docId);
            }
            return RedirectToAction("CarList", "Home");
        }
Beispiel #2
0
        public ActionResult AllDocuments()
        {
            int orgId = 0;
            DateTime? Ds = null;
            DateTime? Dp = null;
            if (Request.Cookies["DocCookie"] != null)
            {
                if (Request.Cookies["DocCookie"]["org"] != "")
                {
                    orgId = Convert.ToInt32(Request.Cookies["DocCookie"]["org"]);
                }
                if (Request.Cookies["DocCookie"]["dateS"] != "")
                {
                    Ds = Convert.ToDateTime(Request.Cookies["DocCookie"]["dateS"]);
                }
                if (Request.Cookies["DocCookie"]["datePo"] != "")
                {
                    Dp = Convert.ToDateTime(Request.Cookies["DocCookie"]["datePo"]);
                }
            }
            ViewBag.DropDownListOrg = (orgId != 0) ? new SelectList(dataManager.Organizations.GetOrgList(), "id", "Name", orgId) : new SelectList(dataManager.Organizations.GetOrgList(), "id", "Name", null);
            ViewBag.DocTypes = dataManager.DocumentTypes.GetDocumentTypes();
            IEnumerable<cars> cars = (orgId != 0) ? dataManager.Cars.GetCars().Where(x => x.BranchListId == orgId) : dataManager.Cars.GetCars();
            if (cars.Count() != 0)
            {
                CarListViewModel carList = new CarListViewModel();
                if (Ds != null && Dp != null)
                {
                    carList.DateS = Ds;
                    carList.DatePo = Dp;
                }
                carList.CarList = new List<CarViewModel>();
                foreach (cars c in cars)
                {
                    int colorPrior = 0;
                    int maxColorProir = 0;
                    IEnumerable<documents> docs = (Ds != null && Dp != null) ? dataManager.Documents.GetDocumentsByCar(c.CarId).Where(x => x.datePo >= Ds && x.datePo <= Dp).OrderBy(x => x.datePo) : dataManager.Documents.GetDocumentsByCar(c.CarId).OrderBy(x => x.datePo);

                    CarViewModel car = new CarViewModel();
                    car.Id = c.CarId;
                    car.CarNumber = c.CarNumber;
                    car.StateNumber = c.StateNumber;
                    if (c.BranchListId != null)
                    {
                        car.BranchName = c.organizationLists.name;
                    }
                    IEnumerable<documentTypes> docTypes = dataManager.DocumentTypes.GetDocumentTypes();
                    if (docTypes.Count() != 0)
                    {
                        car.DocList = new List<DocumentViewModel>();
                        foreach (documentTypes dt in docTypes)
                        {
                            DocumentViewModel d = new DocumentViewModel();
                            foreach (documents doc in docs)
                            {
                                if (doc.docTypeID == dt.id)
                                {
                                    if (doc.datePo != null)
                                    {
                                        DateTime shortDate = Convert.ToDateTime(doc.datePo);
                                        shortDate.ToShortDateString();
                                        d.DocName = shortDate.ToShortDateString();
                                        d.DatePo = shortDate;
                                        int days = ((TimeSpan)(doc.datePo - DateTime.Today)).Days;
                                        if (days <= 0)
                                        {
                                            d.color = "#ff0000";
                                            colorPrior = 3;
                                        }
                                        if (days > 0 && days <= dt.alarm2)
                                        {
                                            d.color = "#ffd800";
                                            colorPrior = 2;
                                        }
                                        if (days > dt.alarm2 && days <= dt.alarm1)
                                        {
                                            d.color = "#00ff21";
                                            colorPrior = 1;
                                        }
                                    }
                                    else
                                    {
                                        d.DocName = "Есть";
                                    }
                                }
                                if (dt.orgID != c.BranchListId && dt.orgID != null)
                                {
                                    d.DocName = "Не нужно";
                                }
                            }
                            car.DocList.Add(d);
                            if (maxColorProir < colorPrior)
                                maxColorProir = colorPrior;
                        }
                    }
                    if (maxColorProir == 3) car.color = "#ff0000";
                    if (maxColorProir == 2) car.color = "#ffd800";
                    if (maxColorProir == 1) car.color = "#00ff21";
                    carList.CarList.Add(car);
                }
                return View(carList);
            }
            return View();
        }
Beispiel #3
0
 public ActionResult DellDoc(DocumentViewModel model)
 {
     int[] filesId = dataManager.Files.GetFilesForDocument(model.Id);
     if (filesId.Count() != 0)
     {
         dataManager.Files.DellFilesFromDocument(model.Id, filesId);
         foreach (int fileId in filesId)
         {
             dataManager.Files.DeleteFile(fileId);
         }
     }
     dataManager.Documents.DeleteDocument(model.Id);
     return RedirectToAction("CarActiveDocumment", "Home", new { carId = model.CarId });
 }