using Microsoft.Dynamics.ApplicationPlatform.Environment;
using Microsoft.Dynamics.ApplicationPlatform.Environment.Settings;
using System;
using System.Globalization;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
public static class ALM_Global
{
public static str startDateHijri(str _date)
{
int d,m,y;
TransDate dt,dt1;
str finalDate;
str hijriDate = _date;
dt = str2Date(hijriDate,213);
d = dayOfMth(dt);
m = mthofyr(dt);
y = year(dt);
var hdate = new DateTime(y,m, 1);
finalDate = hdate.ToString("MM/dd/yyyy");
return finalDate;
}
public static str endDateHijri(str _date)
{
int days,d,m,y;
TransDate dt,dt1;
str finalDate;
str hijriDate = _date;
dt = str2Date(hijriDate,213);
d = dayOfMth(dt);
m = mthofyr(dt);
y = year(dt);
UmAlQuraCalendar cal = new UmAlQuraCalendar();
days = cal.GetDaysInMonth(y, m);
// var hdate = new DateTime(y,m, days);
finalDate = int2Str(m)+'/'+int2Str(days)+'/'+int2Str(y);
// finalDate = hdate.ToString("MM/dd/yyyy");
return finalDate;
}
public static str hijriToGregorian(str _hijriDate)
{
System.Globalization.CultureInfo arCul = new System.Globalization.CultureInfo("ar-SA");
System.Globalization.CultureInfo enCul = new System.Globalization.CultureInfo("en-US");
System.DateTime tempDateTime;
str strTemp,finalDate,hDate,hmonth,hYear;
System.String[] arr;
date grDate;
str hijriDate;
;
//grDate = str2Date(_hijriDate,123);
//hDate = date2Str(_hijriDate,123,DateDay::Digits2,DateSeparator::Slash,DateMonth::Digits2,DateSeparator::Slash,DateYear::Digits4);
//all expected dates formats
arr = new System.String[4]();
arr.SetValue("dd/MM/yyyy", 0);
arr.SetValue("M/dd/yyyy" , 1);
arr.SetValue("M/d/yyyy" , 2);
arr.SetValue("MM/dd/yyyy", 3);
if(_hijriDate != '')
{
tempDateTime = System.DateTime::ParseExact(_hijriDate, arr, arCul, System.Globalization.DateTimeStyles::AllowWhiteSpaces);
strTemp = tempDateTime.ToString("MM/dd/yyyy");
//grDate = str2date(strTemp, 123);
finalDate = strTemp;
}
return finalDate;
}
public static str getMonthHijri(TransDate date, int periods)
{
str hDate,hmonth,hYear,finalDate;
int gDate,gMonth,gYear;
;
gDate = dayOfMth(_date);
gMonth = mthOfYr(_date);
gYear = year(_date);
// Sets a DateTime of the Gregorian calendar.
DateTime myDT = new DateTime(gYear,gMonth,gDate, new GregorianCalendar());
// Creates an instance of the HijriCalendar.
HijriCalendar myCal = new HijriCalendar();
myDT = myCal.AddMonths( myDT, _periods );
hDate = int2Str(myCal.GetDayOfMonth(myDT));
hmonth = int2Str(myCal.GetMonth(myDT));
hYear = int2Str(myCal.GetYear(myDT));
finalDate = hmonth+"/"+hdate+"/"+hYear;
return finalDate;
}
public static str getNextMonthHijri(str date, int periods)
{
str hDate,hmonth,hYear,finalDate,hijriDate, dt1,dt2;
int gDate,gDate1,gMonth,gYear;
;
dt1 = strDel(_date,1,3);
//info(a);
dt2 = strDel(dt1,3,5);
//Info(b);
gDate = str2Int(dt2);
gMonth = str2Int(strDel(_date,3,8));
gYear = str2Int(strDel(_date,1,6));
//// Sets a DateTime of the Gregorian calendar.
DateTime myDT = new DateTime(gYear,gMonth,gDate, new HijriCalendar());
// Creates an instance of the HijriCalendar.
HijriCalendar myCal = new HijriCalendar();
myDT = myCal.AddMonths( myDT, _periods );
hDate = int2Str(myCal.GetDayOfMonth(myDT));
hmonth = int2Str(myCal.GetMonth(myDT));
hYear = int2Str(myCal.GetYear(myDT));
finalDate = hmonth+"/"+hdate+"/"+hYear;
return finalDate;
}
public static str getNextWeekHijri(str date, int periods)
{
str hDate,hmonth,hYear,finalDate,hijriDate, dt1,dt2;
int gDate,gDate1,gMonth,gYear;
;
dt1 = strDel(_date,1,3);
//info(a);
dt2 = strDel(dt1,3,5);
//Info(b);
gDate = str2Int(dt2);
gMonth = str2Int(strDel(_date,3,8));
gYear = str2Int(strDel(_date,1,6));
//// Sets a DateTime of the Gregorian calendar.
DateTime myDT = new DateTime(gYear,gMonth,gDate, new HijriCalendar());
// Creates an instance of the HijriCalendar.
HijriCalendar myCal = new HijriCalendar();
myDT = myCal.AddWeeks( myDT, _periods );
hDate = int2Str(myCal.GetDayOfMonth(myDT));
hmonth = int2Str(myCal.GetMonth(myDT));
hYear = int2Str(myCal.GetYear(myDT));
finalDate = hmonth+"/"+hdate+"/"+hYear;
return finalDate;
}
public static str getHijriDate(TransDate _date)
{
int gDate,gMonth,gYear;
gDate = dayOfMth(_date);
gMonth = mthOfYr(_date);
gYear = year(_date);
System.Globalization.CultureInfo arCul = new System.Globalization.CultureInfo("ar-SA");
DateTime dt = new DateTime(gYear, gMonth, gDate);
str s = dt.ToString("M/dd/yyyy", arCul);
//MessageBox.Show(s);
return s;
}
}
using Microsoft.Dynamics.ApplicationPlatform.Environment.Settings;
using System;
using System.Globalization;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
public static class ALM_Global
{
public static str startDateHijri(str _date)
{
int d,m,y;
TransDate dt,dt1;
str finalDate;
str hijriDate = _date;
dt = str2Date(hijriDate,213);
d = dayOfMth(dt);
m = mthofyr(dt);
y = year(dt);
var hdate = new DateTime(y,m, 1);
finalDate = hdate.ToString("MM/dd/yyyy");
return finalDate;
}
public static str endDateHijri(str _date)
{
int days,d,m,y;
TransDate dt,dt1;
str finalDate;
str hijriDate = _date;
dt = str2Date(hijriDate,213);
d = dayOfMth(dt);
m = mthofyr(dt);
y = year(dt);
UmAlQuraCalendar cal = new UmAlQuraCalendar();
days = cal.GetDaysInMonth(y, m);
// var hdate = new DateTime(y,m, days);
finalDate = int2Str(m)+'/'+int2Str(days)+'/'+int2Str(y);
// finalDate = hdate.ToString("MM/dd/yyyy");
return finalDate;
}
public static str hijriToGregorian(str _hijriDate)
{
System.Globalization.CultureInfo arCul = new System.Globalization.CultureInfo("ar-SA");
System.Globalization.CultureInfo enCul = new System.Globalization.CultureInfo("en-US");
System.DateTime tempDateTime;
str strTemp,finalDate,hDate,hmonth,hYear;
System.String[] arr;
date grDate;
str hijriDate;
;
//grDate = str2Date(_hijriDate,123);
//hDate = date2Str(_hijriDate,123,DateDay::Digits2,DateSeparator::Slash,DateMonth::Digits2,DateSeparator::Slash,DateYear::Digits4);
//all expected dates formats
arr = new System.String[4]();
arr.SetValue("dd/MM/yyyy", 0);
arr.SetValue("M/dd/yyyy" , 1);
arr.SetValue("M/d/yyyy" , 2);
arr.SetValue("MM/dd/yyyy", 3);
if(_hijriDate != '')
{
tempDateTime = System.DateTime::ParseExact(_hijriDate, arr, arCul, System.Globalization.DateTimeStyles::AllowWhiteSpaces);
strTemp = tempDateTime.ToString("MM/dd/yyyy");
//grDate = str2date(strTemp, 123);
finalDate = strTemp;
}
return finalDate;
}
public static str getMonthHijri(TransDate date, int periods)
{
str hDate,hmonth,hYear,finalDate;
int gDate,gMonth,gYear;
;
gDate = dayOfMth(_date);
gMonth = mthOfYr(_date);
gYear = year(_date);
// Sets a DateTime of the Gregorian calendar.
DateTime myDT = new DateTime(gYear,gMonth,gDate, new GregorianCalendar());
// Creates an instance of the HijriCalendar.
HijriCalendar myCal = new HijriCalendar();
myDT = myCal.AddMonths( myDT, _periods );
hDate = int2Str(myCal.GetDayOfMonth(myDT));
hmonth = int2Str(myCal.GetMonth(myDT));
hYear = int2Str(myCal.GetYear(myDT));
finalDate = hmonth+"/"+hdate+"/"+hYear;
return finalDate;
}
public static str getNextMonthHijri(str date, int periods)
{
str hDate,hmonth,hYear,finalDate,hijriDate, dt1,dt2;
int gDate,gDate1,gMonth,gYear;
;
dt1 = strDel(_date,1,3);
//info(a);
dt2 = strDel(dt1,3,5);
//Info(b);
gDate = str2Int(dt2);
gMonth = str2Int(strDel(_date,3,8));
gYear = str2Int(strDel(_date,1,6));
//// Sets a DateTime of the Gregorian calendar.
DateTime myDT = new DateTime(gYear,gMonth,gDate, new HijriCalendar());
// Creates an instance of the HijriCalendar.
HijriCalendar myCal = new HijriCalendar();
myDT = myCal.AddMonths( myDT, _periods );
hDate = int2Str(myCal.GetDayOfMonth(myDT));
hmonth = int2Str(myCal.GetMonth(myDT));
hYear = int2Str(myCal.GetYear(myDT));
finalDate = hmonth+"/"+hdate+"/"+hYear;
return finalDate;
}
public static str getNextWeekHijri(str date, int periods)
{
str hDate,hmonth,hYear,finalDate,hijriDate, dt1,dt2;
int gDate,gDate1,gMonth,gYear;
;
dt1 = strDel(_date,1,3);
//info(a);
dt2 = strDel(dt1,3,5);
//Info(b);
gDate = str2Int(dt2);
gMonth = str2Int(strDel(_date,3,8));
gYear = str2Int(strDel(_date,1,6));
//// Sets a DateTime of the Gregorian calendar.
DateTime myDT = new DateTime(gYear,gMonth,gDate, new HijriCalendar());
// Creates an instance of the HijriCalendar.
HijriCalendar myCal = new HijriCalendar();
myDT = myCal.AddWeeks( myDT, _periods );
hDate = int2Str(myCal.GetDayOfMonth(myDT));
hmonth = int2Str(myCal.GetMonth(myDT));
hYear = int2Str(myCal.GetYear(myDT));
finalDate = hmonth+"/"+hdate+"/"+hYear;
return finalDate;
}
public static str getHijriDate(TransDate _date)
{
int gDate,gMonth,gYear;
gDate = dayOfMth(_date);
gMonth = mthOfYr(_date);
gYear = year(_date);
System.Globalization.CultureInfo arCul = new System.Globalization.CultureInfo("ar-SA");
DateTime dt = new DateTime(gYear, gMonth, gDate);
str s = dt.ToString("M/dd/yyyy", arCul);
//MessageBox.Show(s);
return s;
}
}
No comments:
Post a Comment