Ejemplo n.º 1
0
        public void UpFile()
        {
            IDatabase     database    = DataFactory.Database();
            DbTransaction isOpenTrans = database.BeginTrans();

            string msg = "上传成功!";//返回信息

            string fileList = null;
            var    groupId  = Guid.NewGuid();

            List <Files> fileses = new List <Files>();

            try
            {
                int iTotal = Request.Files.Count;
                for (int i = 0; i < iTotal; i++)
                {
                    HttpPostedFileBase file = HttpContext.Request.Files[i];
                    if (file != null && (file.ContentLength > 0 || !string.IsNullOrEmpty(file.FileName)))
                    {
                        Stream stream = file.InputStream;
                        string md5    = DirFileHelper.GetMd5StringByStream(stream);

                        var files = database.FindEntity <Files>(md5);
                        if (string.IsNullOrEmpty(files.Md5))
                        {
                            //#region stream to byte[]

                            //byte[] bytes = new byte[stream.Length];
                            //stream.Read(bytes, 0, bytes.Length);
                            //stream.Seek(0, SeekOrigin.Begin);


                            //#endregion


                            //#region byte to stream
                            ////  Stream stream = new MemoryStream(bytes);
                            //#endregion


                            Files f = new Files
                            {
                                Md5           = md5,
                                FileName      = file.FileName,
                                FileType      = Path.GetExtension(file.FileName),
                                ContentType   = file.ContentType,
                                Discriminator = "Files"
                                                //Bytes = bytes.ToArray(),
                            };
                            database.Insert(f, isOpenTrans);
                            fileses.Add(f);
                            //上传文件

                            if (new Remote(Config.GetValue("RemoteConn")).Connect())
                            {
                                file.SaveAs($"{Config.GetValue("FormUDPath")}{md5}");
                            }
                        }
                        else
                        {
                            fileses.Add(files);
                        }

                        //返回前台的文件名
                        fileList += file.FileName + ",";
                    }
                }

                database.Insert(new FileGroup
                {
                    GroupGuid   = groupId,
                    CreateTime  = DateTime.Now,
                    CreateEmpNo = "1109001"
                }, isOpenTrans);

                List <FilesFileGroup> ffGroup = fileses.Select(c => new FilesFileGroup
                {
                    Md5       = c.Md5,
                    GroupGuid = groupId
                }).ToList();


                database.Insert(ffGroup, isOpenTrans);
                database.Commit();
            }
            catch (NullReferenceException)
            {
                database.Rollback();
                Response.Write("<script>alert('请登陆后继续操作!!!');window.parent.location.href='/Account/Login'</script>");
                Response.Flush();
                return;
            }
            catch (Exception exception)
            {
                database.Rollback();
                msg = "上传失败,请联系管理员" + exception.Message;
            }



            Response.Write("<script>window.parent.Finish('" + msg + "|" + groupId + "|" + fileList + "');</script>");
        }
