private void actForwardDocument_Execute(object sender, SimpleActionExecuteEventArgs e)
        {
            os = Application.CreateObjectSpace();
            Document currentDoc = View.CurrentObject as Document;
            Document newDoc     = os.CreateObject <Document>(); //.GetObject<Document>(currentDoc);

            //newDoc = currentDoc.CloneDocument(newDoc.Session);
            newDoc.DocId       = currentDoc.DocId;
            newDoc.IsApproveed = false;
            newDoc.Note        = @"<u>VB chuyển tiếp:</u><br />" + currentDoc.DocId;
            newDoc.Excerpt     = string.Format("[CT] {0}", currentDoc.Excerpt);
            newDoc.DocDate     = currentDoc.DocDate;
            //newDoc.DocSignees = os.GetObject<DocumentSignees>(currentDoc.DocSignees);
            newDoc.DocOrganization = os.GetObject <DocumentSigneesOrganization>(currentDoc.DocOrganization);
            newDoc.EmployeeReceiveds.Clear();
            newDoc.DocumentEmployees.Clear();
            newDoc.ParentDocument = os.GetObject <Document>(currentDoc);
            //newDoc.Save();
            //Lấy file đính kèm
            foreach (DocumentFile curDocFile in currentDoc.FileAttachments)
            {
                if (curDocFile != null)
                {
                    DocumentFile newDocFile = os.CreateObject <DocumentFile>();
                    newDocFile.Document = os.GetObject(newDoc);
                    newDocFile.DocFile  = os.GetObject(curDocFile.DocFile);
                    newDocFile.Save();
                }
            }
            ///////
            //os.CommitChanges();

            Employee curUser = SecuritySystem.CurrentUser as Employee;

            // Gán người duyệt nếu user chuyển tiếp có vị trí lớn hơn 50
            if (curUser.Position.PositionLevel >= 50)
            {
                newDoc.IsApproveed = true;
                newDoc.EmpApproved = os.GetObject <Employee>(curUser);
                DocumentEmployees approver = os.CreateObject <DocumentEmployees>();
                approver.LinkDocument = newDoc;
                approver.LinkEmployee = newDoc.EmpApproved;
                newDoc.DocumentEmployees.Add(approver);
            }
            //CriteriaOperator crit;
            DocumentEmployees objDEmp = os.CreateObject <DocumentEmployees>();
            //DocumentEmployees objDE = os.FindObject<DocumentEmployees>(new BinaryOperator()); //os.CreateObject<DocumentEmployees>();
            //DetailView dv = Application.CreateDetailView(os, "DocumentEmployees_DetailView_Forward", true, objDEmp);
            DetailView dvDocument = Application.CreateDetailView(os, "Document_DetailView_New", true, newDoc);

            //ShowViewParameters svp = new ShowViewParameters(dv);
            //svp.TargetWindow = DevExpress.ExpressApp.TargetWindow.NewModalWindow;
            //svp.CreatedView = dv;
            //svp.NewWindowTarget = NewWindowTarget.Default;
            dvDocument.ViewEditMode          = ViewEditMode.Edit;
            e.ShowViewParameters.CreatedView = dvDocument;
            os.SetModified(newDoc);
            //Application.ShowViewStrategy.ShowView(e.ShowViewParameters, new ShowViewSource(Frame, actForwardDocument)); // null, null));
        }
