Пример #1
0
        // return:
        //      -1  出错
        //      0   放弃处理
        //      1   正常结束
        public int DoRecPathLines()
        {
            this.tabControl_input.SelectedTab = this.tabPage_paths;

            this.EnableControls(false);
            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("");
            stop.BeginLoop();
            this.Update();
            this.MainForm.Update();

            try
            {
                return(DoTextLines());
            }
            finally
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
                stop.HideProgress();

                this.EnableControls(true);
            }
        }
Пример #2
0
 /// <summary>
 /// 结束一个循环
 /// </summary>
 public void EndLoop()
 {
     stop.EndLoop();
     stop.OnStop -= new StopEventHandler(this.DoStop);
     stop.Initial("");
     stop.HideProgress();
     stop.Style = StopStyle.None;
 }
Пример #3
0
        // 打印解释内容
        void menu_printHtml_Click(object sender, EventArgs e)
        {
            string strError = "";

            if (this.listView_records.SelectedItems.Count == 0)
            {
                strError = "尚未选定要打印的行";
                goto ERROR1;
            }

            List<string> filenames = new List<string>();
            string strFileNamePrefix = this.MainForm.DataDir + "\\~operlog_print_";
            string strFilename = strFileNamePrefix + (1).ToString() + ".html";
            filenames.Add(strFilename);

            File.Delete(strFilename);

            StreamUtil.WriteText(strFilename,
    "<html>" +
    GetHeadString(false) +
    "<body>");

            Stop stop = new DigitalPlatform.Stop();
            stop.Register(MainForm.stopManager, true);	// 和容器关联

            stop.OnStop += new StopEventHandler(this.DoStopPrint);
            stop.Initial("正在创建打印页面 ...");
            stop.BeginLoop();

            m_webExternalHost = new WebExternalHost();
            m_webExternalHost.Initial(this.MainForm, null);
            m_webExternalHost.IsInLoop = true;

            this.GetSummary += new GetSummaryEventHandler(OperLogForm_GetSummary);
            try
            {
                stop.SetProgressRange(0, this.listView_records.SelectedItems.Count);
                int i = 0;
                foreach (ListViewItem item in this.listView_records.SelectedItems)
                {
                    Application.DoEvents();

                    if (stop != null && stop.State != 0)
                    {
                        strError = "用户中断";
                        goto ERROR1;
                    }

                    OperLogItemInfo info = (OperLogItemInfo)item.Tag;

                    string strLogFileName = ListViewUtil.GetItemText(item, COLUMN_FILENAME);
                    string strIndex = ListViewUtil.GetItemText(item, COLUMN_INDEX);

                    string strXml = "";
                    // 从服务器获得
                    // return:
                    //      -1  出错
                    //      0   正常
                    //      1   用户中断
                    int nRet = GetXml(item,
            out strXml,
            out strError);
                    if (nRet == 1)
                        return;
                    if (nRet == -1)

                        goto ERROR1;

                    Global.SetXmlString(this.webBrowser_xml,
    strXml,
    this.MainForm.DataDir,
    "operlogexml");

                    string strHtml = "";
                    // 创建解释日志记录内容的 HTML 字符串
                    // return:
                    //      -1  出错
                    //      0   成功
                    //      1   未知的操作类型
                    nRet = GetHtmlString(strXml,
                        false,
                        out strHtml,
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;
                    if (nRet == 1)
                        strHtml = strError;

                    StreamUtil.WriteText(strFilename,
        "<p class='record_title'>" + strLogFileName + " : " + strIndex + "</p>" + strHtml);

                    stop.SetProgressValue(i + 1);
                    i++;
                }
            }
            finally
            {
                this.GetSummary -= new GetSummaryEventHandler(OperLogForm_GetSummary);
                if (m_webExternalHost != null)
                {
                    m_webExternalHost.IsInLoop = false;
                    m_webExternalHost.Destroy();
                    m_webExternalHost = null;
                }

                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStopPrint);
                stop.Initial("打印页面创建完成");
                stop.HideProgress();

                if (stop != null) // 脱离关联
                {
                    stop.Unregister();	// 和容器关联
                    stop = null;
                }
            }

            StreamUtil.WriteText(strFilename,
"</body></html>");

            // TODO: 浏览器控件连接javascript host
            HtmlPrintForm printform = new HtmlPrintForm();

            printform.Text = "打印解释内容";
            printform.MainForm = this.MainForm;
            printform.Filenames = filenames;

            this.MainForm.AppInfo.LinkFormState(printform, "operlogform_printform_state");
            printform.ShowDialog(this);
            this.MainForm.AppInfo.UnlinkFormState(printform);

            return;
        ERROR1:
            MessageBox.Show(this, strError);
        }
