public void UpdateStatus(string statusStripMessage, bool incrementProgress = true) { //SyncLock ThreadLockObj bool stillAddingFunctions = MatManFunctionCollection.GetObject().StillAddingFunctions; //int functionsRemainingInQueue = PWFunctionCollection.GetObject().Count; int totalFunctionsAddedToQueue = MatManFunctionCollection.GetObject().TotalFunctionsAddedToQueue + 1; int totalProcessedBySAP = SAPRequest.GetObject().TotalProcessedBySAP; this.ElapsedTime = DateTime.Now - this.ProcessStartTime; if (totalProcessedBySAP < 1) { // report progress of RTD reading functions into batch if (ElapsedTime.TotalSeconds > 0) { // Update the CalculationCount text box this.uxCalculationCountTextBox.Text = totalFunctionsAddedToQueue.ToString() + " functions in processing queue..."; // Update the Balance Records Text Box this.uxBalanceRecordsSummedTextBox.Text = totalFunctionsAddedToQueue.ToString() + "...pending"; // Update the CalculationTimeTextBox decimal processRate = Convert.ToDecimal(totalFunctionsAddedToQueue / ElapsedTime.TotalSeconds); uxCalculationTimeTextBox.Text = ElapsedTime.Minutes.ToString() + " : " + ElapsedTime.Seconds.ToString() + " at " + processRate.ToString("0.00") + " cells/sec"; StatusStrip.Text = statusStripMessage; } } else if (totalProcessedBySAP >= 1) { if (ElapsedTime.TotalSeconds > 0) { //Update the CalculationCount text box this.uxCalculationCountTextBox.Text = totalFunctionsAddedToQueue.ToString() + " functions being processed by SAP..."; // Update the Balance Records Text Box this.uxBalanceRecordsSummedTextBox.Text = totalProcessedBySAP.ToString(); // Update the CalculationTimeTextBox decimal processRate = Convert.ToDecimal(totalProcessedBySAP / ElapsedTime.TotalSeconds); uxCalculationTimeTextBox.Text = ElapsedTime.Minutes.ToString() + " : " + ElapsedTime.Seconds.ToString() + " at " + processRate.ToString("0.00") + " cells/sec"; StatusStrip.Text = statusStripMessage; } } this.Refresh(); }
public static void ClearPreviousRun() { MatManFunctionCollection.GetObject().Clear(); MatManFunctionCollection.GetObject().TotalFunctionsAddedToQueue = 0; SAPRequest.GetObject().TotalProcessedBySAP = 0; SAPRequest.ReturnValuesList.Clear(); //MatManCalcEngine.GetObject().CurrentFunctionsByCellAddress.Clear(); //MatManCalcEngine.GetObject().ConnectDataCount = 0; //MatManCalcEngine.GetObject().TopicCount = 0; //MatManCalcEngine.GetObject().UserInitiatedCalc = true; }
public static SAPRequest GetObject() { if (SAPRequest.m_sapRequest == null) { lock (syncRoot) { if (SAPRequest.m_sapRequest == null) { SAPRequest.m_sapRequest = new SAPRequest(); } } } return(SAPRequest.m_sapRequest); }
/// <summary> /// Sends the Batch to SAP - This would be part of processing functions phase /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void myBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { this.ProcessStartTime = DateTime.Now; MatManFunctionCollection.GetObject().Clear(); MatManFunctionCollection.GetObject().TotalFunctionsAddedToQueue = 0; //SAPRequest.GetObject().FunctionBatch.Clear() SAPRequest.GetObject().TotalProcessedBySAP = 0; m_cancelOperation = false; Thread.Sleep(2000); while (true) { if ((MatManFunctionCollection.GetObject().Count > 0 && m_executeFunctions && !m_isRunning)) { m_isRunning = true; FunctionExecutionType functionType = (FunctionExecutionType)Properties.Settings.Default.FunctionExecutionType; SAPRequest.GetObject().ProcessSAPRequests(functionType, Settings.Default.MaximumBatchSize); } if (m_cancelOperation) { MatManFunctionCollection.GetObject().StillAddingFunctions = true; m_executeFunctions = false; m_isRunning = true; break; // TODO: might not be correct. Was : Exit While } System.Threading.Thread.Sleep(250); //' Breaks us out of while loop if ((SAPRequest.GetObject().TotalProcessedBySAP == MatManFunctionCollection.GetObject().TotalFunctionsAddedToQueue) && m_Progress == 100) { MatManFunctionCollection.GetObject().StillAddingFunctions = true; m_executeFunctions = false; break; } if ((MatManFunctionCollection.GetObject().Count == 0)) { break; } } }
/// <summary> /// OnLoad is overidden to provide localization strings for the form /// </summary> /// <param name="e"></param> protected override void OnLoad(EventArgs e) { // FunctionAdded & Function Removed EventHandlers MatManFunctionCollection.GetObject().OnFunctionAdded += functionCollection_OnFunctionAdded; MatManFunctionCollection.GetObject().OnFunctionRemoved += functionCollection_OnFunctionRemoved; //// FunctionProcessed and BatchCompleted EventHandlers SAPRequest.GetObject().FunctionProcessedBySAP += sapRequest_FunctionProcessedBySAP; m_connectDataCount = 0; this.uxCalculationTimeLabel.Text = iiiwave.MatManLib.Localization.Localize.ReturnProgressDataForm_uxCalculationTimeLabel_Text; this.uxBalanceRecordsSummedLabel.Text = iiiwave.MatManLib.Localization.Localize.ReturnProgressDataForm_uxBalanceRecordsSummedLabel_Text; this.uxCalculationCountLabel.Text = iiiwave.MatManLib.Localization.Localize.ReturnProgressDataForm_uxCalculationCountLabel_Text; this.uxCancelButton.Text = iiiwave.MatManLib.Localization.Localize.ReturnProgressDataForm_uxCancelButton_Text; if (Settings.Default.FunctionExecutionType == (int)FunctionExecutionType.RetrievingData) { this.Text = "Retrieving Data"; } else if (Settings.Default.FunctionExecutionType == (int)FunctionExecutionType.ValidateData) { this.Text = "Validating Data"; } else { this.Text = "Posting Data"; } this.uxCancelButton.Enabled = false; m_cancelOperation = false; // Initialize Form this.uxProgressBar.Value = 0; this.m_Progress = 0; // Initialize counters and booleans MatManFunctionCollection.GetObject().Clear(); // Start the background worker myBackgroundWorker.WorkerReportsProgress = true; myBackgroundWorker.WorkerSupportsCancellation = true; myBackgroundWorker.RunWorkerAsync(); }
/// <summary> /// Function was ADDED to the Queue /// FormProcessState is --> AddingFunctions /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void functionCollection_OnFunctionAdded(object sender, FunctionAddedEventArgs e) { int totalAddedToQueue = e.TotalAddedToQueue; int totalProcessedBySAP = SAPRequest.GetObject().TotalProcessedBySAP; }
protected override void OnFormClosing(FormClosingEventArgs e) { if (m_cancelOperation) { myBackgroundWorker.CancelAsync(); while ((myBackgroundWorker.IsBusy)) { Thread.Sleep(500); continue; } Thread.Sleep(500); OnDataFormClosing?.Invoke(); // Remove event listeners MatManFunctionCollection.GetObject().OnFunctionAdded -= functionCollection_OnFunctionAdded; MatManFunctionCollection.GetObject().OnFunctionRemoved -= functionCollection_OnFunctionRemoved; SAPRequest.GetObject().FunctionProcessedBySAP -= sapRequest_FunctionProcessedBySAP; Thread.Sleep(500); MessageBox.Show(this, "Process has been cancelled"); m_cancelOperation = false; // Clear out PWFunctionCollection completely MatManFunctionCollection.GetObject().Dispose(); // Clear out SAPRequest completely SAPRequest.GetObject().Dispose(); } else { this.uxProgressBar.Value = 100; this.Refresh(); Application.DoEvents(); Thread.Sleep(1000); this.uxProgressBar.Value = 100; this.uxToolStripStatusLabel.Text = "Done"; this.StatusStrip.BackColor = Color.FromArgb(80, 161, 216); this.Refresh(); Application.DoEvents(); OnDataFormClosing?.Invoke(); // Remove event listeners MatManFunctionCollection.GetObject().OnFunctionAdded -= functionCollection_OnFunctionAdded; MatManFunctionCollection.GetObject().OnFunctionRemoved -= functionCollection_OnFunctionRemoved; SAPRequest.GetObject().FunctionProcessedBySAP -= sapRequest_FunctionProcessedBySAP; // Clear out PWFunctionCollection completely MatManFunctionCollection.GetObject().Dispose(); // Clear out SAPRequest completely SAPRequest.GetObject().Dispose(); Thread.Sleep(2000); OnUpdateValues?.Invoke(); } base.OnFormClosing(e); //FileLogger.WriteEntry(System.Reflection.MethodBase.GetCurrentMethod().Name + " " + DateTime.Now.ToString("HH:mm:ss dd-MMM-yyyy") + " -- Trace Type: Stop ") }
private void myBackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { lock (ThreadLockObj) { bool stillAddingFunctions = MatManFunctionCollection.GetObject().StillAddingFunctions; int remainingInQueue = MatManFunctionCollection.GetObject().Count; int totalAddedToQueue = MatManFunctionCollection.GetObject().TotalFunctionsAddedToQueue; int totalProcessedBySAP = SAPRequest.GetObject().TotalProcessedBySAP; decimal progressDec = ((decimal)totalProcessedBySAP / (decimal)totalAddedToQueue) * 100; m_Progress = (int)progressDec; try { this.ElapsedTime = DateTime.Now - this.ProcessStartTime; if (m_cancelOperation) { this.uxProgressBar.Value = 100; this.Refresh(); Application.DoEvents(); } else if (stillAddingFunctions) { if (totalProcessedBySAP < totalAddedToQueue) { //this.uxToolStripStatusLabel.Text = Convert.ToString(e.UserState); this.uxCalculationCountTextBox.Text = "SAP is processing functions..."; this.uxBalanceRecordsSummedTextBox.Text = "Total Functions Queued: " + totalAddedToQueue.ToString() + " -- Processing: " + totalProcessedBySAP.ToString(); // Items being processed by SAP - Update the CalculationTimeTextBox decimal processRate = Convert.ToDecimal(totalProcessedBySAP / ElapsedTime.TotalSeconds); uxCalculationTimeTextBox.Text = totalProcessedBySAP.ToString() + " Functions processed by SAP at " + ElapsedTime.Minutes.ToString() + " : " + ElapsedTime.Seconds.ToString() + "- Process Rate: " + processRate.ToString("0.00") + " cells/sec"; this.uxProgressBar.Value = m_Progress; this.Refresh(); // (2) Done } else if (totalProcessedBySAP == totalAddedToQueue) { //this.uxToolStripStatusLabel.Text = Convert.ToString(e.UserState); this.uxCalculationCountTextBox.Text = "SAP is processing functions..."; this.uxBalanceRecordsSummedTextBox.Text = "Total Functions Queued: " + totalAddedToQueue.ToString() + " -- Complete: " + totalProcessedBySAP.ToString(); // Items being processed by SAP - Update the CalculationTimeTextBox decimal processRate = Convert.ToDecimal(totalProcessedBySAP / ElapsedTime.TotalSeconds); uxCalculationTimeTextBox.Text = totalProcessedBySAP.ToString() + " processed at " + ElapsedTime.Minutes.ToString() + " : " + ElapsedTime.Seconds.ToString() + "- Process Rate: " + processRate.ToString("0.00") + " cells/sec"; this.uxProgressBar.Value = m_Progress; this.Refresh(); Application.DoEvents(); } // RTD has COMPLETED adding functions to the queue. The background worker sends remaining functions to SAP to be processed // Excel is done reading functions - process the remaining batch } else if (!stillAddingFunctions) { this.uxCancelButton.Enabled = true; if (totalProcessedBySAP < totalAddedToQueue) { //this.uxToolStripStatusLabel.Text = Convert.ToString(e.UserState); this.uxCalculationCountTextBox.Text = "SAP is processing functions..."; this.uxBalanceRecordsSummedTextBox.Text = "Total Functions Queued: " + totalAddedToQueue.ToString() + " -- Complete: " + totalProcessedBySAP.ToString(); // Items being processed by SAP - Update the CalculationTimeTextBox decimal processRate = Convert.ToDecimal(totalProcessedBySAP / ElapsedTime.TotalSeconds); uxCalculationTimeTextBox.Text = totalProcessedBySAP.ToString() + " processed at " + ElapsedTime.Minutes.ToString() + " : " + ElapsedTime.Seconds.ToString() + "- Process Rate: " + processRate.ToString("0.00") + " cells/sec"; if ((m_Progress < 90)) { this.uxProgressBar.Value = m_Progress; } else { this.uxProgressBar.Value = 100; } this.Refresh(); //Application.DoEvents(); } else if (totalProcessedBySAP == totalAddedToQueue) { //this.uxToolStripStatusLabel.Text = Convert.ToString(e.UserState); this.uxCalculationCountTextBox.Text = "SAP is processing functions..."; this.uxBalanceRecordsSummedTextBox.Text = "Total Functions Queued: " + totalAddedToQueue.ToString() + " -- Complete: " + totalProcessedBySAP.ToString(); // Items being processed by SAP - Update the CalculationTimeTextBox decimal processRate = Convert.ToDecimal(totalProcessedBySAP / ElapsedTime.TotalSeconds); uxCalculationTimeTextBox.Text = totalProcessedBySAP.ToString() + " processed at " + ElapsedTime.Minutes.ToString() + " : " + ElapsedTime.Seconds.ToString() + "- Process Rate: " + processRate.ToString("0.00") + " cells/sec"; this.uxProgressBar.Value = 100; this.Refresh(); Application.DoEvents(); } } } catch (Exception ex) { //MessageBox.Show(ex.Message) } } }
public static void ValidateSAPData(PlanningFunctionGroup activityPlanGroup, int functionCount) { lock (m_syncObject) { if (activityPlanGroup.FunctionList.Count > 0) { IRfcFunction sapValidateCostPlanFunction = SapConnection.GetObject().CurrentDestination.Repository.CreateFunction("BAPI_ACT_PRICE_CHECK_AND_POST"); IRfcTable returnTable = null; try { ///*** --- IMPORT (SAP TAB) -------------------------------***// IRfcStructure headerInfoStructure = sapValidateCostPlanFunction.GetStructure("HEADER_INFO"); // HEADER_INFO headerInfoStructure.SetValue("CO_AREA", ((ActivityPlan)activityPlanGroup.FunctionList[0]).ControllingArea); // 3 headerInfoStructure.SetValue("FISC_YEAR", ((ActivityPlan)activityPlanGroup.FunctionList[0]).FiscalYear); // 4 headerInfoStructure.SetValue("PERIOD_FROM", ((ActivityPlan)activityPlanGroup.FunctionList[0]).PeriodFrom); // 5 headerInfoStructure.SetValue("PERIOD_TO", ((ActivityPlan)activityPlanGroup.FunctionList[0]).PeriodTo); // 6 headerInfoStructure.SetValue("VERSION", ((ActivityPlan)activityPlanGroup.FunctionList[0]).Version); // 8 headerInfoStructure.SetValue("DOC_HDR_TX", ((ActivityPlan)activityPlanGroup.FunctionList[0]).DocumentHeaderText); // 9 headerInfoStructure.SetValue("PLAN_CURRTYPE", ((ActivityPlan)activityPlanGroup.FunctionList[0]).PlanningCurrency); // 10 sapValidateCostPlanFunction.SetValue("DELTA", ((ActivityPlan)activityPlanGroup.FunctionList[0]).Delta); // 11 sapValidateCostPlanFunction.SetValue("TESTRUN", "X"); // "X" - Validate Only, " " - Post foreach (IPlanningFunction myFunction in activityPlanGroup.FunctionList) { try { /*** --- IDX_STRUCTURE -- CO Planning: Plan Activity BAPIs -------------- ***/ IRfcTable indexTable = sapValidateCostPlanFunction.GetTable("IDX_STRUCTURE"); indexTable.Append(); indexTable.SetValue("OBJECT_INDEX", ((ActivityPlan)myFunction).ObjectIndex.ToString("000000")); indexTable.SetValue("VALUE_INDEX", ((ActivityPlan)myFunction).ValueIndex.ToString("000000")); indexTable.SetValue("ATTRIB_INDEX", "000000"); /*** --- OBJECT -- CO Planning: Objects for Plan Activity BAPIs --------- ***/ IRfcTable coObjectTable = sapValidateCostPlanFunction.GetTable("OBJECT"); coObjectTable.Append(); string objectIndex = ((ActivityPlan)myFunction).ObjectIndex.ToString("000000"); string valueIndex = ((ActivityPlan)myFunction).ValueIndex.ToString("000000"); try { if (coObjectTable.GetValue("OBJECT_INDEX") != null) { if (coObjectTable.GetValue("OBJECT_INDEX").ToString() != objectIndex) { coObjectTable.SetValue("OBJECT_INDEX", ((ActivityPlan)myFunction).ObjectIndex.ToString("000000")); // Calculated } } else { coObjectTable.SetValue("OBJECT_INDEX", ((ActivityPlan)myFunction).ObjectIndex.ToString("000000")); // Calculated } } catch (Exception ex) { coObjectTable.SetValue("OBJECT_INDEX", ((ActivityPlan)myFunction).ObjectIndex.ToString("000000")); } coObjectTable.SetValue("COSTCENTER", ((ActivityPlan)myFunction).CostCenter); // 12 coObjectTable.SetValue("ACTTYPE", ((ActivityPlan)myFunction).ActivityType); // 13 /*** --- ACCOUNT_PLAN_TOTVALUE -- CO Planning: Objects for Primary Cost BAPIs --------- ***/ IRfcTable totValueTable = sapValidateCostPlanFunction.GetTable("TOT_VALUE"); totValueTable.Append(); totValueTable.SetValue("VALUE_INDEX", ((ActivityPlan)myFunction).ValueIndex.ToString("000000")); // Calculated if (((ActivityPlan)myFunction).Price != string.Empty) { totValueTable.SetValue("PRICE_FIX", ((ActivityPlan)myFunction).Price); // 2 totValueTable.SetValue("DIST_KEY_PRICE_FIX", ((ActivityPlan)myFunction).DistributionKey); totValueTable.SetValue("PRICE_UNIT", "00001"); } else { totValueTable.SetValue("PRICE_FIX", "0"); } totValueTable.SetValue("ACTVTY_QTY", ((ActivityPlan)myFunction).Quantity); // 1 totValueTable.SetValue("DIST_KEY_QUAN", ((ActivityPlan)myFunction).DistributionKey); // 7 //// ToDo totValueTable.SetValue("CURRENCY", ((ActivityPlan)myFunction).TransactionCurrency); // 14 myFunction.Updated = true; } catch (Exception ex) { myFunction.ValidationResult = ex.Message; } } } catch (Exception exp) { foreach (IPlanningFunction myFunction in activityPlanGroup.FunctionList) { myFunction.ValidationResult = exp.Message; } } try { sapValidateCostPlanFunction.Invoke(SapConnection.GetObject().CurrentDestination); } catch (Exception ex) { DialogResult r = MessageBox.Show("SAP Authorization Error: " + ex.Message, "Error", System.Windows.Forms.MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); if (r == DialogResult.OK) { } ReturnProgressDataForm.CancelProcess(); return; } returnTable = sapValidateCostPlanFunction.GetTable("RETURN"); foreach (IPlanningFunction myFunction in activityPlanGroup.FunctionList) { if (!SAPRequest.ReturnValuesList.ContainsKey(myFunction.Signature)) { SAPRequest.ReturnValuesList.Add(myFunction.Signature, myFunction); } } if (returnTable.RowCount > 0) { try { string logPath = LogFile.CheckCreateLogFolder() + "\\PWLogValOnly" + DateTime.Now.ToString("(dd-MMM-yyyy-HH-mm-ss-f)") + ".txt"; if (!File.Exists(logPath)) { using (TextWriter writer = File.CreateText(logPath)) { writer.WriteLine("VALIDATION ONLY: " + DateTime.Now.ToString("(dd-MMM-yyyy-HH-mm-ss-f)")); writer.WriteLine(" "); for (int y = 0; y <= (returnTable.RowCount - 1); y += 1) { for (int z = 0; z <= (returnTable[y].ElementCount - 1); z += 1) { string par = returnTable[y][z].Metadata.Name; string val = returnTable[y].GetString(z); string messageLine = par + " : " + val; writer.WriteLine(messageLine); } writer.WriteLine(" "); } } } } catch (Exception ex) { //MessageBox.Show(ex.Message) } for (int j = 0; j <= (returnTable.RowCount - 1); j++) { int row = Convert.ToInt32(returnTable[j].GetString("ROW")) - 1; string message = returnTable[j].GetString("MESSAGE"); if (row < 0) { row = 0; } string rType = string.Empty; string messageV1 = string.Empty; string messageV2 = string.Empty; string messageV3 = string.Empty; string messageV4 = string.Empty; string rNumber = string.Empty; rType = returnTable[j].GetString("TYPE"); messageV1 = returnTable[j].GetString("MESSAGE_V1"); messageV2 = returnTable[j].GetString("MESSAGE_V2"); for (int i = 0; i <= (activityPlanGroup.FunctionList.Count - 1); i++) { int elementLocation = SAPRequest.GetObject().TotalProcessedBySAP + i; if (elementLocation < 0) { elementLocation = 0; } string activityType = ((ActivityPlan)SAPRequest.ReturnValuesList.Values.ElementAt(elementLocation)).ActivityType; string costCenter = ((ActivityPlan)SAPRequest.ReturnValuesList.Values.ElementAt(elementLocation)).CostCenter; try { messageV1 = messageV1.TrimStart('0'); messageV2 = messageV2.TrimStart('0'); } catch (Exception ex) { } try { if (i == row && !string.IsNullOrEmpty(message)) { SAPRequest.ReturnValuesList.Values.ElementAt(elementLocation).Result = message; } else if (i != row && rType == "E") { try { if (messageV1 == activityType || messageV2 == activityType) { // account for incrementing batch number SAPRequest.ReturnValuesList.Values.ElementAt(elementLocation).Result = message; } else if (messageV1 != activityType && messageV1 != costCenter && row == 0) { rNumber = returnTable[j].GetString("NUMBER"); if (rNumber != string.Empty) { SAPRequest.ReturnValuesList.Values.ElementAt(elementLocation).Result = message; if (ReturnProgressDataForm.OperationCancelled) { break; } } } } catch (Exception ex) { } } else if (rType == "I") { foreach (IPlanningFunction myFunction in activityPlanGroup.FunctionList) { SAPRequest.ReturnValuesList[myFunction.Signature].Result = message; if (ReturnProgressDataForm.OperationCancelled) { break; } } return; } } catch (Exception ex) { } if (ReturnProgressDataForm.OperationCancelled) { break; } } if (ReturnProgressDataForm.OperationCancelled) { break; } } foreach (IPlanningFunction myFunction in activityPlanGroup.FunctionList) { if ((SAPRequest.ReturnValuesList[myFunction.Signature].Result == null) || (SAPRequest.ReturnValuesList[myFunction.Signature].Result == string.Empty)) { SAPRequest.ReturnValuesList[myFunction.Signature].Result = "pwValidated"; } if (ReturnProgressDataForm.OperationCancelled) { break; } } } else { foreach (IPlanningFunction myFunction in activityPlanGroup.FunctionList) { SAPRequest.ReturnValuesList[myFunction.Signature].Result = "pwValidated"; if (ReturnProgressDataForm.OperationCancelled) { break; } } } } } }
public static void PostSAPData(PlanningFunctionGroup costPlanGroup, int functionCount) { lock (m_syncObject) { if (costPlanGroup.FunctionList.Count > 0) { IRfcFunction sapPostCostPlanFunction = SapConnection.GetObject().CurrentDestination.Repository.CreateFunction("BAPI_COSTACTPLN_POSTPRIMCOST"); IRfcFunction sapCommitWorkFunction = SapConnection.GetObject().CurrentDestination.Repository.CreateFunction("BAPI_TRANSACTION_COMMIT"); IRfcTable returnTable = null; try { IRfcStructure headerInfoStructure = sapPostCostPlanFunction.GetStructure("HEADERINFO"); // HEADER_INFO headerInfoStructure.SetValue("CO_AREA", ((CostPlan)costPlanGroup.FunctionList[0]).ControllingArea); // 3 headerInfoStructure.SetValue("FISC_YEAR", ((CostPlan)costPlanGroup.FunctionList[0]).FiscalYear); // 4 headerInfoStructure.SetValue("PERIOD_FROM", ((CostPlan)costPlanGroup.FunctionList[0]).PeriodFrom); // 5 headerInfoStructure.SetValue("PERIOD_TO", ((CostPlan)costPlanGroup.FunctionList[0]).PeriodTo); // 6 headerInfoStructure.SetValue("VERSION", ((CostPlan)costPlanGroup.FunctionList[0]).Version); // 8 headerInfoStructure.SetValue("DOC_HDR_TX", ((CostPlan)costPlanGroup.FunctionList[0]).DocumentHeaderText); // 9 headerInfoStructure.SetValue("PLAN_CURRTYPE", ((CostPlan)costPlanGroup.FunctionList[0]).PlanningCurrency); // 10 sapPostCostPlanFunction.SetValue("DELTA", ((CostPlan)costPlanGroup.FunctionList[0]).Delta); // 11 foreach (IPlanningFunction myFunction in costPlanGroup.FunctionList) { try { IRfcTable coObjectTable = sapPostCostPlanFunction.GetTable("COOBJECT"); // OBJECT string objectIndex = ((CostPlan)myFunction).ObjectIndex.ToString("000000"); string valueIndex = ((CostPlan)myFunction).ValueIndex.ToString("000000"); coObjectTable.Append(); try { if (coObjectTable.GetValue("OBJECT_INDEX") != null) { if (((string)coObjectTable.GetValue("OBJECT_INDEX")) != objectIndex) { coObjectTable.SetValue("OBJECT_INDEX", ((CostPlan)myFunction).ObjectIndex.ToString("000000")); // Calculated } } else { coObjectTable.SetValue("OBJECT_INDEX", ((CostPlan)myFunction).ObjectIndex.ToString("000000")); // Calculated } } catch (Exception ex) { coObjectTable.SetValue("OBJECT_INDEX", ((CostPlan)myFunction).ObjectIndex.ToString("000000")); } coObjectTable.SetValue("COSTCENTER", ((CostPlan)myFunction).CostCenter); // 11 coObjectTable.SetValue("ACTTYPE", ((CostPlan)myFunction).ActivityType); // 13 coObjectTable.SetValue("ORDERID", ((CostPlan)myFunction).OrderID); // 14 coObjectTable.SetValue("WBS_ELEMENT", ((CostPlan)myFunction).WBSElement); // 15 IRfcTable totValueTable = sapPostCostPlanFunction.GetTable("TOTVALUE"); // TOT_VALUE totValueTable.Append(); totValueTable.SetValue("VALUE_INDEX", ((CostPlan)myFunction).ValueIndex.ToString("000000")); // Calculated if (((CostPlan)myFunction).FixedInputValue != string.Empty) { totValueTable.SetValue("FIX_VALUE", ((CostPlan)myFunction).FixedInputValue); // 2 } else { totValueTable.SetValue("FIX_VALUE", "0"); } totValueTable.SetValue("DIST_KEY_FIX_VAL", ((CostPlan)myFunction).DistributionKey); // 6 totValueTable.SetValue("COST_ELEM", ((CostPlan)myFunction).CostElement); // 12 totValueTable.SetValue("FUNCTION", ((CostPlan)myFunction).FunctionalArea); // 16 totValueTable.SetValue("FUND", ((CostPlan)myFunction).Fund); // 17 totValueTable.SetValue("GRANT_NBR", ((CostPlan)myFunction).Grant); // 18 totValueTable.SetValue("TRANS_CURR", ((CostPlan)myFunction).TransactionCurrency); // 19 IRfcTable indexTable = sapPostCostPlanFunction.GetTable("INDEXSTRUCTURE"); // IDX_STRUCTURE indexTable.Append(); indexTable.SetValue("OBJECT_INDEX", ((CostPlan)myFunction).ObjectIndex.ToString("000000")); indexTable.SetValue("VALUE_INDEX", ((CostPlan)myFunction).ValueIndex.ToString("000000")); indexTable.SetValue("ATTRIB_INDEX", "000000"); myFunction.Updated = true; } catch (Exception ex) { myFunction.ValidationResult = ex.Message; } } } catch (Exception exp) { foreach (IPlanningFunction myFunction in costPlanGroup.FunctionList) { myFunction.ValidationResult = exp.Message; } } try { RfcSessionManager.BeginContext(SapConnection.GetObject().CurrentDestination); sapPostCostPlanFunction.Invoke(SapConnection.GetObject().CurrentDestination); sapCommitWorkFunction.Invoke(SapConnection.GetObject().CurrentDestination); RfcSessionManager.EndContext(SapConnection.GetObject().CurrentDestination); } catch (Exception ex) { DialogResult r = MessageBox.Show("SAP Authorization Error: " + ex.Message, "Error", System.Windows.Forms.MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); if (r == DialogResult.OK) { } ReturnProgressDataForm.CancelProcess(); return; } returnTable = sapPostCostPlanFunction.GetTable("RETURN"); foreach (IPlanningFunction myFunction in costPlanGroup.FunctionList) { if (!SAPRequest.ReturnValuesList.ContainsKey(myFunction.Signature)) { SAPRequest.ReturnValuesList.Add(myFunction.Signature, myFunction); } } if (returnTable.RowCount > 0) { try { string logPath = LogFile.CheckCreateLogFolder() + "\\PWLogValOnly" + DateTime.Now.ToString("(dd-MMM-yyyy-HH-mm-ss-f)") + ".txt"; if (!File.Exists(logPath)) { using (TextWriter writer = File.CreateText(logPath)) { writer.WriteLine("VALIDATION AND POST: " + DateTime.Now.ToString("(dd-MMM-yyyy-HH-mm-ss-f)")); writer.WriteLine(" "); for (int y = 0; y <= (returnTable.RowCount - 1); y += 1) { for (int z = 0; z <= (returnTable[y].ElementCount - 1); z += 1) { string par = returnTable[y][z].Metadata.Name; string val = returnTable[y].GetString(z); string messageLine = par + " : " + val; writer.WriteLine(messageLine); } writer.WriteLine(" "); } } } } catch (Exception ex) { //MessageBox.Show(ex.Message) } for (int j = 0; j <= (returnTable.RowCount - 1); j++) { int row = Convert.ToInt32(returnTable[j].GetString("ROW")) - 1; string message = returnTable[j].GetString("MESSAGE"); if (row < 0) { row = 0; } string rType = string.Empty; string messageV1 = string.Empty; string messageV2 = string.Empty; string messageV3 = string.Empty; string messageV4 = string.Empty; string rNumber = string.Empty; rType = returnTable[j].GetString("TYPE"); messageV1 = returnTable[j].GetString("MESSAGE_V1"); messageV2 = returnTable[j].GetString("MESSAGE_V2"); for (int i = 0; i <= (costPlanGroup.FunctionList.Count - 1); i++) { int elementLocation = SAPRequest.GetObject().TotalProcessedBySAP + i; if (elementLocation < 0) { elementLocation = 0; } string costElement = ((CostPlan)SAPRequest.ReturnValuesList.Values.ElementAt(elementLocation)).CostElement; string costCenter = ((CostPlan)SAPRequest.ReturnValuesList.Values.ElementAt(elementLocation)).CostCenter; try { messageV1 = messageV1.TrimStart('0'); messageV2 = messageV2.TrimStart('0'); } catch (Exception ex) { } try { if (i == row && !string.IsNullOrEmpty(message)) { SAPRequest.ReturnValuesList.Values.ElementAt(elementLocation).Result = message; } else if (i != row && rType == "E") { try { if (messageV1 == costElement || messageV2 == costElement) { // account for incrementing batch number SAPRequest.ReturnValuesList.Values.ElementAt(elementLocation).Result = message; } else if (messageV1 != costElement && messageV1 != costCenter && row == 0) { rNumber = returnTable[j].GetString("NUMBER"); if (rNumber != string.Empty) { SAPRequest.ReturnValuesList.Values.ElementAt(elementLocation).Result = message; if (ReturnProgressDataForm.OperationCancelled) { break; } } } } catch (Exception ex) { } } else if (rType == "I") { foreach (IPlanningFunction myFunction in costPlanGroup.FunctionList) { SAPRequest.ReturnValuesList[myFunction.Signature].Result = message; if (ReturnProgressDataForm.OperationCancelled) { break; } } return; } } catch (Exception ex) { } if (ReturnProgressDataForm.OperationCancelled) { break; } } if (ReturnProgressDataForm.OperationCancelled) { break; } } foreach (IPlanningFunction myFunction in costPlanGroup.FunctionList) { if (SAPRequest.ReturnValuesList[myFunction.Signature].Result == null | SAPRequest.ReturnValuesList[myFunction.Signature].Result == string.Empty) { SAPRequest.ReturnValuesList[myFunction.Signature].Result = "pwValidated"; } if (ReturnProgressDataForm.OperationCancelled) { break; } } } else { foreach (IPlanningFunction myFunction in costPlanGroup.FunctionList) { SAPRequest.ReturnValuesList[myFunction.Signature].Result = "pwValidated"; if (ReturnProgressDataForm.OperationCancelled) { break; } } } } } }