Exemplo n.º 1
0
        /// <summary>
        /// تاریخ میلادی معادل آخرین روز سال شمسی
        /// </summary>
        /// <param name="year"></param>
        /// <returns></returns>
        public static DateTime FaEndOfYear(int year)
        {
            var daysInMonth = PersianCalendar.GetDaysInMonth(year, 12);
            var result      = PersianCalendar.ToDateTime(year, 12, daysInMonth, 0, 0, 0, 0);

            return(result.Date);
        }
Exemplo n.º 2
0
        static void DrawCalendar(DateTime date, bool highlightDay, bool showYear)
        {
            string[]        mn = { "Farvardin", "Ordibehesht", "Khordad", "Tir", "Mordad", "Shahrivar", "Mehr", "Aban", "Azar", "Dey", "Bahman", "Esfand" };
            PersianCalendar p  = new PersianCalendar();
            string          t  = string.Empty;

            if (showYear == true)
            {
                t = mn[p.GetMonth(date) - 1] + " " + p.GetYear(date).ToString();
            }
            else
            {
                t = mn[p.GetMonth(date) - 1];
            }
            for (int i = 0; i < 10 - (t.Length / 2) - (t.Length % 2); i++)
            {
                Console.Write(" ");
            }
            Console.WriteLine(t);
            Console.WriteLine("Sh Ye Do Se Ch Pa Jo");
            int days       = p.GetDaysInMonth(p.GetYear(date), p.GetMonth(date));
            int currentDay = 1;
            int fas        = (int)p.GetDayOfWeek(new DateTime(date.Year, date.Month, 1));

            for (int j = 0; j <= 5; j++)
            {
                for (int i = 0; i <= 6; i++)
                {
                    if (currentDay > days + fas)
                    {
                        break;
                    }
                    currentDay++;
                    if (currentDay > fas + 1)
                    {
                        if ((currentDay - fas - 1 == p.GetDayOfMonth(date)) && (highlightDay == true))
                        {
                            Console.ForegroundColor = ConsoleColor.Black;
                            Console.BackgroundColor = ConsoleColor.White;
                        }
                        string d = (currentDay - fas - 1).ToString();
                        if (d.Length > 1)
                        {
                            Console.Write((currentDay - fas - 1).ToString("00"));
                        }
                        else
                        {
                            Console.Write((currentDay - fas - 1).ToString(" 0"));
                        }
                        Console.ResetColor();
                        Console.Write(" ");
                    }
                    else
                    {
                        Console.Write("   ");
                    }
                }
                Console.WriteLine("");
            }
        }
Exemplo n.º 3
0
        public static StartEndMonth StartEndMonth(this DateTime date)
        {
            var dateTime        = new DateTime(date.Year, date.Month, date.Day, new GregorianCalendar());
            var persianCalendar = new PersianCalendar();

            StartEndMonth startEndMonth = new StartEndMonth();

            var Day   = persianCalendar.GetDayOfMonth(dateTime).ToString();
            var Month = persianCalendar.GetMonth(dateTime).ToString();
            var Year  = persianCalendar.GetYear(dateTime).ToString();

            var days = persianCalendar.GetDaysInMonth(persianCalendar.GetYear(date), persianCalendar.GetMonth(date), PersianCalendar.PersianEra);

            //var days = persianCalendar.GetDaysInMonth(persianCalendar.GetDayOfMonth(dateTime), persianCalendar.GetMonth(dateTime), PersianCalendar.PersianEra);

            var startStr  = $"{persianCalendar.GetYear(dateTime)}/{persianCalendar.GetMonth(dateTime).ToString("00")}/01";
            var endStr    = $"{persianCalendar.GetYear(dateTime)}/{persianCalendar.GetMonth(dateTime).ToString("00")}/{days.ToString("00")}";
            var startDate = ToDateTime(startStr);
            var endDate   = ToDateTime(endStr);

            startEndMonth.StartDate = startDate;
            startEndMonth.EndDate   = endDate;

            return(startEndMonth);
        }
Exemplo n.º 4
0
        /// <summary>
        /// تاریخ انتهای سال شمسی را برمیگرداند
        /// </summary>
        /// <param name="date">تاریخ میلادی</param>
        /// <returns></returns>
        public static PersianDateTime GetEndOfShamsiYear(DateTime date)
        {
            PersianCalendar pc = new PersianCalendar();

            pc.GetYear(date);
            return(new PersianDateTime(pc.GetYear(date), 12, pc.GetDaysInMonth(pc.GetYear(date), 12)));
        }
