Ge tCity State Zip REGEX

by ssi 17. December 2015 17:43

   private string[] GetCityStateZip(string sAddress)

        {

            //string[] split = sAddress.Split(new Char[] { ' ', });

            //return split;

            sAddress = sAddress.Replace(".", "");

            sAddress = sAddress.Replace(",", ", ");

            sAddress = sAddress.Replace("  ", " ");

            string[] aRet = new string[3];

            Regex addressPattern = new Regex(@"(?<city>[A-Za-z',.\s]+) (?<state>([A-Za-z]{2}|[A-Za-z]{2},))\s*(?<zip>\d{5}(-\d{4})|\d{5})");

 

            MatchCollection matches = addressPattern.Matches(sAddress);

 

            for (int mc = 0; mc < matches.Count; mc++)

            {

                aRet[pADDR_CITY] = matches[mc].Groups["city"].Value;

                aRet[pADDR_STATE] = matches[mc].Groups["state"].Value;

                aRet[pADDR_ZIP] = matches[mc].Groups["zip"].Value;

            }

            return aRet;

        }

 

Tags:

CSharp | Regex

restore :Console.WriteLine

by ssi 17. December 2015 14:25
#if TEST_DATE
            Console.WriteLine("Enter <q> to quit:");
            string line = Console.ReadLine();
            if (line == "q")
            {
                // break;
            }
#endif

Tags: , ,

CSharp

Console.WriteLine

by ssi 17. December 2015 14:18
#if TEST_DATE
            Console.WriteLine("Enter <q> to quit:");
            string line = Console.ReadLine();
            if (line == "q")
            {
                // break;
            }
#endif

Tags: , ,

CSharp

List<>

by ssi 17. December 2015 12:50
List<DocumentTab> THEDOCS = GetDocumentTab();
      private List<DocumentTab> GetDocumentTab()
      {
          List<DocumentTab> DOCAT = new List<DocumentTab>();
          DocumentTab rcd = new DocumentTab();
          rcd.Short_Name = "DOC1";
          rcd.TAB_NAME = "DOC01";
          DOCAT.Add(rcd);
 
          rcd = new DocumentTab();
          rcd.Short_Name = "DOC2";
          rcd.TAB_NAME = "DCO02";
          DOCAT.Add(rcd);
 
          rcd = new DocumentTab();
          rcd.Short_Name = "DOC3";
          rcd.TAB_NAME = "DOC03";
          DOCAT.Add(rcd);
 
          rcd = new DocumentTab();
          rcd.Short_Name = "DOC4";
          rcd.TAB_NAME = "4thDOC";
          DOCAT.Add(rcd);
 
 
 
          return DOCAT;
      }

Tags:

CSharp

List Scheduler Tasks

by ssi 17. December 2015 12:44
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32.TaskScheduler;
using System.Diagnostics.Eventing.Reader;
 
namespace ListSchedulerTasks
{
    class Program
    {
        static string sFolder = "<MS scheduler folder>";
        static List<SchedulerTasks> SCHEDTASK = new List<SchedulerTasks>();
        static void Main(string[] args)
        {
            string sVer = "15.12.15.a";
            Console.WriteLine("{0}", sVer);
            EnumAllTasks();
            Console.WriteLine("{0}""Its over");
 
            foreach (var ts in SCHEDTASK)
                Console.WriteLine("Name: {0} => next{1} en{2} lst{3} res:{4}", ts.Name, ts.NextRunTime, ts.Enabled, ts.LastRunTime, ts.LastTaskResult);
 
            Console.ReadLine();
        }
 
 
        static void EnumAllTasks()
        {
            using (TaskService ts = new TaskService())
                EnumFolderTasks(ts.RootFolder);
        }
 
