private void initLabels()
 {
     PersianDate pd = new PersianDate(DateTime.Today);
     date_Lbl.Content = pd.ToShortDateString();
     newId = getNewId();
     ID_Lbl.Content = Codes.ApartmanMaskooniForooshi + " -  " + newId;
 }
Esempio n. 2
0
        private bool TryParseDateTime(string datetime, out DateTime?dt)
        {
            dt = null;

            try
            {
                if (string.IsNullOrEmpty(datetime))
                {
                    return(false);
                }

                if (CultureHelper.IsFarsiCulture())
                {
                    dt = PersianDate.Parse(datetime);
                }
                else
                {
                    dt = DateTime.Parse(datetime);
                }

                if (dt.HasValue)
                {
                    dt = dt.Value.Date;
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 3
0
        protected override DateTime ExtractDateTimeFromCellDate(DateTime date)
        {
            PersianDate pd = date;

            if (View == DateEditCalendarViewType.MonthInfo)
            {
                return(new PersianDate(pd.Year, pd.Month, CorrectDay(pd.Year, pd.Month, pd.Day), pd.Hour, pd.Minute, pd.Second, pd.Millisecond));
            }

            if (View == DateEditCalendarViewType.YearInfo)
            {
                return(new PersianDate(pd.Year, pd.Month, CorrectDay(pd.Year, pd.Month, pd.Day), SelectedDate.Hour, SelectedDate.Minute, SelectedDate.Second, SelectedDate.Millisecond));
            }

            if (View == DateEditCalendarViewType.YearsInfo)
            {
                return(new PersianDate(pd.Year, pd.Month, CorrectDay(pd.Year, pd.Month, pd.Day), SelectedDate.Hour, SelectedDate.Minute, SelectedDate.Second, SelectedDate.Millisecond));
            }

            if (View != DateEditCalendarViewType.YearsGroupInfo)
            {
                return(pd);
            }

            var yearDiff = pd.Year == 1 ? 0 : pd.Year;

            return(new PersianDate(yearDiff + pd.Year % 10, pd.Month, CorrectDay(yearDiff + pd.Year % 10, pd.Month, pd.Day), SelectedDate.Hour, SelectedDate.Minute, SelectedDate.Second, SelectedDate.Millisecond));
        }
Esempio n. 4
0
        /// <summary>
        /// Convert DateTime to a formatted string(ShortDatePattern)
        /// </summary>
        /// <param name="value">DateTime</param>
        /// <param name="targetType">string</param>
        /// <param name="parameter">null</param>
        /// <param name="culture"></param>
        /// <returns>formatted or empty string</returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (culture == null)
            {
                throw new ArgumentNullException("culture");
            }

            DateTimeFormatInfo dateTimeFormat = culture.DateTimeFormat;

            if (dateTimeFormat == null)
            {
                throw new ArgumentNullException("culture");
            }

            if (value != null && value is DateTime)
            {
                DateTime date = (DateTime)value;

                if (CultureHelper.IsFarsiCulture)
                {
                    PersianDate pd = date;
                    return(pd.ToString("g"));
                }
                else
                {
                    return(date.ToString(dateTimeFormat.ShortDatePattern, dateTimeFormat));
                }
            }

            return(string.Empty);
        }
Esempio n. 5
0
        private void btnAddMonth_Click(object sender, EventArgs e)
        {
            PersianDate pd = new PersianDate(calendar.AddMonths(DateTime.Now, 2));

            lblMessage.Text   = pd.ToString();
            lblToWritten.Text = pd.ToWritten();
        }
Esempio n. 6
0
        public void Can_Convert_To_Written()
        {
            PersianDate pd      = new PersianDate("1384/1/1");
            string      written = pd.ToWritten();

            Assert.AreEqual(string.Format("{0} {1} {2} {3}", pd.LocalizedWeekDayName, pd.Day, pd.LocalizedMonthName, pd.Year), written);
        }
Esempio n. 7
0
        public void Seven_DaysOfWeek_Index_Value_Validity()
        {
            var pd1 = new PersianDate(1387, 8, 2);

            Assert.AreEqual(pd1.DayOfWeek, DayOfWeek.Thursday);

            var pd2 = new PersianDate(1387, 8, 3);

            Assert.AreEqual(pd2.DayOfWeek, DayOfWeek.Friday);

            var pd3 = new PersianDate(1387, 8, 4);

            Assert.AreEqual(pd3.DayOfWeek, DayOfWeek.Saturday);

            var pd4 = new PersianDate(1387, 8, 5);

            Assert.AreEqual(pd4.DayOfWeek, DayOfWeek.Sunday);

            var pd5 = new PersianDate(1387, 8, 6);

            Assert.AreEqual(pd5.DayOfWeek, DayOfWeek.Monday);

            var pd6 = new PersianDate(1387, 8, 7);

            Assert.AreEqual(pd6.DayOfWeek, DayOfWeek.Tuesday);

            var pd7 = new PersianDate(1387, 8, 8);

            Assert.AreEqual(pd7.DayOfWeek, DayOfWeek.Wednesday);
        }
Esempio n. 8
0
        public void Comparing_PersianDate_Using_Less_Than_Operator_Differing_Millisecond()
        {
            PersianDate pd1 = new PersianDate(1384, 1, 29, 20, 20, 10, 21);
            PersianDate pd2 = new PersianDate(1384, 1, 29, 20, 20, 10, 22);

            CheckDates(pd1, pd2);
        }
Esempio n. 9
0
        public void PersianDate_Instance_Creates_StringBased_HashCode()
        {
            PersianDate pd       = PersianDate.Now;
            int         hashcode = pd.ToString("s").GetHashCode();

            Assert.AreEqual(hashcode, pd.GetHashCode());
        }
Esempio n. 10
0
        public void Comparing_PersianDate_Using_Less_Than_Operator_Differing_Day()
        {
            PersianDate pd1 = new PersianDate(1384, 1, 29);
            PersianDate pd2 = new PersianDate(1384, 1, 30);

            CheckDates(pd1, pd2);
        }
Esempio n. 11
0
        public void Comparing_Persian_Date_Using_Less_Than_Operator_Differing_Minute()
        {
            PersianDate pd1 = new PersianDate(1384, 1, 29, 20, 20);
            PersianDate pd2 = new PersianDate(1384, 1, 29, 20, 35);

            CheckDates(pd1, pd2);
        }
Esempio n. 12
0
        public void Compare_PersianDate_Using_Not_Equal_Operator()
        {
            PersianDate pd1 = new PersianDate(1380, 11, 23);
            PersianDate pd2 = new PersianDate(1384, 1, 30);

            Assert.True(pd1 != pd2);
        }
Esempio n. 13
0
        public void Compare_PersianDate_Using_Less_Than_Operator()
        {
            PersianDate pd2 = new PersianDate(1380, 11, 23);
            PersianDate pd1 = new PersianDate(1384, 1, 30);

            Assert.True(pd2 < pd1);
        }
Esempio n. 14
0
        public void ToString_With_General_Parameter_Returns_Date_And_Time()
        {
            var pd = new PersianDate(1380, 1, 1);
            var am = PersianDateTimeFormatInfo.AMDesignator;

            Assert.AreEqual("1380/01/01 00:00:00 " + am, pd.ToString("G"));
        }
Esempio n. 15
0
        public void Seven_Days_Of_Week_Validity()
        {
            var pd1 = new PersianDate(1386, 6, 1);

            Assert.AreEqual(pd1.DayOfWeek, DayOfWeek.Thursday);

            var pd2 = new PersianDate(1386, 6, 2);

            Assert.AreEqual(pd2.DayOfWeek, DayOfWeek.Friday);

            var pd3 = new PersianDate(1386, 6, 3);

            Assert.AreEqual(pd3.DayOfWeek, DayOfWeek.Saturday);

            var pd4 = new PersianDate(1386, 6, 4);

            Assert.AreEqual(pd4.DayOfWeek, DayOfWeek.Sunday);

            var pd5 = new PersianDate(1386, 6, 5);

            Assert.AreEqual(pd5.DayOfWeek, DayOfWeek.Monday);

            var pd6 = new PersianDate(1386, 6, 6);

            Assert.AreEqual(pd6.DayOfWeek, DayOfWeek.Tuesday);

            var pd7 = new PersianDate(1386, 6, 7);

            Assert.AreEqual(pd7.DayOfWeek, DayOfWeek.Wednesday);
        }
Esempio n. 16
0
        public void Can_Create_With_HourAndMinute()
        {
            PersianDate pd = new PersianDate(1384, 1, 1, 20, 30);

            Assert.AreEqual(0, pd.Second);
            Assert.AreEqual(0, pd.Millisecond);
        }
Esempio n. 17
0
        public void Can_Get_Localized_Month_Name()
        {
            var pd        = new PersianDate(1380, 1, 1);
            var monthName = pd.LocalizedMonthName;

            Assert.AreEqual(monthName, PersianDateTimeFormatInfo.MonthNames[0]);
        }
Esempio n. 18
0
        public void Compare_PersianDate_With_Null_Using_Operator_Throws()
        {
            PersianDate pd1 = PersianDate.Now;
            PersianDate pd2 = null;

            Assert.Throws <InvalidOperationException>(() => { var result = pd1 > pd2; });
        }
Esempio n. 19
0
 private void initLabels()
 {
     PersianDate pd = new PersianDate(DateTime.Today);
     Lbl_Date.Content = pd.ToShortDateString();
     newId = getNewId();
     Lbl_ID.Content = Codes.MaghazeEstijari + " -  " + newId;
 }
Esempio n. 20
0
        public static int ToPersianDate_8Num(this PersianDate date)
        {
            var persianDate      = new PersianDate(date).ToString("d");
            int persianDate_8Num = int.Parse(persianDate.Replace("/", string.Empty));

            return(persianDate_8Num);
        }
Esempio n. 21
0
        public void Can_Convert_To_Written()
        {
            PersianDate pd = new PersianDate("1384/1/1");
            string written = pd.ToWritten();

            Assert.AreEqual(string.Format("{0} {1} {2} {3}", pd.LocalizedWeekDayName, pd.Day, pd.LocalizedMonthName, pd.Year), written);
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is string)
            {
                string converting = (string)value;
                if (string.IsNullOrEmpty(converting))
                {
                    return(null);
                }

                if (CultureHelper.IsFarsiCulture())
                {
                    PersianDate pd;
                    if (PersianDate.TryParse(converting, out pd))
                    {
                        return(pd);
                    }
                }
                else
                {
                    DateTime dt;
                    if (DateTime.TryParse(converting, out dt))
                    {
                        return(dt.ToPersianDate());
                    }
                }
            }

            return(null);
        }
Esempio n. 23
0
        protected override string GetCellText(DateTime date, int row, int column)
        {
            var pd = (PersianDate)date;

            if (View == DateEditCalendarViewType.QuarterInfo)
            {
                return((row * 2 + column + 1).ToString());
            }

            if (View == DateEditCalendarViewType.YearInfo)
            {
                return(pd.LocalizedMonthName);
            }

            if (View == DateEditCalendarViewType.YearsInfo)
            {
                return(toFarsi.Convert(pd.Year.ToString()));
            }

            if (View == DateEditCalendarViewType.YearsGroupInfo)
            {
                var dateEnd = new PersianDate(pd.Year + 9, 1, 1);
                return(toFarsi.Convert(pd.Year + "-\n" + dateEnd.Year));
            }

            return(toFarsi.Convert(pd.Day.ToString()));
        }
    protected void lnk_lessonPost_Click(object sender, EventArgs e)
    {
        try
        {

            PersianDate pd = new PersianDate(txt_lr_showndate.Text);

            string str = FarsiLibrary.Utils.PersianDateConverter.ToGregorianDate(pd);

            new MainDataModuleTableAdapters.tbl_lesson_resultsTableAdapter().Insert(
                Convert.ToInt32(drp_lr_lesson_link.SelectedValue),
                Convert.ToDouble(txt_lr_result.Text),
                Convert.ToDateTime(str),
                DateTime.Now,
                Convert.ToInt32(Session["owner"].ToString()),
                Convert.ToInt32(drp_lr_customer_link.SelectedValue)
                );
            gr_studentresultslist.DataBind();
            lbl_newlessonresult_errmsg.Text = "";
        }
        catch (Exception _e)
        {
            lbl_newlessonresult_errmsg.Text = "اطلاعات ثبت نشد" + _e.Message;
        }
    }
Esempio n. 25
0
 private void initLabels()
 {
     PersianDate pd = new PersianDate(DateTime.Today);
     date_Lbl.Content = pd.ToShortDateString();
     newId = getNewId();
     ID_Lbl.Content = Codes.HouseEstijari + " -  " + newId;
 }
 protected override void OnValueValidating(ValueValidatingEventArgs e)
 {
     try
     {
         string txt = e.Value.ToString();
         if (string.IsNullOrEmpty(txt) || txt == FALocalizeManager.GetLocalizerByCulture(Thread.CurrentThread.CurrentUICulture).GetLocalizedString(StringID.Validation_NullText))
         {
             e.HasError = false;
         }
         else if (mv.MonthViewControl.DefaultCulture.Equals(mv.MonthViewControl.PersianCulture))
         {
             PersianDate pd = PersianDate.Parse(txt, GetFormatByFormatInfo(FormatInfo));
             e.HasError = false;
             mv.MonthViewControl.IsNull = false;
             mv.MonthViewControl.SelectedDateTime = pd;
         }
         else if (mv.MonthViewControl.DefaultCulture.Equals(mv.MonthViewControl.InvariantCulture))
         {
             DateTime dt = DateTime.Parse(txt);
             e.HasError = false;
             mv.MonthViewControl.IsNull = false;
             mv.MonthViewControl.SelectedDateTime = dt;
         }
     }
     catch (Exception)
     {
         e.HasError = true;
         mv.MonthViewControl.IsNull = true;
     }
 }
Esempio n. 27
0
        static void OnSelectedDateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            PersianDatePicker pdp = d as PersianDatePicker;
            var date = e.NewValue as DateTime?;

            if (date != null)
            {
                if (pdp.PersianSelectedDate == null || pdp.PersianSelectedDate.ToDateTime() != date.Value)
                {
                    PersianDate newDate;
                    if (PersianDate.TryParse(date.Value, out newDate))
                    {
                        d.SetValue(PersianSelectedDateProperty, newDate);
                    }
                    else
                    {
                        d.SetValue(PersianSelectedDateProperty, null);
                    }
                }
            }
            else
            {
                d.SetValue(PersianSelectedDateProperty, null);
            }
        }
