public List <Entity> updateRequests(iGna iGouna, EntityCollection LaunchRequests, IOrganizationService _service, ITracingService tracingService) { for (int i = 0; i < iGouna.M.Count; i++) { for (int j = 0; j < iGouna.M[i].Unt.Count; j++) { var clientArray = iGouna.M[i].Clnt.Split('$'); if (clientArray[0] == "customer") { tracingService.Trace("E1.1"); LaunchRequests.Entities.Where(x => x.Contains("ldv_customerid") && ((EntityReference)x["ldv_unitid"]).Id == new Guid(iGouna.M[i].Unt[j]) && ((EntityReference)x["ldv_customerid"]).Id == new Guid(clientArray[1]) && ((OptionSetValue)x["ldv_prioritycode"]).Value == int.Parse(iGouna.M[i].Pr)).ToList().ForEach(x => x["ldv_statuscode"] = new OptionSetValue(3));//won tracingService.Trace("E1.2"); } else if (clientArray[0] == "lead") { tracingService.Trace("E1.3"); LaunchRequests.Entities.Where(x => x.Contains("ldv_leadid") && ((EntityReference)x["ldv_unitid"]).Id == new Guid(iGouna.M[i].Unt[j]) && ((EntityReference)x["ldv_leadid"]).Id == new Guid(clientArray[1]) && ((OptionSetValue)x["ldv_prioritycode"]).Value == int.Parse(iGouna.M[i].Pr)).ToList().ForEach(x => x["ldv_statuscode"] = new OptionSetValue(3));//won tracingService.Trace("E1.4"); } } } tracingService.Trace("E1111"); var updateRequestStatus = new List <Entity>(); if (LaunchRequests.Entities.Count > 0) { for (int i = 0; i < LaunchRequests.Entities.Count; i++) { //change draft requests to lost. if (((OptionSetValue)LaunchRequests[i]["ldv_statuscode"]).Value == 1) //draft { LaunchRequests[i]["ldv_statuscode"] = new OptionSetValue(4); //lost } Entity updateRequest = new Entity("ldv_launchrequest", LaunchRequests.Entities[i].Id); updateRequest["ldv_statuscode"] = LaunchRequests.Entities[i]["ldv_statuscode"]; updateRequest["statecode"] = new OptionSetValue(1); //inactive try { _service.Update(updateRequest); } catch (Exception ex) { updateRequestStatus.Add(LaunchRequests.Entities[i]); } } } return(updateRequestStatus); }
public bool updateResultDocuments(iGna iGouna, IOrganizationService _service, EntityReference currentProject, ITracingService tracingService) { #region Statistics Result tracingService.Trace("F1"); if (currentProject == null) { tracingService.Trace("F2"); } Entity _annotation = new Entity("annotation"); _annotation.Attributes["objectid"] = currentProject; // related entity _annotation.Attributes["objecttypecode"] = "new_project"; //related entitylogicalname _annotation.Attributes["subject"] = $"Launch Request Result - {DateTime.Now.ToString()}"; //Selected Units / Total Units = 91 / 825 //<D rst="13" unt="13" Eff="100.00"/> if (iGouna.D == null) { tracingService.Trace("F3"); } if (iGouna.D.rst == null) { tracingService.Trace("F4"); } if (iGouna.D.unt == null) { tracingService.Trace("F5"); } if (iGouna.D.Eff == null) { tracingService.Trace("F6"); } if (iGouna.D.MsdUnt == null) { tracingService.Trace("F7"); } _annotation.Attributes["notetext"] = $"Selected Units / Total Units = {iGouna.D.rst} / {iGouna.D.unt} Efficiency={iGouna.D.Eff}"; tracingService.Trace("F8"); _service.Create(_annotation); #endregion return(false); }
public iGna Deserialize(string input, ITracingService tracingService) { tracingService.Trace(input); var result = new iGna(); result.M = new List <ClientResult>(); XDocument doc = XDocument.Parse(input); //deserialize every M row in result foreach (XElement xe in doc.Descendants("M")) { ClientResult currentResult = new ClientResult(); currentResult.Clnt = xe.Attribute("Clnt").Value; currentResult.Pr = xe.Attribute("Pr").Value; currentResult.Cnt = xe.Attribute("Cnt").Value; result.M.Add(currentResult); //split units from comma separated to input to class var units = (xe.Attribute("Unt").Value.Split(',')); for (int i = 0; i < units.Length; i++) { currentResult.Unt.Add(units[i]); } } //statistcs result, bottom row foreach (XElement xe in doc.Descendants("D")) { StaticsResults currentResult = new StaticsResults(); currentResult.rst = xe.Attribute("rst").Value; currentResult.unt = xe.Attribute("unt").Value; currentResult.Eff = xe.Attribute("Eff").Value; if (xe.Attribute("MsdUnt") != null) { currentResult.MsdUnt = xe.Attribute("MsdUnt").Value; } result.D = currentResult; } return(result); }
public static bool generateExcelResult(iGna iGouna, EntityCollection allLaunchRequests, EntityReference currentProject, IOrganizationService _service, ITracingService tracingService) { tracingService.Trace("G1"); //1- Get Excel Template Record; var templateQuery = new QueryExpression() { EntityName = "ldv_exceltemplate", }; templateQuery.Criteria.AddCondition(new ConditionExpression("statecode", ConditionOperator.Equal, 0)); templateQuery.Criteria.AddCondition(new ConditionExpression("ldv_name", ConditionOperator.Equal, "Launch Request Results")); var templateObj = _service.RetrieveMultiple(templateQuery).Entities.FirstOrDefault(); if (templateQuery != null) { tracingService.Trace("G2"); var templateFileQe = new QueryExpression() { EntityName = "annotation", ColumnSet = new ColumnSet("filename", "documentbody", "mimetype") }; templateFileQe.Criteria.AddCondition(new ConditionExpression("objectid", ConditionOperator.Equal, templateObj.Id)); tracingService.Trace("G3"); var _file = _service.RetrieveMultiple(templateFileQe).Entities.FirstOrDefault(); tracingService.Trace("G3.1"); tracingService.Trace("file " + (_file == null).ToString()); var fileName = _file.GetAttributeValue <string>("filename"); tracingService.Trace("G3.2"); var bytes = Convert.FromBase64String(_file.GetAttributeValue <string>("documentbody")); var mimetype = _file.GetAttributeValue <string>("mimetype"); Stream stream = new MemoryStream(bytes); ExcelPackage pck = new ExcelPackage(stream); //Assign Unit and Sale Data var wb = pck.Workbook; var ws = wb.Worksheets[1]; //Project Name ws.Cells["A1"].Value = "Project Name: " + currentProject.Name; var wonRequestsCustomers = allLaunchRequests.Entities.Where(x => ((OptionSetValue)x.Attributes["ldv_statuscode"]).Value == 3 && x.Contains("ldv_customerid")).GroupBy(x => ((EntityReference)x["ldv_customerid"])).ToList(); var wonRequestLeads = allLaunchRequests.Entities.Where(x => ((OptionSetValue)x.Attributes["ldv_statuscode"]).Value == 3 && x.Contains("ldv_leadid")).GroupBy(x => ((EntityReference)x["ldv_leadid"])).ToList(); tracingService.Trace("G4"); for (int i = 0; i < wonRequestsCustomers.Count; i++) { //serial number ws.Cells["A" + (3 + i)].Value = i + 1; //Client ws.Cells["B" + (3 + i)].Value = wonRequestsCustomers[i].Key.Name; //client Type ws.Cells["C" + (3 + i)].Value = "Customer"; //Client Type var currentRequests = wonRequestsCustomers[i].ToList(); //Unit Comma Separated var unitsNamesWon = ""; for (int j = 0; j < currentRequests.Count; j++) { if (j == 0) { unitsNamesWon = ((EntityReference)currentRequests[j]["ldv_unitid"]).Name; } else { unitsNamesWon = unitsNamesWon + "," + ((EntityReference)currentRequests[j]["ldv_unitid"]).Name; } } ws.Cells["D" + (3 + i)].Value = unitsNamesWon; ws.Cells["D" + (3 + i)].Style.WrapText = true; //Order if (wonRequestsCustomers[i].ToList()[0].Contains("ldv_order")) { ws.Cells["E" + (3 + i)].Value = wonRequestsCustomers[i].ToList()[0]["ldv_order"]; } //Priority ws.Cells["F" + (3 + i)].Value = wonRequestsCustomers[i].ToList()[0].FormattedValues["ldv_prioritycode"]; //Owner ws.Cells["G" + (3 + i)].Value = ((EntityReference)wonRequestsCustomers[i].ToList()[0]["ownerid"]).Name; } tracingService.Trace("G5"); var customerCount = wonRequestsCustomers.Count; for (int i = 0; i < wonRequestLeads.Count; i++) { //serial number ws.Cells["A" + (3 + i + customerCount)].Value = i + 1 + customerCount; //Client ws.Cells["B" + (3 + i + customerCount)].Value = wonRequestLeads[i].Key.Name; //client Type ws.Cells["C" + (3 + i + customerCount)].Value = "Lead"; //Client Type var currentRequests = wonRequestLeads[i].ToList(); //Unit Comma Separated var unitsNamesWon = ""; for (int j = 0; j < currentRequests.Count; j++) { if (j == 0) { unitsNamesWon = ((EntityReference)currentRequests[j]["ldv_unitid"]).Name; } else { unitsNamesWon = unitsNamesWon + "," + ((EntityReference)currentRequests[j]["ldv_unitid"]).Name; } } ws.Cells["D" + (3 + i + customerCount)].Value = unitsNamesWon; ws.Cells["D" + (3 + i)].Style.WrapText = true; //Order ws.Cells["E" + (3 + i + customerCount)].Value = wonRequestLeads[i].ToList()[0]["ldv_order"]; //Priority ws.Cells["F" + (3 + i + customerCount)].Value = wonRequestLeads[i].ToList()[0].FormattedValues["ldv_prioritycode"]; //Owner ws.Cells["G" + (3 + i + customerCount)].Value = ((EntityReference)wonRequestLeads[i].ToList()[0]["ownerid"]).Name; } //autofit units column //ws.Column(4).AutoFit(); //tracingService.Trace("before autofit"); //ws.Column(4).AutoFit(0, 100); //tracingService.Trace("after autofit"); tracingService.Trace("G6"); //Statistics ws.Cells["K2"].Value = iGouna.D.rst; ws.Cells["K3"].Value = iGouna.D.unt; ws.Cells["K4"].Value = iGouna.D.Eff; #region table styling int firstColumn = 1; int lastColumn = 7; int firstRow = 2; int lastRow = customerCount + wonRequestLeads.Count + 2; ExcelRange rg = ws.Cells[firstRow, firstColumn, lastRow, lastColumn]; ExcelTable tab = ws.Tables.Add(rg, "Table123"); tab.TableStyle = TableStyles.Medium2; //ws.Cells[ws.Dimension.Address].AutoFitColumns(); //Worksheet.Cells[Worksheet.Dimension.Address].AutoFitColumns(); #endregion //tracingService.Trace("before getbyte"); var UpdatedBytes = pck.GetAsByteArray(); //tracingService.Trace("after getbyte"); var baseString = Convert.ToBase64String(UpdatedBytes); //tracingService.Trace("converted to base64"); //Create Annotation Entity _annotation = new Entity("annotation"); _annotation["documentbody"] = baseString; _annotation["mimetype"] = mimetype; _annotation["filename"] = currentProject.Name + " Launch Results - " + DateTime.Now.ToString("f") + ".xlsx"; _annotation["isdocument"] = true; _annotation["objectid"] = currentProject; #region Statistics Result tracingService.Trace("F1"); if (currentProject == null) { tracingService.Trace("F2"); } //Selected Units / Total Units = 91 / 825 //<D rst="13" unt="13" Eff="100.00"/> if (iGouna.D == null) { tracingService.Trace("F3"); } if (iGouna.D.rst == null) { tracingService.Trace("F4"); } if (iGouna.D.unt == null) { tracingService.Trace("F5"); } if (iGouna.D.Eff == null) { tracingService.Trace("F6"); } if (iGouna.D.MsdUnt == null) { tracingService.Trace("F7"); } _annotation.Attributes["subject"] = $"Launch Request Result - {DateTime.Now.ToString()}"; _annotation.Attributes["notetext"] = $"Selected Units / Total Units = {iGouna.D.rst} / {iGouna.D.unt} Efficiency={iGouna.D.Eff}"; tracingService.Trace("F8"); _service.Create(_annotation); #endregion var id = _service.Create(_annotation); tracingService.Trace("end of all"); } return(false); }