Exemple #1
0
 public void DoWithJsonContent()
 {
     try
     {
         Regex           regex           = new Regex("{(.*?)}");
         ServiceConfig   serviceConfig   = ServiceHelper.GetServiceConfig(printTemp.ModelName);
         List <Field>    fields          = serviceConfig.fields;
         MatchCollection matchCollection = regex.Matches(formatContent);
         if (matchCollection.Count > 0)
         {
             string field;
             for (int num = matchCollection.Count - 1; num >= 0; num--)
             {
                 string text  = "";
                 Match  match = matchCollection[num];
                 try
                 {
                     string value = match.Groups[1].Value;
                     field = (value.Contains(":") ? value.Substring(0, value.IndexOf(':')) : value);
                     field = (field.Contains(",") ? field.Split(',')[1] : field);
                     string text2  = value.Contains(":") ? value.Substring(value.IndexOf(':') + 1) : "";
                     string strA   = value.Contains(",") ? value.Split(',')[0] : "";
                     Field  field2 = fields.FirstOrDefault((Field a) => a.name == field);
                     if (string.Compare(strA, "s", true) == 0)
                     {
                         text = ServiceHelper.GetSettingValue(field);
                         if (!string.IsNullOrEmpty(text2))
                         {
                             text = DoWithSystemMark(text, text2);
                         }
                     }
                     if (field.StartsWith("#") && dicPageInfo.ContainsKey(field.Substring(1)))
                     {
                         text = dicPageInfo[field.Substring(1)].ToString();
                     }
                     else if (ModelDetailData.ContainsKey(field))
                     {
                         if ((field2 != null && field2.type == "many2one") || field.ToLower() == "createuser" || field.ToLower() == "modifyuser")
                         {
                             List <string> list = ModelDetailData[field] as List <string>;
                             text = list[1];
                         }
                         else if (field2 != null && field2.type == "many2many")
                         {
                             List <List <string> > list2 = ModelDetailData[field] as List <List <string> >;
                             List <string>         list3 = new List <string>();
                             foreach (List <string> item in list2)
                             {
                                 list3.Add(item[1]);
                             }
                             text = string.Join(",", list3);
                         }
                         else
                         {
                             text = DoWithSystemMark(ModelDetailData[field], text2);
                         }
                     }
                 }
                 catch
                 {
                 }
                 if (string.IsNullOrEmpty(text))
                 {
                     text = "&nbsp;";
                 }
                 formatContent = formatContent.Substring(0, match.Index) + text + formatContent.Substring(match.Index + match.Value.Length);
             }
         }
     }
     catch
     {
     }
 }