Exemplo n.º 5
0
    private void Fill_cmbDayControl_PeriodRepeat(ComboBox cmbDay, int Year, int Month)
    {
        int DayCount           = 0;
        GregorianCalendar gCal = new GregorianCalendar();
        PersianCalendar   pCal = new PersianCalendar();
        int year = pCal.GetYear(new DateTime(Year, 1, 1));

        switch (this.LangProv.GetCurrentLanguage())
        {
        case "fa-IR":
            DayCount = pCal.GetDaysInMonth(year, Month);
            break;

        case "en-US":
            DayCount = gCal.GetDaysInMonth(year, Month);
            break;
        }
        for (int i = 1; i <= DayCount; i++)
        {
            ComboBoxItem cmbItemDay = new ComboBoxItem();
            cmbItemDay.Text = cmbItemDay.Value = i.ToString();
            cmbDay.Items.Add(cmbItemDay);
        }
        cmbDay.SelectedIndex = 0;
    }
Exemplo n.º 6
0
    public static void Main()
    {
        PersianCalendar jc       = new PersianCalendar();
        DateTime        thisDate = DateTime.Now;

        //--------------------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------------------
        Console.WriteLine("\n........... Selected Properties .....................\n");
        Console.Write("Eras:");
        foreach (int era in jc.Eras)
        {
            Console.WriteLine(" era = {0}", era);
        }
        //--------------------------------------------------------------------------------
        Console.WriteLine("\nTwoDigitYearMax = {0}", jc.TwoDigitYearMax);
        //--------------------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------------------
        Console.WriteLine("\n............ Selected Methods .......................\n");

        //--------------------------------------------------------------------------------
        Console.WriteLine("GetDayOfYear: day = {0}", jc.GetDayOfYear(thisDate));
        //--------------------------------------------------------------------------------
        Console.WriteLine("GetDaysInMonth: days = {0}",
                          jc.GetDaysInMonth(thisDate.Year, thisDate.Month,
                                            PersianCalendar.PersianEra));
        //--------------------------------------------------------------------------------
        Console.WriteLine("GetDaysInYear: days = {0}",
                          jc.GetDaysInYear(thisDate.Year, PersianCalendar.PersianEra));
        //--------------------------------------------------------------------------------
        Console.WriteLine("GetLeapMonth: leap month (if any) = {0}",
                          jc.GetLeapMonth(thisDate.Year, PersianCalendar.PersianEra));
        //-------------------------------------------------------------
        Console.WriteLine("GetMonthsInYear: months in a year = {0}",
                          jc.GetMonthsInYear(thisDate.Year, PersianCalendar.PersianEra));
        //--------------------------------------------------------------------------------
        Console.WriteLine("IsLeapDay: This is a leap day = {0}",
                          jc.IsLeapDay(thisDate.Year, thisDate.Month, thisDate.Day,
                                       PersianCalendar.PersianEra));
        //--------------------------------------------------------------------------------
        Console.WriteLine("IsLeapMonth: This is a leap month = {0}",
                          jc.IsLeapMonth(thisDate.Year, thisDate.Month,
                                         PersianCalendar.PersianEra));
        //--------------------------------------------------------------------------------
        Console.WriteLine("IsLeapYear: 1370 is a leap year = {0}",
                          jc.IsLeapYear(1370, PersianCalendar.PersianEra));
        //--------------------------------------------------------------------------------

        // Get the 4-digit year for a year whose last two digits are 99. The 4-digit year
        // depends on the current value of the TwoDigitYearMax property.

        Console.WriteLine("ToFourDigitYear:");
        Console.WriteLine("  If TwoDigitYearMax = {0}, ToFourDigitYear(99) = {1}",
                          jc.TwoDigitYearMax, jc.ToFourDigitYear(99));
        jc.TwoDigitYearMax = thisDate.Year;
        Console.WriteLine("  If TwoDigitYearMax = {0}, ToFourDigitYear(99) = {1}",
                          jc.TwoDigitYearMax, jc.ToFourDigitYear(99));
    }
Exemplo n.º 7
0
        /// <summary>
        /// Get Day of Month (31 Or 30)
        /// </summary>
        /// <param name="y"></param>
        /// <param name="m"></param>
        /// <returns></returns>
        private int CheckNumberOfDayInMonth(string y, string m)
        {
            PersianCalendar p = new PersianCalendar();


            int day = p.GetDaysInMonth(Convert.ToInt32(y), Convert.ToInt32(m));

            return(day);
        }
