Exemplo n.º 1
0
        public ActionResult Create([Bind(Include = "ID,LastName,FirstMidName,salutation,JoinedDate,JobTitle,Department,CompanyEmail,ResumePath,DisplayPhotoPath,team,DisplayPhotoFile,ResumeFile,EmployeeNumber")] Employee employee)
        {
            string root         = Server.MapPath("~/Assets/Employees/" + employee.ID); // ~/Assets/products/software1
            string PhotoFolder  = root + "\\photo folder";
            string ResumeFolder = root + "\\resume";

            string PhotoFullName = "";

            //cover photo
            if (employee.DisplayPhotoFile != null)
            {
                string imageName      = Path.GetFileNameWithoutExtension(employee.DisplayPhotoFile.FileName);       //image
                string imageExtension = Path.GetExtension(employee.DisplayPhotoFile.FileName);                      //.jpg
                PhotoFullName = imageName + imageExtension;                                                         //image.jpg

                employee.DisplayPhotoPath = "~/Assets/Employees/" + employee.ID + "/photo folder/" + PhotoFullName; //  ~/Assets/products/software1/cover image/image.jpg
                PhotoFullName             = Path.Combine(Server.MapPath("~/Assets/Employees/" + employee.ID + "/photo folder/" + PhotoFullName));
            }

            string ResumeFullName = "";

            //resume
            if (employee.ResumeFile != null)
            {
                string resumeName      = Path.GetFileNameWithoutExtension(employee.ResumeFile.FileName); //image
                string resumeExtension = Path.GetExtension(employee.ResumeFile.FileName);                //.jpg
                ResumeFullName = resumeName + resumeExtension;                                           //image.jpg

                employee.ResumePath = "~/Assets/Employees/" + employee.ID + "/resume/" + ResumeFullName; //  ~/Assets/products/software1/cover image/image.jpg
                ResumeFullName      = Path.Combine(Server.MapPath("~/Assets/Employees/" + employee.ID + "/resume/" + ResumeFullName));
            }



            if (ModelState.IsValid)
            {
                Directory.CreateDirectory(root);
                Directory.CreateDirectory(PhotoFolder);
                Directory.CreateDirectory(ResumeFolder);

                if (employee.DisplayPhotoFile != null)
                {
                    employee.DisplayPhotoFile.SaveAs(PhotoFullName);
                }
                if (employee.ResumeFile != null)
                {
                    employee.ResumeFile.SaveAs(ResumeFullName);
                }


                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(employee));
        }
Exemplo n.º 2
0
        public ActionResult Create([Bind(Include = "ToolID,Title,Description,Tag,CoverImagePath,GalleryPath,DocumentationPath,InstallationPath,VideoPath")] Tool tool)
        {
            if (ModelState.IsValid)
            {
                db.Tools.Add(tool);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tool));
        }
Exemplo n.º 3
0
        public ActionResult Create([Bind(Include = "ID,LastName,FirstMidName,salutation,JoinedDate,JobTitle,Department,CompanyEmail,ResumePath,DisplayPhotoPath")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(employee));
        }
