public DosarExtended(Dosar d, bool _selected) { this.Dosar = d; this.AsiguratCasco = (Asigurat)d.GetAsiguratCasco().Result; this.AsiguratRca = (Asigurat)d.GetAsiguratRca().Result; this.AutoCasco = (Auto)d.GetAutoCasco().Result; this.AutoRca = (Auto)d.GetAutoRca().Result; this.Intervenient = (Intervenient)d.GetIntervenient().Result; this.SocietateCasco = (SocietateAsigurare)d.GetSocietateCasco().Result; this.SocietateRca = (SocietateAsigurare)d.GetSocietateRca().Result; this.TipDosar = (Nomenclator)d.GetTipDosar().Result; this.selected = _selected; }
public void ExportDosareToExcel(string _sort, string _order, string _filter, string _limit) { try { JObject jObj = (JObject)JsonConvert.DeserializeObject(_filter); string filterName = jObj["filterName"].ToString(); string filterKey = jObj["filterKey"].ToString(); object[] args = JsonConvert.DeserializeObject <object[]>(jObj["args"].ToString()); _filter = PredefinedFilters.CreateFilter(filterName, filterKey, args); } catch { } string conStr = Session["conStr"].ToString(); //ConfigurationManager.ConnectionStrings["MySQLConnectionString"].ConnectionString; int _CURENT_USER_ID = Convert.ToInt32(Session["CURENT_USER_ID"]); DosareRepository dr = new DosareRepository(_CURENT_USER_ID, conStr); //Dosar[] dosare = (Dosar[])dr.GetFiltered(null, null, String.Format(" DOSARE.DATA_SCA = '{0}' AND DOSARE.ID_SOCIETATE_CASCO = '{1}' AND DOSARE.ID_SOCIETATE_RCA = '{2}' ", CommonFunctions.ToMySqlFormatDate(d), Convert.ToInt32(Session["ID_SOCIETATE"]), Convert.ToInt32(id_soc_rca)), null).Result; Dosar[] dosare = (Dosar[])dr.GetFiltered(_sort, _order, _filter, _limit).Result; DataTable table = (DataTable)JsonConvert.DeserializeObject(JsonConvert.SerializeObject(dosare, Formatting.None, new Newtonsoft.Json.Converters.IsoDateTimeConverter() { DateTimeFormat = SOCISA.CommonFunctions.DATE_FORMAT }), (typeof(DataTable))); List <string> columns_to_remove = new List <string>(); foreach (DataColumn dc in table.Columns) { if ( !dc.ColumnName.ToLower().Equals("id") && !dc.ColumnName.ToLower().Contains("nr_dosar_casco") && !dc.ColumnName.ToLower().Contains("nr_sca") && !dc.ColumnName.ToLower().Contains("data_sca") && !dc.ColumnName.ToLower().Contains("nr_polita_casco") && !dc.ColumnName.ToLower().Contains("nr_auto_casco") && !dc.ColumnName.ToLower().Contains("nr_polita_rca") && !dc.ColumnName.ToLower().Contains("nr_auto_rca") && !dc.ColumnName.ToLower().Contains("data_eveniment") && !dc.ColumnName.ToLower().Contains("valoare_regres") && !dc.ColumnName.ToLower().Contains("data_avizare") ) { columns_to_remove.Add(dc.ColumnName); } } foreach (string col_name in columns_to_remove) { table.Columns.Remove(col_name); } DataColumn newdc = new DataColumn("ASIGURAT_CASCO", Type.GetType("System.String")); table.Columns.Add(newdc); newdc = new DataColumn("ASIGURATOR_RCA", Type.GetType("System.String")); table.Columns.Add(newdc); table.AcceptChanges(); foreach (DataRow drow in table.Rows) { try { Dosar dosar = new Dosar(_CURENT_USER_ID, conStr, Convert.ToInt32(drow["ID"])); Asigurat aCasco = (Asigurat)dosar.GetAsiguratCasco().Result; drow["ASIGURAT_CASCO"] = aCasco.DENUMIRE; SocietateAsigurare sRca = (SocietateAsigurare)dosar.GetSocietateRca().Result; drow["ASIGURATOR_RCA"] = sRca.DENUMIRE; } catch (Exception exp) { LogWriter.Log(exp); } } table.AcceptChanges(); using (ExcelPackage pack = new ExcelPackage()) { ExcelWorksheet ws = pack.Workbook.Worksheets.Add("Dosare"); ws.Cells["A1"].LoadFromDataTable(table, true); var ms = new System.IO.MemoryStream(); pack.SaveAs(ms); Response.BinaryWrite(ms.GetBuffer()); } }