Esempio n. 28
0
        private void ValidateText()
        {
            PersianDate date;

            string txt = this.Text.Replace('_', ' ');

            if (PersianDate.TryParse(txt, out date))
            {
                this.PersianSelectedDate = date;
                this.DisplayDate         = date;
                this.Text = date.ToString();
            }
            else
            {
                this.PersianSelectedDate = null;
                this.DisplayDate         = this.PersianSelectedDate ?? PersianDate.Today;
                if (this.AllowNull)
                {
                    this.Text = "____/__/__";
                }
                else
                {
                    this.Text = this.PersianSelectedDate.ToString();
                }
            }
        }
Esempio n. 29
0
        private void btnDeductDays(object sender, EventArgs e)
        {
            PersianDate pd = new PersianDate(calendar.AddDays(DateTime.Now, -66));

            lblMessage.Text   = pd.ToString();
            lblToWritten.Text = pd.ToWritten();
        }
Esempio n. 30
0
        private void SetMonthMode()
        {
            this.decadeUniformGrid.Visibility = this.yearUniformGrid.Visibility = Visibility.Collapsed;
            this.monthUniformGrid.Visibility  = Visibility.Visible;

            int         year            = DisplayDate.Year;
            int         month           = DisplayDate.Month;
            PersianDate firstDayInMonth = new PersianDate(year, month, 1);

            Style insideButtonStyle = (Style)this.FindResource("InsideButtonsStyle");
            Style GrayButtonStyle   = (Style)this.FindResource("GrayButtonsStyle");

            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 7; j++)
                {
                    PersianDate date = null;
                    bool        dateInRange;

                    try
                    {
                        date        = MonthModeRowColumnToDate(i, j, firstDayInMonth);
                        dateInRange = date >= DisplayDateStart && date <= DisplayDateEnd;
                    }
                    catch (OverflowException)
                    {
                        dateInRange = false;
                    }

                    var button = monthModeButtons[i, j];

                    if (dateInRange && date.Month == firstDayInMonth.Month)
                    {
                        button.Style     = insideButtonStyle;
                        button.Content   = date.Day.ToString();
                        button.IsEnabled = true;
                        button.Tag       = date;
                    }
                    else if (dateInRange)
                    {
                        button.Style     = GrayButtonStyle;
                        button.Content   = date.Day.ToString();
                        button.IsEnabled = true;
                        button.Tag       = date;
                    }
                    else
                    {
                        button.Tag        = null;
                        button.Content    = "";
                        button.IsEnabled  = false;
                        button.Background = Brushes.Transparent;
                    }
                }
            }

            this.titleButton.Content = ((PersianMonth)month).ToString() + " " + year.ToString();

            this.TodayCheck();
            this.SelectedDateCheck(null);
        }
