protected void dsLoc_Selecting(object sender, Microsoft.AspNet.EntityDataSource.EntityDataSourceSelectingEventArgs e) { eCAR3Entities pContext = new eCAR3Entities(); // We need constants for these! List <String> pLocs = LocTreeCache.GetCreateLocsForUser(User.UserId, 0x0002); if (pLocs == null) { return; } StringBuilder sb = new StringBuilder(); int i = 0; // This works to get all of them foreach (string pLoc in pLocs) { if (i > 0) { sb.Append(","); } sb.Append("'" + pLoc + "'"); i++; } e.DataSource.Where = string.Format("it.RowKey in {{{0}}}", sb.ToString()); }
protected void btnSpoof_Click(object sender, EventArgs e) { // Not sure we can update the view - let's see what this does // We should add an error panel to the root view? if (cbSpoofUsers.SelectedItem == null) { return; } eCAR3Entities pContext = new eCAR3Entities(); ListEditItem pItem = cbSpoofUsers.SelectedItem; int nId = (int)pItem.Value; CARUser pUser = pContext.CARUsers.Single(x => x.UserId == nId); if (Session [SessionVars.MkCurUserId] != null && nId == (int)Session [SessionVars.MkCurUserId]) { Session [SessionVars.MkSpoofId] = null; // Back to originally logged on user } else { Session [SessionVars.MkSpoofId] = nId; } Session [SessionVars.MkCurUserId] = nId; Session [SessionVars.MkCurUserName] = pUser.UserName; Session [SessionVars.MkCurUserBits] = pUser.RoleBits; // Redirect to default page - this might not be a valid page any more! Response.Redirect("~/Default.aspx"); }
protected void Page_Init(object sender, EventArgs e) { PageContext = new eCAR3Entities(); // For debugging only (with security turned off) String sUserEMail = Context.User.Identity.Name; if (sUserEMail.Length == 0 && Request.IsLocal) { String sDefaultUser = System.Configuration.ConfigurationManager.AppSettings ["DefaultUser"]; if (sDefaultUser != null) { sUserEMail = sDefaultUser; } } // Context.User.Identity.Name - is actually the user's e-mail address // We'll get the name from the database if (sUserEMail != (string)Session [SessionVars.MkLoginEMail]) { // This would actually fail if a user is logged in and THEN we delete him, since we don't check on every page load // We can change this if necessary, but this performs better CARUser pUserRow; pUserRow = PageContext.CARUsers.FirstOrDefault(x => x.UserEMail == sUserEMail); // Get our user // We are doing this on every page load for now // We can refine this later if (pUserRow == null) { Response.Redirect("/Unauthorized.aspx"); return; } // We can have a separate page for incorrect privileges! // For now - you need SOME privileges - this is just for testing if (pUserRow.UserRoles.Count == 0) { Response.Redirect("/Unauthorized.aspx"); return; } Session [SessionVars.MkLoginEMail] = pUserRow.UserEMail; Session [SessionVars.MkLoginId] = pUserRow.UserId; Session [SessionVars.MkLoginName] = pUserRow.UserName; Session [SessionVars.MkLoginUserBits] = pUserRow.RoleBits; // This should happen on the first login only Session [SessionVars.MkCurUserId] = pUserRow.UserId; Session [SessionVars.MkCurUserName] = pUserRow.UserName; Session [SessionVars.MkCurUserBits] = pUserRow.RoleBits; } // Set our common session variables // This could be a function with a try/catch! SetSessionInt(SessionVars.MkWA); SetSessionInt(SessionVars.MkCAR); }
// This is the same as above, except with the addition of a comment to the WF protected void cbModal_Callback(object sender, CallbackEventArgsBase e) { // Create the comment eCAR3Entities pContext = new eCAR3Entities(); CARComment pComment = new CARComment(); pComment.Comments = memoComments.Text; pComment.UserId = User.UserId; pComment.CARId = CAR.CARId; pComment.Flags = 0; pComment.Recommendation = 0; int wfAssignID = 0; if (Assignment != null) { wfAssignID = Assignment.WFAssignId; } else { //Find the associated WFAssign Id for admin wfAssignID = FindAdminAssignmentID(); } pComment.WFAssignId = wfAssignID; pContext.CARComments.Add(pComment); pComment.Timestmp = DateTime.Now; pContext.SaveChanges(); memoComments.Text = ""; //Clear the memo text }
// This is the same as above, except with the addition of a comment to the WF protected void cbComments_Callback(object sender, CallbackEventArgsBase e) { String sAction = e.Parameter; //Updating the default comments string mainComments = ""; switch (sAction) { case "Approve": mainComments = "Approved."; break; case "Revise/Hold": mainComments = "Sending to creator for revision because - " + txtComments.Text; break; case "Decline": mainComments = "This was declined because - " + txtComments.Text; break; default: mainComments = "n/a"; break; } // Add the comment to the CAR - we'll also add it to the assignment // For now - find the workflow item if (Assignment != null) { eCAR3Entities pContext = new eCAR3Entities(); CARComment pComment = new CARComment(); pComment.Comments = mainComments; pComment.UserId = User.UserId; pComment.CARId = CAR.CARId; pComment.Flags = 0; pComment.Recommendation = 0; pComment.WFAssignId = Assignment.WFAssignId; pContext.CARComments.Add(pComment); pComment.Timestmp = DateTime.Now; pContext.SaveChanges(); // We found a winner! // OK - we should now have the assignment ID right in the workflow item! WFEngine pWFEngine = GetWFEngine(); // Handle item with the specified action pWFEngine.HandleItemAsync(Assignment.WFAssignId, sAction, mainComments); // Change to this if we put this in a callback! ASPxWebControl.RedirectOnCallback("/Default.aspx"); } }
protected void treePillar_CustomJSProperties(object sender, TreeListCustomJSPropertiesEventArgs e) { eCAR3Entities pContext = new eCAR3Entities(); Hashtable pHash = new Hashtable(); foreach (Pillar pRow in pContext.Pillars) { pHash.Add(pRow.PillarId, pRow.Name); } e.Properties["cpNames"] = pHash; }
protected void treeLocation_CustomJSProperties(object sender, TreeListCustomJSPropertiesEventArgs e) { eCAR3Entities pContext = new eCAR3Entities(); Hashtable pHash = new Hashtable(); foreach (vLocTree pRow in pContext.vLocTrees.Where(x => x.RowKey.StartsWith("L"))) { pHash.Add(pRow.RowKey, pRow.Name); } e.Properties["cpNames"] = pHash; }
public void AddCostSheet(eCAR3Entities PpContext, int PnCARId, int PnCategory) { CostSheet pSheet = new CostSheet(); pSheet.CARId = PnCARId; pSheet.Category = PnCategory.ToString(); pSheet.Capital = 0; pSheet.Expense = 0; pSheet.OperLease = 0; pSheet.Percentage = 0; pSheet.CreateTime = DateTime.Now; PpContext.CostSheets.Add(pSheet); }
protected void Page_Load(object sender, EventArgs e) { eCAR3Entities pContext = new eCAR3Entities(); int nLoggedInUserBits = 0; if (Session [SessionVars.MkLoginUserBits] != null) { nLoggedInUserBits = (int)Session [SessionVars.MkLoginUserBits]; } // Prevent spoof unless you are the right person... if ((nLoggedInUserBits & Role.ALLOWSPOOF) != 0) { cbSpoofUsers.Items.Clear(); // Add some logins here to the spoof panel foreach (CARUser pUser in pContext.CARUsers.Where(x => x.Active).OrderBy(x => x.UserName)) { ListEditItem pItem = new ListEditItem(pUser.UserName, pUser.UserId); cbSpoofUsers.Items.Add(pItem); } } else { pnlSpoof.Visible = false; } // FIX THIS! //#PFG int iBits = 0; try { iBits = (int)Session [SessionVars.MkCurUserBits]; } catch { } LoadMenu(); ASPxLabel2.Text = Server.HtmlDecode("Copyright © " + DateTime.Now.Year + " by Smithfield Foods, Inc."); }
protected void cbCreateCAR_Callback(object source, CallbackEventArgs e) { // Create a new CAR here and redirect to its page... eCAR3Entities pContext = new eCAR3Entities(); CARMaster pCAR = new CARMaster(); string[] parameters = e.Parameter.Split(';'); string orgInformation = parameters[0]; // orgId + '|' + locName + '|' + orgPath; string orgId = orgInformation.Split('|')[0]; string orgLocationName = orgInformation.Split('|')[1]; string orgPath = orgInformation.Split('|')[2]; var divisonCharacter = orgPath.Substring(0, 1).ToUpper(); //var threeCharacterLocation = orgLocationName.Replace(/\s +/ g, '').replace(/\./ g, '').substring(0, 3).toUpperCase(); var threeCharacterLocation = orgLocationName.Substring(0, 3).ToUpper(); var twoDigitYear = DateTime.Now.Year.ToString().Substring(2, 2); // produces two digit year -- Ex. 2019 = "19" var threeDigitUniqueSequence = "XXX"; // The database trigger will make this a unique sequential number. var projectNumber = divisonCharacter + '-' + threeCharacterLocation + '-' + twoDigitYear + '-' + threeDigitUniqueSequence; string pillarInformation = parameters[1]; // pillarId + '|' + pillarName + '|' + decr; string pillarId = pillarInformation.Split('|')[0]; string pillarName = pillarInformation.Split('|')[1]; string pillarDescr = pillarInformation.Split('|')[2]; pCAR.OrgId = orgId; pCAR.ProjectNumber = projectNumber; pCAR.CreatedByUserId = UserId; pCAR.CreatedByName = UserDisplayName; pCAR.ProjectTitle = txtTitle.Text; pCAR.CreateTime = DateTime.Now; pCAR.ProjectTypeId = cbProjectType.Value.ToString(); // Set the dropdown ProjectTypeId pCAR.InterestRate = 0.000; // Updated Interest Rate to 0.000 pCAR.ExchangeRate = 0; // Updated Exchange Rate to 0 pCAR.UsefulLifeYears = 0; // Updated Useful Life Years to 0 pCAR.LeaseTermYears = 0; // Updated Lease Term Years to 0 pCAR.NPV = 0; // Updated NPV to 0 pCAR.IRR = 0; // Updated IRR to 0 pCAR.CurrencyTypeId = 1; // Updated Currency Type to U.S. Dollar //Set Desc fields to empty pCAR.ProjectDesc = ""; pCAR.ProjectReason = ""; pCAR.ProjectJustification = ""; pCAR.FiscalYear = DateTime.Now.Year; // Updated Fiscal Year to current year pCAR.PillarId = pillarId; // Set the dropdown PillarId pCAR.Status = "Active"; pContext.CARMasters.Add(pCAR); pContext.SaveChanges(); // TODD: If we could remove this it may speed things up a bit. // We now have the CAR Id AddCostSheet(pContext, pCAR.CARId, 1); AddCostSheet(pContext, pCAR.CARId, 2); AddCostSheet(pContext, pCAR.CARId, 3); AddCostSheet(pContext, pCAR.CARId, 4); // Bootstrap the workflow process // This should probably not be here // This should be a function in the workflow engine! WFEngine pEngine = GetWFEngine(); WF pWF = pEngine.CreateWorkflow(pCAR.CARId); // This call assigns the workflow to an individual user string sURL = pEngine.Assign(pWF, "Create", "CREATE", UserId, null, pCAR.CARId.ToString()); // Redirect the users browser to the newly create CAR. //ASPxWebControl.RedirectOnCallback(sURL); // I removed this because the line below may be a tiny bit faster. cbCreateCAR.JSProperties ["cp_result"] = sURL; // Return to the client side where the JavaScript redirects to this CAR page. }