Below is a MySql trigger to insert/update other table
Trigger in backend is very useful to report the input data in many different way.. This will be last step in performance tuning when the data double up drastically.
DROP trigger IF EXISTS "Trigger Name";
delimiter $$
CREATE TRIGGER "Trigger Name"
AFTER INSERT ON "Table Name - where the trigger will be fired on Insert/Update"
FOR EACH ROW
BEGIN
Declare l_count, l_topErrorCount INT;
Declare l_Top1Error, l_Top2Error, l_Top3Error VARCHAR(150);
//To determine where you need to update or insert the value in other table
SELECT COUNT(*) INTO l_topErrorCount FROM "Table Name"
WHERE Team = NEW.Team
AND Date = NEW.ErrorDate
AND Report = NEW.Report;
////
You Logic goes here.....
//Retrive Top Error...//
////
IF l_topErrorCount > 0 THEN
UPDATE "Table Name"
SET Top1Error= l_Top1Error,
Top2Error=l_Top2Error,
Top3Error=l_Top3Error
WHERE Team = NEW.Team
AND Date = NEW.ErrorDate
AND Report = NEW.Report;
ELSE
INSERT INTO "Table Name"
(Date, Team, Report, Top1Error, Top2Error, Top3Error)
VALUES(NEW.ErrorDate, NEW.Team, NEW.Report, l_Top1Error, l_Top2Error, l_Top3Error);
END IF;
END;
$$
How to Write bunch of text to a file
Here is one of the way to Write bunch of text to flat file:
1 2 3 4 5 6 7 8 9 10 11 12 | Public Sub WriteFile(ByVal sText As String, ByVal sFile As String, Optional ByVal bAppendMode As Boolean = True) Try Dim Stream_Writer As New IO.StreamWriter(sFile, bAppendMode) Stream_Writer.Write(sText & vbCrLf) Stream_Writer.Flush() Stream_Writer.Close() Catch ex As Exception 'Statements to handle Errors Finally End Try End Sub |
How to Check whether given file exists or not
Here is the code to Check whether the given file exists or not in VB.Net:
1 2 3 | Public Function IsFileExists(ByVal strFileName As String) As Boolean IsFileExists = System.IO.File.Exists(strFileName) End Function |
How to get System’s active printer name
Here is the code to get the System's active printer name:
1 2 3 4 | Private Function GetActivePrinter() As String Dim ps As New Drawing.Printing.PrinterSettings() Return ps.PrinterName End Function |
Using XML Nodes and implement RegEx in VB.Net
Retrive the information from the XML File and evalute the string using the Regular expression.
XML File which we will iterate and retrive data from:
Pattern.xml:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <?xml version="1.0" encoding="utf-8" ?> - <MatchingCriterias> - <CriteriaForAllPages> <MatchingCriteria Value="Chksum: \d(2,)" /> </CriteriaForAllPages> - <CriteriaForDeletedPages> - <Criteria Name="DocHeaderPage"> <MatchingCriteria Value="DOC \d+ \:?\s?Header" /> </Criteria> - <Criteria Name="SubmissionHeaderPage"> <MatchingCriteria Value="JobNumber:" /> <MatchingCriteria Value="SUBMISSION" /> <MatchingCriteria Value="SUBMISSION-CONTACT" /> </Criteria> - <Criteria Name="DocumentDescriptionPage"> <MatchingCriteria Value="JobNumber:" /> <MatchingCriteria Value="Name" /> <MatchingCriteria Value="Description" /> <MatchingCriteria Value="DOC \d+" /> </Criteria> </CriteriaForDeletedPages> </MatchingCriterias> |
VB Code to retreive the informations:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | Imports System.Text.RegularExpressions Imports System.Xml Imports System.IO Private Function IsDocHeaderPage(ByRef oPage As String) As Boolean Dim xmlCriteriaDoc As XmlDocument, lstCriteria As XmlNodeList, nodeCriteria As XmlNode, nodeChildCriteria As XmlNode Dim blnCheckCriteria As Boolean xmlCriteriaDoc = New XmlDocument Try xmlCriteriaDoc.Load("C://Temp//Pattern.xml") If Not xmlCriteriaDoc Is Nothing Then lstCriteria = xmlCriteriaDoc.SelectNodes("//CriteriaForAllPages") If Not lstCriteria Is Nothing Then For Each nodeCriteria In lstCriteria For Each nodeChildCriteria In nodeCriteria.ChildNodes 'using regular expression with the pattern retreived blnCheckCriteria = Regex.IsMatch(oPage.ToString, nodeChildCriteria.Attributes("Value").InnerText.ToString(), RegexOptions.Singleline) If blnCheckCriteria Then IsDocHeaderPage = False Return IsDocHeaderPage End If Next nodeChildCriteria Next nodeCriteria End If lstCriteria = xmlCriteriaDoc.SelectNodes("//CriteriaForDeletedPages/Criteria") If Not lstCriteria Is Nothing Then For Each nodeCriteria In lstCriteria For Each nodeChildCriteria In nodeCriteria.ChildNodes blnCheckCriteria = Regex.IsMatch(oPage.Contents.CreateSingleContent.Stream.ToString, nodeChildCriteria.Attributes("Value").InnerText.ToString(), RegexOptions.Singleline) If Not blnCheckCriteria Then Exit For End If If nodeChildCriteria Is nodeCriteria.LastChild Then IsDocHeaderPage = True IsAnyHeaderPageExists = True Return IsDocHeaderPage End If Next nodeChildCriteria Next nodeCriteria End If End If Catch ex As Exception IsDocHeaderPage = False MessageBox.Show(ex.Message) End Try End Function |








