public ActionResult Edit(Project Project) { Project oProject = new Project(); oProject.ProjectID = System.Convert.ToInt32(Project.ProjectID); oProject = ProjectData.Select_Record(Project); if (ModelState.IsValid) { bool bSucess = false; bSucess = ProjectData.Update(oProject, Project); if (bSucess == true) { return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "Can Not Update"); } } // ComboBox ViewData["ProjectStatusID"] = new SelectList(Project_ProjectStatusData.List(), "ProjectStatusID", "ProjectStatusName", Project.ProjectStatusID); ViewData["ClientID"] = new SelectList(Project_ClientData.List(), "ClientID", "ClientName", Project.ClientID); ViewData["ArchitectID"] = new SelectList(Project_ArchitectData.List(), "ArchitectID", "ArchitectName", Project.ArchitectID); ViewData["CompanyID"] = new SelectList(Project_CompanyData.List(), "CompanyID", "CompanyName", Project.CompanyID); return(View(Project)); }
// GET: /Project/Edit/<id> public ActionResult Edit( Int32?ProjectID ) { if ( ProjectID == null ) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Project Project = new Project(); Project.ProjectID = System.Convert.ToInt32(ProjectID); Project = ProjectData.Select_Record(Project); if (Project == null) { return(HttpNotFound()); } // ComboBox ViewData["ProjectStatusID"] = new SelectList(Project_ProjectStatusData.List(), "ProjectStatusID", "ProjectStatusName", Project.ProjectStatusID); ViewData["ClientID"] = new SelectList(Project_ClientData.List(), "ClientID", "ClientName", Project.ClientID); ViewData["ArchitectID"] = new SelectList(Project_ArchitectData.List(), "ArchitectID", "ArchitectName", Project.ArchitectID); ViewData["CompanyID"] = new SelectList(Project_CompanyData.List(), "CompanyID", "CompanyName", Project.CompanyID); return(View(Project)); }
// GET: /Project/Create public ActionResult Create() { // ComboBox ViewData["ProjectStatusID"] = new SelectList(Project_ProjectStatusData.List(), "ProjectStatusID", "ProjectStatusName"); ViewData["ClientID"] = new SelectList(Project_ClientData.List(), "ClientID", "ClientName"); ViewData["ArchitectID"] = new SelectList(Project_ArchitectData.List(), "ArchitectID", "ArchitectName"); ViewData["CompanyID"] = new SelectList(Project_CompanyData.List(), "CompanyID", "CompanyName"); return(View()); }
// GET: /Project/Delete/<id> public ActionResult Delete( Int32?ProjectID ) { if ( ProjectID == null ) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } dtProjectStatus = Project_ProjectStatusData.SelectAll(); dtClient = Project_ClientData.SelectAll(); dtArchitect = Project_ArchitectData.SelectAll(); dtCompany = Project_CompanyData.SelectAll(); Project Project = new Project(); Project.ProjectID = System.Convert.ToInt32(ProjectID); Project = ProjectData.Select_Record(Project); Project.ProjectStatus = new ProjectStatus() { ProjectStatusID = (Int32)Project.ProjectStatusID , ProjectStatusName = (from DataRow rowProjectStatus in dtProjectStatus.Rows where Project.ProjectStatusID == (int)rowProjectStatus["ProjectStatusID"] select(String) rowProjectStatus["ProjectStatusName"]).FirstOrDefault() }; Project.Client = new Client() { ClientID = (Int32)Project.ClientID , ClientName = (from DataRow rowClient in dtClient.Rows where Project.ClientID == (int)rowClient["ClientID"] select(String) rowClient["ClientName"]).FirstOrDefault() }; Project.Architect = new Architect() { ArchitectID = (Int32)Project.ArchitectID , ArchitectName = (from DataRow rowArchitect in dtArchitect.Rows where Project.ArchitectID == (int)rowArchitect["ArchitectID"] select(String) rowArchitect["ArchitectName"]).FirstOrDefault() }; Project.Company = new Company() { CompanyID = (Int32)Project.CompanyID , CompanyName = (from DataRow rowCompany in dtCompany.Rows where Project.CompanyID == (int)rowCompany["CompanyID"] select(String) rowCompany["CompanyName"]).FirstOrDefault() }; if (Project == null) { return(HttpNotFound()); } return(View(Project)); }
public ActionResult Create([Bind(Include = "ProjectName" + "," + "BillingName" + "," + "Description" + "," + "Location" + "," + "StartDate" + "," + "EndDate" + "," + "ProjectStatusID" + "," + "ClientID" + "," + "ArchitectID" + "," + "CompanyID" + "," + "AddUserID" + "," + "AddDate" + "," + "ArchiveUserID" + "," + "ArchiveDate" )] Project Project) { if (ModelState.IsValid) { bool bSucess = false; bSucess = ProjectData.Add(Project); if (bSucess == true) { return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "Can Not Insert"); } } // ComboBox ViewData["ProjectStatusID"] = new SelectList(Project_ProjectStatusData.List(), "ProjectStatusID", "ProjectStatusName", Project.ProjectStatusID); ViewData["ClientID"] = new SelectList(Project_ClientData.List(), "ClientID", "ClientName", Project.ClientID); ViewData["ArchitectID"] = new SelectList(Project_ArchitectData.List(), "ArchitectID", "ArchitectName", Project.ArchitectID); ViewData["CompanyID"] = new SelectList(Project_CompanyData.List(), "CompanyID", "CompanyName", Project.CompanyID); return(View(Project)); }
// GET: /Project/ 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 ? "Project 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["ProjectIDSortParm"] = sortOrder == "ProjectID_asc" ? "ProjectID_desc" : "ProjectID_asc"; ViewData["ProjectNameSortParm"] = sortOrder == "ProjectName_asc" ? "ProjectName_desc" : "ProjectName_asc"; ViewData["BillingNameSortParm"] = sortOrder == "BillingName_asc" ? "BillingName_desc" : "BillingName_asc"; ViewData["DescriptionSortParm"] = sortOrder == "Description_asc" ? "Description_desc" : "Description_asc"; ViewData["LocationSortParm"] = sortOrder == "Location_asc" ? "Location_desc" : "Location_asc"; ViewData["StartDateSortParm"] = sortOrder == "StartDate_asc" ? "StartDate_desc" : "StartDate_asc"; ViewData["EndDateSortParm"] = sortOrder == "EndDate_asc" ? "EndDate_desc" : "EndDate_asc"; ViewData["ProjectStatusIDSortParm"] = sortOrder == "ProjectStatusID_asc" ? "ProjectStatusID_desc" : "ProjectStatusID_asc"; ViewData["ClientIDSortParm"] = sortOrder == "ClientID_asc" ? "ClientID_desc" : "ClientID_asc"; ViewData["ArchitectIDSortParm"] = sortOrder == "ArchitectID_asc" ? "ArchitectID_desc" : "ArchitectID_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"; dtProject = ProjectData.SelectAll(); dtProjectStatus = Project_ProjectStatusData.SelectAll(); dtClient = Project_ClientData.SelectAll(); dtArchitect = Project_ArchitectData.SelectAll(); dtCompany = Project_CompanyData.SelectAll(); try { if (!string.IsNullOrEmpty(Convert.ToString(Session["SearchField"])) & !string.IsNullOrEmpty(Convert.ToString(Session["SearchCondition"])) & !string.IsNullOrEmpty(Convert.ToString(Session["SearchText"]))) { dtProject = ProjectData.Search(Convert.ToString(Session["SearchField"]), Convert.ToString(Session["SearchCondition"]), Convert.ToString(Session["SearchText"])); } } catch { } var Query = from rowProject in dtProject.AsEnumerable() join rowProjectStatus in dtProjectStatus.AsEnumerable() on rowProject.Field <Int32>("ProjectStatusID") equals rowProjectStatus.Field <Int32>("ProjectStatusID") join rowClient in dtClient.AsEnumerable() on rowProject.Field <Int32>("ClientID") equals rowClient.Field <Int32>("ClientID") join rowArchitect in dtArchitect.AsEnumerable() on rowProject.Field <Int32>("ArchitectID") equals rowArchitect.Field <Int32>("ArchitectID") join rowCompany in dtCompany.AsEnumerable() on rowProject.Field <Int32?>("CompanyID") equals rowCompany.Field <Int32>("CompanyID") select new Project() { ProjectID = rowProject.Field <Int32>("ProjectID") , ProjectName = rowProject.Field <String>("ProjectName") , BillingName = rowProject.Field <String>("BillingName") , Description = rowProject.Field <String>("Description") , Location = rowProject.Field <String>("Location") , StartDate = rowProject.Field <DateTime>("StartDate") , EndDate = rowProject.Field <DateTime?>("EndDate") , ProjectStatus = new ProjectStatus() { ProjectStatusID = rowProjectStatus.Field <Int32>("ProjectStatusID") , ProjectStatusName = rowProjectStatus.Field <String>("ProjectStatusName") } , Client = new Client() { ClientID = rowClient.Field <Int32>("ClientID") , ClientName = rowClient.Field <String>("ClientName") } , Architect = new Architect() { ArchitectID = rowArchitect.Field <Int32>("ArchitectID") , ArchitectName = rowArchitect.Field <String>("ArchitectName") } , Company = new Company() { CompanyID = rowCompany.Field <Int32>("CompanyID") , CompanyName = rowCompany.Field <String>("CompanyName") } , AddUserID = rowProject.Field <Int32>("AddUserID") , AddDate = rowProject.Field <DateTime>("AddDate") , ArchiveUserID = rowProject.Field <Int32?>("ArchiveUserID") , ArchiveDate = rowProject.Field <DateTime?>("ArchiveDate") }; switch (sortOrder) { case "ProjectID_desc": Query = Query.OrderByDescending(s => s.ProjectID); break; case "ProjectID_asc": Query = Query.OrderBy(s => s.ProjectID); break; case "ProjectName_desc": Query = Query.OrderByDescending(s => s.ProjectName); break; case "ProjectName_asc": Query = Query.OrderBy(s => s.ProjectName); break; case "BillingName_desc": Query = Query.OrderByDescending(s => s.BillingName); break; case "BillingName_asc": Query = Query.OrderBy(s => s.BillingName); break; case "Description_desc": Query = Query.OrderByDescending(s => s.Description); break; case "Description_asc": Query = Query.OrderBy(s => s.Description); break; case "Location_desc": Query = Query.OrderByDescending(s => s.Location); break; case "Location_asc": Query = Query.OrderBy(s => s.Location); break; case "StartDate_desc": Query = Query.OrderByDescending(s => s.StartDate); break; case "StartDate_asc": Query = Query.OrderBy(s => s.StartDate); break; case "EndDate_desc": Query = Query.OrderByDescending(s => s.EndDate); break; case "EndDate_asc": Query = Query.OrderBy(s => s.EndDate); break; case "ProjectStatusID_desc": Query = Query.OrderByDescending(s => s.ProjectStatus.ProjectStatusName); break; case "ProjectStatusID_asc": Query = Query.OrderBy(s => s.ProjectStatus.ProjectStatusName); break; case "ClientID_desc": Query = Query.OrderByDescending(s => s.Client.ClientName); break; case "ClientID_asc": Query = Query.OrderBy(s => s.Client.ClientName); break; case "ArchitectID_desc": Query = Query.OrderByDescending(s => s.Architect.ArchitectName); break; case "ArchitectID_asc": Query = Query.OrderBy(s => s.Architect.ArchitectName); 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.ProjectID); break; } if (command == "Export") { GridView gv = new GridView(); DataTable dt = new DataTable(); dt.Columns.Add("Project I D", typeof(string)); dt.Columns.Add("Project Name", typeof(string)); dt.Columns.Add("Billing Name", typeof(string)); dt.Columns.Add("Description", typeof(string)); dt.Columns.Add("Location", typeof(string)); dt.Columns.Add("Start Date", typeof(string)); dt.Columns.Add("End Date", typeof(string)); dt.Columns.Add("Project Status I D", typeof(string)); dt.Columns.Add("Client I D", typeof(string)); dt.Columns.Add("Architect I D", 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.ProjectID , item.ProjectName , item.BillingName , item.Description , item.Location , item.StartDate , item.EndDate , item.ProjectStatus.ProjectStatusName , item.Client.ClientName , item.Architect.ArchitectName , 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)))); }