Exemple #2
0
 public void DoWithJsonXmlContent()
 {
     try
     {
         Regex regex  = new Regex("<!--START-->([\\s\\S]*?)<!--END-->");
         Regex regex2 = new Regex("{(.*?)}");
         List <Dictionary <string, object> > list = null;
         MatchCollection matchCollection          = regex.Matches(formatContent);
         if (matchCollection.Count > 0)
         {
             List <string> list2 = new List <string>();
             for (int i = 0; i < matchCollection.Count; i++)
             {
                 list2.Add(matchCollection[i].Value);
             }
             StringBuilder stringBuilder = new StringBuilder();
             foreach (string item in list2)
             {
                 Regex           regex3           = new Regex("data-field=\"(.*?)\"");
                 MatchCollection matchCollection2 = regex3.Matches(item);
                 if (matchCollection2.Count == 0)
                 {
                     return;
                 }
                 string        fieldName     = matchCollection2[0].Groups[1].Value;
                 ServiceConfig serviceConfig = ServiceHelper.GetServiceConfig(printTemp.ModelName);
                 Field         field2        = serviceConfig.fields.FirstOrDefault((Field a) => a.name == fieldName);
                 if (field2 == null)
                 {
                     return;
                 }
                 ServiceConfig serviceConfig2 = ServiceHelper.GetServiceConfig(field2.relationModel);
                 List <Field>  fields         = serviceConfig2.fields;
                 List <Dictionary <string, object> > list3 = null;
                 if (ModelDetailData.ContainsKey(fieldName))
                 {
                     list3 = (ModelDetailData[fieldName] as List <Dictionary <string, object> >);
                 }
                 if (list3 != null && list3.Any())
                 {
                     if (list == null)
                     {
                         list = list3;
                     }
                     MatchCollection matchCollection3 = regex2.Matches(item);
                     int             num = -1;
                     foreach (Dictionary <string, object> item2 in list3)
                     {
                         num++;
                         string text = item.ToString();
                         for (int i = matchCollection3.Count - 1; i >= 0; i--)
                         {
                             Match  match = matchCollection3[i];
                             string value = match.Groups[1].Value;
                             string field = value.Contains(":") ? value.Substring(0, value.IndexOf(':')) : value;
                             field = (field.Contains(",") ? field.Split(',')[1] : field);
                             string string_ = value.Contains(":") ? value.Substring(value.IndexOf(':') + 1) : "";
                             Field  field3  = fields.FirstOrDefault((Field a) => a.name == field);
                             string text2   = "";
                             if (field == "rownumbers")
                             {
                                 text2 = DoWithSystemMark(num + 1, string_);
                             }
                             else if (item2.ContainsKey(field))
                             {
                                 if ((field3 != null && field3.type == "many2one") || field.ToLower() == "createuser" || field.ToLower() == "modifyuser")
                                 {
                                     List <string> list4 = item2[field] as List <string>;
                                     text2 = list4[1];
                                 }
                                 else if (field3 != null && field3.type == "many2many")
                                 {
                                     List <List <string> > list5 = item2[field] as List <List <string> >;
                                     List <string>         list6 = new List <string>();
                                     foreach (List <string> item3 in list5)
                                     {
                                         list6.Add(item3[1]);
                                     }
                                     text2 = string.Join(",", list6);
                                 }
                                 else
                                 {
                                     text2 = DoWithSystemMark(item2[field], string_);
                                 }
                             }
                             if (string.IsNullOrEmpty(text2))
                             {
                                 text2 = "&nbsp;";
                             }
                             text = text.Substring(0, match.Index) + text2 + text.Substring(match.Index + match.Value.Length);
                         }
                         stringBuilder.Append(text);
                     }
                 }
             }
             formatContent = regex.Replace(formatContent, stringBuilder.ToString());
         }
         MatchCollection matchCollection4 = regex2.Matches(formatContent);
         if (matchCollection4.Count > 0)
         {
             for (int i = matchCollection4.Count - 1; i >= 0; i--)
             {
                 Match  match = matchCollection4[i];
                 string value = match.Groups[1].Value;
                 string text3 = value.Contains(":") ? value.Substring(0, value.IndexOf(':')) : value;
                 text3 = (text3.Contains(",") ? text3.Split(',')[1] : text3);
                 string string_ = value.Contains(":") ? value.Substring(value.IndexOf(':') + 1) : "";
                 string text4   = value.Contains(",") ? value.Split(',')[0] : "";
                 string text2   = "";
                 if (!string.IsNullOrEmpty(text4))
                 {
                     if (string.Compare(text4, "s", true) == 0)
                     {
                         text2 = ServiceHelper.GetSettingValue(text3);
                         if (!string.IsNullOrEmpty(string_))
                         {
                             text2 = DoWithSystemMark(text2, string_);
                         }
                     }
                     else if (text4 == "count")
                     {
                         text2 = ObjectExtensions.ToStr((object)list.Count);
                     }
                     else
                     {
                         double num2 = 0.0;
                         double num3 = 0.0;
                         double num4 = 0.0;
                         foreach (Dictionary <string, object> item4 in list)
                         {
                             if (item4.ContainsKey(text3))
                             {
                                 double num5 = DataHelper.ConvertValue <double>(item4[text3]);
                                 if (num5 > num3)
                                 {
                                     num3 = num5;
                                 }
                                 if (num5 < num4)
                                 {
                                     num4 = num5;
                                 }
                                 num2 += num5;
                             }
                         }
                         double num6 = 0.0;
                         if (text4 == "sum")
                         {
                             num6 = num2;
                         }
                         else if (text4 == "avg")
                         {
                             num6 = num2 / (double)list.Count;
                         }
                         else if (text4 == "max")
                         {
                             num6 = num3;
                         }
                         else if (text4 == "min")
                         {
                             num6 = num4;
                         }
                         text2 = DoWithSystemMark(num6, string_);
                     }
                     if (string.IsNullOrEmpty(text2))
                     {
                         text2 = "&nbsp;";
                     }
                     formatContent = formatContent.Substring(0, match.Index) + text2 + formatContent.Substring(match.Index + match.Value.Length);
                 }
             }
         }
     }
     catch
     {
     }
 }