Esempio n. 31
0
        static object CoercePersianSelectedDate(DependencyObject d, object o)
        {
            PersianDatePicker pdp   = d as PersianDatePicker;
            PersianDate       value = (PersianDate)o;

            if (value != null)
            {
                if (value < pdp.DisplayDateStart)
                {
                    return(pdp.DisplayDateStart);
                }

                if (value > pdp.DisplayDateEnd)
                {
                    return(pdp.DisplayDateEnd);
                }
            }
            else
            {
                if (pdp.AllowNull == false)
                {
                    if (pdp.PersianSelectedDate == null)
                    {
                        return(PersianDate.Today);
                    }
                    else
                    {
                        return(pdp.PersianSelectedDate);
                    }
                }
            }

            return(o);
        }
Esempio n. 32
0
        private void btnToday_Click(object sender, EventArgs e)
        {
            PersianDate pd = PersianDate.Now;

            lblMessage.Text   = pd.ToString();
            lblToWritten.Text = pd.ToWritten();
        }
Esempio n. 33
0
        private void drawMonthCalendar()
        {
            var startDay = PersianDate.Find1StDayOfMonth(CalendarData.Year, CalendarData.Month, CalendarAttributes.CalendarType);

            int noOfDays;

            if (CalendarAttributes.CalendarType == CalendarType.PersianCalendar)
            {
                noOfDays = CalendarData.Month <= 6 ? 31 : 30;
            }
            else
            {
                noOfDays = DateTime.DaysInMonth(CalendarData.Year, CalendarData.Month);
            }

            if (CalendarData.Month == 12 && CalendarAttributes.CalendarType == CalendarType.PersianCalendar)
            {
                noOfDays = CalendarData.Year.IsLeapYear(CalendarAttributes.CalendarType) ? 30 : 29;
            }

            var monthCells = createEmptyCells();

            fillCells(startDay, noOfDays, monthCells);
            addCells(monthCells);
        }
