UsrWorkMode.cs 7.3 KB
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Asa.FaceControl;
using BLL;
using ClosedXML.Excel;
using Model;
using SmartScan.SetControl.WPF.Model;
using static SmartScan.SetControl.WPF.Model.NeoAlertBox;

namespace SmartScan
{
    public partial class UsrWorkMode : UserControl, ISetMenu
    {
        public UsrWorkMode()
        {
            InitializeComponent();

            //打印机
            LstPrinter.Items.AddRange(Printer.AllName);
            LstPrinter.Text = BLLCommon.config.PrinterName;
            if (BLLCommon.config.PrintLandscape)
                RdoLandscape.Checked = true;
            else
                RdoVertical.Checked = true;

            //图像保存
            ((FaceRadioBox)facePanel1.Controls["Rdo" + BLLCommon.config.HistoryImage.ToString()]).Checked = true;

            //6个复选框
            ChkSelectPN.Checked = BLLCommon.config.SelectHttpPN;
            ChkLabelEmptyCheck.Checked = BLLCommon.config.LabelEmptyCheck;
            ChkOpenEnterWork.Checked = BLLCommon.config.OpenStartWork;
            ChkPrintCompletedClear.Checked = BLLCommon.config.PrintCompletedClear;
            ChkOpenMaximize.Checked = BLLCommon.config.OpenMaximize;
            ChkTriggerOpenLight.Checked = BLLCommon.config.TriggerOpenLight;
            ChkPromptAfterPrinting.Checked = BLLCommon.config.PromptAfterPrinting;
            ChkAutoPrint.Checked = BLLCommon.config.AutoPrint;
            ChkAllowModifyPrint.Checked = Config.AllowModifyPrintInfo;
            ChkCheckFunction.Checked = BLLCommon.config.CheckFunction; ;
            //默认标签
            LstLabel.Items.AddRange(BLLCommon.labelEdit.Name);
            LstLabel.Text = BLLCommon.config.DefaultPrintLabel;

            //优先模板
            LstMate.Items.AddRange(BLLCommon.mateEdit.Name);
            LstMate.Text = BLLCommon.config.DefaultMaterialName;

            Language.SetLanguage(this);
        }

        public FacePanel GetPanel()
        {
            return facePanel1;
        }

        public void Save()
        {
            //保存打印机
            BLLCommon.config.PrintLandscape = RdoLandscape.Checked;
            if (LstPrinter.SelectedIndex == -1)
            {
                if (LstPrinter.Items.Count == 1)
                    BLLCommon.config.PrinterName = LstPrinter.Items[0];
            }
            else
            {
                BLLCommon.config.PrinterName = LstPrinter.Text;
            }
        
            //追溯图像保存
            if (RdoOriginal.Checked)
                BLLCommon.config.HistoryImage = HistoryImage.Original;
            else if (RdoCondense.Checked)
                BLLCommon.config.HistoryImage = HistoryImage.Condense;
            else if (RdoNoImage.Checked)
                BLLCommon.config.HistoryImage = HistoryImage.NoImage;

            //默认打印标签
            if (LstLabel.SelectedIndex == -1)
            {
                if (LstLabel.Items.Count == 1)
                    BLLCommon.config.DefaultPrintLabel = LstLabel.Items[0];
            }
            else
            {
                BLLCommon.config.DefaultPrintLabel = LstLabel.Text;
            }

            //优先匹配模板
            if (LstMate.SelectedIndex == -1)
            {
                if (LstMate.Items.Count == 1)
                    BLLCommon.config.DefaultMaterialName = LstMate.Items[0];
            }
            else
            {
                BLLCommon.config.DefaultMaterialName = LstMate.Text;
            }

            //6个复选框
            BLLCommon.config.SelectHttpPN = ChkSelectPN.Checked;
            BLLCommon.config.LabelEmptyCheck = ChkLabelEmptyCheck.Checked;
            BLLCommon.config.OpenStartWork = ChkOpenEnterWork.Checked;
            BLLCommon.config.OpenMaximize = ChkOpenMaximize.Checked;
            BLLCommon.config.PrintCompletedClear = ChkPrintCompletedClear.Checked;
            BLLCommon.config.TriggerOpenLight = ChkTriggerOpenLight.Checked;
            BLLCommon.config.PromptAfterPrinting = ChkPromptAfterPrinting.Checked;
            BLLCommon.config.AutoPrint = ChkAutoPrint.Checked;
            BLLCommon.config.CheckFunction = ChkCheckFunction.Checked;

            BLLCommon.config.Save();
        }

        int i = 0;
        private void but_Readfileprint_Click(object sender, EventArgs e)
        {
            Dictionary<int, Dictionary<string, string>> valuePairs = new Dictionary<int, Dictionary<string, string>>();
            i++;
            if (i==10)
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Multiselect =false;
                openFileDialog.Title = "请选择文件";
                openFileDialog.Filter = "所有文件(*.*)|*.*";
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    string file=openFileDialog.FileName;
                    ContinuousPrinting(file);
                }
                i = 0;
            }
        }

        public delegate void PrintDelegate(Dictionary<string, string> content);
        public static event PrintDelegate Printing;
        public void ContinuousPrinting(string filepath)
        {
            Dictionary<int, Dictionary<string, string>> valuePairs = new Dictionary<int, Dictionary<string, string>>();
            if (!File.Exists(filepath))
            {
                string YU = BLLCommon.config.Language;
               
                if (YU == "English")
                {
                    bool result = NeoAlertBox.Show( "", "File not found", AlertType.Warning, "NEO SCAN", true);
                }
                else if (YU=="日语")
                {
                    bool result = NeoAlertBox.Show("", "ファイルが存在しません", AlertType.Warning, "NEO SCAN", true);
                }
                else
                {
                    bool result = NeoAlertBox.Show( "", "文件不存在", AlertType.Warning, "NEO SCAN", true);
                }
                return;
            }
            var Titles = ExtraFileData.ParseXLSFileTitle(filepath);
            try
            {
                XLWorkbook wb = new XLWorkbook(filepath);
                IXLWorksheet ws = wb.Worksheet(1);
                int emptyrow = 0;
                int currow = 1;
                while (emptyrow < 3)
                {
                    var rowdata = new Dictionary<string, string>();
                    for (int i = 0; i < Titles.Count; i++)
                    {
                        var v = ws.Row(currow + 1).Cell(i + 1).Value.ToString().Trim();
                        rowdata.Add(Titles[i], v);                        
                    }
                    currow++;
                    if (!valuePairs.ContainsKey(currow))
                    {
                        valuePairs.Add(currow, rowdata);
                    }

                    if (rowdata.Values.Contains(""))
                    {
                        emptyrow++;
                    }                                      
                }
            }
            catch (Exception ex)
            {
                LogNet.log.Info("数据源加载文件出错:" + ex.ToString());
            }

            foreach (var item in valuePairs)
            {
                Printing?.Invoke(item.Value);
            }
        }
    }
}