Beispiel #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);
                }
            }
        }
Beispiel #2
0
        private void Save()
        {
            ControlUtils.ShowLoading(this.loading, "保存中……");
            bool isAutoSearch = cbNeedAutoSearchDel.IsChecked == true;

            lock (sync)
            {
                if (!IsUpdating)
                {
                    IsUpdating = true;

                    var delieryConfig = GetPageConfig(ImportDataType.交割单);
                    var softConfig    = GetPageConfig(ImportDataType.软件委托);

                    if (SelectedTable != null)
                    {
                        SaveOneTable(SelectedTable, delieryConfig, softConfig);
                    }
                    else if (MatchConfigData.Count > 0)
                    {
                        List <string> groupNames = new List <string>();
                        foreach (string item in listBoxMatched.Items)
                        {
                            var groupName = item.GetFileName().GetGroupName();
                            if (item.GetImportType() == ImportDataType.软件委托 && !string.IsNullOrEmpty(groupName) && !groupNames.Contains(groupName))
                            {
                                groupNames.Add(groupName.ToUpper());
                            }
                        }

                        listBoxMatched.ItemsSource    = null;
                        listBoxNotMatched.ItemsSource = NotMatchConfigData.Select(_ => _.TableName.GetFileName());
                        MatchConfigData.Clear();

                        var saving = new Action(() => { SaveMatchedTables(delieryConfig, softConfig); });

                        var completeUIAction = new Action(() => {
                            ControlUtils.HideLoading(this.loading);
                            if (OnDBChangeComplete != null)
                            {
                                OnDBChangeComplete.Invoke();
                            }

                            if (cbNeedAutoSearchDel.IsChecked == true)
                            {
                                AutoSaveDelivery(groupNames, this.dpDate.SelectedDate.Value);
                            }
                        });

                        CommonUtils.RunAsync(this.Dispatcher, saving, null, null, completeUIAction);
                    }
                    IsUpdating = false;
                }
            }
        }
Beispiel #3
0
 private void listBoxNotMatched_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (e.AddedItems.Count > 0)
     {
         var tableName = e.AddedItems[0] as string;
         if (!string.IsNullOrEmpty(tableName))
         {
             var dt = NotMatchConfigData.First(_ => _.TableName.EndsWith(tableName));
             InitPageByFileName(dt.TableName);
             SetPageData(dt);
             SelectedTable = dt;
         }
     }
 }
Beispiel #4
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("保存失败,详情请检查日志!"); }));
            }
        }
Beispiel #5
0
        private void SaveOneTable(DataTable dt, Dictionary <string, string> deliConfig, Dictionary <string, string> softConfig)
        {
            string msg;
            bool   isSuccess = true;
            bool   isDeli    = cboDataType.SelectedIndex == 0;

            Task.Run(() => {
                using (DataComparisionDataset db = new DataComparisionDataset())
                {
                    if (isDeli)
                    {
                        isSuccess = SaveAsDeliveryData(dt, db, deliConfig, true, out msg);
                    }
                    else
                    {
                        isSuccess = SaveAsSoftwareData(dt, db, softConfig, true, out msg);
                    }
                }

                this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
                {
                    MessageBox.Show(isSuccess ? "保存完毕!" : msg);
                    if (isSuccess && !isDeli)
                    {
                        if (OnImportComplete != null)
                        {
                            //批量的软件委托,或者单独一个。
                            var listGroupName = new List <string>();
                            foreach (DataRow row in dt.Rows)
                            {
                                var groupName = row["组合号"].ToString();
                                if (!string.IsNullOrEmpty(groupName) && !listGroupName.Contains(groupName))
                                {
                                    listGroupName.Add(groupName.ToUpper());
                                }
                            }
                            OnImportComplete.Invoke(listGroupName, this.dpDate.SelectedDate.Value);
                        }

                        List <string> groupNames = new List <string>();
                        foreach (DataRow row in dt.Rows)
                        {
                            var group = (row["组合号"] + "").ToUpper();
                            if (!groupNames.Contains(group))
                            {
                                groupNames.Add(group);
                            }
                        }
                        if (cbNeedAutoSearchDel.IsChecked == true)
                        {
                            AutoSaveDelivery(groupNames, this.dpDate.SelectedDate.Value);
                        }
                    }
                    if (NotMatchConfigData.Contains(dt))
                    {
                        NotMatchConfigData.Remove(dt);
                        listBoxNotMatched.ItemsSource = NotMatchConfigData.Select(_ => _.TableName.GetFileName());
                    }

                    SelectedTable = null;
                    ControlUtils.HideLoading(this.loading);
                    dgImportData.ItemsSource = null;

                    if (OnDBChangeComplete != null)
                    {
                        OnDBChangeComplete.Invoke();
                    }
                }));
            });
        }
Beispiel #6
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);
        }