public ActionResult AddPer(PerModel region, string acc, string TSHD, string TPD, string RVSBD, string TA) { if ((string)Session["Access"] != null) { Per p = new Per(); if ((string)Session["Access"] == "MainAdmin") { p.RegionName = region.RegionName; } else { p.RegionName = acc; } p.OD = region.OD; p.NMD = region.NMD; p.MBD = region.MBD; p.TSHD = TSHD; p.TPD = TPD; p.RVSBD = RVSBD; p.TA = TA; p.TF = region.TF; p.DG = region.DG; database.Pers.Add(p); database.SaveChanges(); return(RedirectToAction("Regions", "Admin")); } else { Session["Save"] = "False"; return(Content("ثبت نشد")); } }
//------Edit-Actions-----\\ //---Edit-Periud public ActionResult EditPer(int ID) { PerModel pm = new PerModel(); var r = database.Pers.Find(ID); if (r.RegionName == (string)Session["Access"] || (string)Session["Access"] == "MainAdmin") { pm.RegionName = r.RegionName; pm.ID = r.ID; pm.OD = r.OD; pm.NMD = r.NMD; pm.MBD = r.MBD; pm.TSHD = r.TSHD; pm.TPD = r.TPD; pm.RVSBD = r.RVSBD; pm.TA = r.TA; pm.TF = r.TF; pm.DG = r.DG; return(View(pm)); } else { return(RedirectToAction("Index", "Home")); } }
public ActionResult EditPer(PerModel y, int ID, string acc, string TSHD, string TPD, string RVSBD, string TA) { if ((string)Session["Access"] != null) { var f = database.Pers.Find(ID); if (f.RegionName == (string)Session["Access"] || (string)Session["Access"] == "MainAdmin") { f.RegionName = y.RegionName; if ((string)Session["Access"] != "MainAdmin") { f.RegionName = Session["Access"].ToString(); } f.OD = y.OD; f.NMD = y.NMD; f.MBD = y.MBD; f.TSHD = TSHD; f.TPD = TPD; f.RVSBD = RVSBD; f.TA = TA; f.TF = y.TF; f.DG = y.DG; database.SaveChanges(); return(RedirectToAction("Regions", "Admin")); } else { return(RedirectToAction("Regions", "Admin")); } } else { return(RedirectToAction("Index", "Home")); } }
//------List-Actions-----\\ //---Regions-List public ActionResult Regions(string search, string Combo, string Export) { System.Globalization.PersianCalendar pc = new System.Globalization.PersianCalendar(); ViewBag.DateNow = (pc.GetYear(DateTime.Now) + "/" + pc.GetMonth(DateTime.Now) + "/" + pc.GetDayOfMonth(DateTime.Now)); ViewBag.AdminNum = database.Admins.Count(); ViewBag.ProjNum = database.Pers.Count(); string ac = (string)Session["Access"]; List <PerModel> perlist = new List <PerModel>(); if ((string)Session["Access"] != null) { var per = database.Pers.OrderByDescending(x => x.ID).ToList(); if ((string)Session["Access"] != "MainAdmin") { per = database.Pers.OrderByDescending(x => x.ID).Where(x => x.RegionName == ac).ToList(); } //---MainAdmin if (!String.IsNullOrWhiteSpace(search)) { if (Combo == "RN") { per = per.Where(x => x.RegionName == search).ToList(); } if (Combo == "OD") { per = per.Where(x => x.OD.Contains(search)).ToList(); } if (Combo == "NM") { per = per.Where(x => x.NMD.Contains(search)).ToList(); } if (Combo == "MB") { per = per.Where(x => x.MBD.Contains(search)).ToList(); } if (Combo == "TSH") { per = per.Where(x => x.TSHD == search).ToList(); } if (Combo == "TP") { per = per.Where(x => x.TPD == search).ToList(); } if (Combo == "RVSB") { per = per.Where(x => x.RVSBD == search).ToList(); } if (Combo == "TA") { per = per.Where(x => x.TA == search).ToList(); } if (Combo == "TF") { per = per.Where(x => x.TF == Int32.Parse(search)).ToList(); } if (Combo == "DG") { per = per.Where(x => x.DG == Int32.Parse(search)).ToList(); } } foreach (var item in per) { PerModel p = new PerModel(); p.ID = item.ID; p.RegionName = item.RegionName; p.OD = item.OD; p.NMD = item.NMD; p.MBD = item.MBD; p.TSHD = item.TSHD; p.TPD = item.TPD; p.RVSBD = item.RVSBD; p.TA = item.TA; p.TF = item.TF; p.DG = item.DG; perlist.Add(p); } //---Export if (Export == "1") { //var admins = database.Admins.ToList(); ExcelPackage pck = new ExcelPackage(); ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Report"); ws.Cells["A1"].Value = "comm"; ws.Cells["B1"].Value = "com1"; ws.Cells["A2"].Value = "گزارش"; ws.Cells["B2"].Value = "لیست کاربران منطقه"; ws.Cells["A3"].Value = "تاریخ"; ws.Cells["B3"].Value = string.Format("{0:dd MMM yyyy} at {0:H mm tt})", pc.GetYear(DateTime.Now) + "/" + pc.GetMonth(DateTime.Now) + "/" + pc.GetDayOfMonth(DateTime.Now)); ws.Cells["A6"].Value = "منطقه"; ws.Cells["B6"].Value = "عنوان دوره"; ws.Cells["C6"].Value = "نام مدیر دوره"; ws.Cells["D6"].Value = "مکان برگذاری دوره"; ws.Cells["E6"].Value = "تاریخ شروع"; ws.Cells["F6"].Value = "تاریخ پایان"; ws.Cells["G6"].Value = "روز و ساعت برگذاری"; ws.Cells["H6"].Value = "تاریخ آزمون"; ws.Cells["I6"].Value = "تعداد فراگیر"; ws.Cells["J6"].Value = "درآمد گواهینامه"; int _i = 7; foreach (var item in perlist) { ws.Row(_i).Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; if (_i % 2 == 0) { ws.Row(_i).Style.Fill.BackgroundColor.SetColor(ColorTranslator.FromHtml(string.Format("GreenYellow"))); } else { ws.Row(_i).Style.Fill.BackgroundColor.SetColor(ColorTranslator.FromHtml(string.Format("Pink"))); } ws.Cells[string.Format("A{0}", _i)].Value = item.RegionName; ws.Cells[string.Format("B{0}", _i)].Value = item.OD; ws.Cells[string.Format("C{0}", _i)].Value = item.NMD; ws.Cells[string.Format("D{0}", _i)].Value = item.MBD; ws.Cells[string.Format("E{0}", _i)].Value = item.TSHD; ws.Cells[string.Format("F{0}", _i)].Value = item.TPD; ws.Cells[string.Format("G{0}", _i)].Value = item.RVSBD; ws.Cells[string.Format("H{0}", _i)].Value = item.TA; ws.Cells[string.Format("I{0}", _i)].Value = item.TF; ws.Cells[string.Format("J{0}", _i)].Value = item.DG; _i++; } ws.Cells["A:AZ"].AutoFitColumns(); Response.Clear(); Response.ContentType = "applicaton/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AddHeader("Content-disposition", "attachment: filename=" + "ExportReport.xlsx"); Response.BinaryWrite(pck.GetAsByteArray()); Response.End(); string filename2 = AppDomain.CurrentDomain.BaseDirectory + "خروجی اکسل از جدول دوره های مناطق هلال احمر تهران" + DateTime.Now.Millisecond.ToString() + ".xlsx"; } return(View(perlist)); } else { return(RedirectToAction("Index", "Home")); } }