/// <summary>
        /// 显示数据导入对话框。
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="clientRule"></param>
        /// <param name="bindingSource"></param>
        public void ShowDataImportDialog(MB.WinBase.IFace.IViewGridForm viewGridForm,
                                         MB.WinBase.Binding.BindingSourceEx bindingSource)
        {
            _ViewGridForm  = viewGridForm;
            _ClientRule    = viewGridForm.ClientRuleObject as MB.WinBase.IFace.IClientRule;
            _BindingSource = bindingSource;

            IDocDataImportProvider importProvider = _ClientRule as IDocDataImportProvider;

            if (importProvider == null)
            {
                MB.Util.TraceEx.Write(string.Format("业务类 {0} 还没有实现相应的数据导入接口 {1}",
                                                    _ClientRule.GetType().FullName, "IDocDataImportProvider"), MB.Util.APPMessageType.SysErrInfo);
                throw new MB.Util.APPException("当前模块尚未提供数据导入的功能", APPMessageType.DisplayToUser);
            }
            var importInfo = DefaultDataImportDialog.ShowDataImport(_ViewGridForm as Form, _ClientRule, _ClientRule.ClientLayoutAttribute.UIXmlConfigFile, true);

            if (importInfo == null)
            {
                return;
            }

            IList hasImportEntity;
            bool  b = importProvider.DataImport(_ViewGridForm, importInfo, out hasImportEntity);

            if (!b)
            {
                return;
            }

            DialogResult re = MB.WinBase.MessageBoxEx.Question("数据导入成功,是否需要从数据库中重新刷新数据?");

            if (re == DialogResult.Yes)
            {
                _ViewGridForm.Refresh();
            }
            else
            {
                if (hasImportEntity == null && hasImportEntity.Count == 0)
                {
                    return;
                }

                foreach (object entity in hasImportEntity)
                {
                    _BindingSource.Add(entity);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        ///  显示数据导入处理窗口。
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="buiObj"></param>
        /// <param name="xmlFileName"></param>
        /// <param name="importImmediate">判断是否为直接导入</param>
        /// <returns></returns>
        public static DataImportInfo ShowDataImport(IWin32Window parent, MB.WinBase.IFace.IClientRule buiObj, string xmlFileName, bool importImmediate, Func <DataSet, DataSet> businessCheckAfterLoadImportData)
        {
            string file = MB.WinBase.ShareLib.Instance.SelectedFile("Excel 文件 (*.xls)|*.xls|文本文件(*.txt)|*.txt");

            if (string.IsNullOrEmpty(file))
            {
                return(null);
            }
            if (!file.EndsWith(".xls") && !file.EndsWith(".txt"))
            {
                throw new MB.Util.APPException(string.Format("文件 {0} 对应的文件类型暂不支持!", file), MB.Util.APPMessageType.DisplayToUser);
            }

            try {
                DefaultDataImportDialog dialog = new DefaultDataImportDialog(importImmediate);
                DataSet dsData = dialog.LoadImportData(parent, buiObj, xmlFileName, file);

                //新增插入业务检查,检查的方法从外部嵌入
                if (businessCheckAfterLoadImportData != null)
                {
                    dsData = dialog.BusinessValidate(businessCheckAfterLoadImportData, dsData);
                }
                bool exists = dsData != null && dsData.Tables.Count > 0 && dsData.Tables[0].Rows.Count > 0;
                if (exists)
                {
                    DialogResult importSure = dialog.ShowDialog();
                    if (importSure == DialogResult.OK)
                    {
                        return(dialog.CurrentImportInfo);
                    }
                }
                else
                {
                    DialogResult re = MB.WinBase.MessageBoxEx.Question("没有匹配到任何需要导入的数据,是否需要重新选择");
                    if (re == DialogResult.Yes)
                    {
                        return(ShowDataImport(parent, buiObj, xmlFileName, importImmediate));
                    }
                }
                return(null);
            }
            catch (Exception ex) {
                throw new MB.Util.APPException(string.Format("加载需要导入的文件{0} 有误!", file), MB.Util.APPMessageType.DisplayToUser, ex);
            }
        }