// Query of Manage: 編輯名稱 private void RenameFolder(string path, string idPath, string newPath, string newNickName) { string[] paths = path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); string[] newPaths = newPath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); string[] ids = idPath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); int level = paths.Count(); int id = 0; ApiHelper api = new ApiHelper(); switch (level) { case 1: id = Convert.ToInt32(ids[0]); if (api.Rename(path, newPath)) { try { CLv1Classify.InsertOrUpdate(id, newPaths[0], newNickName); GetBreadcrumbBarPath(); navBar.Path = path; } catch (Exception ex) { throw ex; } } break; case 2: id = Convert.ToInt32(ids[1]); int classfyId = Convert.ToInt32(ids[0]); if (api.Rename(path, newPath)) { try { CLv2Customer.InsertOrUpdate(id, newPaths[1], newNickName, classfyId); GetBreadcrumbBarPath(2); navBar.Path = path; } catch (Exception ex) { throw ex; } } break; case 3: id = Convert.ToInt32(ids[2]); if (api.Rename(path, newPath)) { try { CLv3CustomerBranch.InsertOrUpdate(id, newPaths[2], newNickName, 0); GetBreadcrumbBarPath(3); navBar.Path = path; } catch (Exception ex) { throw ex; } } break; case 4: id = Convert.ToInt32(ids[3]); if (api.Rename(path, newPath)) { try { CLv4Line.InsertOrUpdate(id, newPaths[3], newNickName, 0); GetBreadcrumbBarPath(4); navBar.Path = path; } catch (Exception ex) { throw ex; } } break; case 5: id = Convert.ToInt32(ids[4]); int result = api.RenameCategorys(paths[4], newPaths[4]); if (result >= 0) { try { CFileCategory.InsertOrUpdate(id, newPaths[4], newNickName); GetBreadcrumbBarPath(5); navBar.Path = path; } catch (Exception ex) { throw ex; } } break; }; }
public void bgworkerStartUpload_DoWorkHandler(object sender, DoWorkEventArgs e) { ApiHelper api = new ApiHelper(); BackgroundWorker bgworkerStartUpload = sender as BackgroundWorker; Dictionary<string, string> fileInfo = (Dictionary<string, string>)e.Argument; Dictionary<string, string> asyncResult = new Dictionary<string, string>(); asyncResult.Add("IsCompleted", "false"); asyncResult.Add("FileId", fileInfo["FileId"]); asyncResult.Add("RemoteFilePath", fileInfo["RemoteFilePath"]); // Asynchronous FTP Upload Chilkat.Ftp2 ftp = new Chilkat.Ftp2(); bool success; success = ftp.UnlockComponent(GlobalHelper.ComponentCode); if (success != true) { MessageBox.Show(ftp.LastErrorText); return; } ftp.Hostname = GlobalHelper.FtpHost; ftp.Username = GlobalHelper.FtpUsername; ftp.Password = GlobalHelper.FtpPasswrod; // Resume upload ftp.RestartNext = true; // Connect and login to the FTP server. success = ftp.Connect(); if (success != true) { MessageBox.Show(ftp.LastErrorText); return; } string localFilename = fileInfo["LocalFilePath"]; string remoteFilename = fileInfo["RemoteFilePath"]; long localFilesize = Convert.ToInt64(fileInfo["LocalFileSize"]); success = ftp.AsyncPutFileStart(localFilename, remoteFilename); if (success != true) { MessageBox.Show(ftp.LastErrorText); return; } while (ftp.AsyncFinished != true) { if (_cancelList.Contains(fileInfo["FileId"])) { ftp.AsyncAbort(); break; } if (api.CheckPath(remoteFilename)) { long remoteFilesize = api.GetFileSize(remoteFilename); double percentage = ((double)remoteFilesize / (double)localFilesize) * 100; bgworkerStartUpload.ReportProgress((int)percentage); } // Sleep 0.5 second. ftp.SleepMs(500); } bool uploadSuccess = false; // Did the upload succeed? if (ftp.AsyncSuccess == true) { uploadSuccess = true; bgworkerStartUpload.ReportProgress(100); asyncResult["IsCompleted"] = "true"; } else { } ftp.Disconnect(); ftp.Dispose(); // Change Local file name back to original string originalFilePath = fileInfo["LocalFilePath"].Replace(GlobalHelper.TempUploadFileExt, String.Empty); if (uploadSuccess || _cancelList.Contains(fileInfo["FileId"])) { File.Move(fileInfo["LocalFilePath"], originalFilePath); } if (uploadSuccess) { // Move local file to Recycle bin FileSystem.DeleteFile(originalFilePath, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); // Remove temp extension from remote file string newName = remoteFilename.Replace(GlobalHelper.TempUploadFileExt, String.Empty); api.Rename(remoteFilename, newName); // Insert record into db int categoryId = Convert.ToInt32(fileInfo["ModelFileCategoryId"]); int lineId = Convert.ToInt32(fileInfo["ModelLineId"]); CFile.InsertOrUpdate(null, categoryId, lineId, fileInfo["ModelOriginFileName"], fileInfo["ModelFileName"], false, GlobalHelper.LoginUserID, fileInfo["ModelFileHash"]); } e.Result = asyncResult; }