Esempio n. 1
0
 private void M_SaveAs_Click(object sender, EventArgs e)
 {
     try
     {
         SaveFilePath.ShowDialog();
         if (!string.IsNullOrEmpty(SaveFilePath.SelectedPath))
         {
             string SavePath = SaveFilePath.SelectedPath;
             DocCreate();
             File.Copy($"{Application.StartupPath}\\{Tb_DocName.Text}.docx", $"{SavePath}\\{Tb_DocName.Text}.docx", true);
             CreateDocFile = $"{SavePath}\\{Tb_DocName.Text}.docx";
             File.Delete($"{Application.StartupPath}\\{Tb_DocName.Text}.docx");
             string apicode = UtilityHelper.CreateApiDocNo();
             sqlite.SetSQLiteConnection(Application.StartupPath + "\\" + "ApiSettingDb.dll");
             //增加Sqlite数据库记录+增加签名说明
             sqlite.ExecuteNonQuery($"INSERT INTO ApiDocSetting (ApiDocCode, DocName, Author, DocType,DocSaveFile) VALUES ('{apicode}', '{Tb_DocName.Text}', '{Tb_Author.Text}', '{doctype}','{CreateDocFile}')", new Dictionary <string, string>());
             SaveDbApiCode = apicode;
             MessageBox.Show("保存成功!");
             isFirst = false;
         }
         else
         {
             MessageBox.Show("未选择文件夹不能保存!");
         }
     }
     catch (Exception err)
     {
         MessageBox.Show($"Program Error:{err.Message}!");
     }
 }
Esempio n. 2
0
        private void CreateDirAndDownLoad(filepath entity)
        {
            var path = entity.file_Path;

            if (string.IsNullOrEmpty(path))
            {
                return;
            }
            var dirName = entity.file_innerTxt;

            //List<string> dirPathNameList = _dirPathList.Where(item => item.file_Path == entity.file_parent_path).Select(item => item.file_innerTxt).Distinct( ).ToList();
            //string dealString = (string.IsNullOrEmpty(dirName) ? (dirPathNameList.Count != 0 ? dirPathNameList[0].ToString( ) : (fileNames[fileNames.Length - 3] + @"\"
            //      + fileNames[fileNames.Length - 2])) : dirName);
            //dealString = dealString.ToCharArray( ).Where(ch => !(@"\/*|:?*<> ".ToCharArray( ).Contains(ch))).Aggregate(string.Empty, ( f, ch ) => f + ch);

            try
            {
                var fileNames = path.Split('/');
                if (fileNames.Length == 0)
                {
                    return;
                }
                var fileName = fileNames[fileNames.Length - 1];

                var dealString = string.IsNullOrEmpty(dirName)
                    ? fileNames[fileNames.Length - 3] + @"\"
                                 + fileNames[fileNames.Length - 2]
                    : dirName;
                //处理目录中非法的字符
                dealString =
                    dealString.ToCharArray()
                    .Where(ch => !@"\/*|:?*<> ".ToCharArray().Contains(ch))
                    .Aggregate(string.Empty, (f, ch) => f + ch);
                var createDir =
                    (SaveFilePath.EndsWith(@"\") ? SaveFilePath : SaveFilePath + @"\")
                    + dealString + @"\";

                if (!Directory.Exists(createDir))
                {
                    try
                    {
                        Directory.CreateDirectory(createDir);
                    }
                    catch
                    {
                        MyMessageBox.Add(string.Format("路径 {0} 存在错误!文件名 {1} ", createDir, fileName));
                        Console.WriteLine("路径 {0} 存在错误!文件名 {1} ", createDir, fileName);
                    }
                }
                fileName = createDir + fileName;
                Tool.DownLoad(path, fileName);
                //  Console.WriteLine("线程 {0} 执行完了! 下载地址 {1} 本机地址 {2} ", Thread.CurrentThread.ManagedThreadId, path, fileName);
            }
            catch (Exception)
            {
                // Console.WriteLine(e.Data + "\n" + e.Message);
            }
        }