public ActionResult Prescriptions() { var model = new PrescDynamicsListViewModel(); int MyId = Convert.ToInt32(User.Identity.GetUserId()); List <Region> regions; var MyCountryCode = RegionRep.Get((int)CUserRep.FindBy(i => i.id == MyId).FirstOrDefault().base_region_id).country_code; if (User.IsInRole("admin") || User.IsInRole("DD")) { regions = RegionRep.FindBy(i => (bool)i.is_actual == true).OrderBy(k => k.name).ToList(); } if (User.IsInRole("seeAllUsers")) { regions = RegionRep.FindBy(i => (bool)i.is_actual == true && i.country_code.Equals(MyCountryCode)).OrderBy(k => k.name).ToList(); } else { regions = AssignedRegionsRep.FindBy(i => i.cuser_id == MyId).GroupBy(i => new { i.region_id, i.Region.name }) .Select(i => new Region { id = (int)i.First().region_id, name = i.First().Region.name }).OrderBy(p => p.name).ToList(); } model.region_id = regions.First().id; ViewBag.RegionList = new SelectList(regions, "id", "name", model.region_id); List <Report_> modes = new List <Report_>(); modes.Add(new Report_() { id = 0, name = "уп. / грн." }); modes.Add(new Report_() { id = 1, name = "уп." }); modes.Add(new Report_() { id = 2, name = "грн." }); ViewBag.ChooseMode = new SelectList(modes, "id", "name", model.mode_id); model.year_ = DateTime.Now.Year; Journal record = new Journal() { operation_name = "Просмотр отчета Динамика назначений", cuser_name = User.Identity.GetUserName(), edited_date = DateTime.Now }; JournalRep.AddOrUpdate(record); return(View(model)); }
public PartialViewResult PrescDynamics(PrescDynamicsListViewModel obj) { if (obj.Search != null && obj.Search.Length == 0) { obj.Search = null; } obj.presc_dynamics = PrescDynamicsRep.FindBy(obj.predicate).ToList(); if (obj.OnlyTotals) { obj.presc_dynamics = obj.presc_dynamics.Where(i => i.product_id == 0).ToList(); } return(PartialView(obj)); }
public ActionResult ExportExcelOld(string Search, int year_, int region_id) { string reg = RegionRep.Get(region_id).name; var obj = new PrescDynamicsListViewModel(); obj.Search = Search; if (Search != null && Search.Length == 0) { obj.Search = null; } obj.year_ = year_; obj.region_id = region_id; var gv = new GridView(); gv.DataSource = PrescDynamicsRep.FindBy(obj.predicate).ToList(); gv.DataBind(); Response.ClearContent(); Response.Buffer = true; Response.AddHeader("content-disposition", "attachment; filename=Назначения " + reg + ".xls"); Response.ContentType = "application/ms-excel"; Response.Charset = ""; StringWriter objStringWriter = new StringWriter(); HtmlTextWriter objHtmlTextWriter = new HtmlTextWriter(objStringWriter); for (int i = 0; i < gv.Rows.Count; i++) { for (int j = 17; j < gv.Rows[i].Cells.Count; j++) { gv.Rows[i].Cells[j].Attributes.Add("class", "textmode"); } } gv.RenderControl(objHtmlTextWriter); string style = @"<style> .textmode { mso-number-format:\@; } </style>"; Response.Write(style); Response.Output.Write(objStringWriter.ToString()); Response.Flush(); Response.End(); return(View()); }
public PartialViewResult PrescDynamicsSum(PrescDynamicsListViewModel obj) { var model = new PrescDynamicsSumListViewModel(); model.Search = obj.Search; if (obj.Search != null && obj.Search.Length == 0) { model.Search = null; } model.region_id = obj.region_id; model.mode_id = obj.mode_id; model.year_ = obj.year_; model.presc_dynamics = PrescDynamicSumRep.FindBy(model.predicate).ToList(); if (obj.OrderParameter != null) { model.presc_dynamics = Ordering.OrderBy <PrescDynamics_Pivot_sum>(model.presc_dynamics, obj.OrderParameter, obj.OrderDir).ToList(); } if (obj.OnlyTotals) { model.presc_dynamics = model.presc_dynamics.Where(i => i.product_id == 0).ToList(); } return(PartialView(model)); }
public ActionResult ExportExcelAll(string Search, int year_) { var obj = new PrescDynamicsListViewModel(); obj.Search = Search; if (Search != null && Search.Length == 0) { obj.Search = null; } obj.year_ = year_; var gv = new GridView(); gv.DataSource = PrescDynamicsRep.FindBy(i => i.year_ == year_).ToList(); gv.DataBind(); var gv1 = new GridView(); gv1.DataSource = PrescDynamicsQRep.FindBy(i => i.year_ == year_).ToList(); gv1.DataBind(); var gv2 = new GridView(); gv2.DataSource = PrescDynamicSumRep.FindBy(i => i.year_ == year_).ToList(); gv2.DataBind(); using (XLWorkbook wb = new XLWorkbook()) { //first page DataTable dt = new DataTable("Назначения уп. грн."); foreach (TableCell cell in gv.HeaderRow.Cells) { dt.Columns.Add(cell.Text); } dt.Columns[0].DataType = typeof(Int32); dt.Columns[4].DataType = typeof(Int32); dt.Columns[6].DataType = typeof(Int32); dt.Columns[8].DataType = typeof(Int32); dt.Columns[10].DataType = typeof(Int32); dt.Columns[12].DataType = typeof(Int32); dt.Columns[14].DataType = typeof(Int32); dt.Columns[16].DataType = typeof(Int32); foreach (GridViewRow row in gv.Rows) { dt.Rows.Add(); for (int j = 0; j < row.Cells.Count; j++) { if (row.Cells[j].Text != " ") { dt.Rows[dt.Rows.Count - 1][j] = row.Cells[j].Text; } } } wb.Worksheets.Add(dt); //second page DataTable dt1 = new DataTable("уп."); foreach (TableCell cell in gv1.HeaderRow.Cells) { dt1.Columns.Add(cell.Text); } dt1.Columns[0].DataType = typeof(Int32); dt1.Columns[4].DataType = typeof(Int32); dt1.Columns[6].DataType = typeof(Int32); dt1.Columns[8].DataType = typeof(Int32); dt1.Columns[10].DataType = typeof(Int32); dt1.Columns[12].DataType = typeof(Int32); dt1.Columns[14].DataType = typeof(Int32); for (int i = 16; i < dt1.Columns.Count; i++) { dt1.Columns[i].DataType = typeof(Int32); } foreach (GridViewRow row in gv1.Rows) { dt1.Rows.Add(); for (int j = 0; j < row.Cells.Count; j++) { if (row.Cells[j].Text != " ") { dt1.Rows[dt1.Rows.Count - 1][j] = row.Cells[j].Text; } } } wb.Worksheets.Add(dt1); //third page DataTable dt2 = new DataTable("грн."); foreach (TableCell cell in gv2.HeaderRow.Cells) { dt2.Columns.Add(cell.Text); } dt2.Columns[0].DataType = typeof(Int32); dt2.Columns[4].DataType = typeof(Int32); dt2.Columns[6].DataType = typeof(Int32); dt2.Columns[8].DataType = typeof(Int32); dt2.Columns[10].DataType = typeof(Int32); dt2.Columns[12].DataType = typeof(Int32); dt2.Columns[14].DataType = typeof(Int32); for (int i = 16; i < dt2.Columns.Count; i++) { dt2.Columns[i].DataType = typeof(Int32); } foreach (GridViewRow row in gv2.Rows) { dt2.Rows.Add(); for (int j = 0; j < row.Cells.Count; j++) { if (row.Cells[j].Text != " ") { dt2.Rows[dt2.Rows.Count - 1][j] = row.Cells[j].Text; } } } wb.Worksheets.Add(dt2); //Export the Excel file. Response.Clear(); Response.Buffer = true; Response.Charset = ""; Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AddHeader("content-disposition", "attachment;filename=Назначения " + year_ + ".xls"); using (MemoryStream MyMemoryStream = new MemoryStream()) { wb.SaveAs(MyMemoryStream); MyMemoryStream.WriteTo(Response.OutputStream); Response.Flush(); Response.End(); } } return(View()); }