Exemplo n.º 4
0
        private void simpleButton4_Click(object sender, EventArgs e)
        {
            bindingTool.Num           = teNumber.Text;
            bindingTool.Name          = teName.Text;
            bindingTool.Specification = teSpec.Text;
            bindingTool.Manufactory   = teManu.Text;
            bindingTool.ExpDate       = DateTime.Parse(teExpDate.Text);
            bindingTool.ExpiredDate   = DateTime.Parse(DtExpiredDate.Text);

            toolContext.Tools.AddOrUpdate(bindingTool);
            toolContext.SaveChanges();
        }
        public static void Initialize(ToolContext toolContext)
        {
            if (toolContext.Roles.Any())
            {
                return;
            }

            var roles = new List <RoleModel>
            {
                new RoleModel()
                {
                    Name = "Admin"
                },
                new RoleModel()
                {
                    Name = "Stock keeper"
                },
                new RoleModel()
                {
                    Name = "User"
                }
            };

            foreach (var role in roles)
            {
                toolContext.Roles.Add(role);
            }

            toolContext.SaveChanges();
        }
        public static void Initialize(ToolContext toolContext)
        {
            if (toolContext.Stocks.Any())
            {
                return;
            }

            var stocks = new List <StockModel>
            {
                new StockModel()
                {
                    Id         = Guid.NewGuid().ToString(),
                    Name       = "Tool Stock N3",
                    Department = toolContext.Departments.First(d => d.Name == "The workshop N3")
                },
                new StockModel()
                {
                    Id         = Guid.NewGuid().ToString(),
                    Name       = "Tool Stock N6",
                    Department = toolContext.Departments.First(d => d.Name == "The workshop N6")
                },
                new StockModel()
                {
                    Id         = Guid.NewGuid().ToString(),
                    Name       = "Tool Stock N4",
                    Department = toolContext.Departments.First(t => t.Name == "The workshop N4")
                }
            };

            toolContext.Stocks.AddRange(stocks);

            toolContext.SaveChanges();
        }
Exemplo n.º 7
0
        public static void Initialize(ToolContext toolContext)
        {
            if (toolContext.Departments.Any())
            {
                return;
            }

            var departments = new List <DepartmentModel>
            {
                new DepartmentModel {
                    Id = Guid.NewGuid().ToString(), Name = "The tool-die management"
                },
                new DepartmentModel {
                    Id = Guid.NewGuid().ToString(), Name = "The experimental workshop"
                },
                new DepartmentModel {
                    Id = Guid.NewGuid().ToString(), Name = "The flexible manufacturing systems workshop"
                },
                new DepartmentModel {
                    Id = Guid.NewGuid().ToString(), Name = "The workshop N3"
                },
                new DepartmentModel {
                    Id = Guid.NewGuid().ToString(), Name = "The workshop N6"
                },
                new DepartmentModel {
                    Id = Guid.NewGuid().ToString(), Name = "The workshop N4"
                }
            };

            toolContext.Departments.AddRange(departments);
            toolContext.SaveChanges();
        }
Exemplo n.º 8
0
        private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.InitialDirectory = Application.StartupPath;
            ofd.Title            = "选择要导入的文件";
            ofd.Multiselect      = false;
            ofd.Filter           = "Excel文件|*.xls";
            ofd.FilterIndex      = 2;
            ofd.RestoreDirectory = true;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                string filePath = ofd.FileName;
                string fileName = ofd.SafeFileName;
                if (filePath.EndsWith("xls"))
                {
                    string  connectionStr = "Provider = Microsoft.ACE.OLEDB.12.0 ; Data Source =" + filePath + ";Extended Properties='Excel 12.0;HDR=Yes;IMEX=1'";
                    DataSet ds            = OleDbHelper.ExecuteDateSet(connectionStr, CommandType.Text, "select * from [Sheet1$]");
                    if (ds.Tables.Count > 0)
                    {
                        DataTable          dt       = ds.Tables[0];
                        List <ToolsEntity> tempList = new List <ToolsEntity>();
                        try
                        {
                            var x = dt.Rows.Count;
                            foreach (DataRow item in dt.Rows)
                            {
                                ToolsEntity temp = new ToolsEntity
                                {
                                    Manufactory   = item[2].ToString(),
                                    Name          = item[1].ToString(),
                                    Num           = item[0].ToString(),
                                    Url           = item[3].ToString(),
                                    Specification = item[4].ToString(),
                                    ExpDate       = DateTime.Parse(item[5].ToString()),
                                    ExpiredDate   = DateTime.Parse(item[7].ToString()),
                                    BroDate       = DateTime.Now,
                                    Status        = byte.Parse(item[6].ToString())
                                };
                                tempList.Add(temp);
                            }
                        }
                        catch
                        {
                            XtraMessageBox.Show("录入数据错误");
                            return;
                        }
                        toolContext.Tools.AddOrUpdate(tempList.ToArray());
                        toolContext.SaveChanges();
                    }
                }
            }
        }
