// public void ReloadFile() // { // // Reload file if selected file is valid // if (!string.IsNullOrEmpty(this.currentFilePath)) // { // // Read from file // string content = FileHelper.ReadFile(this.currentFilePath, true, // MyConfig.GetSetting(MyConfig.Key_StudentName)); // // // Load it to Text // tbCode.Text = content; // lblFileName.Text = Path.GetFileName(this.currentFilePath); // } // else // { // tbCode.Text = ""; // lblFileName.Text = "(select a file from exercise list)"; // } // } public void LoadFileLists() { string[] list = FileHelper.ListFiles(MyFileHelper.GetSubfolderPath(MyFileHelper.FOLDER_COMPULSORY)); lvCompulsory.View = View.Details; lvCompulsory.Columns.Add("FileName", -2); lvCompulsory.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None; lvCompulsory.Items.Clear(); foreach (string file in list) { string name = Path.GetFileName(file); ListViewItem item = lvCompulsory.Items.Add(new ListViewItem(new string[] { name })); item.Tag = file; } list = FileHelper.ListFiles(MyFileHelper.GetSubfolderPath(MyFileHelper.FOLDER_ADDITIONAL)); lvAdditional.View = View.Details; lvAdditional.Columns.Add("FileName", -2); lvAdditional.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None; lvAdditional.Items.Clear(); foreach (string file in list) { string name = Path.GetFileName(file); ListViewItem item = lvAdditional.Items.Add(new ListViewItem(new string[] { name })); item.Tag = file; } }
private void btSetName_Click(object sender, EventArgs e) { string strNewName = tbName.Text.Trim(); if (strNewName.ToLower() != strName.ToLower() && !string.IsNullOrEmpty(strName)) { DialogResult dialogResult = MessageBox.Show("Updating name will reset all completed exercises. Continue?", "Update Name", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dialogResult == DialogResult.No) { return; } } // Save name and hash to configSetting MyConfig.SetSetting(MyConfig.Key_StudentName, strNewName); MyConfig.SetSetting(MyConfig.Key_StudentHash, MyConfig.GetHashFromName(strNewName.ToLower())); // Copy all exercises MyFileHelper.CopyExerciseFolders(); MyFileHelper.GenerateEmptyFilesFromList(); btSetName.Enabled = false; Application.Restart(); }
private void btRefresh_Click(object sender, EventArgs e) { string name = MyConfig.GetSetting(MyConfig.Key_StudentName); if (string.IsNullOrEmpty(name)) { FormSetup f = new FormSetup(); f.ShowDialog(); } if (string.IsNullOrEmpty(MyConfig.GetSetting(MyConfig.Key_StudentName).Trim())) { MessageBox.Show("Name must be set to use the program", "Empty Name", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); Environment.Exit(0); } string hash = MyConfig.GetSetting(MyConfig.Key_StudentHash); if (hash != MyConfig.GetHashFromName(name)) { hash = MyConfig.GetHashFromName(name); MyConfig.SetSetting(MyConfig.Key_StudentHash, hash); } MyFileHelper.CopyExerciseFolders(); MyFileHelper.GenerateEmptyFilesFromList(); SetTitle(); LoadFileLists(); lvCompulsory.SelectedItems.Clear(); lvAdditional.SelectedItems.Clear(); UpdateWithListItem(); }
private void BtImport_Click(object sender, EventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); dialog.DefaultExt = ".zip"; // Default file extension dialog.Filter = "zip files (*.zip)|*.zip|All files (*.*)|*.*"; dialog.FileName = MyConfig.GetSetting(MyConfig.Key_StudentHash) + ".zip"; if (dialog.ShowDialog() == DialogResult.OK) { string fileName = dialog.FileName; if (!File.Exists(fileName)) { MessageBox.Show(fileName, "File NOT Found"); return; } string userFolder = MyFileHelper.GetUserfolderPath(); DialogResult dialogResult = MessageBox.Show("This will overwrite existing exercise files. Continue?", "Import Profile", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dialogResult == DialogResult.No) { return; } ZipArchiveExtensions.ExtractZipFileToDirectory(fileName, userFolder, true); Application.Restart(); } }
public Int32 Execute() { String WinLFS_Path = this.Address.Replace('|', '\\'); DirectoryInfo DirectoryListRequest = new DirectoryInfo(WinLFS_Path); if (this.ReturnDirectories) { List <DirectoryInfo> DirList = new List <DirectoryInfo> (1024 * 4); DirList.AddRange(DirectoryListRequest.GetDirectories()); var Dirs = from D in DirList where (D.Attributes & (FileAttributes.System | FileAttributes.Hidden)) == 0 select D; foreach (var DirInfo in Dirs) { this.Objects.Add(new FileRecord() { Type = (int)EFileNodeType.Directory, Name = DirInfo.Name, SizeText = "", Owner = "ChuckNorris", Flags = (int)DirInfo.Attributes, }); } } if (this.ReturnFiles) { List <FileInfo> FileList = new List <FileInfo> (1024 * 4); FileList.AddRange(DirectoryListRequest.GetFiles()); var Files = from F in FileList where (F.Attributes & (FileAttributes.System | FileAttributes.Hidden)) == 0 select F; foreach (var FileInfo in Files) { this.Objects.Add(new FileRecord() { Type = (int)EFileNodeType.File, Name = FileInfo.Name, // Размер файлов я пока передаю строкой. Так как в JSON нет полноценной поддержки Int64. SizeText = MyFileHelper.GetSizeHint(FileInfo.Length), Owner = "ChuckNorris", Flags = (int)FileInfo.Attributes, }); } } return(StatusResult_Success); }
//将本地sqlite数据库文件上传到服务器 public static void UploadLocalDB() { string testdbPath = "C:\\db\\test.db"; byte[] byte_testdb = MyFileHelper.File2Bytes(testdbPath); string hexstring_file = MyByteStringHelper.ByteToHexStr(byte_testdb); string data = JsonConvert.SerializeObject(hexstring_file); httpRequestHelper.PostRequest("http://mzhdemo.xyz:1996/api/ClientToServer//UploadDatabase", data, "application/json"); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); try { Encrytor.Check(); } catch (Exception ex) { MyFileHelper.Write(ex.ToString()); } }
public void AddFileToAdditionalListView(string inputFile) { // Copy the file into "additional" folder string fileName = Path.GetFileName(inputFile); string destFile = Path.Combine(MyFileHelper.GetSubfolderPath(MyFileHelper.FOLDER_ADDITIONAL), fileName); bool exists = File.Exists(destFile); if (exists) { DialogResult answer = MessageBox.Show($"Overwrite existing file: {fileName}?", "Overwrite File", MessageBoxButtons.YesNo); if (answer == DialogResult.No) { return; } } string content = FileHelper.ReadFile(inputFile); FileHelper.WriteFile(destFile, content, true, MyConfig.GetSetting(MyConfig.Key_StudentHash)); tabFileLists.SelectTab(1); ListViewItem item = null; if (!exists) { item = lvAdditional.Items.Add(new ListViewItem(new string[] { fileName })); item.Tag = destFile; } else { item = lvAdditional.FindItemWithText(fileName); } if (item != null) { UpdateWithListItem(item); lvAdditional.SelectedItems.Clear(); lvAdditional.Items[item.Index].Focused = true; lvAdditional.Items[item.Index].Selected = true; } }
public static void ImportAllCSV() { var db = new StockSupportSystemEntities(); var stocks = db.Database.SqlQuery <stock>("select * from stock where id<700000 and id >=600000").ToList(); foreach (stock stk in stocks) { string code = stk.type + stk.id; string now_day = DateTime.Now.ToString("yyyy-MM-dd"); string now_datetime = now_day.Split('-')[0] + now_day.Split('-')[1] + now_day.Split('-')[2]; string url = string.Format("http://quotes.money.163.com/service/chddata.html?code={0}&start=19900101&end={1}&fields=TCLOSE;LOW;HIGH;TOPEN;LCLOSE;CHG;PCHG;VOTURNOVER", code.Trim(), now_datetime); HttpWebRequest request = HttpWebRequest.Create(url) as HttpWebRequest; request.Method = "GET"; request.ProtocolVersion = new Version(1, 1); HttpWebResponse response = request.GetResponse() as HttpWebResponse; if (response.StatusCode == HttpStatusCode.NotFound) { return; } // 转换为byte类型 System.IO.Stream stream = response.GetResponseStream(); if (Directory.Exists(StockInfoRootPath)) { if (!File.Exists(StockInfoRootPath + "\\" + code.Trim() + ".CSV")) { MyFileHelper.CreateFileContent(StockInfoRootPath + "\\" + code.Trim() + ".CSV", ""); } //创建本地文件写入流 Stream fs = new FileStream(StockInfoRootPath + "\\" + code.Trim() + ".CSV", FileMode.Create); byte[] bArr = new byte[2048]; int size = stream.Read(bArr, 0, (int)bArr.Length); while (size > 0) { fs.Write(bArr, 0, size); size = stream.Read(bArr, 0, (int)bArr.Length); } fs.Close(); stream.Close(); } } }
protected override void OnStartup(StartupEventArgs e) { // 定义应用程序启动时要处理的内容 if (MyFileHelper.IsExistFile(XmlHelper.PersonXmlPath)) { MyFileHelper.ClearFile(XmlHelper.PersonXmlPath); } else { MyFileHelper.CreateFileContent(XmlHelper.PersonXmlPath, ""); } if (!MyFileHelper.IsExistFile(FileHelper.dbpath)) { if (!MyFileHelper.IsExistDirectory(FileHelper.dbfilepath)) { MyFileHelper.CreateDirectory(FileHelper.dbfilepath); } bool result = MyFileHelper.CopyFile(FileHelper.sourcedbpath, FileHelper.dbpath); } }
private void btNewFile_Click(object sender, EventArgs e) { string filename = Interaction.InputBox("Enter file name", "Create New File", "myfile.c", -1, -1); if (string.IsNullOrEmpty(filename.Trim())) { return; } if (!filename.EndsWith(".c")) { filename = filename + ".c"; } filename = FileHelper.SanitizeFileName(filename); if (!string.IsNullOrEmpty(filename)) { // Create new file and add to additional_list string toFolder = MyFileHelper.GetSubfolderPath(MyFileHelper.FOLDER_ADDITIONAL); string filePath = Path.Combine(toFolder, filename); if (File.Exists(filePath)) { MessageBox.Show($"File name already exists: {filename}", "Create File Failed", MessageBoxButtons.OK); return; } if (!string.IsNullOrEmpty(filePath)) { FileHelper.WriteFile(filePath, ""); tabFileLists.SelectTab(1); ListViewItem item = lvAdditional.Items.Add(new ListViewItem(new string[] { filename })); item.Tag = filePath; lvAdditional.SelectedItems.Clear(); lvAdditional.Items[item.Index].Focused = true; lvAdditional.Items[item.Index].Selected = true; } } }
private void BtExport_Click(object sender, EventArgs e) { SaveFileDialog dialog = new SaveFileDialog(); dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); dialog.DefaultExt = ".zip"; // Default file extension dialog.Filter = "zip files (*.zip)|*.zip|All files (*.*)|*.*"; string hash = MyConfig.GetSetting(MyConfig.Key_StudentHash); dialog.FileName = hash + ".zip"; DialogResult result = dialog.ShowDialog(this); if (result != DialogResult.OK || string.IsNullOrEmpty(dialog.FileName)) { return; } try { if (File.Exists(dialog.FileName)) { File.Delete(dialog.FileName); } string zipPath = dialog.FileName; string userFolder = MyFileHelper.GetSubfolderPath(); ZipFile.CreateFromDirectory(userFolder, zipPath); MessageBox.Show("Exported: " + dialog.FileName, "Export Profile Successful", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Export Profile Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }