Esempio n. 1
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtDocumentDirectory.Text))
            {
                return;
            }

            if (string.IsNullOrEmpty(txtExcelFileName.Text))
            {
                return;
            }

            //branch here for logic on window task type?

            string dirPath = txtDocumentDirectory.Text;
            mParentType = (ParentTypeEnum) Enum.Parse(typeof (ParentTypeEnum), comboBoxParentType.Text, true);

            mStopwatch.Start();

            AddMessageToGrid("Import started...", Common.ImporterMessageType.Info, true);

            AttachmentLoader loader = new AttachmentLoader(dirPath, mExcelFileInfo, mParentType);

            loader.AddMessage += (message, type, force) =>
            {
                AddMessageToGrid(message, type, force);
            };

            loader.ProgressChanged += (count) =>
            {
                lblCount.Text = count;
            };

            loader.ProgressComplete += (message) =>
                {
                    string settingValue = CommonUtils.GetAppSettingValue(CommonUtils.AppSettingKey.UploadedDocumentsPathRoot);

                    string path = Path.Combine(settingValue, "import_ui_messages.csv");

                    for (int i = 0; i < 10; i++)
                    {
                        if (File.Exists(path))
                        {
                            path = Path.Combine(settingValue, string.Format("import_ui_messages{0}.csv", i));
                        }
                        else
                        {
                            break;
                        }
                    }

                    using (StreamWriter sw = new StreamWriter(path))
                    {
                        WriteToCSV(txtComment.Text, listView, sw);
                        AddMessageToGrid("Finished: ", Common.ImporterMessageType.Info, true);
                    }

                    AddMessageToGrid(message, Common.ImporterMessageType.Info, false);
                };

            loader.Run();
        }