// GET: /Client/Delete/<id> public ActionResult Delete( Int32?ClientID ) { if ( ClientID == null ) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } dtCompany = Client_CompanyData.SelectAll(); Client Client = new Client(); Client.ClientID = System.Convert.ToInt32(ClientID); Client = ClientData.Select_Record(Client); Client.Company = new Company() { CompanyID = (Int32)Client.CompanyID , CompanyName = (from DataRow rowCompany in dtCompany.Rows where Client.CompanyID == (int)rowCompany["CompanyID"] select(String) rowCompany["CompanyName"]).FirstOrDefault() }; if (Client == null) { return(HttpNotFound()); } return(View(Client)); }
public ActionResult Edit(Client Client) { Client oClient = new Client(); oClient.ClientID = System.Convert.ToInt32(Client.ClientID); oClient = ClientData.Select_Record(Client); if (ModelState.IsValid) { bool bSucess = false; bSucess = ClientData.Update(oClient, Client); if (bSucess == true) { return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "Can Not Update"); } } // ComboBox ViewData["CompanyID"] = new SelectList(Client_CompanyData.List(), "CompanyID", "CompanyName", Client.CompanyID); return(View(Client)); }
// GET: /Client/Edit/<id> public ActionResult Edit( Int32?ClientID ) { if ( ClientID == null ) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Client Client = new Client(); Client.ClientID = System.Convert.ToInt32(ClientID); Client = ClientData.Select_Record(Client); if (Client == null) { return(HttpNotFound()); } // ComboBox ViewData["CompanyID"] = new SelectList(Client_CompanyData.List(), "CompanyID", "CompanyName", Client.CompanyID); return(View(Client)); }
// GET: /Client/Create public ActionResult Create() { // ComboBox ViewData["CompanyID"] = new SelectList(Client_CompanyData.List(), "CompanyID", "CompanyName"); return(View()); }
public ActionResult Create([Bind(Include = "ClientName" + "," + "Address1" + "," + "Address2" + "," + "City" + "," + "District" + "," + "State" + "," + "PinCode" + "," + "ContactNo" + "," + "EMail" + "," + "GSTIN" + "," + "CompanyID" + "," + "AddUserID" + "," + "AddDate" + "," + "ArchiveUserID" + "," + "ArchiveDate" )] Client Client) { if (ModelState.IsValid) { bool bSucess = false; bSucess = ClientData.Add(Client); if (bSucess == true) { return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "Can Not Insert"); } } // ComboBox ViewData["CompanyID"] = new SelectList(Client_CompanyData.List(), "CompanyID", "CompanyName", Client.CompanyID); return(View(Client)); }
// GET: /Client/ 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 ? "Client 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["ClientIDSortParm"] = sortOrder == "ClientID_asc" ? "ClientID_desc" : "ClientID_asc"; ViewData["ClientNameSortParm"] = sortOrder == "ClientName_asc" ? "ClientName_desc" : "ClientName_asc"; ViewData["Address1SortParm"] = sortOrder == "Address1_asc" ? "Address1_desc" : "Address1_asc"; ViewData["Address2SortParm"] = sortOrder == "Address2_asc" ? "Address2_desc" : "Address2_asc"; ViewData["CitySortParm"] = sortOrder == "City_asc" ? "City_desc" : "City_asc"; ViewData["DistrictSortParm"] = sortOrder == "District_asc" ? "District_desc" : "District_asc"; ViewData["StateSortParm"] = sortOrder == "State_asc" ? "State_desc" : "State_asc"; ViewData["PinCodeSortParm"] = sortOrder == "PinCode_asc" ? "PinCode_desc" : "PinCode_asc"; ViewData["ContactNoSortParm"] = sortOrder == "ContactNo_asc" ? "ContactNo_desc" : "ContactNo_asc"; ViewData["EMailSortParm"] = sortOrder == "EMail_asc" ? "EMail_desc" : "EMail_asc"; ViewData["GSTINSortParm"] = sortOrder == "GSTIN_asc" ? "GSTIN_desc" : "GSTIN_asc"; ViewData["CompanyIDSortParm"] = sortOrder == "CompanyID_asc" ? "CompanyID_desc" : "CompanyID_asc"; ViewData["AddUserIDSortParm"] = sortOrder == "AddUserID_asc" ? "AddUserID_desc" : "AddUserID_asc"; ViewData["AddDateSortParm"] = sortOrder == "AddDate_asc" ? "AddDate_desc" : "AddDate_asc"; ViewData["ArchiveUserIDSortParm"] = sortOrder == "ArchiveUserID_asc" ? "ArchiveUserID_desc" : "ArchiveUserID_asc"; ViewData["ArchiveDateSortParm"] = sortOrder == "ArchiveDate_asc" ? "ArchiveDate_desc" : "ArchiveDate_asc"; dtClient = ClientData.SelectAll(); dtCompany = Client_CompanyData.SelectAll(); try { if (!string.IsNullOrEmpty(Convert.ToString(Session["SearchField"])) & !string.IsNullOrEmpty(Convert.ToString(Session["SearchCondition"])) & !string.IsNullOrEmpty(Convert.ToString(Session["SearchText"]))) { dtClient = ClientData.Search(Convert.ToString(Session["SearchField"]), Convert.ToString(Session["SearchCondition"]), Convert.ToString(Session["SearchText"])); } } catch { } var Query = from rowClient in dtClient.AsEnumerable() join rowCompany in dtCompany.AsEnumerable() on rowClient.Field <Int32>("CompanyID") equals rowCompany.Field <Int32>("CompanyID") select new Client() { ClientID = rowClient.Field <Int32>("ClientID") , ClientName = rowClient.Field <String>("ClientName") , Address1 = rowClient.Field <String>("Address1") , Address2 = rowClient.Field <String>("Address2") , City = rowClient.Field <String>("City") , District = rowClient.Field <String>("District") , State = rowClient.Field <String>("State") , PinCode = rowClient.Field <String>("PinCode") , ContactNo = rowClient.Field <String>("ContactNo") , EMail = rowClient.Field <String>("EMail") , GSTIN = rowClient.Field <String>("GSTIN") , Company = new Company() { CompanyID = rowCompany.Field <Int32>("CompanyID") , CompanyName = rowCompany.Field <String>("CompanyName") } , AddUserID = rowClient.Field <Int32>("AddUserID") , AddDate = rowClient.Field <DateTime>("AddDate") , ArchiveUserID = rowClient.Field <Int32?>("ArchiveUserID") , ArchiveDate = rowClient.Field <DateTime?>("ArchiveDate") }; switch (sortOrder) { case "ClientID_desc": Query = Query.OrderByDescending(s => s.ClientID); break; case "ClientID_asc": Query = Query.OrderBy(s => s.ClientID); break; case "ClientName_desc": Query = Query.OrderByDescending(s => s.ClientName); break; case "ClientName_asc": Query = Query.OrderBy(s => s.ClientName); break; case "Address1_desc": Query = Query.OrderByDescending(s => s.Address1); break; case "Address1_asc": Query = Query.OrderBy(s => s.Address1); break; case "Address2_desc": Query = Query.OrderByDescending(s => s.Address2); break; case "Address2_asc": Query = Query.OrderBy(s => s.Address2); break; case "City_desc": Query = Query.OrderByDescending(s => s.City); break; case "City_asc": Query = Query.OrderBy(s => s.City); break; case "District_desc": Query = Query.OrderByDescending(s => s.District); break; case "District_asc": Query = Query.OrderBy(s => s.District); break; case "State_desc": Query = Query.OrderByDescending(s => s.State); break; case "State_asc": Query = Query.OrderBy(s => s.State); break; case "PinCode_desc": Query = Query.OrderByDescending(s => s.PinCode); break; case "PinCode_asc": Query = Query.OrderBy(s => s.PinCode); break; case "ContactNo_desc": Query = Query.OrderByDescending(s => s.ContactNo); break; case "ContactNo_asc": Query = Query.OrderBy(s => s.ContactNo); break; case "EMail_desc": Query = Query.OrderByDescending(s => s.EMail); break; case "EMail_asc": Query = Query.OrderBy(s => s.EMail); break; case "GSTIN_desc": Query = Query.OrderByDescending(s => s.GSTIN); break; case "GSTIN_asc": Query = Query.OrderBy(s => s.GSTIN); break; case "CompanyID_desc": Query = Query.OrderByDescending(s => s.Company.CompanyName); break; case "CompanyID_asc": Query = Query.OrderBy(s => s.Company.CompanyName); break; case "AddUserID_desc": Query = Query.OrderByDescending(s => s.AddUserID); break; case "AddUserID_asc": Query = Query.OrderBy(s => s.AddUserID); break; case "AddDate_desc": Query = Query.OrderByDescending(s => s.AddDate); break; case "AddDate_asc": Query = Query.OrderBy(s => s.AddDate); break; case "ArchiveUserID_desc": Query = Query.OrderByDescending(s => s.ArchiveUserID); break; case "ArchiveUserID_asc": Query = Query.OrderBy(s => s.ArchiveUserID); break; case "ArchiveDate_desc": Query = Query.OrderByDescending(s => s.ArchiveDate); break; case "ArchiveDate_asc": Query = Query.OrderBy(s => s.ArchiveDate); break; default: // Name ascending Query = Query.OrderBy(s => s.ClientID); break; } if (command == "Export") { GridView gv = new GridView(); DataTable dt = new DataTable(); dt.Columns.Add("Client I D", typeof(string)); dt.Columns.Add("Client Name", typeof(string)); dt.Columns.Add("Address1", typeof(string)); dt.Columns.Add("Address2", typeof(string)); dt.Columns.Add("City", typeof(string)); dt.Columns.Add("District", typeof(string)); dt.Columns.Add("State", typeof(string)); dt.Columns.Add("Pin Code", typeof(string)); dt.Columns.Add("Contact No", typeof(string)); dt.Columns.Add("E Mail", typeof(string)); dt.Columns.Add("G S T I N", typeof(string)); dt.Columns.Add("Company I D", typeof(string)); dt.Columns.Add("Add User I D", typeof(string)); dt.Columns.Add("Add Date", typeof(string)); dt.Columns.Add("Archive User I D", typeof(string)); dt.Columns.Add("Archive Date", typeof(string)); foreach (var item in Query) { dt.Rows.Add( item.ClientID , item.ClientName , item.Address1 , item.Address2 , item.City , item.District , item.State , item.PinCode , item.ContactNo , item.EMail , item.GSTIN , item.Company.CompanyName , item.AddUserID , item.AddDate , item.ArchiveUserID , item.ArchiveDate ); } 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)))); }