//POST : api/Picture/id public async Task <IHttpActionResult> Post(string id) { string SAVE_DIR = string.IsNullOrEmpty(id) ? UPLOAD_DIR : Path.Combine(UPLOAD_DIR, id); //check file type if (!Request.Content.IsMimeMultipartContent()) { throw new Exception_DG("unsupported media type", 2005); } string dir = Path.Combine(IO_Helper_DG.RootPath_MVC, "/temp"); IO_Helper_DG.CreateDirectoryIfNotExist(dir); var provider = new MultipartFormDataStreamProvider(dir); // Read the form data. await Request.Content.ReadAsMultipartAsync(provider); List <string> fileNameList = new List <string>(); StringBuilder sb = new StringBuilder(); long fileTotalSize = 0; int fileIndex = 1; // This illustrates how to get the file names. foreach (MultipartFileData file in provider.FileData) { //new folder string saveDir = Path.Combine(IO_Helper_DG.RootPath_MVC, SAVE_DIR); IO_Helper_DG.CreateDirectoryIfNotExist(saveDir); if (File.Exists(file.LocalFileName)) { //get file name string fileName = file.Headers.ContentDisposition.FileName.Substring(1, file.Headers.ContentDisposition.FileName.Length - 2); //create new file name string newFileName = String.Concat(Guid.NewGuid(), ".", fileName.Split('.')[1]); string newFullFileName = Path.Combine(saveDir, newFileName); fileNameList.Add(Path.Combine(SAVE_DIR, newFileName)); FileInfo fileInfo = new FileInfo(file.LocalFileName); fileTotalSize += fileInfo.Length; sb.Append($" #{fileIndex} Uploaded file: {newFileName} ({ fileInfo.Length} bytes)"); fileIndex++; File.Move(file.LocalFileName, newFullFileName); Trace.WriteLine("1 file copied , filePath=" + newFullFileName); } } return(OK($"{fileNameList.Count} file(s) /{fileTotalSize} bytes uploaded successfully! Details -> {sb.ToString()} -- qx_frame {DateTime_Helper_DG.Get_DateTime_Now_24HourType()}", fileNameList, fileNameList.Count)); }
//Export To Excel private void button22_Click(object sender, EventArgs e) { string filePath = textBox6.Text.Trim(); string fileComplexPath = $"{ filePath + DataBaseName}.xlsx"; IO_Helper_DG.CreateDirectoryIfNotExist(filePath); new Thread(() => { Office_Helper_DG.DataTableToExcel(fileComplexPath, textBox9.Text.Trim(), this.DataBaseTable); }).Start(); MessageBox.Show("OutPut->" + fileComplexPath); }
//将文本框文件保存到桌面 private void saveCodeToFile() { string dirPath = textBox6.Text; string fileComplexPath = dirPath + textBox4.Text + comboBox1.Text; IO_Helper_DG.CreateDirectoryIfNotExist(dirPath); using (FileStream fs = new FileStream(fileComplexPath, FileMode.Create)) { StreamWriter sw = new StreamWriter(fs); sw.Write(CodeTxt); sw.Close(); } }
//POST : api/File public async Task <IHttpActionResult> Post() { string SAVE_DIR = UPLOAD_DIR; //save folder string root = Path.Combine(IO_Helper_DG.RootPath_MVC, SAVE_DIR); //check path is exist if not create it IO_Helper_DG.CreateDirectoryIfNotExist(root); IList <string> fileNameList = new List <string>(); StringBuilder sb = new StringBuilder(); long fileTotalSize = 0; int fileIndex = 1; //get files from request HttpFileCollection files = HttpContext.Current.Request.Files; await Task.Run(() => { foreach (var f in files.AllKeys) { HttpPostedFile file = files[f]; if (!string.IsNullOrEmpty(file.FileName)) { string fileLocalFullName = Path.Combine(root, file.FileName); file.SaveAs(fileLocalFullName); fileNameList.Add(Path.Combine(SAVE_DIR, file.FileName)); FileInfo fileInfo = new FileInfo(fileLocalFullName); fileTotalSize += fileInfo.Length; sb.Append($" #{fileIndex} Uploaded file: {file.FileName} ({ fileInfo.Length} bytes)"); fileIndex++; Trace.WriteLine("1 file copied , filePath=" + fileLocalFullName); } } }); return(OK($"{fileNameList.Count} file(s) /{fileTotalSize} bytes uploaded successfully! Details -> {sb.ToString()} -- qx_frame {DateTime_Helper_DG.Get_DateTime_Now_24HourType()}", fileNameList, fileNameList.Count)); }
//Generate Three-Layout-Frame private void button15_Click(object sender, EventArgs e) { //Generate QX_Frame.Data.Entities textBox2.Text = "QX_Frame.Data.Entities"; textBox7.Text = ""; textBox8.Text = $"Entity<{DataBaseName}, {TableName}>"; CommonComponent(() => NetEntityWithBantina.CreateCode(CreateInfoDic)); //Generate QX_Frame.Data.QueryObject textBox3.Text = "using QX_Frame.App.Base;\nusing QX_Frame.Data.Entities;\nusing System;\nusing System.Linq.Expressions;"; textBox2.Text = "QX_Frame.Data.QueryObject"; textBox7.Text = "QueryObject"; textBox8.Text = $"WcfQueryObject<{DataBaseName}, {TableName}>"; CommonComponent(() => QX_FrameToQueryObject.CreateCode(CreateInfoDic)); //Generate QX_Frame.Data.Service textBox3.Text = "using QX_Frame.App.Base;\nusing QX_Frame.Data.Contract;\nusing QX_Frame.Data.Entities;"; textBox2.Text = "QX_Frame.Data.Service"; textBox7.Text = "Service"; string tableNameRelace = TableName.Replace("TB_", "").Replace("tb_", "").Replace("t_", "").Replace("T_", ""); textBox5.Text = tableNameRelace; textBox8.Text = $"WcfService, I{tableNameRelace}Service"; CommonComponent(() => QX_FrameToDataService.CreateCode(CreateInfoDic)); string dirPath = textBox6.Text; string fileComplexPath = dirPath + "ClassRegister.txt"; IO_Helper_DG.CreateDirectoryIfNotExist(dirPath); using (StreamWriter sw = new StreamWriter(fileComplexPath, true)) { sw.WriteLine($"AppBase.Register(c => new {tableNameRelace}Service());"); sw.Close(); } //Generate QX_Frame.Data.Contract textBox3.Text = "using QX_Frame.Data.Entities;"; textBox2.Text = "QX_Frame.Data.Contract"; textBox5.Text = $"I{textBox5.Text.Replace("TB_", "").Replace("tb_", "").Replace("t_", "").Replace("T_", "")}"; textBox7.Text = "Service"; textBox8.Text = ""; CommonComponent(() => QX_FrameToDataContract.CreateCode(CreateInfoDic)); }