Exemplo n.º 9
0
        public IActionResult SaveEditedTool(int id, string start, string end)
        {
            try
            {
                var booking = Context.Bookings.FirstOrDefault(x => x.Id == id);
                if (booking == null)
                {
                    return(BadRequest());
                }
                booking.StartDate            = DateTime.Parse(start);
                booking.EndDate              = DateTime.Parse(end);
                Context.Entry(booking).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                Context.SaveChanges();

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }
Exemplo n.º 10
0
        public ActionResult Create([Bind(Include = "ToolID,Title,Description,Tag,CoverImagePath,GalleryPath,DocumentationPath,InstallationPath,VideoPath,CoverImageFile,DocumentationFiles,InstallationFiles,VideoFiles,GalleryFiles")] Tool tool)
        {
            string root                = Server.MapPath("~/Assets/Tools/" + tool.Title); // ~/Assets/products/software1
            string coverFolder         = root + "\\cover folder";
            string documentationFolder = root + "\\documentation";
            string galleryFolder       = root + "\\gallery";
            string installationFolder  = root + "\\installation";
            string videoFolder         = root + "\\video";

            int ID = tool.ToolID;

            //cover photo
            string imageName      = Path.GetFileNameWithoutExtension(tool.CoverImageFile.FileName);  //image
            string imageExtension = Path.GetExtension(tool.CoverImageFile.FileName);                 //.jpg
            string coverFullName  = imageName + imageExtension;                                      //image.jpg

            tool.CoverImagePath = "~/Assets/Tools/" + tool.Title + "/cover folder/" + coverFullName; //  ~/Assets/products/software1/cover image/image.jpg
            coverFullName       = Path.Combine(Server.MapPath("~/Assets/Tools/" + tool.Title + "/cover folder/" + coverFullName));


            //documentation
            //string documentationFullName = "";
            //if(tool.DocumentationFiles != null)
            //{
            //    string documentation = Path.GetFileNameWithoutExtension(tool.DocumentationFiles.FileName);  //documentation
            //    string documentationExtension = Path.GetExtension(tool.DocumentationFiles.FileName);  //.pdf
            //    documentationFullName = documentation + documentationExtension;  //documentation.pdf

            //    tool.DocumentationPath = "~/Assets/Tools/" + tool.Title + "/documentation/" + documentationFullName;  //  ~/Assets/products/software1/cover image/image.jpg
            //    documentationFullName = Path.Combine(Server.MapPath("~/Assets/Tools/" + tool.Title + "/documentation/" + documentationFullName));
            //}


            //installation
            //string installationFullName = "";
            //if(tool.InstallationFiles != null)
            //{
            //    string installation = Path.GetFileNameWithoutExtension(tool.InstallationFiles.FileName);  //installation
            //    string installationExtension = Path.GetExtension(tool.InstallationFiles.FileName);  //.exe
            //    installationFullName = installation + installationExtension;  //installation.exe

            //    tool.InstallationPath = "~/Assets/Tools/" + tool.Title + "/installation/" + installationFullName;  //  ~/Assets/products/software1/cover image/image.jpg
            //    installationFullName = Path.Combine(Server.MapPath("~/Assets/Tools/" + tool.Title + "/installation/" + installationFullName));
            //}


            //video
            //string videoFullName = "";
            //if(tool.VideoFile != null)
            //{
            //    string video = Path.GetFileNameWithoutExtension(tool.VideoFile.FileName);  //video
            //    string videoExtension = Path.GetExtension(tool.VideoFile.FileName);  //.mp4
            //    videoFullName = video + videoExtension;  //video.mp4

            //    tool.VideoPath = "~/Assets/Tools/" + tool.Title + "/video/" + videoFullName;  //  ~/Assets/products/software1/cover image/image.jpg
            //    videoFullName = Path.Combine(Server.MapPath("~/Assets/Tools/" + tool.Title + "/video/" + videoFullName));

            //}


            tool.GalleryPath       = "~/Assets/Tools/" + tool.Title + "/gallery/"; //  ~/Assets/products/software1/gallery/
            tool.DocumentationPath = "~/Assets/Tools/" + tool.Title + "/documentation/";
            tool.InstallationPath  = "~/Assets/Tools/" + tool.Title + "/Installation/";
            tool.VideoPath         = "~/Assets/Tools/" + tool.Title + "/Video/";

            if (ModelState.IsValid && !Directory.Exists(root))
            {
                //Create folders
                Directory.CreateDirectory(root);
                Directory.CreateDirectory(documentationFolder);
                Directory.CreateDirectory(coverFolder);
                Directory.CreateDirectory(galleryFolder);
                Directory.CreateDirectory(installationFolder);
                Directory.CreateDirectory(videoFolder);

                //save files to respective folders
                //if(tool.DocumentationFile != null)
                //{
                //    tool.DocumentationFile.SaveAs(documentationFullName);
                //}
                //if(tool.VideoFile != null)
                //{
                //    tool.VideoFile.SaveAs(videoFullName);
                //}
                //if(tool.InstallationFile != null)
                //{
                //    tool.InstallationFile.SaveAs(installationFullName);
                //}
                tool.CoverImageFile.SaveAs(coverFullName);

                foreach (HttpPostedFileBase file in tool.GalleryFiles)
                {
                    //Checking file is available to save.
                    if (file != null)
                    {
                        string galleryFileName      = Path.GetFileNameWithoutExtension(file.FileName); //image
                        string galleryFileExtention = Path.GetExtension(file.FileName);                //.jpg
                        string galleryFileFullName  = galleryFileName + galleryFileExtention;

                        galleryFileFullName = Path.Combine(Server.MapPath("~/Assets/Tools/" + tool.Title + "/gallery/" + galleryFileFullName));;   //image.jpg
                        //Save file to server folder
                        file.SaveAs(galleryFileFullName);
                        //assigning file uploaded status to ViewBag for showing message to user.
                    }
                }

                foreach (HttpPostedFileBase file in tool.DocumentationFiles)
                {
                    //Checking file is available to save.
                    if (file != null)
                    {
                        string documentFileName      = Path.GetFileNameWithoutExtension(file.FileName); //image
                        string documentFileExtention = Path.GetExtension(file.FileName);                //.jpg
                        string documentFileFullName  = documentFileName + documentFileExtention;

                        documentFileFullName = Path.Combine(Server.MapPath("~/Assets/Tools/" + tool.Title + "/documentation/" + documentFileFullName));;   //image.jpg
                        //Save file to server folder
                        file.SaveAs(documentFileFullName);
                        //assigning file uploaded status to ViewBag for showing message to user.
                    }
                }

                foreach (HttpPostedFileBase file in tool.InstallationFiles)
                {
                    //Checking file is available to save.
                    if (file != null)
                    {
                        string installationFileName     = Path.GetFileNameWithoutExtension(file.FileName); //image
                        string installationExtention    = Path.GetExtension(file.FileName);                //.jpg
                        string installationFileFullName = installationFileName + installationExtention;

                        installationFileFullName = Path.Combine(Server.MapPath("~/Assets/Tools/" + tool.Title + "/installation/" + installationFileFullName));;   //image.jpg
                        //Save file to server folder
                        file.SaveAs(installationFileFullName);
                        //assigning file uploaded status to ViewBag for showing message to user.
                    }
                }

                foreach (HttpPostedFileBase file in tool.InstallationFiles)
                {
                    //Checking file is available to save.
                    if (file != null)
                    {
                        string videoFileName     = Path.GetFileNameWithoutExtension(file.FileName); //image
                        string videoExtention    = Path.GetExtension(file.FileName);                //.jpg
                        string videoFileFullName = videoFileName + videoExtention;

                        videoFileFullName = Path.Combine(Server.MapPath("~/Assets/Tools/" + tool.Title + "/video/" + videoFileFullName));;   //image.jpg
                        //Save file to server folder
                        file.SaveAs(videoFileFullName);
                        //assigning file uploaded status to ViewBag for showing message to user.
                    }
                }



                db.Tools.Add(tool);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tool));
        }
Exemplo n.º 11
0
 public void Save()
 {
     _toolContext.SaveChanges();
 }