Esempio n. 34
0
        private void setYearMode()
        {
            this.monthUniformGrid.Visibility = this.decadeUniformGrid.Visibility = Visibility.Collapsed;
            this.yearUniformGrid.Visibility  = Visibility.Visible;

            this.titleButton.Content = this.DisplayDate.Year.ToString();

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    int month = j + i * 3 + 1;
                    if (new PersianDate(DisplayDate.Year, month, PersianDate.DaysInMonth(DisplayDate.Year, month)) >= DisplayDateStart &&
                        new PersianDate(DisplayDate.Year, month, 1) <= DisplayDateEnd)
                    {
                        yearModeButtons[i, j].Content   = ((PersianMonth)month).ToString();
                        yearModeButtons[i, j].IsEnabled = true;
                    }
                    else
                    {
                        yearModeButtons[i, j].Content   = "";
                        yearModeButtons[i, j].IsEnabled = false;
                    }
                }
            }
        }
Esempio n. 35
0
        static object coerceDisplayDateStart(DependencyObject d, object o)
        {
            PersianCalendar pc    = d as PersianCalendar;
            PersianDate     value = (PersianDate)o;

            return(o);
        }
        public void Can_Convert_Strings_ToDateTime()
        {
            PersianDate pd = new PersianDate(1380, 1, 1);
            DateTime converted = pd.ToDateTime();
            DateTime dt = PersianDateConverter.ToGregorianDateTime(pd.ToString());

            Assert.AreEqual(dt, converted);
        }
        public void DateTime_Automatically_Cast_To_PersianDate_Equality()
        {
            var pd = new PersianDate(1403, 12, 30);
            PersianDate dt = new DateTime(2025, 3, 20);

            Assert.AreEqual(dt.Year, pd.Year);
            Assert.AreEqual(dt.Month, pd.Month);
            Assert.AreEqual(dt.Day, pd.Day);
        }
