コード例 #1
0
        public ActionResult DeleteMapping(XMLSettingVM vm)
        {
            #region 從暫存 Session XMLMappings 刪除
            List <tblXMLMapping> xmlMappings = new List <tblXMLMapping>();;
            string ColumnName = string.Empty;

            try
            {
                xmlMappings = JsonConvert.DeserializeObject <List <tblXMLMapping> >(Cache.GetCache("XMLMappings"));
            }
            catch { }
            tblXMLMapping mapping = xmlMappings.Find(x => x.TagName.Equals(vm.TagName, StringComparison.OrdinalIgnoreCase));
            if (mapping != null)
            {
                ColumnName = mapping.FieldName;
                xmlMappings.Remove(mapping);
            }

            Cache.SetLimitedCache("XMLMappings", xmlMappings);

            // Father Tag Option
            var fatherTag = new StringBuilder();
            fatherTag.AppendFormat("<option value='{0}'>{1}</option>", "", "-Please Select-");
            foreach (var m in xmlMappings)
            {
                fatherTag.AppendFormat("<option value='{0}'>{1}</option>", m.TagName, m.TagName);
            }
            #endregion

            #region 從暫存 Session setedColumns 刪除
            List <tblSQLColumns> setedColumns = new List <tblSQLColumns>();;
            try
            {
                setedColumns = JsonConvert.DeserializeObject <List <tblSQLColumns> >(Cache.GetCache("setedColumns"));
            }
            catch { }
            tblSQLColumns column = setedColumns.Find(x => x.ColumnName.Equals(ColumnName, StringComparison.OrdinalIgnoreCase));
            if (column != null)
            {
                setedColumns.Remove(column);
            }

            Cache.SetLimitedCache("setedColumns", setedColumns);
            #endregion

            var options = new StringBuilder();
            options.AppendFormat("<option value='{0}'>{1}</option>", "", "-Please Select-");
            using (tblSQLColumnsRepository rep = new tblSQLColumnsRepository())
            {
                List <tblSQLColumns>        allColumns   = rep.getAllColumns(vm.SQLName).ToList();
                IEnumerable <tblSQLColumns> unsetColumns = allColumns.Except(setedColumns, new ColumnComparer());
                foreach (var c in unsetColumns)
                {
                    options.AppendFormat("<option value='{0}'>{1}</option>", c.ColumnName, c.ColumnName);
                }
            }

            var jsonData = new
            {
                Options          = options.ToString(),
                FatherTagOptions = fatherTag.ToString()
            };
            return(Json(jsonData));
        }
コード例 #2
0
        public ActionResult InsertMapping(XMLSettingVM vm)
        {
            List <tblXMLMapping> xmlMappings = new List <tblXMLMapping>();
            string ColumnName = string.Empty;
            int    idx        = -1;

            #region 寫入暫存 Session XMLMappings
            try
            {
                xmlMappings = JsonConvert.DeserializeObject <List <tblXMLMapping> >(Cache.GetCache("XMLMappings"));
            }
            catch { }

            // 判斷 Tag Name 是否有重複
            if (string.IsNullOrEmpty(vm.TagName) || !vm.TagName.Equals(vm.newTagName, StringComparison.OrdinalIgnoreCase))
            {
                tblXMLMapping map = xmlMappings.Find(x => x.TagName.Equals(vm.newTagName, StringComparison.OrdinalIgnoreCase) &&
                                                     x.FatherTag.Equals(vm.FatherTag, StringComparison.OrdinalIgnoreCase));
                if (map != null)
                {
                    var result = new
                    {
                        status = "Tag Name 已存在!",
                    };
                    return(Json(result));
                }
            }
            // 更新時 將舊暫存資料刪除
            tblXMLMapping mapping = xmlMappings.Find(x => x.TagName.Equals(vm.TagName, StringComparison.OrdinalIgnoreCase) &&
                                                     x.FatherTag.Equals(vm.FatherTag, StringComparison.OrdinalIgnoreCase));
            if (mapping != null)
            {
                ColumnName = mapping.FieldName;
                idx        = mapping.Idx;
                xmlMappings.Remove(mapping);
            }

            // 將新的設定值寫入
            mapping = new tblXMLMapping()
            {
                TagName      = vm.newTagName,
                FieldName    = vm.FieldName ?? string.Empty,
                DefaultValue = vm.DefaultValue,
                FatherTag    = vm.FatherTag ?? string.Empty,
                Idx          = (idx < 0) ? xmlMappings.Count + 1 : idx,
                CanRepeat    = vm.CanRepeat
            };
            xmlMappings.Add(mapping);
            Cache.SetLimitedCache("XMLMappings", xmlMappings);

            // Father Tag Option
            var fatherTag = new StringBuilder();
            fatherTag.AppendFormat("<option value='{0}'>{1}</option>", "", "-Please Select-");
            foreach (var m in xmlMappings)
            {
                fatherTag.AppendFormat("<option value='{0}'>{1}</option>", m.TagName, m.TagName);
            }
            #endregion

            #region 寫入暫存 Session setedColumns
            List <tblSQLColumns> setedColumns = new List <tblSQLColumns>();;
            try
            {
                setedColumns = JsonConvert.DeserializeObject <List <tblSQLColumns> >(Cache.GetCache("setedColumns"));
            }
            catch { }

            // 更換指定欄位時
            if (!ColumnName.Equals(vm.FieldName))
            {
                // 更新時 將原指定的欄位刪除
                tblSQLColumns column = setedColumns.Find(x => x.ColumnName.Equals(ColumnName, StringComparison.OrdinalIgnoreCase));
                if (column != null)
                {
                    setedColumns.Remove(column);
                }

                // 記錄 新指定的欄位
                if (!string.IsNullOrEmpty(vm.FieldName))
                {
                    tblSQLColumns setedColumn = new tblSQLColumns()
                    {
                        SQLName    = vm.SQLName,
                        ColumnName = vm.FieldName
                    };
                    setedColumns.Add(setedColumn);
                }
            }

            Cache.SetLimitedCache("setedColumns", setedColumns);
            #endregion

            var options = new StringBuilder();
            options.AppendFormat("<option value='{0}'>{1}</option>", "", "-Please Select-");
            using (tblSQLColumnsRepository rep = new tblSQLColumnsRepository())
            {
                List <tblSQLColumns>        allColumns   = rep.getAllColumns(vm.SQLName).ToList();
                IEnumerable <tblSQLColumns> unsetColumns = allColumns.Except(setedColumns, new ColumnComparer());
                foreach (var c in unsetColumns)
                {
                    options.AppendFormat("<option value='{0}'>{1}</option>", c.ColumnName, c.ColumnName);
                }
            }

            var jsonData = new
            {
                status           = "ok",
                Options          = options.ToString(),
                FatherTagOptions = fatherTag.ToString()
            };
            return(Json(jsonData));
        }