/// <summary>
        /// 上传
        /// </summary>
        void FileUpLoad()
        {
            try
            {
                if (m_filePathExternal.Trim().Length == 0)
                {
                    if (openFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        m_filePathExternal = openFileDialog1.FileName;
                    }
                }

                if (m_filePathExternal.Trim().Length > 0)
                {
                    CursorControl.SetWaitCursor(this);
                    m_serverFileFtp.Upload(m_filePathExternal, m_filePathInternal);

                    this.Cursor = System.Windows.Forms.Cursors.Arrow;

                    if (GetError())
                    {
                        MessageDialog.ShowPromptMessage("上传成功");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageDialog.ShowErrorMessage(ex.Message);
                this.Cursor = System.Windows.Forms.Cursors.Arrow;
            }
        }
Example #2
0
        void InsertFile(string path, string billNo)
        {
            DepotManagementDataContext ctx = CommentParameter.DepotDataContext;

            try
            {
                DirectoryInfo mydir = new DirectoryInfo(path);

                if (!mydir.Exists)
                {
                    return;
                }

                FileInfo[] fileList = mydir.GetFiles();

                foreach (FileInfo file in fileList)
                {
                    string filePath = file.FullName;
                    Guid   guid     = Guid.NewGuid();

                    string fileName = filePath.Substring(filePath.LastIndexOf("\\") + 1,
                                                         filePath.LastIndexOf(".") - (filePath.LastIndexOf("\\") + 1));
                    string fileType         = filePath.Substring(filePath.LastIndexOf("."));
                    string strFtpServerPath = "/" + ServerTime.Time.Year.ToString() + "/" + ServerTime.Time.Month.ToString() + "/";

                    m_serverFTP.Upload(filePath, strFtpServerPath + guid);

                    if (GetError())
                    {
                        FM_FilePath lnqTemp = new FM_FilePath();

                        lnqTemp.FileUnique    = guid;
                        lnqTemp.FileType      = fileType.ToLower();
                        lnqTemp.FilePath      = strFtpServerPath + guid;
                        lnqTemp.OperationDate = ServerTime.Time;

                        ctx.FM_FilePath.InsertOnSubmit(lnqTemp);
                        ctx.SubmitChanges();

                        ZL_Database_FileStruct tempLnq = new ZL_Database_FileStruct();

                        tempLnq.BillNo         = billNo;
                        tempLnq.CreationTime   = ServerTime.Time;
                        tempLnq.FileUnique     = guid;
                        tempLnq.FileName       = fileName;
                        tempLnq.ID             = Guid.NewGuid();
                        tempLnq.LastModifyTime = ServerTime.Time;
                        tempLnq.ParentID       = null;

                        InsertFileStruct(tempLnq);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 文件上传
        /// </summary>
        /// <param name="guid">唯一编码</param>
        /// <param name="systemPath">系统路径</param>
        /// <param name="type">操作文件访问方式</param>
        public static void File_UpLoad(Guid guid, string systemPath, CE_CommunicationMode type)
        {
            try
            {
                DepotManagementDataContext ctx = CommentParameter.DepotDataContext;

                var varData = from a in ctx.FM_FilePath
                              where a.FileUnique == guid
                              select a;

                if (varData.Count() == 0)
                {
                    FM_FilePath fileInfo = new FM_FilePath();

                    fileInfo.FileUnique = guid;
                    fileInfo.FilePath   =
                        "/" + ServerTime.Time.Year.ToString() + "/" + ServerTime.Time.Month.ToString() + "/" + fileInfo.FileUnique.ToString();
                    fileInfo.FileType      = systemPath.Substring(systemPath.LastIndexOf("."));
                    fileInfo.OperationDate = ServerTime.Time;

                    ctx.FM_FilePath.InsertOnSubmit(fileInfo);

                    DateTime tempdateTime = ServerTime.Time;

                    if (type == CE_CommunicationMode.Socket)
                    {
                        FileServiceSocket serverSocket = new FileServiceSocket(GlobalObject.GlobalParameter.FTPServerIP,
                                                                               GlobalObject.GlobalParameter.FTPServerAdvancedUser,
                                                                               GlobalObject.GlobalParameter.FTPServerAdvancedPassword);
                        serverSocket.Upload(systemPath, fileInfo.FilePath);
                    }
                    else if (type == CE_CommunicationMode.FTP)
                    {
                        FileServiceFTP serverFTP = new FileServiceFTP(GlobalObject.GlobalParameter.FTPServerIP,
                                                                      GlobalObject.GlobalParameter.FTPServerAdvancedUser,
                                                                      GlobalObject.GlobalParameter.FTPServerAdvancedPassword);

                        serverFTP.Upload(systemPath, fileInfo.FilePath);
                    }

                    TimeSpan span = ServerTime.Time - tempdateTime;

                    ctx.SubmitChanges();
                }
                else
                {
                    throw new Exception("文件唯一编码重复");
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        //创建文件
        private void createnewfile_Click(object sender, EventArgs e)
        {
            try
            {
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    Guid guid = Guid.NewGuid();

                    string fileName = openFileDialog1.FileName.Substring(openFileDialog1.FileName.LastIndexOf("\\") + 1,
                                                                         openFileDialog1.FileName.LastIndexOf(".") - (openFileDialog1.FileName.LastIndexOf("\\") + 1));
                    string fileType         = openFileDialog1.FileName.Substring(openFileDialog1.FileName.LastIndexOf("."));
                    string strFtpServerPath = "/" + ServerTime.Time.Year.ToString() + "/" + ServerTime.Time.Month.ToString() + "/";

                    CursorControl.SetWaitCursor(this);
                    m_serverFTP.Upload(openFileDialog1.FileName, strFtpServerPath + guid);
                    this.Cursor = System.Windows.Forms.Cursors.Arrow;

                    if (GetError())
                    {
                        m_serverFileBasic.AddFile(guid, strFtpServerPath + guid, fileType);

                        this.listView1.LabelEdit = true;

                        ZL_Database_FileStruct tempLnq = new ZL_Database_FileStruct();

                        tempLnq.BillNo         = txtBillNo.Text;
                        tempLnq.CreationTime   = ServerTime.Time;
                        tempLnq.FileUnique     = guid;
                        tempLnq.FileName       = fileName;
                        tempLnq.ID             = Guid.NewGuid();
                        tempLnq.LastModifyTime = ServerTime.Time;
                        tempLnq.ParentID       = currentParentID == "" ? null : (Guid?)(new Guid(currentParentID));

                        m_serverQylityDatabase.InsertFileStruct(tempLnq);

                        ListViewItem item = new ListViewItem(new String[] { tempLnq.FileName,
                                                                            m_serverFTP.GetFileSize(strFtpServerPath + guid).ToString(), fileType,
                                                                            tempLnq.CreationTime.ToString(), tempLnq.LastModifyTime.ToString(), tempLnq.ID.ToString(),
                                                                            strFtpServerPath + guid, tempLnq.ParentID.ToString() }, 0);

                        SetListViewItemExtention(fileType, ref item);

                        this.listView1.Items.Add(item);
                        this.listView1.Items[this.listView1.Items.Count - 1].BeginEdit();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageDialog.ShowErrorMessage(ex.Message);
                this.Cursor = System.Windows.Forms.Cursors.Arrow;
            }
        }