Esempio n. 38
0
 public Employee(int employeeID, string lastname, string firstname, string address, string city, PersianDate hireDate, PersianDate birthDate)
 {
     this.employeeID = employeeID;
     this.lastname = lastname;
     this.firstname = firstname;
     this.address = address;
     this.city = city;
     this.hireDate = hireDate;
     this.birthDate = birthDate;
 }
        public void Can_Get_Start_Of_Month()
        {
            var today = new PersianDate(1388, 4, 20);
            var weekend = today.StartOfMonth();

            Assert.That((int)weekend.DayOfWeek, Is.EqualTo((int)DayOfWeek.Monday));
            Assert.That(weekend.Year, Is.EqualTo(1388));
            Assert.That(weekend.Month, Is.EqualTo(4));
            Assert.That(weekend.Day, Is.EqualTo(1));
        }
        public void Can_Get_End_Of_Week()
        {
            var today = new PersianDate(1388, 4, 25);
            var weekend = today.EndOfWeek();

            Assert.That((int)weekend.DayOfWeek, Is.EqualTo((int)DayOfWeek.Friday));
            Assert.That(weekend.Year, Is.EqualTo(1388));
            Assert.That(weekend.Month, Is.EqualTo(4));
            Assert.That(weekend.Day, Is.EqualTo(26));
        }
