Beispiel #1
0
        /// <summary>
        /// 导出模版获取
        /// </summary>
        /// <param name="modelName"></param>
        /// <param name="formatColumn"></param>
        /// <param name="key"></param>
        /// <param name="test"></param>
        /// <param name="clientID"></param>
        /// <returns></returns>
        public Dictionary <string, ExcelModel> GetColumnForJson(string modelName, ref Dictionary <string, ExcelFormatter> formatColumn, string key = "", string test = "", string clientID = "")
        {
            Dictionary <string, ExcelModel> dic = new Dictionary <string, ExcelModel>();
            string path    = Server.MapPath("~/") + "modules/excelmodel/" + modelName + ".json";
            string jsonStr = "";

            try
            {
                if (string.IsNullOrEmpty(key))
                {
                    key = "Item";
                }
                StreamReader sr = new StreamReader(path, Encoding.Default);
                String       line;
                while ((line = sr.ReadLine()) != null)
                {
                    jsonStr += line.ToString();
                }
                JObject jObject = (JObject)JsonConvert.DeserializeObject(jsonStr);
                Dictionary <string, object> jDic =
                    JsonConvert.DeserializeObject <Dictionary <string, object> >(jObject[key].ToString());
                foreach (var keyvalue in jDic)
                {
                    JObject    jChild     = (JObject)JsonConvert.DeserializeObject(keyvalue.Value.ToString());
                    ExcelModel excelModel = GetExcelModel(keyvalue.Key.ToLower(), jChild);
                    if (!excelModel.IsHide || (!string.IsNullOrEmpty(test) && test != "export"))
                    {
                        dic.Add(keyvalue.Key.ToLower(), excelModel);
                        int columnType = Convert.ToInt32(jChild[test + "type"]);
                        if (excelModel.IsFomat && columnType > -1)
                        {
                            string   dataList   = excelModel.DataSource;
                            string[] distType   = dataList.Split('|');
                            string   dropSource = "";
                            if (distType.Length > 1)
                            {
                                if (distType[0] == "List")
                                {
                                    dropSource = distType[1];
                                }
                                else
                                {
                                    if (Convert.ToInt32(distType[1]) > 0)
                                    {
                                        dropSource =
                                            CommonBusiness.GetDropList(
                                                (DropSourceList)Enum.Parse(typeof(DropSourceList), distType[1]), clientID);
                                    }
                                }
                            }
                            formatColumn.Add(keyvalue.Key.ToLower(), new ExcelFormatter()
                            {
                                ColumnName  = excelModel.Title,
                                ColumnTrans =
                                    (EnumColumnTrans)
                                    Enum.Parse(typeof(EnumColumnTrans), columnType.ToString()),
                                DropSource = dropSource
                            });
                        }
                    }
                }
            }
            catch (Exception)
            {
                dic.Add("Error", new ExcelModel()
                {
                    Title = "未找到模版"
                });
                throw;
            }
            return(dic);
        }