        static void EnumFolderTasks(TaskFolder fld)
        {
          
            foreach (Task task in fld.Tasks)
                ActOnTask(task);
            foreach (TaskFolder sfld in fld.SubFolders)
                EnumFolderTasks(sfld);
        }
        static void ActOnTask(Task t)
        {
            if (t.Folder.ToString().Contains(sFolder))
            {
 
              //  Console.WriteLine("Name: {0} => next{1} en{2} lst{3} res:{4}", t.Name, t.NextRunTime, t.Enabled, t.LastRunTime, t.LastTaskResult);
 
                SchedulerTasks rcd = new SchedulerTasks();
                rcd.Name = t.Name;
                rcd.NextRunTime = t.NextRunTime;
                rcd.Enabled = t.Enabled;
                rcd.LastRunTime = t.LastRunTime;
                rcd.LastTaskResult = t.LastTaskResult;
                SCHEDTASK.Add(rcd);
 
 
 
            }
 
 
        }
 
 
    }
}
 
 using System;
 
namespace ListSchedulerTasks
{
    internal class SchedulerTasks
    {
        public bool Enabled { getinternal set; }
        public DateTime LastRunTime { getinternal set; }
        public object LastTaskResult { getinternal set; }
        public string Name { getinternal set; }
        public DateTime NextRunTime { getinternal set; }
    }
}

Tags: , ,

CSharp

CreateFolder

by ssi 17. December 2015 10:54
public class clsFolders
   {
       public void CreateFolder(string sFolder)
       {
           try
           {
               // Determine whether the directory exists.
               if (Directory.Exists(sFolder))
               {
                   Console.WriteLine(string.Format("Path: {0} exists already.", sFolder ));
                   return;
               }
 
               // Try to create the directory.
               DirectoryInfo di = Directory.CreateDirectory(sFolder);
               Console.WriteLine("The directory was created successfully at {0}."Directory.GetCreationTime(sFolder));
 
               //// Delete the directory.
               //di.Delete();
               //Console.WriteLine("The directory was deleted successfully.");
           }
           catch (Exception e)
           {
               Console.WriteLine("The process failed: {0}", e.ToString());
           }
           finally { }
 
       }
 
   }

Tags: ,

CSharp

Limit String

by ssi 17. December 2015 10:52
public static string LimitString(string sTextValue, int nMaxLength, string sTextTemplate)
   {
       /********************************************************************
           created:	2014/02/13
           created:	13:2:2014   16:32
           filename: 	C:\Users\Public\Documents\appsCadence\appsGl\GlTran\GLTrans\Classes\clsStaticMethods.cs
           file path:	C:\Users\Public\Documents\appsCadence\appsGl\GlTran\GLTrans\Classes
           file base:	clsStaticMethods
           file ext:	cs
           author:		ssi
           note: 		Usage : LimitString("Ross Mason",25 , "R:{0}$$$")
           purpose:
       *********************************************************************/
       int nLen = Math.Min(string.Format(sTextTemplate, sTextValue).Length, nMaxLength);
       return string.Format(sTextTemplate, sTextValue).Substring(0, nLen);
   }

Tags: ,

CSharp

TesT For SQL Connection