Esempio n. 41
0
 public static PrimaryMeeting ConvertToPrimaryMeeting(MeetingDB meeting)
 {
     PrimaryMeeting res = new PrimaryMeeting();
     res.Id = meeting.Id;
     res.Subject = meeting.Subject;
     res.Attendees = meeting.Attendees;
     res.Details = meeting.Description;
     res.Duration = meeting.ToString();
     PersianDate date = new PersianDate(meeting.StartDate);
     res.Date = date;
     return res; 
 }
        public void Can_Combine_Date_And_Time_Parts()
        {
            var prevDate = new PersianDate(1380, 1, 1, 5, 22, 30);
            var today = new PersianDate(1388, 4, 25);
            var combined = today.Combine(prevDate);

            Assert.That(combined.Year, Is.EqualTo(1388));
            Assert.That(combined.Month, Is.EqualTo(4));
            Assert.That(combined.Day, Is.EqualTo(25));
            Assert.That(combined.Hour, Is.EqualTo(5));
            Assert.That(combined.Minute, Is.EqualTo(22));
            Assert.That(combined.Second, Is.EqualTo(30));
        }
        /// <summary>
        /// Converts a Persian Date of type <c>String</c> to Gregorian Date of type <c>String</c>.
        /// </summary>
        /// <param name="date"></param>
        /// <returns>Gregorian DateTime representation in string format of evaluated Jalali Date.</returns>
        public static string ToGregorianDate(PersianDate date)
        {
            var jyear = date.Year;
            var jmonth = date.Month;
            var jday = date.Day;

            //Continue
            int i;

            var totalDays = JalaliDays(jyear, jmonth, jday);
            totalDays = totalDays + GYearOff;

            var gyear = (int)(totalDays / (Solar - 0.25 / 33));
            var Div4 = gyear / 4;
            var Div100 = gyear / 100;
            var Div400 = gyear / 400;
            var gdays = totalDays - (365 * gyear) - (Div4 - Div100 + Div400);
            gyear = gyear + 1;

            if (gdays == 0)
            {
                gyear--;
                gdays = GLeap(gyear) == 1 ? 366 : 365;
            }
            else
            {
                if (gdays == 366 && GLeap(gyear) != 1)
                {
                    gdays = 1;
                    gyear++;
                }
            }

            var leap = GLeap(gyear);
            for (i = 0; i <= 12; i++)
            {
                if (gdays <= GDayTable[leap, i])
                {
                    break;
                }

                gdays = gdays - GDayTable[leap, i];
            }

            var iGMonth = i + 1;
            var iGDay = gdays;

            return (Util.toDouble(iGMonth) + "/" + Util.toDouble(iGDay) + "/" + gyear + " " + Util.toDouble(date.Hour) + ":" + Util.toDouble(date.Minute) + ":" + Util.toDouble(date.Second));
        }
Esempio n. 44
0
        public BaghVillaF()
        {
            InitializeComponent();
            PersianDate pd = new PersianDate(DateTime.Today);
            date_Lbl.Content = pd.ToShortDateString();

            address_Txt.Focus();

            price = new DispatcherTimer();
            price.Tick += new EventHandler(price_Tick);
            price.Interval = TimeSpan.FromSeconds(1);
            price.Start();

            WndConfig.setConfig4SimpleSearch(this);
        }
Esempio n. 45
0
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                PersianDate pd = new PersianDate(DateTime.Today);
                String today = pd.ToShortDateString();
                String sql = "EXEC AddUser N'" + User_Txt.Text + "',N'" + Pass_Txt.Password + "',N'" + today + "'," +
                    Insert_CheckBox.IsChecked + "," + Search_CheckBox.IsChecked + "," + Delete_CheckBox.IsChecked + "," + Edit_CheckBox.IsChecked;

                DB.execSql(sql,0);
                MessageBox.Show("کاربر جدید با موفقیت ثبت گردید", "ثبت کاربر", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception)
            {
                MessageBox.Show("خطا در اتصال و یا اجرای درخواست از پایگاه داده ها", "خطا", MessageBoxButton.OK, MessageBoxImage.Error);
            }

        }
        public void Can_Get_End_Of_Week_For_Every_Day_Of_The_Week()
        {
            var firstDay = new PersianDate(1388, 7, 4);
            var secondDay = new PersianDate(1388, 7, 5);
            var thirdDay = new PersianDate(1388, 7, 6);
            var forthDay = new PersianDate(1388, 7, 7);
            var fifthDay = new PersianDate(1388, 7, 8);
            var sixthDay = new PersianDate(1388, 7, 9);
            var seventhDay = new PersianDate(1388, 7, 10);

            Assert.That(firstDay.EndOfWeek(), Is.EqualTo(seventhDay));
            Assert.That(secondDay.EndOfWeek(), Is.EqualTo(seventhDay));
            Assert.That(thirdDay.EndOfWeek(), Is.EqualTo(seventhDay));
            Assert.That(forthDay.EndOfWeek(), Is.EqualTo(seventhDay));
            Assert.That(fifthDay.EndOfWeek(), Is.EqualTo(seventhDay));
            Assert.That(sixthDay.EndOfWeek(), Is.EqualTo(seventhDay));
            Assert.That(seventhDay.EndOfWeek(), Is.EqualTo(seventhDay));
        }
