Пример #1
0
        void _client_SaveUpLoadFileIsExistCompleted(object sender, SMT.Saas.Tools.NewFileUploadWS.SaveUpLoadFileIsExistCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                MessageChildWindow messageWindow = new MessageChildWindow();
                // messageWindow.Message = "Maximum file size is: " + (MaxSize / 1024).ToString() + "KB.";
                messageWindow.Message = "上传已存在的文件时出现错误";
                messageWindow.Show();
            }
            else
            {
                if (e.Result == "EXITST")
                {
                    MessageChildWindow messageWindow = new MessageChildWindow();

                    messageWindow.Message = "上传文件已经存在";
                    messageWindow.Show();
                }
                else
                {
                    _file.FileStream.Dispose();
                    _file.FileStream.Close();
                    _client.ChannelFactory.Close();
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 增加上传文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void addFilesButton_Click(object sender, RoutedEventArgs e)
        {
            string         files1 = ",";
            string         TempID = "";
            OpenFileDialog ofd    = new OpenFileDialog();

            ofd.Multiselect = true;
            try
            {
                if (!string.IsNullOrEmpty(Filter))
                {
                    ofd.Filter = Filter;
                }
            }
            catch (ArgumentException ex)
            {
                throw new Exception("不是正确的上传格式.", ex);
            }
            if (ofd.ShowDialog() == true)
            {
                foreach (FileInfo file in ofd.Files)
                {
                    string   fileName = file.Name;
                    UserFile userFile = new UserFile();
                    userFile.ID                     = ApplicationID;
                    userFile.UserID                 = UserID;
                    userFile.FileName               = file.Name;
                    userFile.FileStream             = file.OpenRead();
                    userFile.UIDispatcher           = this.Dispatcher;
                    userFile.SystemCode             = this.SystemCode;
                    userFile.ModelCode              = this.ModelCode;
                    userFile.Indexl                 = 1;
                    userFile.DisplayThumbnail       = (bool)displayThumbailChckBox.IsChecked;
                    userFile.MD5String              = MD5FileName(file.Name, file.Length.ToString(), UserID, SystemCode, ModelCode) + file.Extension;
                    userFile.UploadProgressChanged += new ProgressChangedEvent(userFile_UploadProgressChanged);
                    userFile.FileFinished          += new UserFile.DelegateFinish(userFile_FileFinished);
                    while (true)
                    {
                        TempID = GetTmpID();
                        if (files1.IndexOf("," + TempID + ",") == -1)
                        {
                            break;
                        }
                    }
                    files1          = files1 + TempID + ",";
                    userFile.TempID = TempID;

                    if (userFile.FileStream.Length <= MaxSize)
                    {
                        _files.Add(userFile);
                    }
                    else
                    {
                        MessageChildWindow messageWindow = new MessageChildWindow();
                        messageWindow.Message = "Maximum file size is: " + (MaxSize / 1024).ToString() + "KB.";
                        messageWindow.Show();
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Open the select file dialog
        /// </summary>
        private void SelectUserFiles()
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Multiselect = true;

            try
            {
                //Check the file filter (filter is used to filter file extensions to select, for example only .jpg files)
                if (!string.IsNullOrEmpty(_fileFilter))
                {
                    ofd.Filter = _fileFilter;
                }
            }
            catch (ArgumentException ex)
            {
                //User supplied a wrong configuration file
                throw new Exception("Wrong file filter configuration.", ex);
            }

            if (ofd.ShowDialog() == true)
            {
                foreach (FileInfo file in ofd.Files)
                {
                    string fileName = file.Name;

                    //Create a new UserFile object
                    UserFile userFile = new UserFile();
                    userFile.FileName          = file.Name;
                    userFile.FileStream        = file.OpenRead();
                    userFile.UIDispatcher      = this.Dispatcher;
                    userFile.HttpUploader      = _HttpUploader;
                    userFile.UploadHandlerName = _uploadHandlerName;

                    //Check for the file size limit (configurable)
                    if (userFile.FileStream.Length <= _maxFileSize)
                    {
                        //Add to the list
                        _files.Add(userFile);
                    }
                    else
                    {
                        MessageChildWindow messageWindow = new MessageChildWindow();
                        messageWindow.Message = "Maximum file size is: " + (_maxFileSize / 1024).ToString() + "KB.";
                        messageWindow.Show();

                        if (MaximumFileSizeReached != null)
                        {
                            MaximumFileSizeReached(this, null);
                        }
                    }
                }
            }
        }
Пример #4
0
 private void UploadFiles()
 {
     if (_files.Count == 0)
     {
         MessageChildWindow messageWindow = new MessageChildWindow();
         messageWindow.Message = "没有任何文件可上传,请选择文件";
         messageWindow.Show();
     }
     else
     {
         _files.UploadFiles();
     }
 }
Пример #5
0
 /// <summary>
 /// Start uploading files
 /// </summary>
 private void UploadFiles()
 {
     if (_files.Count == 0)
     {
         MessageChildWindow messageWindow = new MessageChildWindow();
         messageWindow.Message = "No files to upload. Please select one or more files first.";
         messageWindow.Show();
     }
     else
     {
         //Tell the collection to start uploading
         _files.UploadFiles();
     }
 }
Пример #6
0
 //上传文件
 private void UploadFiles()
 {
     if (_files.Count == 0)
     {
         MessageChildWindow messageWindow = new MessageChildWindow();
         messageWindow.Message = "没有任何文件可上传,请选择文件";
         messageWindow.Show();
     }
     else
     {
         uploadButton.Content = "取消";
         _files.UploadFiles();
         clearFilesButton.Visibility = Visibility.Collapsed;//上传过程中不能清空
     }
 }
Пример #7
0
        /// <summary>
        /// 增加上传文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void addFilesButton_Click(object sender, RoutedEventArgs e)
        {//第2步
            string         files1 = ",";
            string         TempID = "";
            OpenFileDialog ofd    = new OpenFileDialog();

            ofd.Multiselect = Multiselect;//是否可以多选
            try
            {
                if (!string.IsNullOrEmpty(Filter))
                {
                    ofd.Filter = Filter;
                }
            }
            catch (ArgumentException ex)
            {
                throw new Exception("不是正确的上传格式.", ex);
            }
            //string StrSpecial = @"~!@#$%^&*()_+- =`;:'\<>;~!@#¥%……&*()——+=-·";//特殊字符串
            List <string> StrSpecial = GetSpecialString();

            if (ofd.ShowDialog() == true)
            {
                foreach (FileInfo file in ofd.Files)
                {
                    if (file.Length == 0)
                    {
                        MessageBox.Show(file.Name + ":文件内容不能为空!");
                        continue;
                    }
                    string[] StrFrontName = file.Name.Split('.');
                    //控制文件名不为特殊字符
                    if (StrFrontName.Count() > 1)
                    {
                        var ents = from ent in StrSpecial
                                   where StrFrontName[0].Contains(ent) || StrFrontName[1].Contains(ent)
                                   select ent;
                        if (ents.Count() > 0)
                        {
                            MessageBox.Show(file.Name + "文件名存在特殊字符(*&^%$#@!~`?=+|><';:.,)请重新命名!");
                            continue;
                        }
                    }
                    string   fileName = file.Name;
                    UserFile userFile = new UserFile();
                    #region 用户定义设置
                    userFile.SavePath       = this.SavePath;                                                               //文件保存位置目录
                    userFile.SmtFileListId  = Guid.NewGuid().ToString();                                                   // this.SmtFileListId;//主键ID
                    userFile.CustomFileName = String.IsNullOrEmpty(this.CustomFileName) ? file.Name : this.CustomFileName; //文件名(用户自定义)
                    userFile.FileName       = file.Name;                                                                   //文件名
                    userFile.FileType       = file.Extension;                                                              //文件类型(.doc、.xls、.txt、.pdf......)
                    userFile.FileUrl        = this.FileUrl;                                                                //文件地址
                    userFile.FileSize       = Convert.ToDouble(file.Length);                                               //
                    userFile.CompanyCode    = this.CompanyCode;                                                            //公司代号
                    userFile.CompanyName    = this.CompanyName;                                                            //公司名字
                    userFile.SystemCode     = this.SystemCode;                                                             //系统代号
                    userFile.ModelCode      = this.ModelCode;                                                              //模块代号
                    userFile.ThumbnailUrl   = this.ThumbnailUrl;                                                           //缩略图地址
                    int fileCount = _files.Count() + 1;
                    userFile.Indexl              = fileCount;                                                              //排序
                    userFile.Remark              = this.Remark;                                                            //备注
                    userFile.CreateTime          = this.CreateTime;                                                        //创建时间
                    userFile.CreateName          = this.CreateName;                                                        //创建人
                    userFile.UpdateTime          = this.UpdateTime;                                                        //修改时间
                    userFile.UpdateName          = this.UpdateName;                                                        //修改人
                    userFile.ApplicationID       = this.ApplicationID;                                                     //业务ID
                    userFile.NotShowDeleteButton = this.NotShowDeleteButton;                                               //不显示删除按钮
                    userFile.ID     = this.ApplicationID;
                    userFile.UserID = this.UserID;
                    #endregion
                    //userFile.FileName = file.Name;
                    //userFile.SystemCode = this.SystemCode;
                    //userFile.ModelCode = this.ModelCode;
                    //userFile.FileType = this.FileType;
                    userFile.FileStream       = file.OpenRead();
                    userFile.UIDispatcher     = this.Dispatcher;
                    userFile.DisplayThumbnail = (bool)displayThumbailChckBox.IsChecked;
                    userFile.MD5String        = MD5FileName(file.Name, file.Length.ToString(), UserID, SystemCode, ModelCode, this.ApplicationID) + file.Extension;

                    userFile.UploadProgressChanged += new ProgressChangedEvent(userFile_UploadProgressChanged);
                    userFile.FileFinished          += new UserFile.DelegateFinish(userFile_FileFinished);
                    while (true)
                    {
                        TempID = GetTmpID();
                        if (files1.IndexOf("," + TempID + ",") == -1)
                        {
                            break;
                        }
                    }
                    files1          = files1 + TempID + ",";
                    userFile.TempID = TempID;

                    if (userFile.FileStream.Length <= MaxSize)
                    {
                        if (_files.Count > 0)
                        {
                            #region  加重复

                            bool bol = false;
                            for (int i = 0; i < _files.Count; i++)
                            {
                                if (_files[i].FileName == userFile.FileName && _files[i].FileSize == userFile.FileSize)
                                {               //不加重复
                                    bol = true; //有重复
                                }
                            }
                            if (!bol)
                            {
                                _files.Add(userFile);
                            }
                        }
                        else
                        {
                            _files.Add(userFile);
                        }
                        #endregion
                        // _files.Add(userFile);
                    }
                    else
                    {
                        MessageChildWindow messageWindow = new MessageChildWindow();
                        // messageWindow.Message = "Maximum file size is: " + (MaxSize / 1024).ToString() + "KB.";
                        messageWindow.Message = "文件最大限制为: " + ByteConverter.GetSizeName(MaxSize);
                        messageWindow.Show();
                    }
                }
            }
        }
Пример #8
0
        //上传文件
        private void UploadFiles()
        {

            if (_files.Count == 0)
            {
                MessageChildWindow messageWindow = new MessageChildWindow();
                messageWindow.Message = "没有任何文件可上传,请选择文件";
                messageWindow.Show();
            }
            else
            {
                uploadButton.Content = "取消";
                _files.UploadFiles();
                clearFilesButton.Visibility = Visibility.Collapsed;//上传过程中不能清空
            }

        }
Пример #9
0
        /// <summary>
        /// 增加上传文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void addFilesButton_Click(object sender, RoutedEventArgs e)
        {//第2步
            string files1 = ",";
            string TempID = "";
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Multiselect = Multiselect;//是否可以多选
            try
            {
                if (!string.IsNullOrEmpty(Filter))
                    ofd.Filter = Filter;
            }
            catch (ArgumentException ex)
            {
                throw new Exception("不是正确的上传格式.", ex);
            }
            //string StrSpecial = @"~!@#$%^&*()_+- =`;:'\<>;~!@#¥%……&*()——+=-·";//特殊字符串
            List<string> StrSpecial = GetSpecialString();
            if (ofd.ShowDialog() == true)
            {
                foreach (FileInfo file in ofd.Files)
                {
                    if (file.Length == 0)
                    {
                        MessageBox.Show(file.Name+":文件内容不能为空!");
                        continue;
                    }
                    string[] StrFrontName = file.Name.Split('.');
                    //控制文件名不为特殊字符
                    if (StrFrontName.Count() > 1)
                    {                        
                        var ents = from ent in StrSpecial
                                   where StrFrontName[0].Contains(ent) || StrFrontName[1].Contains(ent)
                                   select ent;
                        if (ents.Count() > 0)
                        {
                            MessageBox.Show(file.Name + "文件名存在特殊字符(*&^%$#@!~`?=+|><';:.,)请重新命名!");
                            continue;
                        }                        
                    }
                    string fileName = file.Name;
                    UserFile userFile = new UserFile();
                    #region 用户定义设置
                    userFile.SavePath = this.SavePath;//文件保存位置目录
                    userFile.SmtFileListId = Guid.NewGuid().ToString();// this.SmtFileListId;//主键ID
                    userFile.CustomFileName = String.IsNullOrEmpty(this.CustomFileName) ? file.Name : this.CustomFileName;//文件名(用户自定义)
                    userFile.FileName =file.Name;//文件名
                    userFile.FileType = file.Extension;//文件类型(.doc、.xls、.txt、.pdf......)
                    userFile.FileUrl = this.FileUrl;//文件地址
                    userFile.FileSize =Convert.ToDouble(file.Length);//
                    userFile.CompanyCode = this.CompanyCode;//公司代号
                    userFile.CompanyName = this.CompanyName;//公司名字
                    userFile.SystemCode = this.SystemCode;//系统代号
                    userFile.ModelCode = this.ModelCode;//模块代号
                    userFile.ThumbnailUrl = this.ThumbnailUrl;//缩略图地址
                    int fileCount = _files.Count() + 1;
                    userFile.Indexl = fileCount;//排序
                    userFile.Remark = this.Remark;//备注
                    userFile.CreateTime =this.CreateTime;//创建时间
                    userFile.CreateName = this.CreateName;//创建人
                    userFile.UpdateTime = this.UpdateTime;//修改时间
                    userFile.UpdateName = this.UpdateName;//修改人
                    userFile.ApplicationID = this.ApplicationID;//业务ID
                    userFile.NotShowDeleteButton = this.NotShowDeleteButton;//不显示删除按钮
                    userFile.ID = this.ApplicationID;
                    userFile.UserID = this.UserID;
                    #endregion
                    //userFile.FileName = file.Name;
                    //userFile.SystemCode = this.SystemCode;
                    //userFile.ModelCode = this.ModelCode;
                    //userFile.FileType = this.FileType;
                    userFile.FileStream = file.OpenRead();
                    userFile.UIDispatcher = this.Dispatcher;                 
                    userFile.DisplayThumbnail = (bool)displayThumbailChckBox.IsChecked;
                    userFile.MD5String = MD5FileName(file.Name, file.Length.ToString(), UserID, SystemCode, ModelCode,this.ApplicationID) + file.Extension;
                    
                    userFile.UploadProgressChanged += new ProgressChangedEvent(userFile_UploadProgressChanged);
                    userFile.FileFinished += new UserFile.DelegateFinish(userFile_FileFinished);
                    while (true)
                    {
                        TempID = GetTmpID();
                        if (files1.IndexOf("," + TempID + ",") == -1)
                            break;
                    }
                    files1 = files1 + TempID + ",";
                    userFile.TempID = TempID;

                    if (userFile.FileStream.Length <= MaxSize)
                    {
                        if (_files.Count > 0)
                        {
                            #region 不加重复
                            
                            bool bol = false;
                            for (int i = 0; i < _files.Count; i++)
                            {
                                if (_files[i].FileName == userFile.FileName && _files[i].FileSize == userFile.FileSize)
                                {//不加重复
                                    bol = true;//有重复
                                }                              
                            }
                              if(!bol)
                                {
                                    _files.Add(userFile);
                                }
                        }
                        else
                        {
                            _files.Add(userFile);
                        }
                        #endregion
                        // _files.Add(userFile);                    
                      
                    }
                    else
                    {
                        MessageChildWindow messageWindow = new MessageChildWindow();
                       // messageWindow.Message = "Maximum file size is: " + (MaxSize / 1024).ToString() + "KB.";
                         messageWindow.Message = "文件最大限制为: " + ByteConverter.GetSizeName(MaxSize);                        
                        messageWindow.Show();
                    }
                }
            }
        }
Пример #10
0
        private void UploadFiles()
        {

            if (_files.Count == 0)
            {
                MessageChildWindow messageWindow = new MessageChildWindow();
                messageWindow.Message = "没有任何文件可上传,请选择文件";
                messageWindow.Show();
            }
            else
            {
                _files.UploadFiles();
            }
          
        }
Пример #11
0
 /// <summary>
 /// 增加上传文件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void addFilesButton_Click(object sender, RoutedEventArgs e)
 {
      string files1=",";
     string TempID = "";
     OpenFileDialog ofd = new OpenFileDialog();
     ofd.Multiselect = true;
     try
     {
         if (!string.IsNullOrEmpty(Filter))
             ofd.Filter = Filter;
     }
     catch (ArgumentException ex)
     {
         throw new Exception("不是正确的上传格式.", ex);
     }
     if (ofd.ShowDialog() == true)
     {
         foreach (FileInfo file in ofd.Files)
         {
             
             string fileName = file.Name;
             UserFile userFile = new UserFile();
             userFile.ID = ApplicationID;
             userFile.UserID = UserID;
             userFile.FileName = file.Name;
             userFile.FileStream = file.OpenRead();
             userFile.UIDispatcher = this.Dispatcher;
             userFile.SystemCode = this.SystemCode;
             userFile.ModelCode = this.ModelCode;
             userFile.Indexl = 1;
             userFile.DisplayThumbnail = (bool)displayThumbailChckBox.IsChecked;
             userFile.MD5String = MD5FileName(file.Name, file.Length.ToString(), UserID,SystemCode,ModelCode) + file.Extension;
             userFile.UploadProgressChanged += new ProgressChangedEvent(userFile_UploadProgressChanged);
             userFile.FileFinished += new UserFile.DelegateFinish(userFile_FileFinished);
             while (true)
                 {
                     TempID = GetTmpID();
                     if (files1.IndexOf("," + TempID + ",") == -1)
                         break;
                 }
                 files1 = files1 + TempID + ",";
                 userFile.TempID = TempID;
          
             if (userFile.FileStream.Length <= MaxSize)
             {
               
                 _files.Add(userFile);
             }
             else
             {
                 MessageChildWindow messageWindow = new MessageChildWindow();
                 messageWindow.Message = "Maximum file size is: " + (MaxSize / 1024).ToString() + "KB.";
                 messageWindow.Show();
             }
         }
     }
 }
Пример #12
0
 /// <summary>
 /// Start uploading files
 /// </summary>
 private void UploadFiles()
 {
     if (_files.Count == 0)
     {  
         MessageChildWindow messageWindow = new MessageChildWindow();
         messageWindow.Message = "No files to upload. Please select one or more files first.";
         messageWindow.Show();
     }
     else
     {
         //Tell the collection to start uploading
         _files.UploadFiles();
     }
 }
Пример #13
0
        /// <summary>
        /// Open the select file dialog
        /// </summary>
        private void SelectUserFiles()
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Multiselect = true;

            try
            {
                //Check the file filter (filter is used to filter file extensions to select, for example only .jpg files)
                if (!string.IsNullOrEmpty(_fileFilter))
                    ofd.Filter = _fileFilter;
            }
            catch (ArgumentException ex)
            {
                //User supplied a wrong configuration file
                throw new Exception("Wrong file filter configuration.", ex);
            }

            if (ofd.ShowDialog() == true)
            {
                foreach (FileInfo file in ofd.Files)
                {
                    string fileName = file.Name;

                    //Create a new UserFile object
                    UserFile userFile = new UserFile();
                    userFile.FileName = file.Name;
                    userFile.FileStream = file.OpenRead();
                    userFile.UIDispatcher = this.Dispatcher;
                    userFile.HttpUploader = _HttpUploader;
                    userFile.UploadHandlerName = _uploadHandlerName;

                    //Check for the file size limit (configurable)
                    if (userFile.FileStream.Length <= _maxFileSize)
                    {
                        //Add to the list
                        _files.Add(userFile);
                    }
                    else
                    {
                        MessageChildWindow messageWindow = new MessageChildWindow();
                        messageWindow.Message = "Maximum file size is: " + (_maxFileSize / 1024).ToString() + "KB.";
                        messageWindow.Show();

                        if (MaximumFileSizeReached != null)
                            MaximumFileSizeReached(this, null);

                    }
                }
            }
        }
Пример #14
0
 void _client_SaveUpLoadFileIsExistCompleted(object sender, SMT.Saas.Tools.NewFileUploadWS.SaveUpLoadFileIsExistCompletedEventArgs e)
 {
     if (e.Error != null)
     {
         MessageChildWindow messageWindow = new MessageChildWindow();
         // messageWindow.Message = "Maximum file size is: " + (MaxSize / 1024).ToString() + "KB.";
         messageWindow.Message = "上传已存在的文件时出现错误";
         messageWindow.Show();
     }
     else
     {
         if (e.Result == "EXITST")
         {
             MessageChildWindow messageWindow = new MessageChildWindow();
             
             messageWindow.Message = "上传文件已经存在";
             messageWindow.Show();
         }
         else
         {
             _file.FileStream.Dispose();
             _file.FileStream.Close();
             _client.ChannelFactory.Close();
         }
     }
 }