Regex: Stripping Unwanted Chararcters

by ssi 10. June 2016 07:51
public static string StripLeadingZeros(string sAlphaNumberText)
       {
           /*
            * That will trim trailing zeros if they appear after the period in a decimal number (it will always leave a single zero).
            *  It also accounts for numbers that appear at the very end.
            */
           string sRet = "";
 
           sRet = Regex.Replace(sAlphaNumberText,
                        @"(?<=\.\d+?)0+(?=\D|$)",
                        String.Empty);
           return sRet;
       }
 
       public static string StripWhitespace(string sAlphaNumberText)
       {
           /*
            * sStrip Whitespace
            */
           string sRet = "";
 
           sRet = Regex.Replace(sAlphaNumberText, @"\s+""");
           return sRet;
       }
       public static string StripAllButNumbers(string sAlphaNumberText)
       {
           /*
            * strip all characters except numbers
            */
           string sRet = "";
 
           sRet = Regex.Replace(sAlphaNumberText, @"[^\d]"String.Empty);
           return sRet;
       }
       public static string StripNumbers(string sAlphaNumberText)
       {
           /*
            * sStrip Numbers
            */
           string sRet = "";
 
           sRet = Regex.Replace(sAlphaNumberText, @"[\d-]"string.Empty);
           return sRet;
       }
 
       public static string StripAllSpecialCharacters(string sAlphaNumberText)
       {
           /*
            * Strip All Special Characters
            */
           string sRet = "";
 
           sRet = Regex.Replace(sAlphaNumberText, "[^0-9a-zA-Z]+""");
           return sRet;
       }

Tags: , , ,

Blog | CSharp | Regex

First of Current Month/First of Current Month

by ssi 11. February 2016 09:28

--First of Current Month
--First of Current Month
select    DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0) as Firstday                                              
    ,dateadd(day, -1, dateadd(month, 1, dateadd(day, 1 - day(GETDATE()), GETDATE()))) as lastday

Tags: ,

CSharp | SQL

Software Release

by ssi 19. January 2016 09:55

Tags:

CSharp

EWS Managed API 2.0

by ssi 13. January 2016 10:06

 

https://msdn.microsoft.com/en-us/library/office/dd633709.aspx

Applies to: EWS Managed API

The Exchange Web Services (EWS) Managed API provides a simple and full-featured interface for developing and extending applications that use EWS. You can use the EWS Managed API to access EWS in versions of Exchange starting with Exchange Server 2007 Service Pack 1 (SP1), including Exchange Online.

The EWS Managed API provides user-friendly abstractions of XML messages, XML serialization, and the formation of the HTTP requests and responses that are sent between the client and server.

You can download the EWS Managed API from the Microsoft Download Center.

Tags:

CSharp

Timespan Start Stop Clock

by ssi 13. January 2016 09:48
DateTime dStopCLock = DateTime.Now;
TimeSpan ts = dStartCLock - dStopCLock;
double differenceInSeconds = ts.TotalSeconds;
ts = TimeSpan.FromSeconds(ts.TotalSeconds);
 
string sDuration = string.Format("Dur: {0:D2}h:{1:D2}m:{2:D2}s",
             ts.Hours,
             ts.Minutes,
             ts.Seconds);
Console.WriteLine(sDuration);

Tags:

CSharp

Freeze Rows In Excel

by ssi 13. January 2016 08:13
wb.PrintHCenter = true;
      int nTopFreezeRow = 0;
      int nIgnore = 0;
      int nBottomFreezeRow = 4;
     string stest = "$1:$3,$C:$C";
      stest = string.Format("${0}:${1},${2}:${2}", 1,   nBottomFreezeRow, "C"); //must  be 1
      wb.PrintTitles = stest; //Not  sure  about the $C:$C part
      wb.freezePanes(nTopFreezeRow, nIgnore, nBottomFreezeRow, nIgnore, false);
 
      if (BigPaper)
          wb.setPrintPaperSize((int)(8.5 * 1440), (int)(14 * 1440));
      RangeStyle rs = wb.getRangeStyle();

Tags: , , ,

CSharp | SmartXLS

Bankers' Rounding.

by ssi 8. January 2016 08:39

Round half to even