Пример #4
0
        int ProcessSelectedRecords(Delegate_processLog func,
            out string strError)
        {
            strError = "";

            if (this.listView_records.SelectedItems.Count == 0)
            {
                strError = "尚未选定要处理的行";
                return -1;
            }

            Stop stop = new DigitalPlatform.Stop();
            stop.Register(MainForm.stopManager, true);	// 和容器关联

            stop.OnStop += new StopEventHandler(this.DoStopPrint);
            stop.Initial("正在处理日志记录 ...");
            stop.BeginLoop();

            try
            {
                stop.SetProgressRange(0, this.listView_records.SelectedItems.Count);
                int i = 0;
                foreach (ListViewItem item in this.listView_records.SelectedItems)
                {
                    Application.DoEvents();

                    if (stop != null && stop.State != 0)
                    {
                        strError = "用户中断";
                        return -1;
                    }

                    OperLogItemInfo info = (OperLogItemInfo)item.Tag;

                    string strLogFileName = ListViewUtil.GetItemText(item, COLUMN_FILENAME);
                    string strIndex = ListViewUtil.GetItemText(item, COLUMN_INDEX);

                    string strXml = "";
                    // 从服务器获得
                    // return:
                    //      -1  出错
                    //      0   正常
                    //      1   用户中断
                    int nRet = GetXml(item,
            out strXml,
            out strError);
                    if (nRet == 1)
                        return -1;
                    if (nRet == -1)
                        return -1;

                    XmlDocument dom = new XmlDocument();
                    try
                    {
                        dom.LoadXml(strXml);
                    }
                    catch (Exception ex)
                    {
                        strError = "装载日志记录 '" + strLogFileName + ":" + strIndex + "' XML 到 DOM 时发生错误: " + ex.Message;
                        return -1;
                    }

                    if (func != null)
                    {
                        if (func(strLogFileName,
                            Convert.ToInt32(strIndex),
                dom,
                null) == false)
                            break;
                    }

                    stop.SetProgressValue(i + 1);
                    i++;
                }

                return 0;
            }
            finally
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStopPrint);
                stop.Initial("处理完成");
                stop.HideProgress();

                if (stop != null) // 脱离关联
                {
                    stop.Unregister();	// 和容器关联
                    stop = null;
                }
            }
        }