Example #2
0
        protected string SaveFile(UploadedFile uploadedFile)
        {
            //IObjectSpace os = ((DevExpress.ExpressApp.DetailView)(View)).ObjectSpace;
            Session sess = (View.ObjectSpace as DevExpress.ExpressApp.Xpo.XPObjectSpace).Session;

            fileuploads = new FileUploads(sess);
            string appDir = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;
            string appUrl = "./";

            if (uploadedFile.IsValid)
            {
                //fileName = string.Format("{0}{1}", MapPath("~/"), uploadedFile.FileName);
                fileuploads.Name     = uploadedFile.FileName;
                fileuploads.FileName = uploadedFile.FileName;
                fileuploads.FileSize = uploadedFile.ContentLength;
                fileuploads.FileType = uploadedFile.ContentType; //PostedFile
                fileuploads.FileExt  = System.IO.Path.GetExtension(uploadedFile.FileName);

                if (Global.Config == null)
                {
                    Global.Config = Configuration.GetInstance(this.View.ObjectSpace);
                }
                string savePath;// = string.Format("{0}/{1}", appDir, Global.Config.UploadPath);
                //string saveUrl = appUrl + "/" + Global.Config.UploadPath;

                savePath = fileuploads.newFullPathRender(fileuploads.FileName, View.CurrentObject != null ? View.CurrentObject.GetType().Name : "");
                if (!Directory.Exists(savePath))
                {
                    Directory.CreateDirectory(@savePath);
                }

                //Thêm số thứ tự vào tên file để tránh trùng lặp file
                if (File.Exists(string.Format("{0}{1}", savePath, fileuploads.FileName)))
                {
                    int    i           = 1;
                    string tmpFileName = string.Format("{0}.{1}{2}", fileuploads.FileName.Substring(0, fileuploads.FileName.Length - fileuploads.FileExt.Length), i, fileuploads.FileExt);
                    while (File.Exists(string.Format("{0}{1}", savePath, tmpFileName)))
                    {
                        i++;
                        tmpFileName = string.Format("{0}.{1}{2}", fileuploads.FileName.Substring(0, fileuploads.FileName.Length - fileuploads.FileExt.Length), i, fileuploads.FileExt);
                    }
                    fileuploads.FileName = tmpFileName;
                    //File.Delete(string.Format("{0}{1}", savePath, fileuploads.FileName));
                }

                uploadedFile.SaveAs(string.Format("{0}{1}", savePath, fileuploads.FileName)); //uncomment this line
                //fileuploads.FileRealPath = savePath;
                if (HttpContext.Current != null)
                {
                    appUrl = HttpContext.Current.Request.Url.Authority;
                }
                fileuploads.FileUrl = string.Format("{0}{1}{2}", appUrl, fileuploads.FileRealPath.Replace(appDir, ""), fileuploads.FileName);
                fileuploads.Save();
                if (CurrentObject is Document)
                {
                    DocumentFile docFile = new DocumentFile(sess);
                    docFile.DocFile        = fileuploads;
                    docFile.Document       = View.CurrentObject as Document;
                    docFile.UploadComplete = true;
                    docFile.Save();
                    current.FileAttachments.Add(docFile);
                }
                else if (CurrentObject is TaskExtra)
                {
                    TaskExtraFile taskFile = new TaskExtraFile(sess);
                    taskFile.UpFile         = fileuploads;
                    taskFile.TaskExtra      = View.CurrentObject as TaskExtra;
                    taskFile.UploadComplete = true;
                    taskFile.Save();
                    current.FileAttachments.Add(taskFile);
                }
                //sess.CommitTransaction();
                //fileuploads.Session.CommitTransaction();
            }
            return(fileuploads.Name);
        }