A tie-breaking rule that is less biased is round half to even, namely:

  • If the fraction of y is 0.5, then q is the even integer nearest to y.

Thus, for example, +23.5 becomes +24, as does +24.5; while −23.5 becomes −24, as does −24.5.

This method treats positive and negative values symmetrically, and is therefore free of sign bias. More importantly, for reasonable distributions of y values, the expected (average) value of the rounded numbers is the same as that of the original numbers. However, this rule will introduce a towards-zero bias when y − 0.5 is even, and a towards-infinity bias for when it is odd.

This variant of the round-to-nearest method is also called unbiased rounding, convergent rounding, statistician's rounding, Dutch rounding, Gaussian rounding, odd–even rounding,[3] or bankers' rounding.

This is the default rounding mode used in IEEE 754 computing functions and operators.

Tags: ,

CSharp | Notes | SQL

GetImportExportPath

by ssi 8. January 2016 08:05
public static string GetImportExportPath(string sCode, string sPath)
     {
         string sRet = "";
         switch (sCode)
         {
             case "IMPORT":
                 sRet = @"\\FB670SRV01\Docs\Technology\Import\";
                 break;
             case "EXPORT":
                 sRet = @"\\FB670SRV01\Docs\Technology\Reports\";
                 break;
             case "CUSTOM":
                 sRet = sPath;
                 break;
 
             default:
                 sRet = @"\\FB670SRV01\Docs\Technology\Reports\";
 
                 break;
         }
         clsFolders oFld = new clsFolders();
         oFld.CreateFolder(sRet);
         return sRet;
     }

Tags:

CSharp

Ge Total Free Space on a Drive (In KB - Tb)

