public static int InsertCaptureEventForTextConversion(AdvancedRecomendation captureEvent, ReplacementEvent replacementEvent) { int returnCode = -1; int RecommendationId = InsertRecommendationForTextConversion(captureEvent); int CapturePointId = Rec_CapturePoints_TextConv.InsertCapturePointsForTextConversion(RecommendationId, captureEvent.CaptureEventCapturePointsList); replacementEvent.capturePointId = RecommendationId; Advanced_Replacements_TextConv.InsertNewReplacementForTextConversion(replacementEvent); return returnCode; }
public static void SaveReplacementEventForTextConversion(ReplacementEvent replacementEvent, SqlCeConnection conn, SqlCeTransaction transaction) { SqlCeCommand command = new SqlCeCommand(Advanced_Replacements_TextConv_SQL.commandUpdateReplacementByIdTextConv, conn); command.Transaction = transaction; command.Parameters.Add("@name", replacementEvent.name); command.Parameters.Add("@description", replacementEvent.description); command.Parameters.Add("@value", replacementEvent.Value); command.Parameters.Add("@typeId", replacementEvent.typeId); command.Parameters.Add("@capturePointId", replacementEvent.capturePointId); command.Parameters.Add("@userId", replacementEvent.userId); command.Parameters.Add("@usageCount", replacementEvent.usageCount); command.Parameters.Add("@id", replacementEvent.id); command.ExecuteNonQuery(); }
public static List<ReplacementEvent> GetAvailableReplacementsByCaptureIdForTextConversion(int captureEventId, SqlCeConnection conn) { //commandGetCapturePointReplacements List<ReplacementEvent> replacementEvents = new List<ReplacementEvent>(); DataSet availableReplacementsAsDataset = GetAvailableReplacementsAsDatasetForTextConversion(captureEventId, conn); foreach (DataRow row in availableReplacementsAsDataset.Tables[0].Rows) { ReplacementEvent repEvent = new ReplacementEvent(Convert.ToInt32(row["id"]), Convert.ToInt32(row["userId"]), row["name"].ToString(), row["description"].ToString(), row["value"].ToString(), Convert.ToInt32(row["typeId"]), Convert.ToInt32(row["capturePointId"]), Convert.ToInt32(row["usageCount"])); replacementEvents.Add(repEvent); } return replacementEvents; }
public static void SaveCaptureEventByIdForTextConversion(int captureEventId, AdvancedRecomendation captureEvent, ReplacementEvent replacementEvent) { SqlCeTransaction transaction; SqlCeConnection conn = BackEndUtils.GetSqlConnection(); try { conn.Open(); transaction = conn.BeginTransaction(); try { UpdateRecommendationByIdForTextConversion(captureEventId, captureEvent, conn, transaction); Rec_CapturePoints_TextConv.DeletAllRespectiveCapturePointsForTextConversion(captureEventId, conn, transaction); Rec_CapturePoints_TextConv.InsertCapturePointsAsTransactionForTextConversion(captureEventId, captureEvent.CaptureEventCapturePointsList, conn, transaction); replacementEvent.capturePointId = captureEventId; Advanced_Replacements_TextConv.SaveReplacementEventForTextConversion(replacementEvent, conn, transaction); transaction.Commit(); } catch (Exception ex) { CommonUtils.LogError(ex.Message, ex); transaction.Rollback(); } } finally { conn.Close(); } }
public static List<ReplacementEvent> GetAvailableReplacementsByCaptureId(int captureEventId, SqlCeConnection conn) { //commandGetCapturePointReplacements List<ReplacementEvent> replacementEvents = new List<ReplacementEvent>(); if (conn.State == ConnectionState.Open) { DataSet availableReplacementsAsDataset = GetAvailableReplacementsAsDataset(captureEventId, conn); foreach (DataRow row in availableReplacementsAsDataset.Tables[0].Rows) { ReplacementEvent repEvent = new ReplacementEvent(Convert.ToInt32(row["id"]), Convert.ToInt32(row["userId"]), row["name"].ToString(), row["description"].ToString(), row["value"].ToString(), Convert.ToInt32(row["typeId"]), Convert.ToInt32(row["capturePointId"]), Convert.ToInt32(row["usageCount"])); replacementEvents.Add(repEvent); } } else { try { conn.Open(); DataSet availableReplacementsAsDataset = GetAvailableReplacementsAsDataset(captureEventId, conn); foreach (DataRow row in availableReplacementsAsDataset.Tables[0].Rows) { ReplacementEvent repEvent = new ReplacementEvent(Convert.ToInt32(row["id"]), Convert.ToInt32(row["userId"]), row["name"].ToString(), row["description"].ToString(), row["value"].ToString(), Convert.ToInt32(row["typeId"]), Convert.ToInt32(row["capturePointId"]), Convert.ToInt32(row["usageCount"])); replacementEvents.Add(repEvent); } } finally { conn.Close(); } } return replacementEvents; }
public static int InsertNewReplacementForTextConversion(ReplacementEvent replacementEvent) { int replacementId = 0; int numberAffectedRows = 0; SqlCeConnection conn = BackEndUtils.GetSqlConnection(); try { conn.Open(); SqlCeCommand command = new SqlCeCommand(Advanced_Replacements_TextConv_SQL.commandInsertReplacementTextConv, conn); command.Parameters.Add("@name", replacementEvent.name); command.Parameters.Add("@description", replacementEvent.description); command.Parameters.Add("@value", replacementEvent.Value); command.Parameters.Add("@typeId", replacementEvent.typeId); command.Parameters.Add("@capturePointId", replacementEvent.capturePointId); command.Parameters.Add("@userId", replacementEvent.userId); command.Parameters.Add("@usageCount", replacementEvent.usageCount); numberAffectedRows = Convert.ToInt32(command.ExecuteNonQuery()); SqlCeCommand commandMaxId = new SqlCeCommand(Advanced_Replacements_TextConv_SQL.commandMaxReplacementIdTextConv, conn); replacementId = Convert.ToInt32(commandMaxId.ExecuteScalar()); } finally { conn.Close(); } return replacementId; }
private void btnAddReplacementEvent_Click(object sender, EventArgs e) { try { if (IsValidToAddReplacement(txtReplacementName.Text.Trim(), txtReplacementDesc.Text.Trim(), txtReplacementRep.Text.Trim())) { ReplacementEvent replacementEvent = new ReplacementEvent(txtReplacementName.Text.Trim(), txtReplacementDesc.Text.Trim(), txtReplacementRep.Text.Trim(), Convert.ToInt32(cboReplacementType.SelectedValue), ((AdvancedRecomendation)cboCapturePoint.SelectedItem).CaptureEventId, CommonUtils.LoggedInUserId); Advanced_Replacements.InsertNewReplacement(replacementEvent); AdvancedRecomendation selectedAdvancedRec = ((AdvancedRecomendation)cboCapturePoint.SelectedItem); FillReplacementsListBox(selectedAdvancedRec); UpdateUi(CommonUtils.UiPrepareFor.Add); } } catch (Exception ex) { CommonUtils.ShowError(ex.Message, ex); } }
private void PopulateUiWithReplacementValues(ReplacementEvent selectedReplacementEvent) { txtReplacementName.Text = selectedReplacementEvent.name; txtReplacementDesc.Text = selectedReplacementEvent.description; txtReplacementRep.Text = selectedReplacementEvent.Value; cboReplacementType.SelectedValue = selectedReplacementEvent.typeId; }
private void ReplaceFoundNodes(ReplacementEvent replacementEvent, List<XNode> foundNodes) { foreach (XNode foundNode in foundNodes) { try { foundNode.ReplaceWith("<!-- " + GetReplacementValueFromEvent(replacementEvent, foundNode).Trim() + " -->"); } catch (Exception ex) { // replacement failed } } }
private string GetReplacementValueFromEvent(ReplacementEvent replacementEvent, XNode foundNode) { // may be a bug .... ex: with two view-selection under action performed List<NodeAndAttributeCouple> replaceableValues = GetReplacementParametersFromValue(replacementEvent.Value); string completedEvent = replacementEvent.Value; XElement element = XElement.Parse(foundNode.ToString()); for (int i = 0; i < replaceableValues.Count; i++) { if (string.Equals(replaceableValues[i].attrName, "TextValue", StringComparison.InvariantCultureIgnoreCase)) { string textValue = element.DescendantsAndSelf(replaceableValues[i].nodeName).ElementAt(0).Value.Trim(); if (completedEvent.Contains("{" + replaceableValues[i].nodeName + ":TextValue}")) { completedEvent = completedEvent.Replace("{" + replaceableValues[i].nodeName + ":TextValue}", textValue); } else { completedEvent = completedEvent.Replace("{TextValue}", textValue); } } else { if (element.DescendantsAndSelf(replaceableValues[i].nodeName).Attributes(replaceableValues[i].attrName).Count() >= replaceableValues[i].index) { string attrValue = element.DescendantsAndSelf(replaceableValues[i].nodeName).Attributes(replaceableValues[i].attrName).ElementAt(replaceableValues[i].index).Value.Trim(); if (completedEvent.Contains("{" + replaceableValues[i].nodeName + ":" + replaceableValues[i].attrName + "}")) { completedEvent = completedEvent.Replace("{" + replaceableValues[i].nodeName + ":" + replaceableValues[i].attrName + "}", attrValue); } else if (completedEvent.Contains("{" + replaceableValues[i].nodeName + ":" + replaceableValues[i].attrNameWithAt + "}")) { completedEvent = completedEvent.Replace("{" + replaceableValues[i].nodeName + ":" + replaceableValues[i].attrNameWithAt + "}", attrValue); } else if (completedEvent.Contains("{" + replaceableValues[i].attrName + "}")) { completedEvent = completedEvent.Replace("{" + replaceableValues[i].attrName + "}", attrValue); } } } } return completedEvent; }
private string GetParametrizedRepFromGenericOne(ReplacementEvent replacementEvent, XNode xNode) { // may be a bug .... ex: with two view-selection under action performed List<NodeAndAttributeCouple> replaceableValues = GetReplacementParametersFromValue(replacementEvent.Value); string completedEvent = replacementEvent.Value; XElement element = XElement.Parse(xNode.ToString()); for (int i = 0; i < replaceableValues.Count; i++) { if (string.Equals(replaceableValues[i].attrName, "TextValue", StringComparison.InvariantCultureIgnoreCase)) { string textValue = element.DescendantsAndSelf(replaceableValues[i].nodeName).ElementAt(0).Value; completedEvent = completedEvent.Replace("{TextValue}", textValue); } else { string attrValue = element.DescendantsAndSelf(replaceableValues[i].nodeName).Attributes(replaceableValues[i].attrName).ElementAt(0).Value; completedEvent = completedEvent.Replace("{" + replaceableValues[i].attrName + "}", attrValue); } } return completedEvent; }
public static void SaveReplacementEvent(ReplacementEvent replacementEvent) { SqlCeConnection conn = BackEndUtils.GetSqlConnection(); try { conn.Open(); SqlCeCommand command = new SqlCeCommand(Advanced_Replacements_SQL.commandUpdateReplacementById, conn); command.Parameters.Add("@name", replacementEvent.name); command.Parameters.Add("@description", replacementEvent.description); command.Parameters.Add("@value", replacementEvent.Value); command.Parameters.Add("@typeId", replacementEvent.typeId); command.Parameters.Add("@capturePointId", replacementEvent.capturePointId); command.Parameters.Add("@userId", replacementEvent.userId); command.Parameters.Add("@usageCount", replacementEvent.usageCount); command.Parameters.Add("@id", replacementEvent.id); command.ExecuteNonQuery(); } finally { conn.Close(); } }
private void btnSaveCaptureEvent_Click(object sender, EventArgs e) { try { tvOutput.Select(); Recur(tvOutput.Nodes); SaveUpdatedAttributes(); AdvancedRecomendation captureEvent = new AdvancedRecomendation(txtAOName.Text, txtAODescription.Text, txtAOEventIn.Text, captureEventNodes); captureEvent.captureEventCategory = Convert.ToInt32(cboCaptureType.SelectedValue); captureEvent.captureEventUsageCount = CurrentlySelectedCaptureEvent.captureEventUsageCount; ReplacementEvent selectedReplacementEvent = new ReplacementEvent("Replacement-" + txtAOName.Text, "Replacement-" + txtAODescription.Text, txtTextValue.Text, 1); selectedReplacementEvent.id = CurrentlySelectedCaptureEvent.Replacement.id; Advanced_Recomendations_TextConv.SaveCaptureEventByIdForTextConversion(CurrentlySelectedCaptureEvent.CaptureEventId, captureEvent, selectedReplacementEvent); SetAllCombos(); BindCombos(); LoadAvailableARtoList(); ResetForm(); } catch (Exception ex) { CommonUtils.ShowError(ex.Message, ex); } }
private void btnAddCaptureEvent_Click(object sender, EventArgs e) { try { if (eventParsed) { string ruleName = txtAOName.Text.Trim(); string ruleDescription = txtAODescription.Text.Trim(); string ruleEventIn = txtAOEventIn.Text.Trim(); string replacementText = txtTextValue.Text.Trim(); if (IsValidToAddRule(ruleName, ruleDescription, ruleEventIn, replacementText, tvOutput.Nodes[0])) { Recur(tvOutput.Nodes); SaveUpdatedAttributes(); AdvancedRecomendation captureEvent = new AdvancedRecomendation(ruleName, ruleDescription, ruleEventIn, captureEventNodes); captureEvent.captureEventCategory = Convert.ToInt32(cboCaptureType.SelectedValue); captureEvent.captureEventUsageCount = 0; ReplacementEvent replacementEvent = new ReplacementEvent("Replacement-" + ruleName, "Repalcement-" + ruleDescription, replacementText, 1, 0, CommonUtils.LoggedInUserId); Advanced_Recomendations_TextConv.InsertCaptureEventForTextConversion(captureEvent, replacementEvent); CommonUtils.ShowInformation("Capture event inserted successfully!",false); } BindCombos(); LoadAvailableARtoList(); SetAllCombos(); lbAdvancedCE.Select(); } else { CommonUtils.ShowInformation("Please [Parse] the input event before proceeding",true); } } catch (Exception ex) { CommonUtils.ShowError(ex.Message, ex); } }