Exemple #1
0
        public override int Insert(FormM form, DFDictionary entity, ref string message)
        {
            form.GetControlM("SQL").MustInput = string.Empty;
            CheckInput(form, entity);
            var path       = DFPub.RelativeToPhysical(entity["SqlFilePath"]);
            var configPath = DFPub.RelativeToPhysical(entity["ConfigFile"]);
            var dt         = ReadExcel(path);

            if (dt.Columns.Contains("Result"))
            {
                dt.Columns.Remove("Result");
            }
            dt.Columns.Add("Result", typeof(string));
            var tables = GetTableConfig(configPath);

            ProcessData(dt, tables, entity);

            var failed  = dt.AsEnumerable().Count(a => a.GetValue("Result").Length > 0);
            var success = dt.AsEnumerable().Count(a => a.GetValue("Result").Length == 0);

            ExcelReader.WriteDataTableToExcel(dt, path);
            if (failed > 0)
            {
                message = string.Format("成功导入 {0},导入失败 {1},请查看失败日志<br><a href='{2}'>{2}</a>", success, failed, DFPub.PhysicalToRelative(path));
                return(DFPub.EXECUTE_ERROR);
            }
            else
            {
                message = string.Format("成功导入 {0}", success);
                return(DFPub.EXECUTE_SUCCESS);
            }
        }
Exemple #2
0
        public override int Query(FormM form, DFDictionary entity, DataGridVM vm, int start, int limit, ref string message)
        {
            var path    = DFPub.RelativeToPhysical(entity["ConfigFile"]);
            var configs = GetTableConfig(path);

            var t    = configs.FirstOrDefault(a => a.TableName == entity["TableName"]);
            var list = new List <VM_ColumnMetadata>();

            if (t != null)
            {
                list = t.Columns;
            }
            vm.results = list.Count;
            vm.rows    = list;
            return(DFPub.EXECUTE_SUCCESS);
        }
Exemple #3
0
        private int btnSave(FormM form, DFDictionary entity, ref string message)
        {
            var path      = DFPub.RelativeToPhysical(entity["ConfigFile"]);
            var tables    = GetTableConfig(path);
            var tableName = entity["TableName"];
            var t         = tables.FirstOrDefault(a => a.TableName == tableName);

            t.ImportType = entity["ImportType"];
            t.Insert     = entity["Insert"];
            t.Update     = entity["Update"];
            t.CheckExist = entity["CheckExist"];
            var list = GetGridClientData <VM_ColumnMetadata>(entity);

            foreach (var item in list)
            {
                if (!string.IsNullOrWhiteSpace(item.ColumnCheck))
                {
                    var dict = JsonSerializeHelper.DeserializeObject <DFDictionary>(item.ColumnCheck);
                    item.CheckMustInput      = dict["CheckMustInput"];
                    item.CheckNumber         = dict["CheckNumber"];
                    item.CheckMaxLength      = dict["CheckMaxLength"];
                    item.CheckDate           = dict["CheckDate"];
                    item.CheckDateTime       = dict["CheckDateTime"];
                    item.CheckTime           = dict["CheckTime"];
                    item.DefaultValue        = dict["DefaultValue"];
                    item.GetValue            = dict["GetValue"];
                    item.ExecuteDataTable    = dict["ExecuteDataTable"];
                    item.ExecuteSql          = dict["ExecuteSql"];
                    item.DefaultSort         = dict["DefaultSort"];
                    item.ConnectionString    = dict["ConnectionString"];
                    item.IgnoreGetValueError = dict["IgnoreGetValueError"];
                    item.DatabaseType        = dict["DatabaseType"];
                }
            }
            t.Columns = list;
            var el = new XElement("tables", tables.Select(a => a.ToXml()));

            el.Save(path);
            return(DFPub.EXECUTE_SUCCESS);
        }
        public override int Update(FormM form, DFDictionary entity, ref string message)
        {
            var Upload = entity["Upload"];

            if (string.IsNullOrWhiteSpace(Upload))
            {
                throw new WFException("请上传文件");
            }
            var path = DFPub.RelativeToPhysical(Upload);

            if (!File.Exists(path))
            {
                throw new WFException(string.Format("文件 {0} 不存在", path));
            }
            WFDA.Instance.ModelSaveToDB(path);

            var sb = new System.Text.StringBuilder(DFPub.DF_SCRIPT);

            sb.AppendFormat("alert('上传成功');");
            message = sb.ToString();
            return(DFPub.EXECUTE_SUCCESS);
        }
Exemple #5
0
        public override void SetAccess(FormM form, DFDictionary entity)
        {
            var path    = DFPub.RelativeToPhysical(entity["ConfigFile"]);
            var configs = GetTableConfig(path);

            SetSelectDataSource(form, "TableName", configs.Select(a => new DFSelectItem(a.TableName, a.TableName)).ToList());

            if (string.IsNullOrWhiteSpace(entity["TableName"]))
            {
                entity.Add("TableName", configs.FirstOrDefault().TableName);
            }

            if (!IsPostBack() || GetPostbackControl(entity) == "TableName")
            {
                var t = configs.FirstOrDefault(a => a.TableName == entity["TableName"]);
                if (t != null)
                {
                    this.Model.Add("ImportType", t.ImportType);
                    this.Model.Add("Insert", t.Insert);
                    this.Model.Add("Update", t.Update);
                    this.Model.Add("CheckExist", t.CheckExist);
                }
            }
        }