Exemple #1
0
        private void SetTableToList(DataTable dt, string configName, ImportDataType dataType)
        {
            var arr    = (dataType == ImportDataType.交割单) ? deliPropertyNames : softPropertyNames;
            var config = CommonUtils.GetConfig(configName);

            if (string.IsNullOrEmpty(config))
            {
                NotMatchConfigData.Add(dt);
            }
            else
            {
                bool isFitConfig = true;

                var dict = config.FromJson <Dictionary <string, string> >();
                foreach (var item in arr)
                {
                    isFitConfig = isFitConfig && (!dict.ContainsKey(item) || dt.Columns.Contains(dict[item]));
                }

                if (isFitConfig)
                {
                    MatchConfigData.Add(dt);
                }
                else
                {
                    NotMatchConfigData.Add(dt);
                }
            }
        }
Exemple #2
0
        private void SaveMatchedTables(Dictionary <string, string> deliPageConfig, Dictionary <string, string> softPageConfig)
        {
            StringBuilder sb = new StringBuilder(64);

            try
            {
                int successCount = 0;
                using (var db = new DataComparisionDataset())
                {
                    //foreach (DataTable dt in MatchConfigData)
                    //{
                    //    bool isSuccess = false;
                    //    string msg;
                    //    var saveAsDeli = dt.TableName.GetImportType();
                    //    if (saveAsDeli == ImportDataType.软件委托)
                    //        isSuccess = SaveAsSoftwareData(dt, db, softPageConfig, false, out msg);
                    //    else if (saveAsDeli == ImportDataType.交割单)
                    //        isSuccess = SaveAsDeliveryData(dt, db, deliPageConfig, false, out msg);
                    //    else
                    //        msg = "未能从文件名中识别出导入数据类型,将跳过此文件:" + dt.TableName;

                    //    if (isSuccess)
                    //        successCount++;
                    //    else
                    //    {
                    //        if (!string.IsNullOrEmpty(msg)) sb.AppendLine(msg);
                    //        NotMatchConfigData.Add(dt);
                    //    }
                    //}
                    for (int i = 0; i < MatchConfigData.Count; i++)
                    {
                        DataTable dt = MatchConfigData[i];
                        this.Dispatcher.RunAsync(() => { this.loading.ShowLoading(string.Format("正在存储第{0}个文件,总计{1}个文件\r\n当前文件名:{2}", i, MatchConfigData.Count, dt.TableName.GetFileName())); });

                        bool   isSuccess = false;
                        string msg;
                        var    saveAsDeli = dt.TableName.GetImportType();
                        if (saveAsDeli == ImportDataType.软件委托)
                        {
                            isSuccess = SaveAsSoftwareData(dt, db, softPageConfig, false, out msg);
                        }
                        else if (saveAsDeli == ImportDataType.交割单)
                        {
                            isSuccess = SaveAsDeliveryData(dt, db, deliPageConfig, false, out msg);
                        }
                        else
                        {
                            msg = "未能从文件名中识别出导入数据类型,将跳过此文件:" + dt.TableName;
                        }

                        if (isSuccess)
                        {
                            successCount++;
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(msg))
                            {
                                sb.AppendLine(msg);
                            }
                            NotMatchConfigData.Add(dt);
                        }
                    }
                    CommonUtils.Log("保存记录:" + sb.ToString());
                }

                var message = string.Format("批量保存{0}个文件,成功{1}个,失败{2}个。", MatchConfigData.Count, successCount, MatchConfigData.Count - successCount);
                if (successCount < MatchConfigData.Count)
                {
                    message += "失败文件将转入单独保存列表,详细信息请查看日志中的保存记录。";
                }

                this.Dispatcher.ShowMsg(message);
            }
            catch (Exception ex)
            {
                CommonUtils.Log("存入数据库时出现异常!", ex);
                this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { CommonUtils.ShowMsg("保存失败,详情请检查日志!"); }));
            }
        }
Exemple #3
0
        private void ImportFiles(string[] names)
        {
            var action = new Action(() =>
            {
                StringBuilder sb = new StringBuilder(32);
                int failCount    = 0;
                for (int i = 0; i < names.Length; i++)
                {
                    try
                    {
                        string errMsg;
                        DataTable dt = null;
                        if (ReadToDataTable(names[i], out dt, out errMsg))
                        {
                            var fileName = names[i].GetFileName();
                            if (fileName.GetImportType() == ImportDataType.交割单 && string.IsNullOrEmpty(fileName.GetGroupName()))
                            {
                                NotMatchConfigData.Add(dt);
                            }
                            else
                            {
                                var date = fileName.GetDate();
                                if (date == DateTime.MinValue)
                                {
                                    NotMatchConfigData.Add(dt);
                                }
                                else
                                {
                                    var type = names[i].GetImportType();
                                    SetTableToList(dt, names[i].GetFileName().GetGroupName() + Enum.GetName(type.GetType(), type), type);
                                }
                            }
                        }
                        else
                        {
                            sb.AppendLine(errMsg);
                        }
                    }
                    catch (Exception ex)
                    {
                        sb.AppendLine(string.Format("读取文件{0}异常,错误信息:{1}", names[i], ex.Message));
                        failCount++;
                    }
                }
                CommonUtils.Log(sb.ToString());
                Dispatcher.ShowMsg(string.Format("读取文件共{0}个,失败{1}个,成功{2}个,错误信息请查看日志文件。", names.Length, failCount, names.Length - failCount, sb.ToString()));
            });

            var completeUIAction = new Action(() =>
            {
                this.listBoxMatched.ItemsSource    = this.MatchConfigData.Select(_ => _.TableName.GetFileName());
                this.listBoxNotMatched.ItemsSource = this.NotMatchConfigData.Select(_ => _.TableName.GetFileName());

                btnSave.IsEnabled      = listBoxMatched.Items.Count > 0;
                tabFiles.SelectedIndex = listBoxMatched.Items.Count == 0 ? 1 : 0;
                this.loading.HideLoading();
            });


            Dispatcher.RunAsync(action, null, null, completeUIAction);
        }