/// <summary> /// 生成导入界面表格 /// </summary> /// <returns></returns> public static string CreateDataGrid(ImportClass Bodies) { string s = "<DataGridTemplateColumn>\r\n" + "<DataGridTemplateColumn.Header>\r\n" + "<TextBlock Text=\"{DynamicResource Status}\" />\r\n" + "</DataGridTemplateColumn.Header>\r\n" + "<DataGridTemplateColumn.CellTemplate>\r\n" + "<DataTemplate>\r\n" + "<TextBlock Foreground=\"{Binding Color}\" Text=\"{Binding TextState}\" />\r\n" + "</DataTemplate>\r\n" + "</DataGridTemplateColumn.CellTemplate>\r\n" + "</DataGridTemplateColumn>\r\n"; foreach (var ds in Bodies.Body) { string tmp = "<DataGridTemplateColumn Width=\"150\" HeaderStyle=\"{DynamicResource DataGridColumnHeader_Center}\" CellStyle=\"{DynamicResource DataGridCell_Center}\">\r\n" + "<DataGridTemplateColumn.Header>\r\n" + "<TextBlock Text=\"{DynamicResource Grid_" + ds.GRID_CODE + "}\"/>\r\n" + "</DataGridTemplateColumn.Header>\r\n" + "<DataGridTemplateColumn.CellTemplate>\r\n" + "<DataTemplate>\r\n" + "<TextBlock Text=\"{Binding " + ds.GRID_CODE + "}\"/>\r\n" + "</DataTemplate>\r\n" + "</DataGridTemplateColumn.CellTemplate>\r\n" + "</DataGridTemplateColumn>\r\n"; s += tmp; } return(s); }
//生成函数体 public static string GetHasWrodFunction(ImportClass import) { if (import == null) { return(""); } string s = ""; foreach (var ds in import.REPEAT_CODE) { ModelHelper model = new ModelHelper(); string tmp = " cmd." + model.Col(ds) + " == " + model.Col(ds).Replace("Col", "") + ", \r\n"; s += tmp; } string ss = " var ctx = ODAContext.NoTransContext;\r\n" + " var cmd = ctx.GetCmd<>();\r\n" + " var dt = cmd.Where(\r\n" + s + " cmd.ColOrgId == orgId,\r\n" + " cmd.ColEnterpriseId == enterpriseId).Count();\r\n" + " if (dt > 0)\r\n" + " return 1;\r\n" + " else" + " return 0;\r\n"; return(ss); }
/// <summary> /// 生成读取excel的代码 /// </summary> /// <param name="import"></param> /// <returns></returns> public static string CreateXss(ImportClass import) { string s = ""; for (int i = 0; i < import.Body.Count; i++) { string tmp = "model." + import.Body[i].GRID_CODE + " = sheet.GetRow(i).GetCell(" + i + ") == null ? \"\" : sheet.GetRow(i).GetCell(" + i + ").ToString();\r\n\r\n "; s += tmp; } return(s); }
/// <summary> /// 检测List内是否有重复数据 /// </summary> /// <param name="import"></param> /// <returns></returns> public static string CheckImportData(ImportClass import) { string s = ""; foreach (var ds in import.REPEAT_CODE) { s += "x." + ds + " == model." + ds; if (ds != import.REPEAT_CODE.Last()) { s += "&&"; } } return(s); }
/// <summary> /// 生成校验是否重复的代码 /// </summary> /// <param name="import"></param> /// <returns></returns> public static string CreateRepeat(ImportClass import) { string s = "else if (HasWord(model." + import.REPEAT_CODE[0]; for (int i = 1; i < import.REPEAT_CODE.Count; i++) { string tmp = ",model." + import.REPEAT_CODE[i]; s += tmp; } return(s += "))\r\n " + "{\r\n model.TextState = \"失败!词条数据已存在\";\r\n " + "model.Color = \"Red\";\r\n " + "model.IsChecked = false;\r\n " + "}\r\n else\r\n {\r\n model.IsChecked = true;\r\n model.TextState = \"成功!\";\r\n model.Color = \"Green\";\r\n }\r\n\r\n ");; }
//生成检测重复的url public static string GetHasWordUrl(ImportClass import, int t = 0) { if (import == null || (import.REPEAT_CODE.Count == 0 && import.EMPTY_CODE.Count == 0 && import.Body.Count == 0)) { return(""); } if (t == 0)//带/Hasword { string s = "/hasword?"; for (int i = 0; i < import.REPEAT_CODE.Count; i++) { ModelHelper model = new ModelHelper(); string tmp = ""; if (i > 0) { tmp += "&"; } tmp += model.Col(import.REPEAT_CODE[i]).Replace("Col", "") + "={" + model.Col(import.REPEAT_CODE[i]).Replace("Col", "") + "}"; s += tmp; } return(s); } if (t == 1)//带string { ModelHelper model = new ModelHelper(); string s = "string " + model.Col(import.REPEAT_CODE[0]).Replace("Col", ""); for (int i = 1; i < import.REPEAT_CODE.Count; i++) { string tmp = ", string " + model.Col(import.REPEAT_CODE[i]).Replace("Col", ""); s += tmp; } return(s); } else //不带string { string s = ""; for (int i = 0; i < import.REPEAT_CODE.Count; i++) { ModelHelper model = new ModelHelper(); string tmp = model.Col(import.REPEAT_CODE[i]).Replace("Col", "") + ", "; s += tmp; } return(s); } }
/// <summary> /// 生成导入的url /// </summary> /// <param name="ProjectName"></param> /// <param name="import"></param> /// <returns></returns> public static string CreateImportUrl(string ProjectName, ImportClass import) { var ls = ProjectName.Split('.'); string s = "\r\n\t\tpublic const string url_hasword = \"/api/" + ls.Last().ToLower() + "/" + ls.Last().ToLower() + "/hasword?"; for (int i = 0; i < import.REPEAT_CODE.Count(); i++) { ModelHelper model = new ModelHelper(); string tmp = ""; if (i > 0) { tmp += "&"; } tmp += model.Col(import.REPEAT_CODE[i]).Replace("Col", "") + "={" + i + "}"; s += tmp; } return(s + "\";"); }
/// <summary> /// 生成校验重复的函数体 /// </summary> /// <param name="import"></param> /// <returns></returns> public static string CreateRepeatFunction(ImportClass import) { string s = "private bool HasWord(string " + import.REPEAT_CODE[0]; for (int i = 1; i < import.REPEAT_CODE.Count; i++) { string tmp = ", string " + import.REPEAT_CODE[i]; s += tmp; } s += ")\r\n {\r\n var res = plugin.Framework.GetData(Services.url_hasword"; for (int i = 0; i < import.REPEAT_CODE.Count; i++) { ModelHelper model = new ModelHelper(); string tmp = ", " + import.REPEAT_CODE[i]; s += tmp; } return(s + ");"); }
/// <summary> /// 生成校正导入数据是否为空 /// </summary> /// <param name="import"></param> /// <returns></returns> public static string CreateNull(ImportClass import) { string s = ""; for (int i = 0; i < import.EMPTY_CODE.Count; i++) { string tmp = ""; if (i != 0) { tmp += "else "; } tmp += "if (string.IsNullOrEmpty(model." + import.EMPTY_CODE[i] + "))\r\n {\r\n " + "model.TextState = \"失败!\" + Translator.Get(\"Grid_" + import.EMPTY_CODE[i] + "\") + \"不能为空\";\r\n " + "model.Color = \"Red\";\r\n " + "model.IsChecked = false;\r\n "; s += tmp + "}\r\n"; } return(s); }