Пример #5
0
        // parameters:
        //      strFileType barcode/recpath
        // return:
        //      -1  出错
        //      0   放弃
        //      >=1 处理的条数
        int ProcessFile(
            string strFileType,
            out string strError)
        {
            strError = "";

            string strFilename = "";

            if (strFileType == "barcode")
            {
                if (string.IsNullOrEmpty(this.textBox_barcodeFile.Text) == true)
                {
                    OpenFileDialog dlg = new OpenFileDialog();

                    dlg.FileName         = this.textBox_barcodeFile.Text;
                    dlg.Title            = "请指定要打开的条码号文件名";
                    dlg.Filter           = "条码号文件 (*.txt)|*.txt|All files (*.*)|*.*";
                    dlg.RestoreDirectory = true;

                    if (dlg.ShowDialog() != DialogResult.OK)
                    {
                        return(0);
                    }

                    this.textBox_barcodeFile.Text = dlg.FileName;
                }

                strFilename = this.textBox_barcodeFile.Text;
            }
            else if (strFileType == "recpath")
            {
                if (string.IsNullOrEmpty(this.textBox_recPathFile.Text) == true)
                {
                    OpenFileDialog dlg = new OpenFileDialog();

                    dlg.FileName         = this.textBox_recPathFile.Text;
                    dlg.Title            = "请指定要打开的记录路径文件名";
                    dlg.Filter           = "记录路径文件 (*.txt)|*.txt|All files (*.*)|*.*";
                    dlg.RestoreDirectory = true;

                    if (dlg.ShowDialog() != DialogResult.OK)
                    {
                        return(0);
                    }

                    this.textBox_recPathFile.Text = dlg.FileName;
                }

                strFilename = this.textBox_recPathFile.Text;
            }
            else
            {
                strError = "未知的 strFileType '" + strFilename + "'";
                return(-1);
            }

            // 探测文本文件的行数
            // parameters:
            //      bIncludeBlankLine   是包括空行
            // return:
            //      -1  出错
            //      >=0 行数
            long lLineCount = GetTextLineCount(strFilename,
                                               false);

            if (lLineCount != -1)
            {
                stop.SetProgressRange(0, lLineCount);
            }

            int          nCurrentLine = 0;
            StreamReader sr           = null;

            try
            {
                this.textBox_outputBarcodes.Text = "";

                // 打开文件

                sr = new StreamReader(strFilename);

                EnableControls(false);

                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在初始化浏览器组件 ...");
                stop.BeginLoop();
                this.Update();
                this.MainForm.Update();

                try
                {
                    int nRet = 0;

                    // 逐行读入文件内容
                    for (; ;)
                    {
                        Application.DoEvents();
                        if (stop != null)
                        {
                            if (stop.State != 0)
                            {
                                strError = "用户中断1";
                                return(-1);
                            }
                        }


                        string strLine = "";
                        strLine = sr.ReadLine();
                        if (strLine == null)
                        {
                            break;
                        }

                        strLine = strLine.Trim();
                        if (String.IsNullOrEmpty(strLine) == true)
                        {
                            continue;
                        }

                        if (strFileType == "barcode")
                        {
                            stop.SetMessage("正在处理册条码号 " + strLine + " 对应的记录...");
                        }
                        else
                        {
                            stop.SetMessage("正在处理记录路径 " + strLine + " 对应的记录...");
                        }
                        stop.SetProgressValue(nCurrentLine);

                        nCurrentLine++;

                        // 先保存前一条
                        if (this.entityEditControl1.Changed == true)
                        {
                            nRet = DoSave(false,
                                          out strError);
                            if (nRet == -1)
                            {
                                MessageBox.Show(this, strError);
                            }
                        }
                        // DOLOAD:

                        nRet = LoadRecord(false,
                                          strFileType == "barcode" ? strLine : "@path:" + strLine,
                                          out strError);
                        if (nRet != 1)
                        {
                            this.textBox_outputBarcodes.Text += "# " + strLine + " " + strError + "\r\n";
                            continue;
                        }

                        // 自动修改
                        // return:
                        //      0   没有实质性改变
                        //      1   有实质性改变
                        AutoChangeData();

                        if (this.entityEditControl1.Changed == true)
                        {
                            nRet = DoSave(false,
                                          out strError);
                            if (nRet == -1)
                            {
                                this.textBox_outputBarcodes.Text += "# " + strLine + " " + strError + "\r\n";
                                continue;
                            }

                            if (nRet != -1)
                            {
                                this.textBox_outputBarcodes.Text += strLine + "\r\n";
                            }
                        }
                        else
                        {
                            this.textBox_outputBarcodes.Text += "# " + strLine + "\r\n";
                        }
                    }
                }
                finally
                {
                    stop.EndLoop();
                    stop.OnStop -= new StopEventHandler(this.DoStop);
                    stop.Initial("");
                    stop.HideProgress();

                    EnableControls(true);
                }

                return(nCurrentLine);
            }
            catch (Exception ex)
            {
                strError = "QuickChangeEntityForm ProcessFile() exception: " + ExceptionUtil.GetAutoText(ex);
                return(-1);
            }
            finally
            {
                if (sr != null)
                {
                    sr.Close();
                }
            }
        }