Esempio n. 47
0
        /// <summary>
        /// Populates data source and binds data to controls.
        /// </summary>
        private void BindData()
        {
            int baseSize = this.Get<YafBoardSettings>().MemberListPageSize;
            int nCurrentPageIndex = this.PagerTop.CurrentPageIndex;
            this.PagerTop.PageSize = baseSize;

            DateTime sinceDate = DateTime.UtcNow.AddDays(-this.Get<YafBoardSettings>().EventLogMaxDays);       
            DateTime toDate = DateTime.UtcNow;

            var ci = CultureInfo.CreateSpecificCulture(this.GetCulture());

            if (this.SinceDate.Text.IsSet())
            {
                if (this.Get<YafBoardSettings>().UseFarsiCalender && ci.IsFarsiCulture())
                {
                    var persianDate = new PersianDate(this.SinceDate.Text);

                    sinceDate = PersianDateConverter.ToGregorianDateTime(persianDate);
                }
                else
                {
                    DateTime.TryParse(this.SinceDate.Text, ci, DateTimeStyles.None, out sinceDate);
                }
            }

            if (this.ToDate.Text.IsSet())
            {
                if (this.Get<YafBoardSettings>().UseFarsiCalender && ci.IsFarsiCulture())
                {
                    var persianDate = new PersianDate(this.ToDate.Text);

                    toDate = PersianDateConverter.ToGregorianDateTime(persianDate);
                }
                else
                {
                    DateTime.TryParse(this.ToDate.Text, ci, DateTimeStyles.None, out toDate);
                }
            }
           
            //  sinceDate = sinceDate.AddMinutes((double)(this.PageContext.CurrentUserData.TimeZone ?? this.PageContext.TimeZoneUser)).ToUniversalTime();
            // list event for this board
            DataTable dt = CommonDb.eventlog_list(
                this.PageContext.PageModuleID,
                this.PageContext.PageBoardID,
                this.PageContext.PageUserID,
                this.Get<YafBoardSettings>().EventLogMaxMessages,
                this.Get<YafBoardSettings>().EventLogMaxDays,
                nCurrentPageIndex,
                baseSize,
                sinceDate,
                toDate.AddDays(1).AddMinutes(-1),
                this.Types.SelectedValue.Equals("-1") ? null : this.Types.SelectedValue);

            this.List.DataSource = dt;

            this.PagerTop.Count = dt != null && dt.Rows.Count > 0
                                      ? dt.AsEnumerable().First().Field<int>("TotalRows")
                                      : 0;

            // bind data to controls
            this.DataBind();
        }
Esempio n. 48
0
        private string TryFormatEditValue(object editValue)
        {
            if (editValue is DateTime)
            {
                DateTime dt = (DateTime)editValue;

                if (PersianCalendar.IsWithInSupportedRange(dt))
                {
                    PersianDate pd = new PersianDate(dt);
                    return FormatDisplayText(pd);
                }
            }

            return string.Empty;
        }
Esempio n. 49
0
        public void ToString_With_General_Parameter_Returns_Date_And_Time()
        {
            var pd = new PersianDate(1380, 1, 1);
            var am = PersianDateTimeFormatInfo.AMDesignator;

            Assert.AreEqual("1380/01/01 00:00:00 " + am, pd.ToString("G"));
        }
        internal static string DayOfWeek(PersianDate date)
        {
            if (!date.IsNull)
            {
                var dt = ToGregorianDateTime(date);
                return DayOfWeek(dt);
            }

            return string.Empty;
        }