Exemplo n.º 8
0
        private void cmbMonth_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                var date = (cmbYear.SelectedItem.ToString()) + "/" +
                           (cmbMonth.SelectedIndex + 1).ToString() + "/" +
                           (cmbDay.SelectedIndex + 1).ToString();

                PersianCalendar pc = new PersianCalendar();
                int             y = 0, m = 0;
                int.TryParse(cmbYear.SelectedValue.ToString(), out y);
                m = cmbMonth.SelectedIndex + 1;
                var days        = pc.GetDaysInMonth(y, m);
                var dayList     = new List <string>();
                int selectedDay = -1;
                if (int.TryParse(cmbDay.SelectedItem?.ToString() ?? "", out selectedDay))
                {
                    selectedDay = Math.Min(selectedDay, days);
                }
                if (pc.GetDaysInMonth(y, m) != Days.Count)
                {
                    Days.Clear();
                    for (int i = 0; i < days; i++)
                    {
                        Days.Add($"{i + 1}");
                    }
                }
                if (year > 0 && month > 0 && selectedDay > pc.GetDaysInMonth(year, month))
                {
                    selectedDay = pc.GetDaysInMonth(year, month);
                }
                cmbDay.SelectedIndex = selectedDay > -1 ? (selectedDay - 1) : 0;



                if (Date == null || (cmbMonth.SelectedIndex + 1).ToString() != Date.Split('/')[1])
                {
                    Date = date;
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Gets the number of days in the specified month and year of the input persian date.
        /// </summary>
        /// <param name="farsiDate">Persian date. example: 1392/01/05</param>
        public static int GetNumberOfDaysInFarsiMonth(string farsiDate)
        {
            if (!ValidateFarsiDate(farsiDate))
            {
                throw new Exception("Incorrect Persian Date.");
            }
            var pc          = new PersianCalendar();
            var dateSection = farsiDate.Split(new[] { '/' });

            return(pc.GetDaysInMonth(Convert.ToInt32(dateSection[0]), Convert.ToInt32(dateSection[1])));
        }
Exemplo n.º 10
0
        public void LoadDays(int year, int month)
        {
            var days = pc.GetDaysInMonth(year, month);

            day.Items.Clear();
            for (int i = 1; i <= days; i++)
            {
                RadListDataItem dataItem = new RadListDataItem();
                dataItem.Text = i.ToString();
                day.Items.Add(dataItem);
            }
        }
        public async Task <RepResult <MonthVM> > GetMonthData(int personnelId, string shamsiMonthDate)
        {
            if (dbContext != null)
            {
                var monthVm = new MonthVM();
                monthVm.PersonnelId = personnelId;

                PersianDateTime perDt      = PersianDateTime.Parse((shamsiMonthDate + "-01").Replace("-", "/"));
                DateTime        firstDayDt = perDt.ToDateTime();

                PersianCalendar pc = new PersianCalendar();
                monthVm.Year      = pc.GetYear(firstDayDt).ToString();
                monthVm.MonthName = getMonthName(pc.GetMonth(firstDayDt));

                var lenDays = pc.GetDaysInMonth(perDt.Year, perDt.Month);
                monthVm.Days     = new List <DayVM>();
                monthVm.Duration = new DurationVM();
                for (int i = 1; i < lenDays; i++)
                {
                    var dayDate = new DateTime(firstDayDt.Year, firstDayDt.Month, firstDayDt.Day);

                    if (i > 1)
                    {
                        dayDate = dayDate.AddDays(i);
                    }

                    var dayVm = (await dayRep.GetDayData(personnelId, dayDate)).ResultObject;

                    monthVm.Days.Add(dayVm);

                    monthVm.Duration.DurationOfWorkSecends     += dayVm.Duration.DurationOfWorkSecends;
                    monthVm.Duration.DurationOfLeaveSecends    += dayVm.Duration.DurationOfLeaveSecends;
                    monthVm.Duration.DurationOfMisiionSecends  += dayVm.Duration.DurationOfMisiionSecends;
                    monthVm.Duration.DurationOfOverTimeSecends += dayVm.Duration.DurationOfOverTimeSecends;
                }

                monthVm.Duration.DurationOfWork     = Environment.Convert.TimeSpanToReadableString(TimeSpan.FromSeconds(monthVm.Duration.DurationOfWorkSecends));
                monthVm.Duration.DurationOfLeave    = Environment.Convert.TimeSpanToReadableString(TimeSpan.FromSeconds(monthVm.Duration.DurationOfLeaveSecends));
                monthVm.Duration.DurationOfMisiion  = Environment.Convert.TimeSpanToReadableString(TimeSpan.FromSeconds(monthVm.Duration.DurationOfMisiionSecends));
                monthVm.Duration.DurationOfOverTime = Environment.Convert.TimeSpanToReadableString(TimeSpan.FromSeconds(monthVm.Duration.DurationOfOverTimeSecends));


                return(new RepResult <MonthVM> {
                    Successed = true, ResultObject = monthVm
                });
            }

            return(new RepResult <MonthVM>());
        }
Exemplo n.º 12
0
        [Test, Timeout(300000)] // Can take a long time under NCrunch.
        public void BclThroughHistory()
        {
            Calendar       bcl  = new PersianCalendar();
            CalendarSystem noda = CalendarSystem.GetPersianCalendar();

            for (int year = 1; year < 9378; year++)
            {
                for (int month = 1; month < 13; month++)
                {
                    Assert.AreEqual(bcl.GetDaysInMonth(year, month), noda.GetDaysInMonth(year, month),
                                    "Year: {0}; Month: {1}", year, month);
                    for (int day = 1; day < bcl.GetDaysInMonth(year, month); day++)
                    {
                        DateTime  bclDate  = new DateTime(year, month, day, bcl);
                        LocalDate nodaDate = new LocalDate(year, month, day, noda);
                        Assert.AreEqual(bclDate, nodaDate.AtMidnight().ToDateTimeUnspecified());
                        Assert.AreEqual(nodaDate, LocalDateTime.FromDateTime(bclDate).WithCalendar(noda).Date);
                        Assert.AreEqual(year, nodaDate.Year);
                        Assert.AreEqual(month, nodaDate.Month);
                        Assert.AreEqual(day, nodaDate.Day);
                    }
                }
            }
        }
Exemplo n.º 13
0
        public static DateTime LastDayOfShamsiMonth(this string persianDate)
        {
            int             year            = int.Parse(persianDate.Split('/')[0]);
            int             month           = int.Parse(persianDate.Split('/')[1]);
            int             day             = int.Parse(persianDate.Split('/')[2]);
            PersianCalendar persianCalendar = new PersianCalendar();
            DateTime        miladiDate      = new DateTime(year, month, day, persianCalendar);
            int             lastDayOfMonth  = persianCalendar.GetDaysInMonth(year, month);

            for (int i = day; i < lastDayOfMonth; i++)
            {
                miladiDate = miladiDate.AddDays(1);
            }

            return(miladiDate);
        }
Exemplo n.º 14
0
 public static int GetDaysInMonth(int y, int m)
 {
     try
     {
         if (y <= 0 || y >= 12)
         {
             return(0);
         }
         var ps = new PersianCalendar();
         return(ps.GetDaysInMonth(y, m));
     }
     catch (Exception ex)
     {
         WebErrorLog.ErrorInstence.StartErrorLog(ex);
         return(0);
     }
 }
Exemplo n.º 15
0
        private void LoadBarChartData()
        {
            var db     = new Data.GymContextDataContext();
            var pc     = new PersianCalendar();
            int year   = int.Parse(cmbYear.SelectedValue as string),
                month1 = rdMonthReport.IsChecked == true ? cmbMonth.SelectedIndex + 1 : 1,
                month2 = rdMonthReport.IsChecked == true ? cmbMonth.SelectedIndex + 1 : 12,
                day1   = 1,
                day2   = pc.GetDaysInMonth(year, month2);

            var from = new DateTime(year, month1, day1, pc);
            var to   = new DateTime(year, month2, day2, pc);

            var costs = db.Transactions.Where(t => new[] { (int)TransactionType.Cost, (int)TransactionType.Withdraw }.Contains(t.Type));

            costs = costs.Where(c => c.Datetime >= from);
            costs = costs.Where(c => c.Datetime <= to.AddDays(1).AddSeconds(-1));

            var incomes = db.Transactions.Where(t => new int[] { (int)TransactionType.Tuition, (int)TransactionType.SingleSession }.Contains(t.Type));

            incomes = incomes.Where(i => i.Datetime >= from);
            incomes = incomes.Where(i => i.Datetime <= to.AddDays(1).AddSeconds(-1));

            var pair1 = new List <KeyValuePair <string, int> >();

            //costs.GroupBy(c => c.Cost).ToList().ForEach(c =>
            //{
            pair1.Add(new KeyValuePair <string, int>("هزینه", costs.ToList().Select(c => c.Amount).Sum()));
            //});

            var pair2 = new List <KeyValuePair <string, int> >();

            //incomes.GroupBy(i => i.Type).ToList().ForEach(i =>
            //{
            pair2.Add(new KeyValuePair <string, int>("درآمد", incomes.ToList().Select(t => t.Amount).Sum()));
            //});

            ((ColumnSeries)chart.Series[0]).ItemsSource =
                pair2;
            ((ColumnSeries)chart.Series[1]).ItemsSource =
                pair1;
        }
    public static SqlDateTime GetJalaliLastDayOfMonth(DateTime?dateTime)
    {
        if (!dateTime.HasValue)
        {
            return(SqlDateTime.Null);
        }

        var pc = new PersianCalendar();

        try
        {
            var year    = pc.GetYear(dateTime.Value);
            var month   = pc.GetMonth(dateTime.Value);
            var lastDay = pc.GetDaysInMonth(year, month);

            return(pc.ToDateTime(year, month, lastDay, 0, 0, 0, 0));
        }
        catch (Exception)
        {
        }

        return(SqlDateTime.Null);
    }
Exemplo n.º 17
0
        public IList <DateTime> GetMonthDatesList(int year, int month)
        {
            IList <DateTime> MonthDatesList = new List <DateTime>();

            switch (BLanguage.CurrentSystemLanguage)
            {
            case LanguagesName.Parsi:
                PersianCalendar pCal = new PersianCalendar();
                for (int i = 1; i <= pCal.GetDaysInMonth(year, month); i++)
                {
                    MonthDatesList.Add(pCal.ToDateTime(year, month, i, 0, 0, 0, 0));
                }
                break;

            case LanguagesName.English:
                GregorianCalendar gCal = new GregorianCalendar();
                for (int j = 0; j <= gCal.GetDaysInMonth(year, month); j++)
                {
                    MonthDatesList.Add(gCal.ToDateTime(year, month, j, 0, 0, 0, 0));
                }
                break;
            }
            return(MonthDatesList);
        }
        private void FillGridDays(int year, int month)
        {
            dgv_Calenar.Rows.Clear();

            _currentYear  = year;
            _currentMonth = month;

            var calendar = new PersianCalendar();

            lbl_CurrentCalendarDate.Text = new DateTime(year, month, 1, calendar).ToString("MMM yyyy");

            var todayMonthDay = calendar.GetDayOfMonth(DateTime.Now);
            var todayYear     = calendar.GetYear(DateTime.Now);
            var todayMonth    = calendar.GetMonth(DateTime.Now);

            var lastMonthDays =
                month == 1 ? calendar.GetDaysInMonth(year - 1, 12) : calendar.GetDaysInMonth(year, month - 1);
            var currentMonthDays    = calendar.GetDaysInMonth(year, month);
            var fristDayOfWeek      = calendar.GetDayOfWeek(new DateTime(year, month, 1, calendar));
            var fristDayOfWeekIndex = 0;

            if (fristDayOfWeek == DayOfWeek.Saturday)
            {
                fristDayOfWeekIndex = 0;
            }

            else
            {
                fristDayOfWeekIndex = (int)fristDayOfWeek + 1;
            }

            var rowIndex  = 0;
            var cellIndex = 0;

            dgv_Calenar.Rows.Add(1);

            var lastMonthStartDate = lastMonthDays - fristDayOfWeekIndex + 1;

            for (var dayIndex = lastMonthStartDate; dayIndex <= lastMonthDays; dayIndex++)
            {
                dgv_Calenar.Rows[rowIndex].Cells[cellIndex].Tag = new DateTime(month == 1 ? year - 1 : year,
                                                                               month == 1 ? 12 : month - 1, dayIndex, calendar);
                dgv_Calenar.Rows[rowIndex].Cells[cellIndex].Value             = dayIndex;
                dgv_Calenar.Rows[rowIndex].Cells[cellIndex++].Style.ForeColor = Color.SlateGray;
            }

            var SelectedDateExists = false;

            for (var dayIndex = 1; dayIndex <= currentMonthDays; dayIndex++)
            {
                dgv_Calenar.Rows[rowIndex].Cells[cellIndex].Value = dayIndex;
                dgv_Calenar.Rows[rowIndex].Cells[cellIndex].Tag   = new DateTime(year, month, dayIndex, calendar);

                var currentCell = new DateTime(year, month, dayIndex, calendar);

                if (dayIndex == todayMonthDay && month == todayMonth && year == todayYear)
                {
                    dgv_Calenar.Rows[rowIndex].Cells[cellIndex].Style.BackColor = Color.Gray;
                    dgv_Calenar.Rows[rowIndex].Cells[cellIndex].Style.ForeColor = Color.White;
                }

                if (currentCell.Year == SelectedDate.Year && currentCell.Month == SelectedDate.Month &&
                    currentCell.Day == SelectedDate.Day)
                {
                    OnSelectedDateChanged?.Invoke(this, new EventArgs());
                    dgv_Calenar.Rows[rowIndex].Cells[cellIndex].Selected = SelectedDateExists = true;
                }

                cellIndex++;
                {
                    if (cellIndex > 6)
                    {
                        cellIndex = 0;
                        rowIndex++;

                        dgv_Calenar.Rows.Add(1);
                    }
                }
            }

            var nextMonthDay = 1;

            if (cellIndex > 0)
            {
                for (var dayIndex = cellIndex; dayIndex <= 6; dayIndex++)
                {
                    dgv_Calenar.Rows[rowIndex].Cells[cellIndex].Tag = new DateTime(month == 12 ? year + 1 : year,
                                                                                   month == 12 ? 1 : month + 1, dayIndex, calendar);

                    dgv_Calenar.Rows[rowIndex].Cells[cellIndex].Value             = nextMonthDay++;
                    dgv_Calenar.Rows[rowIndex].Cells[cellIndex++].Style.ForeColor = Color.SlateGray;
                }
            }

            foreach (var row in dgv_Calenar.Rows.OfType <DataGridViewRow>())
            {
                row.Height = 20;
            }
            if (!SelectedDateExists)
            {
                dgv_Calenar.CurrentCell = null;
            }
        }
Exemplo n.º 19
0
        private void DateTimePicker1_ValueChanged(object sender, EventArgs e)
        {
            dateTimePicker1.CustomFormat = Application.CurrentCulture.DateTimeFormat.LongDatePattern;
            try
            {
                y = persian.GetYear(dateTimePicker1.Value);
                m = persian.GetMonth(dateTimePicker1.Value);
                d = persian.GetDayOfMonth(dateTimePicker1.Value);


                s           = Convert.ToInt32((persian.GetDayOfWeek(dateTimePicker1.Value)));
                label2.Text = string.Format("{3} {2} {1} {0:d4}", y, pm[m - 1], d, wd[s + 1]);

                ya          = arabian.GetYear(dateTimePicker1.Value);
                ma          = arabian.GetMonth(dateTimePicker1.Value);
                da          = arabian.GetDayOfMonth(dateTimePicker1.Value);
                sa          = Convert.ToInt32(arabian.GetDayOfWeek(dateTimePicker1.Value));
                label3.Text = string.Format("{3} {2} {1} {0:d4}", ya, pma[ma - 1], da, wda[sa + 1]);
                DataGridView t = new DataGridView();

                int      iYear     = persian.GetYear(dateTimePicker1.Value);
                int      noflable6 = Array.IndexOf(pm, label6.Text);
                string   dt1       = string.Format("{2:d2}/{1:d2}/{0:d4}", label5.Text, noflable6 + 1, 1);
                DateTime dt2       = DateTime.ParseExact(dt1, "dd/MM/yyyy", CultureInfo.CurrentCulture);
                int      oyear     = persian.GetYear(dt2);
                int      month     = persian.GetMonth(dt2);
                //int s1= Convert.ToInt32((persian.GetDayOfWeek(dt2)));
                int day = 1;

                //dataGridView1.Rows[0].Cells[s1].Value = string.Format("{3} {2} {1} {0:d4}", y, pm[m - 1], d, wd[s1]);
                for (int i = 1; i < 5; i++)
                {
                    //persian.GetDaysInMonth(iYear, noflable6)
                    //Button[] mo = new Button[persian.GetDaysInMonth(iYear, i)];

                    i = dataGridView1.Rows.Add();



                    for (int j = 0; j < 7; j++)
                    {
                        if (day <= persian.GetDaysInMonth(oyear, month))
                        {
                            int      y1 = 0, m1 = 0, d1 = 0, s2, s3;
                            string   dt3 = string.Format("{2:d2}/{1:d2}/{0:d4}", label5.Text, noflable6 + 1, day++);
                            DateTime dt4 = DateTime.ParseExact(dt3, "dd/MM/yyyy", CultureInfo.CurrentCulture);
                            y1 = persian.GetYear(dt4);
                            m1 = persian.GetMonth(dt4);
                            d1 = persian.GetDayOfMonth(dt4);
                            s2 = Convert.ToInt32(persian.GetDayOfWeek(dt4));
                            s3 = Array.IndexOf(wd, wd[s2 + 1]);
                            j  = s3;
                            dataGridView1.Rows[i].Cells[j].Value = $" {pm[m1 - 1]} {y1:d4} {d1}";
                        }


                        //string.Format("{3} {2} {1} {0:d4}", y, pm[m - 1], d, wd[s]);
                    }
                }
            }
            catch (Exception)
            {
                y = persian.GetYear(dateTimePicker1.Value);
                m = persian.GetMonth(dateTimePicker1.Value);
                d = persian.GetDayOfMonth(dateTimePicker1.Value);


                s           = Convert.ToInt32((persian.GetDayOfWeek(dateTimePicker1.Value)));
                label2.Text = string.Format("{3} {2} {1} {0:d4}", y, pm[m - 1], d, wd[s + 1]);

                ya          = arabian.GetYear(dateTimePicker1.Value);
                ma          = arabian.GetMonth(dateTimePicker1.Value);
                da          = arabian.GetDayOfMonth(dateTimePicker1.Value);
                sa          = Convert.ToInt32(arabian.GetDayOfWeek(dateTimePicker1.Value));
                label3.Text = string.Format("{3} {2} {1} {0:d4}", ya, pma[ma - 1], da, wda[sa + 1]);
                DataGridView t = new DataGridView();

                int      iYear     = persian.GetYear(dateTimePicker1.Value);
                int      noflable6 = Array.IndexOf(pm, label6.Text);
                string   dt1       = string.Format("{2:d2}/{1:d2}/{0:d4}", y, m, 1);
                DateTime dt2       = DateTime.ParseExact(dt1, "dd/MM/yyyy", CultureInfo.CurrentCulture);
                int      oyear     = persian.GetYear(dt2);
                int      month     = persian.GetMonth(dt2);
                int      s1        = Convert.ToInt32((persian.GetDayOfWeek(dt2)));
                int      day       = 1;

                //    //dataGridView1.Rows[0].Cells[s1].Value = string.Format("{3} {2} {1} {0:d4}", y, pm[m - 1], d, wd[s1]);
                for (int i = 1; i < 5; i++)
                {
                    //        //persian.GetDaysInMonth(iYear, noflable6)
                    //        //Button[] mo = new Button[persian.GetDaysInMonth(iYear, i)];

                    i = dataGridView1.Rows.Add();



                    for (int j = 0; j < 7; j++)
                    {
                        if (day <= persian.GetDaysInMonth(oyear, month))
                        {
                            int      y1 = 0, m1 = 0, d1 = 0, s2 = 0, s3;
                            string   dt3 = string.Format("{2:d2}/{1:d2}/{0:d4}", y, m, day++);
                            DateTime dt4 = DateTime.ParseExact(dt3, "dd/MM/yyyy", CultureInfo.CurrentCulture);
                            y1 = persian.GetYear(dt4);
                            m1 = persian.GetMonth(dt4);
                            d1 = persian.GetDayOfMonth(dt4);
                            s2 = Convert.ToInt32(persian.GetDayOfWeek(dt4));
                            s3 = Array.IndexOf(wd, wd[s2 + 1]);
                            j  = s3;
                            dataGridView1.Rows[i].Cells[j].Value = $"  {pm[m1 - 1]} {y1:d4} {d1}";
                        }


                        //string.Format("{3} {2} {1} {0:d4}", y, pm[m - 1], d, wd[s]);
                    }
                }
            }

            //dataGridView1.Rows[i].Cells[i].Value=

            //int[] days = new int[persian.GetDaysInMonth(iYear, i)];

            //days[i] = dataGridView1.Rows.Add();
        }
 /// <summary>
 /// Returns the number of days in the specified month of the specified year.
 /// </summary>
 /// <param name="year">An integer from 1 through 9378 that represents the year.</param>
 /// <param name="month">An integer that represents the month, and ranges from 1 through 12.</param>
 /// <returns>The number of days in the specified month of the specified year.</returns>
 public static int GetDaysInMonth(int year, int month)
 {
     return(_persianCalendar.GetDaysInMonth(year, month));
 }
 public int GetDaysInMonth()
 {
     return(calendar.GetDaysInMonth(year, month));
 }
Exemplo n.º 22
0
        static public int GetDaysInMonth(DateTime st1)
        {
            PersianCalendar pc = new PersianCalendar();

            return(pc.GetDaysInMonth(pc.GetYear(st1), pc.GetMonth(st1)));
        }
 /// <summary>
 /// Returns the number of days in the specified month of the specified year.
 /// </summary>
 /// <param name="year">An integer from 1 through 9378 that represents the year.</param>
 /// <param name="month">An integer that represents the month, and ranges from 1 through 12.</param>
 /// <returns>The number of days in the specified month of the specified year.</returns>
 public static int GetDaysInMonth(int year, int month) => _persianCalendar.GetDaysInMonth(year, month);
Exemplo n.º 24
0
 public static SqlString GTS_ASM_GetEndOfShamsiMonth(string ShamsiDate)
 {
     try
     {
         string[]        strs = ShamsiDate.Split('/');
         PersianCalendar pc   = new PersianCalendar();
         if (strs[0].Length == 4)
         {
             return(pc.ToDateTime(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), pc.GetDaysInMonth(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1])), 0, 0, 0, 0).ToString("yyyy/MM/dd"));
         }
         else
         {
             return(pc.ToDateTime(Convert.ToInt32(strs[2]), Convert.ToInt32(strs[1]), pc.GetDaysInMonth(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1])), 0, 0, 0, 0).ToString("yyyy/MM/dd"));
         }
     }
     catch (Exception e)
     {
         throw new Exception(String.Format("GTS GetEndOfShamsiMonth Sended date: {0} {1}", ShamsiDate, e.Message));
     }
 }