by ssi 28. December 2015 10:56
private static long GetTotalFreeSpace(string sDriveName)
       {
           long nRet = -1;
           foreach (DriveInfo drive in DriveInfo.GetDrives())
           {
               if (drive.IsReady && drive.Name == sDriveName)
               {
                   nRet = drive.TotalFreeSpace;
               }
           }
           return nRet;
       }
 
       private static long GetTotalFreeSpace(string sDriveName, string sUnits)
       {
           long nDenominator = 1;
           switch (sUnits)
           {
               case "K":
                   nDenominator = 1024;
                   break;
               case "M":
                   nDenominator = 1048576;
                   break;
               case "G":
                   nDenominator = 1073741824;
                   break;
               case "T":
                   nDenominator = 1099511627776;
                   break;
               default:
                   break;
           }
 
 
           long nRet = -1;
           foreach (DriveInfo drive in DriveInfo.GetDrives())
           {
               if (drive.IsReady && drive.Name == sDriveName)
               {
                   nRet =(longclsCommonStatics.ZeroDouble ((double) drive.TotalFreeSpace, (double)nDenominator) ;
               }
           }
           return nRet;
       }

Tags: , ,

CSharp | SQL

Chart Class Using Smart XLS

by ssi 25. December 2015 16:58
using SmartXLS;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
 
namespace ChartClass
{
    public class clsPROD_DbSizeChart
    {
        private string sStartRange;
        private string sEndRange;
        private string sRngTotal;
 
        public string _acct = "_($* #,##0_);_($* (#,##0);_($* \"-\"??_);_(@_)",
               _noterate = "#,##0.000_);(#,##0.000);_($* \"-\"??_)",
               _currency = "$#,##0.00_);($#,##0.00)",
               _txt = "@",
               _date = "m/d/yyyy",
               _general = "General",
               _generalNumber = "#,##0;(#,##0);_(* \"-\"??_)",
               _intNumber = "#,##0;(#,##0);_(* \"-\"??_)",
               _genNum3 = "#,##0.000;(#,##0.000);_(* \"-\"??_)",
               _percent = "#,##0.00%;(#,##0.00%);_(* \"-\"??_)";
 
        public List<ChartData> CHARTDATA { getset; }
        public string ReportingClassName { getset; }
        public bool ExcelTableFormat { getset; }
        public string CallingAppVersion { getset; }
        public int LoanCount { getset; }
        public string CallingApp { getset; }
        public string ResultType { getset; }
 
        public string RunNote { getset; }
 
        public string ConnectionString { getset; }
 
        public string ReportTitle { getset; }
 
        public string User { getset; }
 
        public string Version { getset; }
 
        public string PageNumber { getset; }
 
        public string ExportPathName { getset; }
 
        public DateTime StartDate { getset; }
 
        public DateTime EndDate { getset; }
 
        public int SheetNumber { getset; }
        public int LastXDays { getset; }
 
        public string SheetName { getset; }
 
        #region Constructor
 
        public clsPROD_DbSizeChart(string sConnect)
        {
            ConnectionString = sConnect;
            // LOG = swLog;
        }
 
        #endregion Constructor
 
        public void ProcessMe(WorkBook wb)
        {
            //format
            //http://msdn.microsoft.com/en-us/library/0c899ak8.aspx
            // WorkBook wb;
            DateTime dStart = StartDate;
            DateTime dEnd = EndDate;
            // string StartRange, eRange, rngTotal;
            decimal nStart;
            bool b = decimal.TryParse(dStart.ToString("yyyyMMdd"), out nStart);
            decimal nEnd;
            b = decimal.TryParse(dEnd.ToString("yyyyMMdd"), out nEnd);
 
            //AMCSupportDataClassesDataContext dcSupport = new AMCSupportDataClassesDataContext(clsCommonStatics.GetSupportConnectionString());
 
        
 
            #region ExcelExport
 
            wb.NumSheets = SheetNumber + 1;
            wb.setSheetName(SheetNumber, SheetName);
            wb.Sheet = SheetNumber;
            double nMarBot = wb.PrintBottomMargin;
            double nMarTop = wb.PrintTopMargin;
            double nMarRt = wb.PrintRightMargin;
            double nMarLt = wb.PrintLeftMargin;
 
            wb.PrintHeader = "";
            wb.PrintFooterMargin = .25d;
            wb.PrintBottomMargin = .5d;
            wb.PrintTopMargin = .25d;
            wb.PrintRightMargin = .25d;
            wb.PrintLeftMargin = .25d;
            wb.PrintGridLines = true;
            wb.PrintScaleFitVPages = 2;
            wb.PrintScaleFitHPages = 1;
            wb.PrintScaleFitToPage = true;
            wb.PrintHCenter = true;
            wb.PrintTitles = "$1:$4,$C:$C"//Not  sure  about the $C:$C part
            wb.setPrintPaperSize((int)(8.5 * 1440), (int)(14 * 1440));
            int nTopFreezeRow = 0;
            int nIgnore = 0;
            int nBottomFreezeRow = 4;
            wb.freezePanes(nTopFreezeRow, nIgnore, nBottomFreezeRow, nIgnore, false);
            wb.PrintLandscape = true;
            RangeStyle rs = wb.getRangeStyle();
 
            int nCol = 0;
            int nRow = 0;
 
          VS201300.clsSXFormatter oFrm = new VS201300.clsSXFormatter(wb);
 
            int nLastCol = 4;
            oFrm.HorizontalAlignment = RangeStyle.HorizontalAlignmentCenterAcrossCells;
            oFrm.Pattern = RangeStyle.PatternSolid;// 1;
            oFrm.PatternFG = Color.MidnightBlue.ToArgb();
            oFrm.FontColor = Color.White;
 
            string[] aHeader =  {
                                  "Date DownLoaded"
                                 ,"File Size"
                                                          };
 
            oFrm.WriteText(ReportTitle, nRow, 0, nRow, aHeader.Length - 1, true, 12, false);
            nRow++;
            oFrm.WriteText(string.Format("Date Range: {0:d} to {1:d}", StartDate, EndDate), nRow, 0, nRow, aHeader.Length - 1, true, 10, false);
            nRow++;
            oFrm.WriteText(string.Format("Run Date: {0:d}"DateTime.Today), nRow, 0, nRow, aHeader.Length - 1, true, 10, false);
            nRow++;
 
            oFrm.WriteText("", nRow, 0, nRow, aHeader.Length - 1, true, 10, false);
 
            nCol = 0;
 
            nCol = 1;
            nCol = 0;
            oFrm.Wrap = true;
            foreach (string s in aHeader)
            {
                oFrm.WriteText(s.Replace("_"" "), nRow, nCol, nRow, nCol, true, 10, true);
                nCol++;
            }
            oFrm.Pattern = RangeStyle.PatternNull;
            oFrm.FontColor = Color.Black;
            oFrm.HorizontalAlignment = RangeStyle.HorizontalAlignmentLeft;
            oFrm.Wrap = false;
            nRow++;
 
            nCol = 0;
            int nLoanCount = 0;
            int nStartRow = nRow;
            int nEndRow = nRow;
            var Sorted = CHARTDATA.OrderBy(r => r.Label);
            int nChartStartRow = nRow;
            foreach (var ln in Sorted)
            {
                oFrm.HorizontalAlignment = RangeStyle.HorizontalAlignmentLeft;
 
                oFrm.WriteText(string.Format("{0}", ln.Label), nRow, nCol, nRow, nCol, false, 10, false);
                wb.setColWidth(nCol, 35 * 256);
                nCol++;
             
 
                oFrm.WriteNumber((double)ln.Value, nRow, nCol, nRow, nCol, false, 10, _genNum3);
                wb.setColWidth(nCol, 20 * 256);
                nCol++;
 
                nEndRow = nRow;
                nRow++;
 
                nCol = 0;
                nLoanCount++;
            }
 
            int nChartEndRow = nEndRow + 1;
 
            int nBottomVertRow = nRow - 1;
 
            #endregion ExcelExport
 
            //  oFrm.WriteText("Loans displayed in red font have not been exported via the GL TRANS report.  The GL TRANS needs to be generated for the date range listed for the loans in red font.", nRow, nCol, nRow, nCol, true, 10, false);
            oFrm.FontColor = Color.Black;
 
            #region UserHouseKeeping
 
            nRow++;
            nRow++;
            nRow++;
 
            VS201300.clsInfo oABt = new VS201300.clsInfo();
            oFrm.WriteText(string.Format("AMC Support Version {0} Report Library Version {1}", Version, oABt.VS2103Version), nRow, 0, nRow, nLastCol, true, 8, false);
       
            #endregion UserHouseKeeping
 
            LoanCount = nLoanCount;
 
          
            wb.Sheet = 0;
 
            #region Chart
 
            //create chart with it's location
            //Columns & Rows
            int left = 3;
            int top = 6;
            int right = 20;
            int bottom = 40;
 
            //create chart with it's location
            ChartShape chart = wb.addChart(left, top, right, bottom);
            chart.ChartType = ChartShape.Line;
 
            string sRange = string.Format("{0}!$A${1}:$B${2}", SheetName, nStartRow, nEndRow);
 
            chart.setLinkRange(sRange, false);
            //set axis title
            chart.setAxisTitle(ChartShape.XAxis, 0, "Date");
            chart.setAxisTitle(ChartShape.YAxis, 0, "Gbytes");
            //set series name
            chart.setSeriesName(0, "File Size");
            //chart.setSeriesName(1, "My Series number 2");
 
            chart.Title = "Download File Size Chart [PROD]";
 
            //set plot area's color to darkgray
            ChartFormat chartFormat = chart.PlotFormat;
            chartFormat.setSolid();
            chartFormat.ForeColor = Color.DarkGray.ToArgb();
            chart.PlotFormat = chartFormat;
 
            //set series 0's color to blue
            ChartFormat seriesformat = chart.getSeriesFormat(0);
            chartFormat.setSolid();
            seriesformat.ForeColor = Color.Red.ToArgb();
            chart.setSeriesFormat(0, seriesformat);
 
            //set series 1's color to red
            //seriesformat = chart.getSeriesFormat(1);
            //seriesformat.setSolid();
            //seriesformat.ForeColor = Color.Red.ToArgb();
            //chart.setSeriesFormat(1, seriesformat);
 
            //set chart title's font property
            ChartFormat titleformat = chart.TitleFormat;
            titleformat.FontSize = 14 * 20;
            titleformat.FontUnderline = true;
            chart.TitleFormat = titleformat;
 
            #endregion Chart
        }
 
      
    }
}

Tags: , , ,

CSharp | linq | SmartXLS

Calendar

<<  May 2024  >>
MoTuWeThFrSaSu
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

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

"Procrastination is, hands down, our favorite form of self-sabotage"
Alyce P. Cornyn-Selby