public List <PropertyInfo> GetProperties() { List <PropertyInfo> rv = new List <PropertyInfo>(); foreach (var subField in SubFieldExps) { var pro = UtilsTool.GetPropertyInfo(subField); if (pro != null) { rv.Add(pro); } } return(rv); }
protected virtual string GetHeader() { string rv = ""; var dis = UtilsTool.GetPropertyInfo(ColumnNameExp).GetCustomAttributes(typeof(DisplayAttribute), false).FirstOrDefault() as DisplayAttribute; if (dis != null) { if (dis.ResourceType == null) { rv = dis.Name; } else { rv = Resources.Language.ResourceManager.GetString(dis.Name); } } return(rv); }
protected override string GetHeader() { string rv = ""; var dis = typeof(ML).GetProperty(UtilsTool.GetPropertyName(LanguageFormat)).GetCustomAttributes(typeof(DisplayAttribute), false).FirstOrDefault() as DisplayAttribute; if (dis != null) { if (dis.ResourceType == null) { rv = dis.Name; } else { rv = Resources.Language.ResourceManager.GetString(dis.Name); } } return(rv); }
public override MvcHtmlString GetText(T source) { string rv = ""; SupportedLanguage CurrentLanguage = UtilsTool.GetCurrentLanguage(); var middle = MiddleField.Compile().Invoke(source); //renyj 2011-6-28 if (middle == null) { return(MvcHtmlString.Create(rv)); } if (middle.MLContents != null) { rv = middle.GetLanguageSpecificContent(LanguageFormat);//.MLContents .Where(x => x.LanguageCode == CurrentLanguage.LanguageCode).Select(LanguageFormat.Compile()).FirstOrDefault(); } if (Format != null) { rv = Format.Invoke(source, rv).ToString(); } return(MvcHtmlString.Create(rv)); }
protected void ValidateDuplicateData(List <ValidationResult> rv) { if (this._duplicatedPropertiesCheck != null && this._duplicatedPropertiesCheck.Groups.Count > 0) { var baseExp = DC.GetSet <TModel>().AsQueryable(); var modelType = typeof(TModel); ParameterExpression para = Expression.Parameter(modelType, "tm"); foreach (var group in this._duplicatedPropertiesCheck.Groups) { List <Expression> conditions = new List <Expression>(); //生成一个表达式,类似于 x=>x.ID != id MemberExpression idLeft = Expression.Property(para, "ID"); ConstantExpression idRight = Expression.Constant(Entity.ID); BinaryExpression idNotEqual = Expression.NotEqual(idLeft, idRight); conditions.Add(idNotEqual); List <PropertyInfo> props = new List <PropertyInfo>(); foreach (var field in group.Fields) { if (field.DirectFieldExp != null) { var item = field.DirectFieldExp; string propertyName = UtilsTool.GetPropertyName(item); var prop = UtilsTool.GetPropertyInfo(item); props.Add(prop); var func = item.Compile(); var val = func.Invoke(this.Entity); if (val == null) { continue; } if (val is string && val.ToString() == "") { var requiredAttrs = prop.GetCustomAttributes(typeof(RequiredAttribute), false); if (requiredAttrs == null || requiredAttrs.Length == 0) { continue; } else { var requiredAtt = requiredAttrs[0] as RequiredAttribute; if (requiredAtt.AllowEmptyStrings == true) { continue; } } } //生成一个表达式,类似于 x=>x.field == val Expression left = Expression.Property(para, propertyName); if (left.Type.IsGenericType && left.Type.GetGenericTypeDefinition() == typeof(Nullable <>)) { left = Expression.Property(left, "Value"); } if (left.Type == typeof(string)) { left = Expression.Call(left, typeof(String).GetMethod("Trim", Type.EmptyTypes)); } if (val is string) { val = val.ToString().Trim(); } ConstantExpression right = Expression.Constant(val); BinaryExpression equal = Expression.Equal(left, right); conditions.Add(equal); } else { dynamic dField = field; Expression exp = dField.GetExpression(Entity, para); if (exp != null) { conditions.Add(exp); } props.AddRange(dField.GetProperties()); } } int count = 0; if (conditions.Count > 1) { Expression conExp = conditions[0]; for (int i = 1; i < conditions.Count; i++) { conExp = Expression.And(conExp, conditions[i]); } MethodCallExpression whereCallExpression = Expression.Call( typeof(Queryable), "Where", new Type[] { modelType }, baseExp.Expression, Expression.Lambda <Func <TModel, bool> >(conExp, new ParameterExpression[] { para })); var result = baseExp.Provider.CreateQuery(whereCallExpression); foreach (var res in result) { count++; } } if (count > 0) { string AllName = ""; foreach (var prop in props) { var dispAttrs = prop.GetCustomAttributes(typeof(DisplayAttribute), false); string name = prop.Name; if (name == "LanguageCode") { continue; } if (dispAttrs != null && dispAttrs.Length > 0) { var attr = dispAttrs[0] as DisplayAttribute; name = attr.Name; if (attr.ResourceType != null) { name = attr.ResourceType.GetProperty(name).GetValue(null, null).ToString(); } } AllName += name + ","; } if (AllName.EndsWith(",")) { AllName = AllName.Remove(AllName.Length - 1); } if (props.Count == 1) { rv.Add(new ValidationResult(AllName + Resources.Language.字段重复, GetValidationFieldName(props[0]))); } else if (props.Count > 1) { rv.Add(new ValidationResult(AllName + Resources.Language.组合字段重复, GetValidationFieldName(props[0]))); } else { rv.Add(new ValidationResult(AllName + Resources.Language.组合字段重复)); } } } } }
public ActionResult btnOutputWord_Click(int record_id) { // 关闭本窗体(触发窗体的关闭事件) //PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); try { var record = db.view_record2word.Find(record_id); string dotName = record.bg_dot_name; if (dotName.Equals("")) { dotName = "xcbl.dot"; } string path = Server.MapPath("~/pbs_data/"); NameValueCollection val1 = (NameValueCollection)ConfigurationManager.GetSection("myUrl"); if (System.IO.File.Exists(path + "\\" + record.record_no + ".doc")) { return(Redirect(val1["apiUrl"] + "GetWordFile?fileName=" + record.record_no + ".doc")); } CCWordApp word = new CCWordApp(); word.OpenFromDot(Server.MapPath("~/App_Data/") + dotName); word.GotoBookMark("kyyear"); word.InsertText(record.ky_date.Value.Year.ToString()); word.GotoBookMark("ky_no"); word.InsertText(record.record_no.Substring(record.record_no.Count() - 6)); word.GotoBookMark("ky_unit"); word.SetFont("Underlined"); word.InsertText(record.unit_full_name); word.SetFont("Underlined"); word.GotoBookMark("kyyear2"); word.InsertText(record.ky_date.Value.Year.ToString()); word.GotoBookMark("ky_no2"); word.InsertText(record.record_no.Substring(record.record_no.Count() - 6)); word.GotoBookMark("ky_unit2"); word.InsertText(record.ky_unit_name); word.GotoBookMark("bg_unit"); word.InsertText(record.bg_unit_name); word.GotoBookMark("ky_date"); word.InsertText(record.ky_date.Value.ToString("yyyy")); word.GotoBookMark("ky_date_month"); word.InsertText(record.ky_date.Value.ToString("MM")); word.GotoBookMark("ky_date_dd"); word.InsertText(record.ky_date.Value.ToString("dd")); word.GotoBookMark("ky_date_hh"); word.InsertText(record.ky_date.Value.ToString("hh")); word.GotoBookMark("ky_date_mm"); word.InsertText(record.ky_date.Value.ToString("mm")); word.GotoBookMark("record_reason"); string reason = record.record_reason; if (reason == null) { reason = ""; } reason = reason.PadRight(340 - reason.ToCharArray().Length); word.InsertText(reason); word.GotoBookMark("kykssj"); word.InsertText(record.kyks_time.Value.ToString("yyyy")); word.GotoBookMark("kykssj_month"); word.InsertText(record.kyks_time.Value.ToString("MM")); word.GotoBookMark("kykssj_dd"); word.InsertText(record.kyks_time.Value.ToString("dd")); word.GotoBookMark("kykssj_hh"); word.InsertText(record.kyks_time.Value.ToString("hh")); word.GotoBookMark("kykssj_mm"); word.InsertText(record.kyks_time.Value.ToString("mm")); word.GotoBookMark("kyjssj"); word.InsertText(record.kyjs_time.Value.ToString("yyyy")); word.GotoBookMark("kyjssj_month"); word.InsertText(record.kyjs_time.Value.ToString("MM")); word.GotoBookMark("kyjssj_dd"); word.InsertText(record.kyjs_time.Value.ToString("dd")); word.GotoBookMark("kyjssj_hh"); word.InsertText(record.kyjs_time.Value.ToString("hh")); word.GotoBookMark("kyjssj_mm"); word.InsertText(record.kyjs_time.Value.ToString("mm")); word.GotoBookMark("xc_loc"); string loc = ""; if (record.xc_loc == null) { loc = record.fs_loc; } else { loc = record.fs_loc + record.xc_loc; } loc = loc.PadRight(190 - loc.ToCharArray().Length); word.InsertText(loc); word.GotoBookMark("bh_flag"); if (record.bh_flag == null) { word.InsertText("无"); } else { if (record.bh_flag.Value == 1) { word.InsertText("有"); } else { word.InsertText("无"); } } word.GotoBookMark("bhr"); word.InsertText(record.bhr_name); word.GotoBookMark("bhr_unit"); word.InsertText(record.bhr_unit_name); word.GotoBookMark("bhr_pos"); word.InsertText(record.bhr_pos); //保护方式 if (record.bh_function != null && record.bh_function.Length > 0 && record.bh_function.Substring(0, 1).Equals("专")) { word.GotoBookMark("bh_function_flag1"); word.replaceText("□", "☑"); } else if (record.bh_function != null && record.bh_function.Length > 0 && record.bh_function.Substring(0, 1).Equals("设")) { word.GotoBookMark("bh_function_flag2"); word.replaceText("□", "☑"); } else if (record.bh_function != null && record.bh_function.Length > 0 && record.bh_function.Substring(0, 1).Equals("封")) { word.GotoBookMark("bh_function_flag3"); word.replaceText("□", "☑"); word.GotoBookMark("bhr_function"); word.InsertText(record.bh_function); } //现场情况 if (record.xc_info != null && record.xc_info.Length > 1 && record.xc_info.Substring(0, 2).Equals("原始")) { word.GotoBookMark("xc_info_flag1"); word.replaceText("□", "☑"); } else if (record.xc_info != null && record.xc_info.Length > 1 && record.xc_info.Substring(0, 2).Equals("变动")) { word.GotoBookMark("xc_info_flag2"); word.replaceText("□", "☑"); } //变动原因 if (record.bd_reason != null && record.bd_reason.Length > 1 && record.bd_reason.Substring(0, 2).Equals("事主")) { word.GotoBookMark("bd_reason_flag1"); word.replaceText("□", "☑"); } else if (record.bd_reason != null && record.bd_reason.Length > 1 && record.bd_reason.Substring(0, 2).Equals("报案")) { word.GotoBookMark("bd_reason_flag2"); word.replaceText("□", "☑"); } else if (record.bd_reason != null && !record.bd_reason.Equals("")) { word.GotoBookMark("bd_reason_flag3"); word.replaceText("□", "☑"); word.GotoBookMark("bd_reason"); word.InsertText(record.bd_reason); } //天气 switch (record.weather_info) { case "阴": word.GotoBookMark("tq_flag1"); word.replaceText("□", "☑"); break; case "晴": word.GotoBookMark("tq_flag2"); word.replaceText("□", "☑"); break; case "雨": word.GotoBookMark("tq_flag3"); word.replaceText("□", "☑"); break; case "雪": word.GotoBookMark("tq_flag4"); word.replaceText("□", "☑"); break; case "雾": word.GotoBookMark("tq_flag5"); word.replaceText("□", "☑"); break; } word.GotoBookMark("wd"); word.InsertText(record.temper_info); word.GotoBookMark("sd"); word.InsertText(record.humidity_info); word.GotoBookMark("fx"); word.InsertText(record.trend_info); //光照 if (record.light_info != null && record.light_info.Contains("自然光")) { word.GotoBookMark("light_flag1"); word.replaceText("□", "☑"); } if (record.light_info != null && record.light_info.Contains("灯光")) { word.GotoBookMark("light_flag2"); word.replaceText("□", "☑"); } if (record.light_info != null && record.light_info.Contains("特种光")) { word.GotoBookMark("light_flag3"); word.replaceText("□", "☑"); } word.GotoBookMark("zhr"); word.InsertText(record.zhr_name); word.GotoBookMark("zhr_unit"); word.InsertText(record.zhr_unit_name); word.GotoBookMark("zhr_pos"); word.InsertText(record.zhr_pos); word.GotoBookMark("xc_disp"); word.InsertText(record.xc_disp.PadRight(1400)); word.GotoBookMark("blr"); string blr = record.blr_name; if (blr == null) { blr = ""; } word.InsertText(blr.PadRight(70)); word.GotoBookMark("ztr"); string ztr = record.ztr_name; if (ztr == null) { ztr = ""; } word.InsertText(ztr.PadRight(70)); word.GotoBookMark("zxr"); string zxr = record.zxr_name; if (zxr == null) { zxr = ""; } word.InsertText(zxr.PadRight(70)); word.GotoBookMark("lxr"); string lxr = record.lxr_name; if (lxr == null) { lxr = ""; } word.InsertText(lxr.PadRight(70)); word.GotoBookMark("lyr"); string lyr = record.lyr_name; if (lyr == null) { lyr = ""; } word.InsertText(lyr.PadRight(70)); word.GotoBookMark("jzrsex"); word.InsertText(record.jzr_sex); word.GotoBookMark("jzrbirth"); word.InsertText(record.jzr_birth); word.GotoBookMark("jzraddress"); word.InsertText(record.jzr_address); word.GotoBookMark("jzrqm"); System.Drawing.Image qmImg = System.Drawing.Image.FromFile(path + record.uuid + "\\" + record.uuid + ".png"); qmImg = UtilsTool.RotateImg(qmImg, -90); string rotatePath = path + "tmp\\" + record.uuid + "_tmp.png"; qmImg.Save(rotatePath); word.InsertPictureStatic(rotatePath, 100, 100); word.GotoBookMark("jzrqm2"); word.InsertPictureStatic(rotatePath, 100, 100); word.GotoBookMark("bg_date1_year"); word.InsertText(UtilsTool.NumtoUpper(DateTime.Now.Year % 10)); word.GotoBookMark("bg_date1_month"); word.InsertText(UtilsTool.MonthtoUpper(DateTime.Now.Month)); word.GotoBookMark("bg_date1_day"); word.InsertText(UtilsTool.DaytoUpper(DateTime.Now.Day)); word.GotoBookMark("bg_date2_year"); word.InsertText(UtilsTool.NumtoUpper(DateTime.Now.Year % 10)); word.GotoBookMark("bg_date2_month"); word.InsertText(UtilsTool.MonthtoUpper(DateTime.Now.Month)); word.GotoBookMark("bg_date2_day"); word.InsertText(UtilsTool.DaytoUpper(DateTime.Now.Day)); word.GotoBookMark("photos"); int i = 1; var pics = db.sys_upload_file.Where(m => m.rec_uuid.Equals(record.uuid)); var ztpics = pics.Where(m => m.file_type == 2004); int ztnum = ztpics.Count(); word.GotoBookMark("zt_num"); word.InsertText("" + ztnum); foreach (sys_upload_file pic in ztpics) { if (ValidateFileType(pic.file_url)) { word.GotoBookMark("photo" + (i++).ToString()); word.InsertLineBreak(14); word.InsertPicture(Server.MapPath("~/App_Data/") + "blank.png", 10, 10);//矫正后续图片位置 string bgFilePath = Server.MapPath("~/App_Data/") + "xct_bg.jpg"; Bitmap bmp = new Bitmap(bgFilePath); Graphics g = Graphics.FromImage(bmp); Font titlefont = new Font("宋体", 65); Font contentfont = new Font("宋体", 40); Font minicontentfont = new Font("宋体", 30); SolidBrush sbrush = new SolidBrush(Color.Black); string title = record.af_time.Value.ToString("yyyyMMdd") + " " + record.fs_loc + record.xc_loc + record.xz; string markHint = ""; if (pic.file_url.Substring(pic.file_url.Length - 8).Equals("xct.jpeg")) { title += "中心现场方位示意图"; markHint = "中心现场"; } else if (pic.file_url.Substring(pic.file_url.Length - 8).Equals("pmt.jpeg")) { title += "中心现场方位示意图"; markHint = "案发位置"; } g.DrawString(title, titlefont, sbrush, new PointF(300, 200)); g.DrawString(markHint, titlefont, sbrush, new PointF(2600, 1150)); if (record.xc_loc.Length > 12) { g.DrawString(record.xc_loc.Substring(0, 12), minicontentfont, sbrush, new PointF(2600, 1770)); g.DrawString(record.xc_loc.Substring(12), minicontentfont, sbrush, new PointF(2600, 1830)); } else { g.DrawString(record.xc_loc, contentfont, sbrush, new PointF(2600, 1800)); } g.DrawString(record.bj_time.Value.ToString("yyyy年MM月dd日 HH时mm分"), contentfont, sbrush, new PointF(2600, 1900)); //g.DrawString(record.unit_full_name, contentfont, sbrush, new PointF(2600, 2030)); if (record.unit_full_name.Length > 12) { g.DrawString(record.unit_full_name.Substring(0, 12), minicontentfont, sbrush, new PointF(2600, 2000)); g.DrawString(record.unit_full_name.Substring(12), minicontentfont, sbrush, new PointF(2600, 2060)); } else { g.DrawString(record.unit_full_name, contentfont, sbrush, new PointF(2600, 2030)); } g.DrawString(record.ztr_name, contentfont, sbrush, new PointF(2600, 2150)); g.DrawString(DateTime.Now.ToString("yyyy年MM月dd日 HH时mm分"), contentfont, sbrush, new PointF(2600, 2270)); System.Drawing.Image mapImg = System.Drawing.Image.FromFile(path + record.uuid + "\\" + pic.file_url); g.DrawImage(mapImg, 100, 400, 2100, 1600); //bmp.Save(path + record.uuid + "\\tmp_" + pic.file_url); System.Drawing.Image img = UtilsTool.RotateImg(bmp, -90); //旋转90度 RectSize target = UtilsTool.getCTSize(img); img.Save(path + record.uuid + "\\tmp_" + pic.file_url); word.InsertPicture(path + record.uuid + "\\tmp_" + pic.file_url, target.width, target.height); word.InsertLineBreak(); //word.SetAlignment("Center"); //word.InsertText(pic.file_hint); //word.InsertPagebreak(); } } var fwpics = pics.Where(m => m.file_type == 2001 || m.file_type == 2002 || m.file_type == 2003).OrderBy(m => m.file_type); int photonum = fwpics.Count(); word.GotoBookMark("photo_num"); word.InsertText("" + photonum); foreach (sys_upload_file pic in fwpics) { if (ValidateFileType(pic.file_url)) { word.GotoBookMark("photo" + (i++).ToString()); word.InsertLineBreak(6); word.InsertPicture(Server.MapPath("~/App_Data/") + "blank.png", 10, 10);//矫正后续图片位置 System.Drawing.Image img = System.Drawing.Image.FromFile(path + record.uuid + "\\" + pic.file_url); RectSize target = UtilsTool.getConfSize(img); word.InsertPicture(path + record.uuid + "\\" + pic.file_url, target.width, target.height); word.InsertLineBreak(); word.SetAlignment("Center"); word.InsertText(pic.file_hint); } } string newFile = path + record.record_no + ".doc"; word.SaveAs(newFile); word.Close(); word.Quit(); return(Redirect(val1["apiUrl"] + "GetWordFile?fileName=" + record.record_no + ".doc")); } catch (Exception exc) { throw (exc); } //return UIHelper.Result(); }
public virtual Type GetColumnType(Type ClassType) { Type rv = ClassType.GetProperty(UtilsTool.GetPropertyName(ColumnNameExp)).PropertyType; return(rv); }
/// <summary> /// MyXls导出 /// </summary> /// <returns></returns> public byte[] GenerateExcel() { XlsDocument xls = new XlsDocument(); Worksheet sheet = xls.Workbook.Worksheets.Add("Sheet1");//状态栏标题名称 Cells cells = sheet.Cells; MakeExcelHeader(ListColumns, cells, 1, 1); int rowIndex = ListColumns.Max(x => x.MaxLevel); int colIndex = 0; //List<Color> allcolors = new List<Color>(); //allcolors.Add(Colors.Default08); //allcolors.Add(Colors.Default09); //allcolors.Add(Colors.Default0A); //allcolors.Add(Colors.Default0B); //allcolors.Add(Colors.Default0C); //allcolors.Add(Colors.Default0D); //allcolors.Add(Colors.Default0E); //allcolors.Add(Colors.Default0F); //allcolors.Add(Colors.Default10); //allcolors.Add(Colors.Default11); //allcolors.Add(Colors.Default12); //allcolors.Add(Colors.Default13); //allcolors.Add(Colors.Default14); //allcolors.Add(Colors.Default15); //allcolors.Add(Colors.Default16); //allcolors.Add(Colors.Default17); //allcolors.Add(Colors.Default18); //allcolors.Add(Colors.Default19); //allcolors.Add(Colors.Default20); //allcolors.Add(Colors.Default1A); //allcolors.Add(Colors.Default1B); //allcolors.Add(Colors.Default1C); //allcolors.Add(Colors.Default1D); //allcolors.Add(Colors.Default1E); //allcolors.Add(Colors.Default1F); //allcolors.Add(Colors.Default20); //allcolors.Add(Colors.Default21); //allcolors.Add(Colors.Default22); //allcolors.Add(Colors.Default23); //allcolors.Add(Colors.Default24); //allcolors.Add(Colors.Default25); //allcolors.Add(Colors.Default26); //allcolors.Add(Colors.Default27); //allcolors.Add(Colors.Default28); //allcolors.Add(Colors.Default29); //allcolors.Add(Colors.Default2A); //allcolors.Add(Colors.Default2B); //allcolors.Add(Colors.Default2C); //allcolors.Add(Colors.Default2D); //allcolors.Add(Colors.Default2E); //allcolors.Add(Colors.Default2F); //allcolors.Add(Colors.Default30); //allcolors.Add(Colors.Default31); //allcolors.Add(Colors.Default32); //allcolors.Add(Colors.Default33); //allcolors.Add(Colors.Default34); //allcolors.Add(Colors.Default35); //allcolors.Add(Colors.Default36); //allcolors.Add(Colors.Default37); //allcolors.Add(Colors.Default38); //allcolors.Add(Colors.Default39); //allcolors.Add(Colors.Default3A); //allcolors.Add(Colors.Default3B); //allcolors.Add(Colors.Default3C); //allcolors.Add(Colors.Default3D); //allcolors.Add(Colors.Default3E); //allcolors.Add(Colors.Default3F); //int xx = 0; Dictionary <IGridColumn <TModel>, int> sameCount = new Dictionary <IGridColumn <TModel>, int>(); foreach (var baseCol in ListColumns) { foreach (var col in baseCol.BottomChildren) { sameCount.Add(col, 0); } } int i = 0; foreach (var row in EntityList) { rowIndex++; colIndex = 0; foreach (var baseCol in ListColumns) { foreach (var col in baseCol.BottomChildren) { colIndex++; //sheet.Cells.AddValueCell(rowIndex, colIndex, row[col.ColumnName].ToString());//将数据添加到xls表格里 //Cell cell= cells.AddValueCell(rowIndex, colIndex, Convert.ToDouble(row[col.ColumnName].ToString()));//转换为数字型 string cellValue = col.GetText(row).ToHtmlString(); object cv = cellValue; int testInt; decimal testFloat; int floatRound = 0; if (!cellValue.StartsWith("0")) { if (int.TryParse(cellValue, out testInt)) { if (testInt <= 100000) { cv = testInt; } } else if (decimal.TryParse(cellValue, out testFloat)) { if (testFloat <= 100000) { cv = testFloat; if (cellValue.Split('.').Count() > 1) { floatRound = cellValue.Split('.')[1].ToArray().Count(); //获取小数位数 } } } } else if (decimal.TryParse(cellValue, out testFloat)) { if (testFloat == 0)//为0时 { cv = 0; floatRound = 0; } else if (testFloat < 1)//modify by yecs 2015-02-26 LSTC税收报表: 小数点的项目被显示为文本格式(小于1的小数) { cv = testFloat; floatRound = cellValue.Split('.')[1].ToArray().Count(); } } Cell cell = cells.Add(rowIndex, colIndex, cv); if (floatRound > 0) { cell.Format = "0."; for (int x = 1; x <= floatRound; x++) { cell.Format += "0"; } } cell.TopLineStyle = 1; cell.BottomLineStyle = 1; cell.LeftLineStyle = 1; cell.RightLineStyle = 1; cell.UseBorder = true; cell.VerticalAlignment = VerticalAlignments.Centered; System.Drawing.Color backColor = col.GetBackGroundColor(row); System.Drawing.Color foreColor = col.GetForeGroundColor(row); if (backColor != System.Drawing.Color.Empty) { cell.Pattern = 1; cell.PatternColor = UtilsTool.GetExcelColor(backColor); } if (col.NeedGroup == true && sameCount[col] == i) { sameCount[col] = sameCount[col] + 1; string lastValue = col.GetText(row).ToHtmlString(); for (int j = i + 1; j < EntityList.Count; j++) { if (col.GetText(EntityList[j]).ToHtmlString() == lastValue) { sameCount[col] = sameCount[col] + 1; } else { break; } } cells.Merge(rowIndex, rowIndex + sameCount[col] - i - 1, colIndex, colIndex); } } } i++; } return(xls.Bytes.ByteArray); }
public Expression GetExpression(T Entity, ParameterExpression para) { ParameterExpression midPara = Expression.Parameter(typeof(V), "tm2"); var list = MiddleExp.Compile().Invoke(Entity); List <Expression> allExp = new List <Expression>(); Expression rv = null; foreach (var li in list) { List <Expression> innerExp = new List <Expression>(); bool needBreak = false; foreach (var SubFieldExp in SubFieldExps) { Expression left = Expression.Property(midPara, UtilsTool.GetPropertyName(SubFieldExp)); if (left.Type.IsGenericType && left.Type.GetGenericTypeDefinition() == typeof(Nullable <>)) { left = Expression.Property(left, "Value"); } if (left.Type == typeof(string)) { left = Expression.Call(left, typeof(String).GetMethod("Trim", Type.EmptyTypes)); } object vv = SubFieldExp.Compile().Invoke(li); if (vv == null) { needBreak = true; continue; } if (vv is string && vv.ToString() == "") { var requiredAttrs = li.GetType().GetProperty(UtilsTool.GetPropertyName(SubFieldExp)).GetCustomAttributes(typeof(RequiredAttribute), false); if (requiredAttrs == null || requiredAttrs.Length == 0) { needBreak = true; continue; } else { var requiredAtt = requiredAttrs[0] as RequiredAttribute; if (requiredAtt.AllowEmptyStrings == true) { needBreak = true; continue; } } } if (vv is string) { vv = vv.ToString().Trim(); } ConstantExpression right = Expression.Constant(vv); BinaryExpression equal = Expression.Equal(left, right); innerExp.Add(equal); } if (needBreak) { continue; } Expression exp = null; if (innerExp.Count == 1) { exp = innerExp[0]; } if (innerExp.Count > 1) { exp = Expression.And(innerExp[0], innerExp[1]); for (int i = 2; i < innerExp.Count; i++) { exp = Expression.And(exp, innerExp[i]); } } if (exp != null) { var any = Expression.Call( typeof(Enumerable), "Any", new Type[] { typeof(V) }, Expression.Property(para, UtilsTool.GetPropertyName(MiddleExp)), Expression.Lambda <Func <V, bool> >(exp, new ParameterExpression[] { midPara })); allExp.Add(any); } } if (allExp.Count == 1) { rv = allExp[0]; } if (allExp.Count > 1) { rv = Expression.Or(allExp[0], allExp[1]); for (int i = 2; i < allExp.Count; i++) { rv = Expression.Or(rv, allExp[i]); } } return(rv); }