Example #3
0
        public ActionResult AddPDF(string webpage, ImageFile pdfThumb, DocumentFile pdf, int pdfOverlay)
        {
            string thumbPath = "";

            if (pdfThumb != null)
            {
                pdfThumb.ValidateForUpload(true);
                if (ModelState.IsValid)
                {
                    pdfThumb.Save("sidebar_pdf_thumb", new System.Drawing.Size(Config.Sidebar.Thumbnail.Width, Config.Sidebar.Thumbnail.Height), false);

                    thumbPath = "/" + pdfThumb.SavePath;
                    pdfThumb.Cleanup();
                }
            }
            else
            {
                ModelState.AddModelError("", "PDF File is not recognized");
            }

            string dbPath = "";

            if (pdf != null)
            {
                pdf.ValidateForUpload(true);
                if (ModelState.IsValid)
                {
                    if (System.IO.Path.GetExtension(pdf.Name).Equals(".pdf"))
                    {
                        ModelState.AddModelError("", "Invalid file type. Expected: .pdf");
                    }
                    if (ModelState.IsValid)
                    {
                        pdf.Save("sidebar_pdf_file" + System.IO.Path.GetExtension(pdf.Name));

                        dbPath = "/" + pdf.SavePath;
                        pdf.Cleanup();
                    }
                }
            }
            else
            {
                ModelState.AddModelError("", "PDF File is not recognized");
            }

            if (!string.IsNullOrEmpty(dbPath) && !string.IsNullOrEmpty(thumbPath))
            {
                DBDataContext db = Utils.DB.GetContext();
                WebPage       pg = db.WebPages.SingleOrDefault(x => x.ID == Convert.ToInt32(webpage));
                if (pg != null)
                {
                    pg.Sidebars.Add(new Sidebar()
                    {
                        TypeID = db.Types.Single(x => x.Name.Equals("PDF")).ID, Source = dbPath, Thumb = thumbPath, IsOverlay = Convert.ToBoolean(pdfOverlay)
                    });
                    try
                    {
                        db.SubmitChanges();
                        return(RedirectToAction("Index", "Sidebar", new { controller = "Sidebar", action = "Index", webpage = webpage }));
                    }
                    catch (Exception ex)
                    {
                        ModelState.AddModelError("", "An unknown error occurred. Please try again in few minutes.");
                        ErrorHandler.Report.Exception(ex, "Sidebar/AddPDF[POST]");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Web Page is doesn't exist");
                }
            }
            else
            {
                ModelState.AddModelError("", "There has been an issue with uploading your PDF file. Please try again in few minutes.");
            }

            if (System.IO.File.Exists(HttpContext.Server.MapPath(dbPath)))
            {
                System.IO.File.Delete(HttpContext.Server.MapPath(dbPath));
            }

            if (System.IO.File.Exists(HttpContext.Server.MapPath(thumbPath)))
            {
                System.IO.File.Delete(HttpContext.Server.MapPath(thumbPath));
            }
            ViewData["Type"]      = "PDF";
            ViewData["WebPageID"] = webpage;
            return(View("Add"));
        }
Example #4
0
        public ActionResult PDFPrev(string webPageId, DocumentFile doc)
        {
            string code = "";

            if (doc != null)
            {
                doc.ValidateForUpload(true);
                if (ModelState.IsValid)
                {
                    if (doc.Save(doc.Name.Replace(" ", "").ToLower()))
                    {
                        code = doc.SavedName;
                        doc.Cleanup();
                    }
                }
            }
            else
            {
                ModelState.AddModelError("", "Document File format is not recognized");
            }

            if (!string.IsNullOrEmpty(code))
            {

                DBDataContext db = Utils.DB.GetContext();
                WebPage pg = db.WebPages.SingleOrDefault(x => x.ID == Convert.ToInt32(webPageId));
                if (pg != null)
                {
                    Body b = pg.Bodies.FirstOrDefault();
                    if (b != null)
                    {
                        //delete existing PDF file
                        if (System.IO.File.Exists(HttpContext.Server.MapPath(Url.Data(b.HTML))))
                        {
                            System.IO.File.Delete(HttpContext.Server.MapPath(Url.Data(b.HTML)));
                        }
                        b.HTML = HttpUtility.HtmlEncode(code);
                    }
                    else
                    {
                        pg.Bodies.Add(new Body() { HTML = HttpUtility.HtmlEncode(code) });
                    }

                    try
                    {
                        db.SubmitChanges();
                        return RedirectToAction("Index", "WebPage", new { controller = "WebPage", action = "Index", webpage = webPageId });
                    }
                    catch (Exception ex)
                    {
                        ModelState.AddModelError("", ex.Message);
                        ErrorHandler.Report.Exception(ex, "Body/PDFPrev [POST]");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Web Page does not exist");
                }

            }
            else
            {
                ModelState.AddModelError("", "There has been an issue with uploading your Document file. Please try again in few minutes.");
            }

            return View();
        }
Example #5
0
        public ActionResult ManageDocument(Document doc, DocumentFile file, ImageFile thumb, string category, string name, string webPageId, string tmpl)
        {
            string dbPath = "", dbThumbPath = "";

            DBDataContext db = Utils.DB.GetContext();

            //check for category <> 0
            int categoryId = 0;
            if (!string.IsNullOrEmpty(name))
            {
                //add category to database
                Category c = new Category()
                {
                    Name = name
                };
                try
                {
                    db.Categories.InsertOnSubmit(c);
                    db.SubmitChanges();
                    categoryId = c.ID;
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", "An unknown error occurred while adding category to the database.");
                    ErrorHandler.Report.Exception(ex, "Body/ManageDocument[HTTPPOST]");
                }
            }
            //no new category, try parsing existing one from dropdown list
            if (categoryId == 0)
            {
                Int32.TryParse(category, out categoryId);
            }

            //validate category
            if (categoryId > 0)
            {

                WebPage page = db.WebPages.SingleOrDefault(x => x.ID == Convert.ToInt32(webPageId));
                if (page != null)
                {

                    if (file != null)
                    {
                        file.ValidateForUpload(true);
                        if (ModelState.IsValid)
                        {
                            string documentName = "doc-lib_" + DateTime.Now.Ticks.ToString() + "_" + new Random().Next(1, 100).ToString() + System.IO.Path.GetExtension(file.Name);

                            if (file.Save(documentName))
                            {
                                dbPath = "/" + file.SavePath;
                                file.Cleanup();
                            }
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Document file is not recognized");
                    }

                    if (thumb != null)
                    {
                        thumb.ValidateForUpload(true);
                        if (ModelState.IsValid)
                        {
                            string thumbName = "doc-lib_thumb_" + DateTime.Now.Ticks.ToString() + "_" + new Random().Next(1, 100).ToString();
                            if (thumb.Save(thumbName, new System.Drawing.Size(Config.DocLib.Thumbnail.Width, Config.DocLib.Thumbnail.Height), false))
                            {
                                dbThumbPath = "/" + thumb.SavePath;
                                thumb.Cleanup();
                            }
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Image file is not recognized");
                    }

                    if (!string.IsNullOrEmpty(dbPath) && !string.IsNullOrEmpty(dbThumbPath))
                    {
                        Category c = db.Categories.SingleOrDefault(x => x.ID == categoryId);
                        Document d = new Document()
                        {
                            Title = doc.Title,
                            Source = dbPath,
                            Thumb = dbThumbPath
                        };
                        d.Category = c;
                        page.Documents.Add(d);

                        try
                        {
                            db.SubmitChanges();
                            return RedirectToAction("DocLib", "Body", new { controller = "Body", action = "DocLib", webpage = webPageId.ToString(), tmpl = tmpl });

                        }
                        catch (Exception ex)
                        {
                            ModelState.AddModelError("", "An unknown error occurred. Please try again in a few minutes.");
                            ErrorHandler.Report.Exception(ex, "Body/ManageDocument[HTTPPOST]");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "There has been an issue with uploading your Image file. Please try again in few minutes.");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Page cannot be found. Please try again in few minutes.");
                }
            }
            else
            {
                ModelState.AddModelError("category", "You must either add new or select valid category for this document.");
            }

            if (System.IO.File.Exists(HttpContext.Server.MapPath(dbPath)))
            {
                System.IO.File.Delete(HttpContext.Server.MapPath(dbPath));
            }
            if (System.IO.File.Exists(HttpContext.Server.MapPath(dbThumbPath)))
            {
                System.IO.File.Delete(HttpContext.Server.MapPath(dbThumbPath));
            }

            ViewData["WebPageID"] = webPageId;
            ViewData["TemplateID"] = tmpl;
            return View("ManageDocument", new Document());
        }
Example #6
0
        public ActionResult ManageDocument(Document doc, DocumentFile file, ImageFile thumb, string category, string name, string webPageId, string tmpl)
        {
            string dbPath = "", dbThumbPath = "";

            DBDataContext db = Utils.DB.GetContext();

            //check for category <> 0
            int categoryId = 0;

            if (!string.IsNullOrEmpty(name))
            {
                //add category to database
                Category c = new Category()
                {
                    Name = name
                };
                try
                {
                    db.Categories.InsertOnSubmit(c);
                    db.SubmitChanges();
                    categoryId = c.ID;
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", "An unknown error occurred while adding category to the database.");
                    ErrorHandler.Report.Exception(ex, "Body/ManageDocument[HTTPPOST]");
                }
            }
            //no new category, try parsing existing one from dropdown list
            if (categoryId == 0)
            {
                Int32.TryParse(category, out categoryId);
            }

            //validate category
            if (categoryId > 0)
            {
                WebPage page = db.WebPages.SingleOrDefault(x => x.ID == Convert.ToInt32(webPageId));
                if (page != null)
                {
                    if (file != null)
                    {
                        file.ValidateForUpload(true);
                        if (ModelState.IsValid)
                        {
                            string documentName = "doc-lib_" + DateTime.Now.Ticks.ToString() + "_" + new Random().Next(1, 100).ToString() + System.IO.Path.GetExtension(file.Name);

                            if (file.Save(documentName))
                            {
                                dbPath = "/" + file.SavePath;
                                file.Cleanup();
                            }
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Document file is not recognized");
                    }

                    if (thumb != null)
                    {
                        thumb.ValidateForUpload(true);
                        if (ModelState.IsValid)
                        {
                            string thumbName = "doc-lib_thumb_" + DateTime.Now.Ticks.ToString() + "_" + new Random().Next(1, 100).ToString();
                            if (thumb.Save(thumbName, new System.Drawing.Size(Config.DocLib.Thumbnail.Width, Config.DocLib.Thumbnail.Height), false))
                            {
                                dbThumbPath = "/" + thumb.SavePath;
                                thumb.Cleanup();
                            }
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Image file is not recognized");
                    }

                    if (!string.IsNullOrEmpty(dbPath) && !string.IsNullOrEmpty(dbThumbPath))
                    {
                        Category c = db.Categories.SingleOrDefault(x => x.ID == categoryId);
                        Document d = new Document()
                        {
                            Title  = doc.Title,
                            Source = dbPath,
                            Thumb  = dbThumbPath
                        };
                        d.Category = c;
                        page.Documents.Add(d);

                        try
                        {
                            db.SubmitChanges();
                            return(RedirectToAction("DocLib", "Body", new { controller = "Body", action = "DocLib", webpage = webPageId.ToString(), tmpl = tmpl }));
                        }
                        catch (Exception ex)
                        {
                            ModelState.AddModelError("", "An unknown error occurred. Please try again in a few minutes.");
                            ErrorHandler.Report.Exception(ex, "Body/ManageDocument[HTTPPOST]");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "There has been an issue with uploading your Image file. Please try again in few minutes.");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Page cannot be found. Please try again in few minutes.");
                }
            }
            else
            {
                ModelState.AddModelError("category", "You must either add new or select valid category for this document.");
            }



            if (System.IO.File.Exists(HttpContext.Server.MapPath(dbPath)))
            {
                System.IO.File.Delete(HttpContext.Server.MapPath(dbPath));
            }
            if (System.IO.File.Exists(HttpContext.Server.MapPath(dbThumbPath)))
            {
                System.IO.File.Delete(HttpContext.Server.MapPath(dbThumbPath));
            }

            ViewData["WebPageID"]  = webPageId;
            ViewData["TemplateID"] = tmpl;
            return(View("ManageDocument", new Document()));
        }
Example #7
0
        public ActionResult PDFPrev(string webPageId, DocumentFile doc)
        {
            string code = "";

            if (doc != null)
            {
                doc.ValidateForUpload(true);
                if (ModelState.IsValid)
                {
                    if (doc.Save(doc.Name.Replace(" ", "").ToLower()))
                    {
                        code = doc.SavedName;
                        doc.Cleanup();
                    }
                }
            }
            else
            {
                ModelState.AddModelError("", "Document File format is not recognized");
            }

            if (!string.IsNullOrEmpty(code))
            {
                DBDataContext db = Utils.DB.GetContext();
                WebPage       pg = db.WebPages.SingleOrDefault(x => x.ID == Convert.ToInt32(webPageId));
                if (pg != null)
                {
                    Body b = pg.Bodies.FirstOrDefault();
                    if (b != null)
                    {
                        //delete existing PDF file
                        if (System.IO.File.Exists(HttpContext.Server.MapPath(Url.Data(b.HTML))))
                        {
                            System.IO.File.Delete(HttpContext.Server.MapPath(Url.Data(b.HTML)));
                        }
                        b.HTML = HttpUtility.HtmlEncode(code);
                    }
                    else
                    {
                        pg.Bodies.Add(new Body()
                        {
                            HTML = HttpUtility.HtmlEncode(code)
                        });
                    }

                    try
                    {
                        db.SubmitChanges();
                        return(RedirectToAction("Index", "WebPage", new { controller = "WebPage", action = "Index", webpage = webPageId }));
                    }
                    catch (Exception ex)
                    {
                        ModelState.AddModelError("", ex.Message);
                        ErrorHandler.Report.Exception(ex, "Body/PDFPrev [POST]");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Web Page does not exist");
                }
            }
            else
            {
                ModelState.AddModelError("", "There has been an issue with uploading your Document file. Please try again in few minutes.");
            }

            return(View());
        }