Esempio n. 51
0
        /// <summary>
        /// Populates data source and binds data to controls.
        /// </summary>
        private void BindData()
        {
            int baseSize = this.Get<YafBoardSettings>().MemberListPageSize;
            int nCurrentPageIndex = this.PagerTop.CurrentPageIndex;
            this.PagerTop.PageSize = baseSize;

            var sinceDate = DateTime.UtcNow.AddDays(-this.Get<YafBoardSettings>().EventLogMaxDays);
            var toDate = DateTime.UtcNow;

            var ci = this.Get<ILocalization>().Culture;

            if (this.SinceDate.Text.IsSet())
            {
                if (this.Get<YafBoardSettings>().UseFarsiCalender && ci.IsFarsiCulture())
                {
                    var persianDate = new PersianDate(this.SinceDate.Text);

                    sinceDate = PersianDateConverter.ToGregorianDateTime(persianDate);
                }
                else
                {
                    DateTime.TryParse(this.SinceDate.Text, ci, DateTimeStyles.None, out sinceDate);
                }
            }

            if (this.ToDate.Text.IsSet())
            {
                if (this.Get<YafBoardSettings>().UseFarsiCalender && ci.IsFarsiCulture())
                {
                    var persianDate = new PersianDate(this.ToDate.Text);

                    toDate = PersianDateConverter.ToGregorianDateTime(persianDate);
                }
                else
                {
                    DateTime.TryParse(this.ToDate.Text, ci, DateTimeStyles.None, out toDate);
                }
            }

            // list event for this board
            DataTable dt = this.GetRepository<EventLog>()
                               .List(
                                   this.PageContext.PageUserID,
                                   this.Get<YafBoardSettings>().EventLogMaxMessages,
                                   this.Get<YafBoardSettings>().EventLogMaxDays,
                                   nCurrentPageIndex,
                                   baseSize,
                                   sinceDate,
                                   toDate.AddDays(1).AddMinutes(-1),
                                   "1003,1004,1005,2000,2001,2002,2003");

            this.List.DataSource = dt;

            this.PagerTop.Count = dt != null && dt.HasRows()
                                      ? dt.AsEnumerable().First().Field<int>("TotalRows")
                                      : 0;

            // bind data to controls
            this.DataBind();
        }
Esempio n. 52
0
        public void Can_Create_With_String_And_Date_Formatting()
        {
            string datestring = "1384/01/03";
            PersianDate pd = new PersianDate(datestring);

            Assert.AreEqual(1384, pd.Year);
            Assert.AreEqual(1, pd.Month);
            Assert.AreEqual(3, pd.Day);
            Assert.AreEqual(0, pd.Hour);
            Assert.AreEqual(0, pd.Minute);
            Assert.AreEqual(0, pd.Second);
            Assert.AreEqual(0, pd.Millisecond);
        }
Esempio n. 53
0
        public void Can_Create_With_HourAndMinute()
        {
            PersianDate pd = new PersianDate(1384, 1, 1, 20, 30);

            Assert.AreEqual(0, pd.Second);
            Assert.AreEqual(0, pd.Millisecond);
        }
Esempio n. 54
0
 public void Can_Create_Minimum_PersianDate_Year_Value()
 {
     var pd = new PersianDate(PersianDate.MinValue.Year, 1, 1);
 }
Esempio n. 55
0
        private void CheckDates(PersianDate smaller, PersianDate greater)
        {
            Assert.True(smaller < greater);
            Assert.True(greater > smaller);

            Assert.False(smaller > greater);
            Assert.False(greater < smaller);
        }
 /// <summary>
 /// Converts a Persian Date of type <c>String</c> to Gregorian Date of type <c>DateTime</c> class.
 /// </summary>
 /// <param name="date">Date to evaluate</param>
 /// <returns>Gregorian DateTime representation of evaluated Jalali Date.</returns>
 public static DateTime ToGregorianDateTime(string date)
 {
     var pd = new PersianDate(date);
     return DateTime.Parse(ToGregorianDate(pd), CultureHelper.NeutralCulture);
 }
 public static DateTime ToGregorianDateTime(PersianDate date)
 {
     return DateTime.Parse(ToGregorianDate(date), CultureHelper.NeutralCulture);
 }
 public static PersianDate Combine(this PersianDate datePart, PersianDate timePart)
 {
     return new PersianDate(datePart.Year, datePart.Month, datePart.Day, timePart.Hour, timePart.Minute, timePart.Second, timePart.Millisecond);
 }
Esempio n. 59
0
        public void ToString_With_Custom_FormatProvider_And_No_Specific_Format_Uses_Generic()
        {
            PersianDate pd = new PersianDate(1383, 4, 5);
            var value1 = pd.ToString(new TestFormatProvider());
            var value2 = pd.ToString("G");

            Assert.AreEqual(value2, value1);
        }
Esempio n. 60
0
        public void ToString_With_Empty_Parameter_Returns_Generic_Format()
        {
            var pd = new PersianDate(1380, 1, 1);
            var am = PersianDateTimeFormatInfo.AMDesignator;
            var result1 = pd.ToString();
            var result2 = pd.ToString(null, null);

            Assert.AreEqual("1380/01/01 00:00:00 " + am, pd.ToString());
            Assert.AreEqual(result1, result2);
        }