private void btnTxtFile_Click(object sender, EventArgs e) { #region Generate .txt file var fileSelector = new FolderBrowserDialog(); var defaultPath = ExportFile.GetDefaultPath("dircPath"); if (defaultPath != "") { fileSelector.SelectedPath = defaultPath; } if (fileSelector.ShowDialog() == DialogResult.OK) { ExportFile.SetFolderPath("dircPath", fileSelector.SelectedPath); var path = string.Format(fileSelector.SelectedPath + @"\{0}{1}.txt", crtOrderNo, purchaserName); var objItems = new ItemManage().GetItemListByOrderNo(crtOrderNo); var objUserInfo = new UserInfo { UserName = tbTo.Text.Trim(), PhoneNumber = tbToPhone.Text.Trim(), Address = tbAddress.Text.Trim(), CardNo = tbIdentityCard.Text.Trim() }; var orderContent = ExportFile.GenerateOrderContent(objItems, objUserInfo, true); ExportFile.CreateOrderFile(path, tbOrderContent.Text.Trim()); MessageBox.Show((zh?"生成 ":"Generating ") + crtOrderNo + purchaserName + (zh?".txt 成功! ":".txt Sucessfully!")); } #endregion }
private void bkgWorkForExportingRecords_DoWork(object sender, DoWorkEventArgs e) { var bkgWorker = sender as BackgroundWorker; var counter = 0; var lstOrderNo = new OrderManage().GetAllOrderNoAndPurchaser(); foreach (var orderInfo in lstOrderNo) { var objItems = new ItemManage().GetItemListByOrderNo(orderInfo.Key); var objUserInfo = new UserInfoManage().GetUserByOrderNo(orderInfo.Key); var orderContent = ExportFile.GenerateOrderContent(objItems, objUserInfo, true); var path = string.Format((string)e.Argument + @"\{0}{1}.txt", orderInfo.Key, orderInfo.Value); ExportFile.CreateOrderFile(path, orderContent); try { bkgWorker.ReportProgress(counter++); } catch (NullReferenceException exception) { Console.WriteLine(exception); throw; } } MessageBox.Show("Exporting all .txt files sucessfully!"); }