Beispiel #1
0
        private NnReader()
        {
#if (DEBUG)
            string path = ConfigurationManager.ConnectionStrings["nnstock_d"].ConnectionString;// 库存路径
            string key  = ConfigurationManager.AppSettings["nnkey"];
#else
            string path = ConfigurationManager.ConnectionStrings["nnstock"].ConnectionString;// 库存路径
            string key  = ConfigurationManager.AppSettings["nnkey"];
#endif
            if (path == null || key == null)
            {
                NnMessage.ShowMessage("配置文件错误", true);
                return;
            }
            int index = 12;
            while (index < 21)
            {
                try
                {
                    mConnection = new OleDbConnection($"Provider=Microsoft.ACE.OLEDB.{index.ToString()}.0;Data Source={path};Persist Security Info=False;Jet OLEDB:Database Password={NnConnection.NnDecrypt(key)}");
                    mConnection.Open();
                    IsValid = true;
                    return;
                }
                catch (Exception e) { ++index; Console.WriteLine(e.ToString()); }
            }
            NnMessage.ShowMessage("数据库错误!", true);
        }
        /// <summary>
        /// 提交
        /// </summary>
        /// <param name="o"></param>
        private void _submit(object o)
        {
            string value = o as string;

            if (string.IsNullOrEmpty(value))
            {
                NnMessage.ShowMessage("上传数据为空!");
                return;
            }
            Dispatcher.Invoke(() => ((Application.Current.MainWindow) as MainWindow)?.StatusBarState(true, "正在上传..."));

            List <Order> list      = _getOrders(value);
            string       erririnfo = _upload(list);

            if (!string.IsNullOrWhiteSpace(erririnfo))
            {
                WarnWindow.ShowMessage(erririnfo);
            }

            Dispatcher.Invoke(() =>
            {
                ((Application.Current.MainWindow) as MainWindow)?.StatusBarState(false, "标签已上传.");
                NAction?.Invoke("init");
            });
        }
        // 搜索结束,善后工作
        private void _end()
        {
            SearchProgress.complete(isContinue);// 如果这个值为false,表示任务没有完成
            if (!isContinue)
            {
                return;
            }

            // 保存
            try
            {
                if (configuration.getBool("issave", false))
                {
                    excelReader.Save();
                }
            }
            catch { NnMessage.ShowMessage("无法保存 请确保文件可写", true); }
            foreach (NnSavePath path in NnConfig._nnConfig.SavePaths)
            {
                try
                {
                    excelReader.SaveAs(path.Path + Path.GetFileNameWithoutExtension(url));
                }
                catch { NnMessage.ShowMessage($"无法保存到 {path.Path}", true); }
            }

            configuration.set("scount", scount);
            configuration.set("stimes", stimes + 1);
            configuration.save();
        }
 private void init(string url)
 {
     this.url = url;// 注意,这里的url在传进来之前确保是excel文件,谁要作死传其他的我不管
     if (!NnReader.Instance.IsValid)
     {
         isContinue = false;
         return;
     }
     try
     {
         configuration = new NnConfiguration();
         // 初始化excel对应列
         initColumn();
     }
     catch (Exception e)
     {
         NnMessage.ShowMessage("配置文件读取错误!");
         isContinue = false;
         Console.WriteLine(e.ToString());
         return;
     }
     if (configuration != null)
     {
         stimes = configuration.getInt("stimes", 0) ?? 0;
         scount = configuration.getInt("scount", 0) ?? 0;
     }
     try
     {
         excelReader        = new NnExcelReader(url);
         excelReader.ToOpen = configuration.getBool("toopen", false);
     }
     catch (Exception e)
     {
         NnMessage.ShowMessage("无excel组件或文件错误!");
         isContinue = false;
         Console.WriteLine(e.ToString());
         return;
     }
 }