Ejemplo n.º 2
0
        public int OldImport(DataSet ds)
        {
            var customers = new TpaModule.TpaCustomerBll().GetList();
            var formTyps  = new BaseServices <FormType>().LoadEntities(c => true);

            DataTable dt          = ds.Tables[0];
            string    publishType = dt.ToString();


            int success = 0;

            foreach (var row in dt.Rows)
            {
                try
                {
                    string fileName = ((DataRow)(row)).ItemArray[0].ToString();
                    string ver      = ((DataRow)(row)).ItemArray[1].ToString();
                    int    pageSize = int.Parse(((DataRow)(row)).ItemArray[2].ToString());
                    string filePath = @"\\192.168.0.4\Minicut\公司文件\文控\图纸电子档\勿动\" + ((DataRow)(row)).ItemArray[3] + ".pdf";

                    string       reason      = ((DataRow)(row)).ItemArray[4].ToString();
                    DateTime     publishDate = DateTime.Parse(((DataRow)(row)).ItemArray[5].ToString());
                    const string publishEmp  = "1109004";
                    bool         isPass      = int.Parse(((DataRow)(row)).ItemArray[7].ToString()) == 1;

                    string fileType = Path.GetExtension(filePath);


                    Guid fileGroup = Guid.NewGuid();
                    using (var fs = new FileStream(filePath, FileMode.Open))
                    {
                        var md5 = DirFileHelper.GetMd5StringByStream(fs);

                        string targetPath = Path.GetFullPath(BaseHelper.UpPath);

                        //将文什上传至文档临时目录
                        BaseHelper.CopyFile(filePath, targetPath + md5);
                        using (var context = ContextFactory.ContextHelper)
                        {
                            //组建文件群组
                            context.FileGroups.Add(new FileGroup()
                            {
                                GroupGuid   = fileGroup,
                                CreateTime  = DateTime.Now,
                                CreateEmpNo = "1109001"
                            });

                            //上传文件

                            if (!context.Fileses.Any(c => c.Md5 == md5))
                            {
                                context.Fileses.Add(new Files()
                                {
                                    Md5         = md5,
                                    FileName    = fileName,
                                    FileType    = fileType,
                                    ContentType = "application/pdf",
                                });
                            }

                            context.FilesFileGroups.AddRange(new List <FilesFileGroup> {
                                new FilesFileGroup()
                                {
                                    Md5 = md5, GroupGuid = fileGroup
                                }
                            });
                            context.SaveChanges();
                        }


                        //组建文件关系
                    }

                    int formId = formTyps.Single(c => c.FormName.Contains(publishType)).FormId;

                    //创建表单内容
                    var form = new Form()
                    {
                        FormNo      = new Applying().CreateFormNo(new object()),
                        FormId      = formId,
                        CreateEmpNo = "1109001",
                        CreateTime  = publishDate,
                        SignPath    = null,
                        FormStatus  = (int)Form.StatusEnum.签核完成,
                        IsEmergents = false,
                        CloseTime   = DateTime.Now
                    };

                    //生成表单
                    new BaseServices <Form>().AddEntity(form);

                    #region insert
                    //生成表单详细页
                    switch (publishType)
                    {
                    case "BOM":
                        new BaseServices <FormDrawingsBom>().AddEntity(new FormDrawingsBom()
                        {
                            CustomerNo  = customers.Single(c => c.CustomerName.Contains(((DataRow)(row)).ItemArray[8].ToString())).CustomerNo,
                            DrawPartNo  = ((DataRow)(row)).ItemArray[9].ToString(),
                            ProductNo   = ((DataRow)(row)).ItemArray[10].ToString(),
                            ProductName = ((DataRow)(row)).ItemArray[11].ToString(),
                            FileCode    = ((DataRow)(row)).ItemArray[12].ToString(),
                            Author      = ((DataRow)(row)).ItemArray[13].ToString(),

                            FormNo = form.FormNo,
                            Mark   = "系统自动导入",

                            DrawVer     = ver,
                            PageSize    = pageSize,
                            FileGroup   = fileGroup,
                            Reason      = reason,
                            IsPublished = false,
                        });
                        break;

                    case "ECN":
                        new BaseServices <FormDrawingsEcn>().AddEntity(new FormDrawingsEcn()
                        {
                            CustomerNo  = customers.Single(c => c.CustomerName.Contains(((DataRow)(row)).ItemArray[8].ToString())).CustomerNo,
                            ProductNo   = ((DataRow)(row)).ItemArray[9].ToString(),
                            ProductName = ((DataRow)(row)).ItemArray[10].ToString(),
                            EcnNo       = ((DataRow)(row)).ItemArray[11].ToString(),
                            PublishEmp  = ((DataRow)(row)).ItemArray[12].ToString(),



                            FormNo = form.FormNo,
                            Mark   = "系统自动导入",

                            DrawVer     = ver,
                            PageSize    = pageSize,
                            FileGroup   = fileGroup,
                            Reason      = reason,
                            IsPublished = false,
                        });
                        break;

                    case "SOP":
                        new BaseServices <FormDrawingsSop>().AddEntity(new FormDrawingsSop()
                        {
                            CustomerNo = customers.Single(c => c.CustomerName.Contains(((DataRow)(row)).ItemArray[8].ToString())).CustomerNo,
                            DrawPartNo = ((DataRow)(row)).ItemArray[9].ToString(),
                            Tag        = ((DataRow)(row)).ItemArray[10].ToString(),
                            Author     = ((DataRow)(row)).ItemArray[11].ToString(),

                            FormNo = form.FormNo,
                            Mark   = "系统自动导入",

                            DrawVer     = ver,
                            PageSize    = pageSize,
                            FileGroup   = fileGroup,
                            Reason      = reason,
                            IsPublished = false,
                        });
                        break;

                    case "包装工艺卡":
                        new BaseServices <FormDrawingsPackage>().AddEntity(new FormDrawingsPackage()
                        {
                            CustomerNo  = customers.Single(c => c.CustomerName.Contains(((DataRow)(row)).ItemArray[8].ToString())).CustomerNo,
                            ProductNo   = ((DataRow)(row)).ItemArray[9].ToString(),
                            ProductName = ((DataRow)(row)).ItemArray[10].ToString(),
                            Author      = ((DataRow)(row)).ItemArray[11].ToString(),

                            FormNo = form.FormNo,
                            Mark   = "系统自动导入",

                            DrawVer     = ver,
                            PageSize    = pageSize,
                            FileGroup   = fileGroup,
                            Reason      = reason,
                            IsPublished = false,
                        });
                        break;

                    case "工艺流程图":
                        new BaseServices <FormDrawingsProcess>().AddEntity(new FormDrawingsProcess()
                        {
                            CustomerNo  = customers.Single(c => c.CustomerName.Contains(((DataRow)(row)).ItemArray[8].ToString())).CustomerNo,
                            DrawPartNo  = ((DataRow)(row)).ItemArray[9].ToString(),
                            ProductNo   = ((DataRow)(row)).ItemArray[10].ToString(),
                            ProductName = ((DataRow)(row)).ItemArray[11].ToString(),
                            Drafter     = ((DataRow)(row)).ItemArray[12].ToString(),



                            FormNo = form.FormNo,
                            Mark   = "系统自动导入",

                            DrawVer     = ver,
                            PageSize    = pageSize,
                            FileGroup   = fileGroup,
                            Reason      = reason,
                            IsPublished = false,
                        });
                        break;

                    case "检规指导书":
                        new BaseServices <FormDrawingsFqc>().AddEntity(new FormDrawingsFqc()
                        {
                            CustomerNo  = customers.Single(c => c.CustomerName.Contains(((DataRow)(row)).ItemArray[8].ToString())).CustomerNo,
                            DrawPartNo  = ((DataRow)(row)).ItemArray[9].ToString(),
                            ProductNo   = ((DataRow)(row)).ItemArray[10].ToString(),
                            ProductName = ((DataRow)(row)).ItemArray[11].ToString(),
                            Author      = ((DataRow)(row)).ItemArray[12].ToString(),


                            FormNo = form.FormNo,
                            Mark   = "系统自动导入",

                            DrawVer     = ver,
                            PageSize    = pageSize,
                            FileGroup   = fileGroup,
                            Reason      = reason,
                            IsPublished = false,
                        });
                        break;

                    case "客户图纸":
                        new BaseServices <FormDrawingsCustomer>().AddEntity(new FormDrawingsCustomer()
                        {
                            CustomerNo  = customers.Single(c => c.CustomerName.Contains(((DataRow)(row)).ItemArray[8].ToString())).CustomerNo,
                            DrawPartNo  = ((DataRow)(row)).ItemArray[9].ToString(),
                            ProductNo   = ((DataRow)(row)).ItemArray[10].ToString(),
                            ProductName = ((DataRow)(row)).ItemArray[11].ToString(),
                            ManagerHead = ((DataRow)(row)).ItemArray[12].ToString(),

                            FormNo = form.FormNo,
                            Mark   = "系统自动导入",

                            DrawVer     = ver,
                            PageSize    = pageSize,
                            FileGroup   = fileGroup,
                            Reason      = reason,
                            IsPublished = false,
                        });
                        break;

                    case "内部图纸":
                        new BaseServices <FormDrawingsInside>().AddEntity(new FormDrawingsInside()
                        {
                            CustomerNo  = customers.Single(c => c.CustomerName.Contains(((DataRow)(row)).ItemArray[8].ToString())).CustomerNo,
                            DrawPartNo  = ((DataRow)(row)).ItemArray[9].ToString(),
                            ProductNo   = ((DataRow)(row)).ItemArray[10].ToString(),
                            ProductName = ((DataRow)(row)).ItemArray[11].ToString(),
                            Drafter     = ((DataRow)(row)).ItemArray[12].ToString(),



                            FormNo = form.FormNo,
                            Mark   = "系统自动导入",

                            DrawVer     = ver,
                            PageSize    = pageSize,
                            FileGroup   = fileGroup,
                            Reason      = reason,
                            IsPublished = false,
                        });
                        break;

                    case "内部型材图":
                        new BaseServices <FormDrawingsProfile>().AddEntity(new FormDrawingsProfile()
                        {
                            CustomerNo  = customers.Single(c => c.CustomerName.Contains(((DataRow)(row)).ItemArray[8].ToString())).CustomerNo,
                            ProfileNo   = ((DataRow)(row)).ItemArray[9].ToString(),
                            ProductNo   = ((DataRow)(row)).ItemArray[10].ToString(),
                            ProductName = ((DataRow)(row)).ItemArray[11].ToString(),
                            Drafter     = ((DataRow)(row)).ItemArray[12].ToString(),



                            FormNo = form.FormNo,
                            Mark   = "系统自动导入",

                            DrawVer     = ver,
                            PageSize    = pageSize,
                            FileGroup   = fileGroup,
                            Reason      = reason,
                            IsPublished = false,
                        });
                        break;

                    case "外来文件":
                        new BaseServices <FormDrawingsExternal>().AddEntity(new FormDrawingsExternal()
                        {
                            CustomerNo  = customers.Single(c => c.CustomerName.Contains(((DataRow)(row)).ItemArray[8].ToString())).CustomerNo,
                            FileName    = ((DataRow)(row)).ItemArray[9].ToString(),
                            FileCode    = ((DataRow)(row)).ItemArray[10].ToString(),
                            MinicutCode = ((DataRow)(row)).ItemArray[11].ToString(),
                            ReciveEmpNo = ((DataRow)(row)).ItemArray[12].ToString(),



                            FormNo = form.FormNo,
                            Mark   = "系统自动导入",

                            DrawVer     = ver,
                            PageSize    = pageSize,
                            FileGroup   = fileGroup,
                            Reason      = reason,
                            IsPublished = false,
                        });
                        break;

                    case "控制计划":
                        new BaseServices <FormDrawingsControlPlan>().AddEntity(new FormDrawingsControlPlan()
                        {
                            CustomerNo = customers.Single(c => c.CustomerName.Contains(((DataRow)(row)).ItemArray[8].ToString())).CustomerNo,
                            ProductNo  = ((DataRow)(row)).ItemArray[9].ToString(),
                            Author     = ((DataRow)(row)).ItemArray[10].ToString(),



                            FormNo = form.FormNo,
                            Mark   = "系统自动导入",

                            DrawVer     = ver,
                            PageSize    = pageSize,
                            FileGroup   = fileGroup,
                            Reason      = reason,
                            IsPublished = false,
                        });
                        break;
                    }
                    #endregion



                    //发行
                    if (this.Published(form.FormNo, 0, publishEmp, publishDate, isPass))
                    {
                        success++;
                    }
                }
                catch (Exception exception)
                {
                    return(Link.ErrorBy(new Exception($"成功导入{success}:Error:{exception.Message}"), this.GetType()));
                }
            }

            return(success);
        }