public ExportBankpurtyForm(TypeExport type) { InitializeComponent(); typeExport = type; if (type == TypeExport.Excel) { saveFileDialog1.Filter = "xlsx files (*.xlsx)|*.xlsx"; } else { saveFileDialog1.Filter = "csv files (*.csv)|*.csv"; } saveFileDialog1.FilterIndex = 0; saveFileDialog1.RestoreDirectory = true; }
public static string GetResourcesJson() { var resources = new Dictionary <string, object>(); (TypeExport.GetAllResxTypes() as List <Type>).ForEach(type => { var texts = ResourceToDictionary(type, CultureInfo.CurrentCulture); resources.Add(type.Name, texts); }); return(JsonConvert.SerializeObject(resources, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() })); }
/// <summary> /// Hàm thực hiện lấy ra danh sách GridView /// </summary> /// <typeparam name="T"></typeparam> /// <param name="columnGridViews">Cấu hình cột của GridView</param> /// <param name="rowspanTotal">Số dòng hiển thị của Header</param> /// <param name="typeExport">Kiểu xuất dữ liệu</param> /// <param name="list">Danh sách cần xuất dữ liệu</param> /// <param name="isShowFooter"></param> /// <returns></returns> /// <remarks>PMNinh</remarks> public static GridView SettingGridView <T>(List <ColumnGridView> columnGridViews, int rowspanTotal, TypeExport typeExport, List <T> list, bool isShowFooter = true) { /* PMNinh: Khởi tạo GridView */ var gridView = new GridView(); foreach (var columnGridView in columnGridViews) { /* PMNinh: Nếu cột hiện tại là Cột dùng để Merge thì bỏ qua */ if (columnGridView.IsMergeHeader) { continue; } /* PMNinh: Cấu hình cột theo những dữ liệu đã truyền vào */ var boundField = new BoundField { DataField = columnGridView.DataField, ConvertEmptyStringToNull = true, ItemStyle = { Width = columnGridView.WidthField, VerticalAlign = VerticalAlign.Middle, Wrap = false } }; /* PMNinh: Cấu hình Type của cột */ switch (columnGridView.TypeField) { case TypeCode.DateTime: boundField.ItemStyle.HorizontalAlign = HorizontalAlign.Center; boundField.DataFormatString = "{0:dd/MM/yyyy HH:mm}"; boundField.NullDisplayText = string.Empty; if (!string.IsNullOrEmpty(columnGridView.FooterText)) { boundField.FooterText = columnGridView.FooterText; boundField.FooterStyle.HorizontalAlign = HorizontalAlign.Center; boundField.FooterStyle.Font.Bold = true; } break; case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: case TypeCode.UInt64: case TypeCode.Double: case TypeCode.Decimal: boundField.NullDisplayText = "0"; boundField.ItemStyle.HorizontalAlign = HorizontalAlign.Right; if (typeExport == TypeExport.Pdf) { boundField.DataFormatString = "{0:N0}"; } else { boundField.ItemStyle.CssClass = "myMoney"; } if (!string.IsNullOrEmpty(columnGridView.FooterText)) { if (typeExport == TypeExport.Pdf) { boundField.FooterText = Convert.ToDecimal(columnGridView.FooterText).ToString("N0"); boundField.FooterStyle.Font.Bold = true; } else { boundField.FooterText = columnGridView.FooterText; boundField.FooterStyle.CssClass = "myMoney"; boundField.FooterStyle.Font.Bold = true; } boundField.FooterStyle.HorizontalAlign = HorizontalAlign.Right; } break; case TypeCode.Boolean: boundField.NullDisplayText = string.Empty; boundField.ItemStyle.HorizontalAlign = HorizontalAlign.Center; break; default: boundField.NullDisplayText = string.Empty; boundField.ItemStyle.HorizontalAlign = HorizontalAlign.Left; break; } gridView.Columns.Add(boundField); } /* PMNinh: Ẩn cột tự động Gen ra */ gridView.AutoGenerateColumns = false; /* PMNinh: Ẩn header */ gridView.ShowHeader = false; /* PMNinh: Hiện Footer */ gridView.ShowFooter = isShowFooter; gridView.DataSource = list; gridView.DataBind(); /* PMNinh: Cấu hình Header cho cột */ gridView = SettingHeader(rowspanTotal, columnGridViews, gridView); return(gridView); }