Exemplo n.º 25
0
        public static DateTime FaEndOfYear(int year)
        {
            int daysInMonth = PersianCalendar.GetDaysInMonth(year, 12);

            return(PersianCalendar.ToDateTime(year, 12, daysInMonth, 0, 0, 0, 0).Date);
        }
Exemplo n.º 26
0
 /// <summary>
 /// Returns days in specified month of the specified year
 /// </summary>
 /// <param name="year">The year</param>
 /// <param name="month">The month - between 1 and 12</param>
 /// <returns>The number of days in month. Takes leap years into account.</returns>
 /// <exception cref="System.ArgumentOutOfRangeException"></exception>
 public static int DaysInMonth(int year, int month)
 {
     return(_calendar.GetDaysInMonth(year, month));
 }
Exemplo n.º 27
0
        private void FillCalander()
        {
            columnIndex = dgCalander.CurrentCell.ColumnIndex;
            rowIndex    = dgCalander.CurrentCell.RowIndex;
            int DayOfWeekNameInMonth = 0;
            int daysInMonth          = pc.GetDaysInMonth(YearName, mounthName);

            for (int i = 1, d = 1, j = 0; i <= 5; i++, j++)
            {
                if (d == daysInMonth)
                {
                    break;
                }
                for (int x = 1; x <= 7; x++, d++)
                {
                    DateTime dtt = pc.ToDateTime(YearName, mounthName, d, 1, 1, 1, 1, 1);
                    #region MyRegion
                    switch (pc.GetDayOfWeek(dtt))
                    {
                    case DayOfWeek.Saturday: DayOfWeekNameInMonth = 0;
                        break;

                    case DayOfWeek.Sunday: DayOfWeekNameInMonth = 1;
                        break;

                    case DayOfWeek.Monday: DayOfWeekNameInMonth = 2;
                        break;

                    case DayOfWeek.Tuesday: DayOfWeekNameInMonth = 3;
                        break;

                    case DayOfWeek.Wednesday: DayOfWeekNameInMonth = 4;
                        break;

                    case DayOfWeek.Thursday: DayOfWeekNameInMonth = 5;
                        break;

                    case DayOfWeek.Friday: DayOfWeekNameInMonth = 6;
                        break;
                    }
                    #endregion
                    dgCalander.Rows[j].Cells["c" + DayOfWeekNameInMonth.ToString()].Value = pc.GetDayOfMonth(dtt);
                    if (DayOfWeekNameInMonth == 6)
                    {
                        dgCalander.Rows[j].Cells["c" + DayOfWeekNameInMonth.ToString()].Style.ForeColor = Color.Red;
                    }
                    if (DayOfWeekNameInMonth == 6)
                    {
                        d++;
                        break;
                    }
                    if (d == daysInMonth)
                    {
                        break;
                    }
                }
            }
            int lastRowData = 0;
            if (dgCalander.Rows[4].Cells["c6"].Value != null)
            {
                if (!string.IsNullOrEmpty(dgCalander.Rows[4].Cells["c6"].Value.ToString()))
                {
                    lastRowData = int.Parse(dgCalander.Rows[4].Cells["c6"].Value.ToString());
                }
            }
            if (lastRowData != 31 && lastRowData != 0)
            {
                if (daysInMonth >= 29 && lastRowData >= 29)
                {
                    int RemainDay = daysInMonth - lastRowData;
                    for (int i = 0; i < RemainDay; i++)
                    {
                        dgCalander.Rows[0].Cells["c" + i.ToString()].Value = ++lastRowData;
                    }
                }
            }
            FindCurrentCell();
        }
Exemplo n.º 28
0
 public static int GetDaysInMonth(int year, int month)
 {
     return(pc.GetDaysInMonth(year, month));
 }
Exemplo n.º 29
0
        public static PersianDateTime GetEndOfShamsiMonth(int persianYear, int persianMonth)
        {
            PersianCalendar pc = new PersianCalendar();

            return(new PersianDateTime(persianYear, persianMonth, pc.GetDaysInMonth(persianYear, persianMonth)));
        }
Exemplo n.º 30
0
 public static PersianDateTime EndDateOfMonth(int year, int month)
 {
     return(new PersianDateTime(year, month, persianCalendar.GetDaysInMonth(year, month), 23, 59, 59, 999));
 }