by ssi 15. December 2015 15:33
private bool GotConnected2SQL(string sConnectionString)
     {
         bool bRet = false;
         SqlConnection mySQLConnection = new SqlConnection(sConnectionString);
         string SQLStatement = "SELECT control FROM [tbvl_ssi_control]";
         string sSql = string.Format(SQLStatement);
         SqlCommand mySQLCommand = mySQLConnection.CreateCommand();
         try
         {
             mySQLCommand.CommandText = sSql;
             SqlDataAdapter mySQLDataAdapter = new SqlDataAdapter();
             mySQLDataAdapter.SelectCommand = mySQLCommand;
             DataSet myDataSet = new DataSet();
 
             mySQLConnection.Open();
             Console.WriteLine("Retrieving rows from the Query");
             mySQLDataAdapter.Fill(myDataSet, "RECS");
             mySQLConnection.Close();
             DataTable myDataTable = myDataSet.Tables["RECS"];
             bRet = true;
         }
         catch (Exception ex)
         {
             MessageBox.Show(string.Format("""SQL Connection Error: {0}", ex.Message), "SQL Connection Status"MessageBoxButtons.OK, MessageBoxIcon.Error);
             bRet = false;
         }
 
         return bRet;
     }

Tags: , ,

CSharp | SQL

Split

by ssi 12. November 2015 16:34

  sRet = sRet.Replace("DB_backup_", "").Replace(".trn.7z", "");

            char[] delimiter = { '_' };

            string[] split = null;

 

            for (int x = 0; x <= 5; x++)

                split = sRet.Split(delimiter, x);

            string sYr = split[0];

            string sMn = split[1];

            string sDy = split[2];

            string sTm = split[3].Substring(0, 4);

            sRet = string.Format("Last TL from : {0}/{1}/{2} @ {3}", sMn, sDy, sYr, sTm);

            return sRet;

 

Tags: ,

CSharp

Control Object Visibility with Interface

by ssi 17. September 2015 11:00
public interface IControlVisible
   {
       void SetControlVisiblity(int nUserLevel);
   }
  public  interface IControlEnable
   {
       void SetControlEnable(bool b);
   } 

  public class FormButton : Interfaces.IControlVisible, Interfaces.IControlEnable     {         public Button Item { getset; }         public int ControlLevel { getset; }         public void SetControlVisiblity(int nUserLevel)         {             Item.Visible = false;             if (nUserLevel <= ControlLevel)                 Item.Visible = true;         }         public void SetControlEnable(bool b)         {             Item.Enabled = b;         }     }     public class FormButton : Interfaces.IControlVisible, Interfaces.IControlEnable
    {         public ToolStripMenuItem Item { getset; }         public int ControlLevel { getset; }         public void SetControlVisiblity(int nUserLevel)         {             Item.Visible = false;             if (nUserLevel <= ControlLevel)                 Item.Visible = true;         }         public void SetControlEnable(bool b)         {             Item.Enabled = b;         }     }     public class ButtonItem : Interfaces.IControlVisible, Interfaces.IControlEnable     {         public ToolStripButton Item { getset; }         public int ControlLevel { getset; }         public void SetControlVisiblity(int nUserLevel)         {             Item.Visible = false;             if (nUserLevel <= ControlLevel)                 Item.Visible = true;         }         public void SetControlEnable(bool b)         {             Item.Enabled = b;         }     }     public class SplitButtonItem : Interfaces.IControlVisible, Interfaces.IControlEnable     {         public ToolStripSplitButton Item { getset; }         public int ControlLevel { getset; }         public void SetControlVisiblity(int nUserLevel)         {             Item.Visible = false;             if (nUserLevel <= ControlLevel)                 Item.Visible = true;         }         public void SetControlEnable(bool b)         {             Item.Enabled = b;         }     }     public class ToolStripDDButtonItem : Interfaces.IControlVisible, Interfaces.IControlEnable     {         public ToolStripDropDownButton Item { getset; }         public int ControlLevel { getset; }         public void SetControlVisiblity(int nUserLevel)         {             Item.Visible = false;             if (nUserLevel <= ControlLevel)                 Item.Visible = true;         }         public void SetControlEnable(bool b)         {             Item.Enabled = b;         }     }     public class MyTextBoxes : Interfaces.IControlEnable, Interfaces.IControlVisible     {         public TextBox Item { getset; }         public int ControlLevel { getset; }         public void SetControlEnable(bool b)         {             Item.Enabled = b;         }         public void SetControlVisiblity(int nUserLevel)         {             Item.Visible = false;             if (nUserLevel <= ControlLevel)                 Item.Visible = true;         }     }

Tags: ,

CSharp

Calendar

<<  July 2025  >>
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

View posts in large calendar

RecentComments

None

Development Team @ Shelbysys

We develop custom database applications for our clients. Our development tool of choice is MS Visual Studio. 

Quotations

"Fill the unforgiving minute with sixty seconds worth of distance run."
Rudyard Kipling