// GET: /InvoiceAdvance/Delete/<id> public ActionResult Delete( Int32?InvoiceID , Int32?AdvancePaymentID ) { if ( InvoiceID == null || AdvancePaymentID == null ) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } dtInvoice = InvoiceAdvance_InvoiceData.SelectAll(); dtAdvancePayment = InvoiceAdvance_AdvancePaymentData.SelectAll(); InvoiceAdvance InvoiceAdvance = new InvoiceAdvance(); InvoiceAdvance.InvoiceID = System.Convert.ToInt32(InvoiceID); InvoiceAdvance.AdvancePaymentID = System.Convert.ToInt32(AdvancePaymentID); InvoiceAdvance = InvoiceAdvanceData.Select_Record(InvoiceAdvance); InvoiceAdvance.Invoice = new Invoice() { InvoiceID = (Int32)InvoiceAdvance.InvoiceID }; InvoiceAdvance.AdvancePayment = new AdvancePayment() { AdvancePaymentID = (Int32)InvoiceAdvance.AdvancePaymentID }; if (InvoiceAdvance == null) { return(HttpNotFound()); } return(View(InvoiceAdvance)); }
// GET: /InvoiceAdvance/ public ActionResult Index(string sortOrder, String SearchField, String SearchCondition, String SearchText, String Export, int?PageSize, int?page, string command) { if (command == "Show All") { SearchField = null; SearchCondition = null; SearchText = null; Session["SearchField"] = null; Session["SearchCondition"] = null; Session["SearchText"] = null; } else if (command == "Add New Record") { return(RedirectToAction("Create")); } else if (command == "Export") { Session["Export"] = Export; } else if (command == "Search" | command == "Page Size") { if (!string.IsNullOrEmpty(SearchText)) { Session["SearchField"] = SearchField; Session["SearchCondition"] = SearchCondition; Session["SearchText"] = SearchText; } } if (command == "Page Size") { Session["PageSize"] = PageSize; } ViewData["SearchFields"] = GetFields((Session["SearchField"] == null ? "Invoice I D" : Convert.ToString(Session["SearchField"]))); ViewData["SearchConditions"] = Library.GetConditions((Session["SearchCondition"] == null ? "Contains" : Convert.ToString(Session["SearchCondition"]))); ViewData["SearchText"] = Session["SearchText"]; ViewData["Exports"] = Library.GetExports((Session["Export"] == null ? "Pdf" : Convert.ToString(Session["Export"]))); ViewData["PageSizes"] = Library.GetPageSizes(); ViewData["CurrentSort"] = sortOrder; ViewData["InvoiceIDSortParm"] = sortOrder == "InvoiceID_asc" ? "InvoiceID_desc" : "InvoiceID_asc"; ViewData["AdvancePaymentIDSortParm"] = sortOrder == "AdvancePaymentID_asc" ? "AdvancePaymentID_desc" : "AdvancePaymentID_asc"; dtInvoiceAdvance = InvoiceAdvanceData.SelectAll(); dtInvoice = InvoiceAdvance_InvoiceData.SelectAll(); dtAdvancePayment = InvoiceAdvance_AdvancePaymentData.SelectAll(); try { if (!string.IsNullOrEmpty(Convert.ToString(Session["SearchField"])) & !string.IsNullOrEmpty(Convert.ToString(Session["SearchCondition"])) & !string.IsNullOrEmpty(Convert.ToString(Session["SearchText"]))) { dtInvoiceAdvance = InvoiceAdvanceData.Search(Convert.ToString(Session["SearchField"]), Convert.ToString(Session["SearchCondition"]), Convert.ToString(Session["SearchText"])); } } catch { } var Query = from rowInvoiceAdvance in dtInvoiceAdvance.AsEnumerable() join rowInvoice in dtInvoice.AsEnumerable() on rowInvoiceAdvance.Field <Int32>("InvoiceID") equals rowInvoice.Field <Int32>("InvoiceID") join rowAdvancePayment in dtAdvancePayment.AsEnumerable() on rowInvoiceAdvance.Field <Int32>("AdvancePaymentID") equals rowAdvancePayment.Field <Int32>("AdvancePaymentID") select new InvoiceAdvance() { Invoice = new Invoice() { InvoiceID = rowInvoice.Field <Int32>("InvoiceID") } , AdvancePayment = new AdvancePayment() { AdvancePaymentID = rowAdvancePayment.Field <Int32>("AdvancePaymentID") } }; switch (sortOrder) { case "InvoiceID_desc": Query = Query.OrderByDescending(s => s.Invoice.InvoiceID); break; case "InvoiceID_asc": Query = Query.OrderBy(s => s.Invoice.InvoiceID); break; case "AdvancePaymentID_desc": Query = Query.OrderByDescending(s => s.AdvancePayment.AdvancePaymentID); break; case "AdvancePaymentID_asc": Query = Query.OrderBy(s => s.AdvancePayment.AdvancePaymentID); break; default: // Name ascending Query = Query.OrderBy(s => s.InvoiceID); break; } if (command == "Export") { GridView gv = new GridView(); DataTable dt = new DataTable(); dt.Columns.Add("Invoice I D", typeof(string)); dt.Columns.Add("Advance Payment I D", typeof(string)); foreach (var item in Query) { dt.Rows.Add( item.Invoice.InvoiceID , item.AdvancePayment.AdvancePaymentID ); } gv.DataSource = dt; gv.DataBind(); ExportData(Export, gv, dt); } int pageNumber = (page ?? 1); int?pageSZ = (Convert.ToInt32(Session["PageSize"]) == 0 ? 5 : Convert.ToInt32(Session["PageSize"])); return(View(Query.ToPagedList(pageNumber, (pageSZ ?? 5)))); }