コード例 #1
0
        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
        }
コード例 #2
0
        private void btnExportTransaction_Click(object sender, EventArgs e)
        {
            #region Generate .xls file

            var fileSelector = new FolderBrowserDialog();
            var defaultPath  = ExportFile.GetDefaultPath("dircPath");
            if (defaultPath != "")
            {
                fileSelector.SelectedPath = defaultPath;
            }
            var timeStamp = DateTime.Now.Date.ToString("ddMMyyyy");
            if (fileSelector.ShowDialog() == DialogResult.OK)
            {
                ExportFile.SetFolderPath("dircPath", fileSelector.SelectedPath);
                var path = string.Format(fileSelector.SelectedPath + @"\销售记录{0}.xls", timeStamp);
                lbFolder.Text = string.Format("     Selected Directory: {0}", path);
                var parameters = new string[2];
                parameters[0] = timeStamp;
                parameters[1] = path;
                if (bkgWorkForExporting.IsBusy != true)
                {
                    bkgWorkForExporting.RunWorkerAsync(parameters);
                }
                btnExportTransaction.Enabled = false;
            }

            #endregion
        }
コード例 #3
0
        /// <summary>
        ///     Import Orders
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnImport_Click(object sender, EventArgs e)
        {
            var fileSelector = new FolderBrowserDialog();
            var defaultPath  = ExportFile.GetDefaultPath("dircPath");

            if (defaultPath != "")
            {
                fileSelector.SelectedPath = defaultPath;
            }
            if (fileSelector.ShowDialog() == DialogResult.OK)
            {
                ExportFile.SetFolderPath("dircPath", fileSelector.SelectedPath);
                lbFolder.Text = string.Format("     Selected Directory: {0}", fileSelector.SelectedPath);
                var files = Directory.GetFiles(fileSelector.SelectedPath).Where(name => name.EndsWith(".txt"));
                prbImport.Maximum = files.ToList().Count;
                prbImport.Step    = 1;
                prbImport.Value   = 0;


                foreach (var file in files.ToList())
                {
                    var objOrder = FormatParsing.ParsePathToFileName(file);
                    objOrder = FormatParsing.ParseContentIntoOrder(file, objOrder);
                    objOrders.Add(objOrder);
                }
                objOrders.Sort();

                if (bkgWorkForImporting.IsBusy != true)
                {
                    bkgWorkForImporting.RunWorkerAsync();
                }
                btnImportRecords.Enabled = false;
            }
        }
コード例 #4
0
        private void btnExportRecords_Click(object sender, EventArgs e)
        {
            #region Batch generate .txt file

            var fileSelector = new FolderBrowserDialog();
            var defaultPath  = ExportFile.GetDefaultPath("dircPath");
            if (defaultPath != "")
            {
                fileSelector.SelectedPath = defaultPath;
            }
            var timeStamp = DateTime.Now.Date.ToString("ddMMyyyy");
            if (fileSelector.ShowDialog() == DialogResult.OK)
            {
                ExportFile.SetFolderPath("dircPath", fileSelector.SelectedPath);
                lbFolder.Text = string.Format("     Selected Directory: {0}", fileSelector.SelectedPath);

                prbImport.Maximum = new OrderManage().GetMaxOrderNo() - 1;
                prbImport.Step    = 1;
                prbImport.Value   = 0;

                if (bkgWorkForExportingRecords.IsBusy != true)
                {
                    bkgWorkForExportingRecords.RunWorkerAsync(fileSelector.SelectedPath);
                }
                btnExportRecords.Enabled = false;
            }

            #endregion
        }
コード例 #5
0
        /// <summary>
        ///     Import the transaction records
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnImportTransaction_Click(object sender, EventArgs e)
        {
            FileDialog fileSelector = new OpenFileDialog();

            fileSelector.Filter = "Text files (*.xls)|*.xls";
            var defaultPath = ExportFile.GetDefaultPath("dircPath");

            if (defaultPath != "")
            {
                fileSelector.InitialDirectory = defaultPath;
            }
            if (fileSelector.ShowDialog() == DialogResult.OK)
            {
                var pos  = fileSelector.FileName.LastIndexOf(@"\", StringComparison.Ordinal);
                var path = fileSelector.FileName.Substring(0, pos);
                ExportFile.SetFolderPath("dircPath", path);
                lbFolder.Text     = string.Format("     Selected Directory: {0}", path);
                prbImport.Step    = 1;
                prbImport.Value   = 0;
                objTransactions   = FormatParsing.ParseContentIntoTransaction(fileSelector.FileName, objTransactions);
                prbImport.Maximum = objTransactions.Count;
                if (bkgWorkForTransaction.IsBusy != true)
                {
                    bkgWorkForTransaction.RunWorkerAsync();
                }
                btnImportTransaction.Enabled = false;
            }
        }
コード例 #6
0
        private void btnOrderText_Click(object sender, EventArgs e)
        {
            if (dgvTransaction.RowCount == 0)
            {
                return;
            }
            var fileSelector = new FolderBrowserDialog();

            fileSelector.Description = zh?"请选择存有订单文本的文件夹:":@"Please choose the folder that stores order text:";
            var defaultPath = ExportFile.GetDefaultPath("dircPath");

            if (defaultPath != "")
            {
                fileSelector.SelectedPath = defaultPath;
            }
            if (fileSelector.ShowDialog() == DialogResult.OK)
            {
                var filename = string.Format(fileSelector.SelectedPath + @"\{0}{1}.txt",
                                             dgvTransaction.CurrentRow.Cells["OrderNo"].Value,
                                             dgvTransaction.CurrentRow.Cells["Purchaser"].Value); // Get the file name

                _frmOrderText    = new FrmOrderText();
                EvtSetOrderText += _frmOrderText.Receiver;
                EvtSetOrderText(ExportFile.ReadOrderFile(filename),
                                dgvTransaction.CurrentRow.Cells["OrderNo"].Value.ToString());
                DisplayMainFrm(false);
                OpenNewForm(_frmOrderText);
            }
        }
コード例 #7
0
        private void btnRegenerate_Click(object sender, EventArgs e)
        {
            #region Generate the Order text

            var objItems    = new ItemManage().GetItemListByOrderNo(_orderNo);
            var objUserInfo = new UserInfoManage().GetUserByOrderNo(_orderNo);
            tbOrderContent.Text = GenerateOrderContent(objItems, objUserInfo, false);

            #endregion

            #region Generate .txt file

            _purchaserName = new OrderManage().GetPurchaserName(_orderNo);
            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", _orderNo,
                                         _purchaserName);

                ExportFile.CreateOrderFile(path, tbOrderContent.Text.Trim());
                if (DialogResult.OK ==
                    MessageBox.Show((zh?"生成":"Generating ") + _orderNo + _purchaserName + (zh?".txt 成功!":".txt Sucessfully!")))
                {
                    //this.Close();
                }
            }

            #endregion

            if (tbOrderContent.Text != "")
            {
                Clipboard.SetDataObject(tbOrderContent.Text);
                tbOrderContent.Focus();
                MessageBox.Show(zh ? "复制到粘贴板" : "Copy to clipboard!");
            }
        }
コード例 #8
0
        private void btnDeleteOrder_Click(object sender, EventArgs e)
        {
            // Display the selected row in datagridview
            //this.dgvTransaction.FirstDisplayedCell = this.dgvTransaction.Rows[Convert.ToInt32(this.orderNo)].Cells[0];
            if (dgvTransaction.RowCount == 0)
            {
                return;
            }

            if (MessageBox.Show(this, zh?"删除?":"Delete?", zh?"提示":"Prompt", MessageBoxButtons.YesNo, MessageBoxIcon.Question) ==
                DialogResult.Yes)
            {
                var objOrder = new OrderManage().GetOrderByOrderNo(_orderNo);
                objOrder.User = new UserInfoManage().GetUserByOrderNo(_orderNo);

                #region Delete the .txt File

                var defaultPath = ExportFile.GetDefaultPath("dircPath");
                if (defaultPath != "")
                {
                    var filename = string.Format(@"{0}\{1}{2}.txt", defaultPath, objOrder.OrderNo, objOrder.Purchaser);
                    if (File.Exists(filename))
                    {
                        File.Delete(filename);
                    }
                }

                #endregion

                new TransactionManage().DeleteTransactionRecord(_orderNo);
                new ItemManage().DeleteItemListByOrderNo(_orderNo);
                new OrderManage().DeleteOrder(objOrder);
                var result = new UserInfoManage().DeleteUser(objOrder.User);
                if (result > 0)
                {
                    MessageBox.Show(zh?"删除数据成功":"Delete data sucessfully!");
                }
                DisplayMainFrm(true);
            }
        }