GetDayOfMonth() публичный Метод

public GetDayOfMonth ( System.DateTime time ) : int
time System.DateTime
Результат int
Пример #1
1
 public void PersianDate()
 {
     PersianCalendar pc = new PersianCalendar();
     DateTime dt = DateTime.Now;
     label17.Text = string.Format("امروز: {0}/{1}/{2}", pc.GetYear(dt), pc.GetMonth(dt), pc.GetDayOfMonth(dt));
 }
Пример #2
0
        public static DateTime GetPersianDateInstance(DateTime now)
        {
            System.Globalization.PersianCalendar jc = new System.Globalization.PersianCalendar();
            String tempdate = jc.GetYear(now) + ":" + jc.GetMonth(now) + ":" + jc.GetDayOfMonth(now);

            return(new DateTime(jc.GetYear(now), jc.GetMonth(now), jc.GetDayOfMonth(now), jc));
        }
Пример #3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["name"] != null)
        {
            TextBox1.Visible = false;
            TextBox2.Visible = false;
            Button1.Text     = "پنل مدیریتی";
            Label2.Text      = Session["name"].ToString();
        }
        System.Globalization.PersianCalendar persiandate = new System.Globalization.PersianCalendar();
        string p_date = persiandate.GetYear(System.DateTime.Now) + "/";

        if (persiandate.GetMonth(System.DateTime.Now) < 10)
        {
            p_date += "0";
        }

        p_date = p_date + persiandate.GetMonth(System.DateTime.Now) + "/";

        if (persiandate.GetDayOfMonth(System.DateTime.Now) < 10)
        {
            p_date += "0";
        }

        p_date = p_date + persiandate.GetDayOfMonth(System.DateTime.Now);

        Label1.Text = p_date;
    }
Пример #4
0
 //ایجاد آرایه ای از تارخ برای مشخص کردن تاریخ های تقویم
 public string CreateArrayDate(IQueryable<DateTime> Date, DateTime MinDate, DateTime MaxDate)
 {
     TimeSpan Compare = (MaxDate).Subtract(MinDate);
     Double DiffrentDays = Compare.TotalDays;
     string ArrayDate = "";
     int Days = Convert.ToInt32(DiffrentDays);
     if ((DiffrentDays / Days != 0) && (Days < DiffrentDays))
         Days++;
     bool Check = false;
     for (int i = 1; i <= Days; i++)
     {
         Check = false;
         foreach (var item in Date)
         {
             if (MinDate.Date == item)
             {
                 Check = true;
                 break;
             }
         }
         if (Check == false)
         {
             PersianCalendar pc = new PersianCalendar();
             if (ArrayDate != "")
             {
                 ArrayDate = ArrayDate + "-";
             }
             ArrayDate = ArrayDate + pc.GetDayOfMonth(MinDate).ToString("00") + ", " + pc.GetMonth(MinDate).ToString("00") + ", " + pc.GetYear(MinDate).ToString("0000");
         }
         MinDate = MinDate.AddDays(1);
     }
     return ArrayDate;
 }
        public string gregorianToShamsi(DateTime date)
        {
            DateTime gregorian = date;
            PersianCalendar pc = new PersianCalendar();
            int pcYear = pc.GetYear(gregorian);
            int pcMonth = pc.GetMonth(gregorian);
            int pcDay = pc.GetDayOfMonth(gregorian);
            string convertedDate;

            if (pcMonth == 1 || pcMonth == 2 || pcMonth == 3 ||
                pcMonth == 4 || pcMonth == 5 || pcMonth == 6)
            {
                if (pcDay == 31)
                    convertedDate = string.Format("{0}/{1}/{2}", pcYear, pcMonth + 1, 1);
                else
                    convertedDate = string.Format("{0}/{1}/{2}", pcYear, pcMonth, pcDay + 1);

            }
            else
            {
                if (pcDay == 30)
                    convertedDate = string.Format("{0}/{1}/{2}", pcYear, pcMonth + 1, 1);
                else
                    convertedDate = string.Format("{0}/{1}/{2}", pcYear, pcMonth, pcDay + 1);
            }
            return convertedDate;
        }
Пример #6
0
        public string DateTodayFullChar()
        {
            string today;

            System.Globalization.PersianCalendar pc = new System.Globalization.PersianCalendar();
            int M = pc.GetMonth(DateTime.Now);
            int d = pc.GetDayOfMonth(DateTime.Now);

            today = pc.GetYear(DateTime.Now).ToString() + "/";
            if (M < 10)
            {
                today += "0" + M.ToString() + "/";
            }
            else
            {
                today += M.ToString() + "/";
            }
            if (d < 10)
            {
                today += "0" + d.ToString();
            }
            else
            {
                today += d.ToString();
            }
            return(today);
        }
 public int getDateInteger(DateTime dt)
 {
     PersianCalendar pc = new PersianCalendar();
     StringBuilder sb = new StringBuilder();
     int month = pc.GetMonth(dt);
     int day = pc.GetDayOfMonth(dt);
     int year = pc.GetYear(dt);
     sb.Append(year);
     if (month < 10)
     {
         sb.Append("0" + month);
     }
     else
     {
         sb.Append(month);
     }
     if (day < 10)
     {
         sb.Append("0" + day);
     }
     else
     {
         sb.Append(day);
     }
     return Convert.ToInt32(sb.ToString());
 }
Пример #8
0
 /// <summary>
 /// تبدیل تاریخ میلادی به شمسی
 /// </summary>
 /// <param name="Date">تاریخ مورد نظر</param>
 /// <param name="Pattern">قالب تاریخ خروجی با در برداشتن <code>M(Month) , D(Day) , Y(Year)</code> مثلا <code>D/M/Y</code></param>
 /// <param name="IsMMDD">ایا خروجی به صورت 1395/02/09 باشد ؟ , پیشفرض خیر</param>
 /// <param name="haveInvalidDate">درصورت معتبر نیودن تاریخ , تاریخ نا معتبر بازگردانده شود ؟</param>
 /// <returns>تاریخ شمسی</returns>
 public static string ConvertMiladiToShamsi(this DateTime Date, string Pattern, bool IsMMDD = false, bool haveInvalidDate = true)
 {
     try
     {
         System.Globalization.PersianCalendar pc = new System.Globalization.PersianCalendar();
         int year  = pc.GetYear(Date);
         int month = pc.GetMonth(Date);
         int day   = pc.GetDayOfMonth(Date);
         if (IsMMDD == true)
         {
             return(Pattern.Replace("Y", year.ToString())
                    .Replace("M", month.ToString().PadLeft(2, '0'))
                    .Replace("D", day.ToString().PadLeft(2, '0')));
         }
         return(Pattern.Replace("Y", year.ToString()).Replace("M", month.ToString()).Replace("D", day.ToString()));
     }
     catch
     {
         if (haveInvalidDate)
         {
             return("تاریخ نامعتبر");
         }
         else
         {
             return("");
         }
     }
 }
Пример #9
0
	    public PersianDate(DateTime georgianDate)
	    {
	        var pc=new PersianCalendar();
	        Year = pc.GetYear(georgianDate);
            Month = pc.GetMonth(georgianDate);
            Day = pc.GetDayOfMonth(georgianDate);
        }
        public static string shamsi(DateTime sdate)
        {
            //تبدیل تاریخ میلادی به شمسی
            try
            {
                //PersianCalendar pc = new PersianCalendar();
                //string year = Convert.ToString(pc.GetYear(sdate));
                //string month = pc.GetMonth(sdate).ToString("00");
                //string day = pc.GetDayOfMonth(sdate).ToString("00");
                //string _hour = pc.GetHour(sdate).ToString("00");
                //string _minute = pc.GetMinute(sdate).ToString("00");
                //string all = year + "/" + month + "/" + day;
                //return all;

                System.Globalization.PersianCalendar shamsi = new System.Globalization.PersianCalendar();
                DateTime sh;
                string   strdate = null;
                strdate = DateTime.Now.ToString("yyyy/MM/dd");
                sh      = DateTime.Parse(strdate);
                int    ysh = shamsi.GetYear(sh);
                int    msh = shamsi.GetMonth(sh);
                int    dsh = shamsi.GetDayOfMonth(sh);
                string all = ysh + "/" + msh + "/" + dsh;
                return(all);
            }
            catch { return(""); }
        }
Пример #11
0
        public static string ToPersianDate(DateTime dt)
        {
            PersianCalendar p = new PersianCalendar();

            return p.GetYear(dt).ToString() + "/" + p.GetMonth(dt).ToString("0") + "/" +
             p.GetDayOfMonth(dt).ToString("00");
        }
        public static string GregorianToPersian(DateTime date)
        {
            var pc        = new System.Globalization.PersianCalendar();
            var firstDate = pc.GetYear(date) + "/" + pc.GetMonth(date) + "/" +
                            pc.GetDayOfMonth(date);
            var array     = firstDate.Split('/');
            var returnVal = "";

            if (array[1].Length == 1)
            {
                array[1] = "0" + array[1];
            }
            if (array[2].Length == 1)
            {
                array[2] = "0" + array[2];
            }
            for (int i = 0; i < array.Length; i++)
            {
                if (i == 0 | i == 1)
                {
                    returnVal += array[i] + "/";
                }
                else
                {
                    returnVal += array[i];
                }
            }
            return(returnVal);
        }
Пример #13
0
        public static string GetPersianDate(DateTime d)
        {
            if (d.ToString() == "1/1/0001 12:00:00 AM")
            {
                return("");
            }
            if (d == Convert.ToDateTime("1900/01/01"))
            {
                return("");
            }
            if (d == Convert.ToDateTime("2100/01/01"))
            {
                return("");
            }
            System.Globalization.PersianCalendar pcal = new System.Globalization.PersianCalendar();
            string YY = pcal.GetYear(d).ToString();
            string MM = pcal.GetMonth(d).ToString();
            string DD = pcal.GetDayOfMonth(d).ToString();

            if (MM.Length == 1)
            {
                MM = "0" + MM;
            }
            if (DD.Length == 1)
            {
                DD = "0" + DD;
            }
            return(YY + "/" + MM + "/" + DD);
        }
Пример #14
0
        public static String GetPersianDate(DateTime now)
        {
            System.Globalization.PersianCalendar jc = new System.Globalization.PersianCalendar();
            String tempdate = jc.GetYear(now) + ":" + jc.GetMonth(now) + ":" + jc.GetDayOfMonth(now);

            return(tempdate);
        }
Пример #15
0
        public string ConvertToIranTimeString(DateTime Date)
        {
            //string zoneId = "Iran Standard Time";
            //TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(zoneId);
            //DateTime result = TimeZoneInfo.ConvertTimeFromUtc(Date, tzi);

            Date = Date.AddMinutes(-150);

            PersianCalendar pc = new PersianCalendar();
            string year = pc.GetYear(Date).ToString();
            string Month = pc.GetMonth(Date).ToString();
            string Day = pc.GetDayOfMonth(Date).ToString();
            string Hour = pc.GetHour(Date).ToString();
            string Minute = pc.GetMinute(Date).ToString();

            if (Month.Length == 1)
            {
                Month = "0" + Month;
            }
            if (Day.Length == 1)
            {
                Day = "0" + Day;
            }
            if (Hour.Length == 1)
            {
                Hour = "0" + Hour;
            }
            if (Minute.Length == 1)
            {
                Minute = "0" + Minute;
            }

            return year + "/" + Month + "/" + Day + " " + Hour + ":" + Minute;
        }
Пример #16
0
 public static string FarsiDateServer()
 {
     try
     {
         DateTime Time1 = DateTime.Now;
         System.Globalization.PersianCalendar PC = new System.Globalization.PersianCalendar();
         string year = PC.GetYear(Time1).ToString(); if (year.Length == 1)
         {
             year = "0" + year;
         }
         string month = PC.GetMonth(Time1).ToString(); if (month.Length == 1)
         {
             month = "0" + month;
         }
         string day = PC.GetDayOfMonth(Time1).ToString(); if (day.Length == 1)
         {
             day = "0" + day;
         }
         year = year.Remove(0, 2);
         return(year + "/" + month + "/" + day);
     }
     catch (Exception exp)
     {
         throw new Exception(exp.Message);
     }
 }
Пример #17
0
        private void frmChek_Load(object sender, EventArgs e)
        {
            Tag = int.Parse((this.Owner as Form1).textBox1.Tag.ToString());

            System.Globalization.PersianCalendar pc = new System.Globalization.PersianCalendar();
            textBox5.Text = pc.GetYear(DateTime.Now).ToString();
            textBox4.Text = pc.GetMonth(DateTime.Now).ToString();
            textBox2.Text = pc.GetDayOfMonth(DateTime.Now).ToString();
        }
Пример #18
0
 public static int?GregorianToPersian_DayOfMonth(this DateTime?date)
 {
     if (date == null)
     {
         return(null);
     }
     System.Globalization.PersianCalendar pc = new System.Globalization.PersianCalendar();
     return(pc.GetDayOfMonth((DateTime)date));
 }
Пример #19
0
        /// <summary>
        /// Convert DateTime to Shamsi Date (DD/MM/YYYY)
        /// </summary>
        public static string ToShamsiDateDMY(this DateTime date)
        {
            System.Globalization.PersianCalendar PC = new System.Globalization.PersianCalendar();
            int intYear  = PC.GetYear(date);
            int intMonth = PC.GetMonth(date);
            int intDay   = PC.GetDayOfMonth(date);

            return(intDay.ToString() + "/" + intMonth.ToString() + "/" + intYear.ToString());
        }
Пример #20
0
        public static string GetPersianDateDigital(DateTime d)
        {
            System.Globalization.PersianCalendar pcal = new System.Globalization.PersianCalendar();
            string YY = pcal.GetYear(d).ToString().PadLeft(4, '0');
            string MM = pcal.GetMonth(d).ToString().PadLeft(2, '0');
            string DD = pcal.GetDayOfMonth(d).ToString().PadLeft(2, '0');

            return(YY + MM + DD);
        }
Пример #21
0
 public string setDate()
 {
     PersianCalendar pdate = new PersianCalendar();
     DateTime nT = new DateTime();
     nT = DateTime.Now;
     string mounth = "";
     if (pdate.GetMonth(nT).ToString().Length == 1)
         mounth = "0" + pdate.GetMonth(nT).ToString();
     else
         mounth = pdate.GetMonth(nT).ToString();
     string day = "";
     if (pdate.GetDayOfMonth(nT).ToString().Length == 1)
         day = "0" + pdate.GetDayOfMonth(nT).ToString();
     else
         day = pdate.GetDayOfMonth(nT).ToString();
     string date = String.Format("{0}/{1}/{2}", pdate.GetYear(nT), mounth, day);
     return date;
 }
Пример #22
0
        //Generate persiandate
        internal static object GetPersianDate(this DateTime obj)
        {
            var pc = new System.Globalization.PersianCalendar();
            //{ year: 1398, month: 9, day: 26}
            var t = new { year = pc.GetYear(obj), month = pc.GetMonth(obj), day = pc.GetDayOfMonth(obj) };

            return(t);
            //+ (pc.GetMonth(obj).ToString() + "/") + pc.GetDayOfMonth(obj).ToString();
        }
Пример #23
0
 private void Form1_Load(object sender, EventArgs e)
 {
     // TODO: This line of code loads data into the 'databaseDataSet.Table1' table. You can move, or remove it, as needed.
     intToPass = "******";
     System.Globalization.PersianCalendar pc = new System.Globalization.PersianCalendar();
     year.Text  = pc.GetYear(DateTime.Now).ToString();
     month.Text = pc.GetMonth(DateTime.Now).ToString();
     day.Text   = pc.GetDayOfMonth(DateTime.Now).ToString();
     comboBoxEx1.SelectedIndex = 0;
 }
 public string gregorianToShamsi(DateTime date)
 {
     DateTime gregorian = date;
     PersianCalendar pc = new PersianCalendar();
     int pcYear = pc.GetYear(gregorian);
     int pcMonth = pc.GetMonth(gregorian);
     int pcDay = pc.GetDayOfMonth(gregorian);
     string convertedDate = string.Format("{0}/{1}/{2}", pcYear, pcMonth, pcDay);
     return convertedDate;
 }
Пример #25
0
    public static string ToPersianDateString(this DateTime georgianDate)
    {
        System.Globalization.PersianCalendar persianCalendar = new System.Globalization.PersianCalendar();

        string year              = persianCalendar.GetYear(georgianDate).ToString();
        string month             = persianCalendar.GetMonth(georgianDate).ToString().PadLeft(2, '0');
        string day               = persianCalendar.GetDayOfMonth(georgianDate).ToString().PadLeft(2, '0');
        string persianDateString = string.Format("{0}/{1}/{2}", year, month, day);

        return(persianDateString);
    }
Пример #26
0
 /// <summary>
 /// متد تبدیل تاریخ میلادی به تاریخ شمسی
 /// </summary>
 /// <param name="dt">تاریخ میلادی</param>
 /// <returns>تاریخ شمسی</returns>
 public static string getPersianDate(DateTime dt)
 {
     PersianCalendar per = new PersianCalendar();
     return (
         "" + per.GetYear(dt) + "/" +
         correctDate("" + per.GetMonth(dt)) + "/" +
         correctDate("" + per.GetDayOfMonth(dt)) + " " +
         correctDate(dt.Hour + "") + ":" +
         correctDate(dt.Minute + "") + ":" +
         correctDate(dt.Second + ""));
 }
Пример #27
0
        public static string MiladiToShamsi(DateTime miladiTarikh)
        {
            PersianCalendar pc           = new System.Globalization.PersianCalendar();
            string          shamsiTarikh = string.Format("{0}/{1}/{2}",
                                                         pc.GetYear(miladiTarikh),
                                                         Convert.ToString(pc.GetMonth(miladiTarikh)).PadLeft(2, '0'),
                                                         Convert.ToString(pc.GetDayOfMonth(miladiTarikh)).PadLeft(2, '0'));


            return(shamsiTarikh);
        }
Пример #28
0
        public static string ToPersianString(this DateTime date)
        {
            var pc    = new System.Globalization.PersianCalendar();
            var month = pc.GetMonth(date);
            var day   = pc.GetDayOfMonth(date);

            var monthStr = month < 10 ? "0" + month : month.ToString();
            var dayStr   = day < 10 ? "0" + day : day.ToString();

            return(string.Format("{0}/{1}/{2}", pc.GetYear(date), monthStr, dayStr));
        }
Пример #29
0
        //Format persian date
        internal static string ToPersianFormat(this DateTime date)
        {
            var pc      = new System.Globalization.PersianCalendar();
            var day     = pc.GetDayOfMonth(date);
            var dayName = pc.GetDayOfWeek(date).ToPersian();
            var month   = pc.GetMonth(date).ToPersianMonth();
            var year    = pc.GetYear(date);

            //یکشنبه - 24 فروردین 95
            return(string.Format("{3} - {2} {1} {0}", year, month, day, dayName));
        }
Пример #30
0
        public static string getPersianDate(System.DateTime dt)
        {
            System.Globalization.PersianCalendar persianCalendar = new System.Globalization.PersianCalendar();
            return string.Concat(new object[]
			{
				persianCalendar.GetYear(dt),
				"/",
				string.Format("{0:00}",persianCalendar.GetMonth(dt)),
				"/",
				string.Format("{0:00}",persianCalendar.GetDayOfMonth(dt))
			});
        }
Пример #31
0
        public static string GetPersianDateTimeDigital(DateTime d)
        {
            System.Globalization.PersianCalendar pcal = new System.Globalization.PersianCalendar();
            string YY = String.Format(pcal.GetYear(d).ToString(), "0000");
            string MM = pcal.GetMonth(d).ToString().PadLeft(2, '0');      //String.Format(pcal.GetMonth(d).ToString(), "00");
            string DD = pcal.GetDayOfMonth(d).ToString().PadLeft(2, '0'); //String.Format(pcal.GetDayOfMonth(d).ToString(), "00");

            return(YY + MM + DD
                   + d.Hour.ToString().PadLeft(2, '0')     // String.Format(d.Hour.ToString(), "00").ToString()
                   + d.Minute.ToString().PadLeft(2, '0')   // String.Format(d.Minute.ToString(), "00").ToString()
                   + d.Second.ToString().PadLeft(2, '0')); // String.Format(d.Second.ToString(), "00").ToString();
        }
Пример #32
0
 public static string getBeforeMonth()
 {
     System.Globalization.PersianCalendar p = new System.Globalization.PersianCalendar();
     DateTime date = DateTime.Today;
     int year = p.GetYear(date);
     int month = p.GetMonth(date);
     int day = p.GetDayOfMonth(date);
     if(month!=1)
         return year + "/" + (month-1).ToString("00") + "/" + day.ToString("00");
     else
         return (year-1) + "/12/" + day.ToString("00");
 }
Пример #33
0
 public static string ToPersian(this DateTime date, string format = "yyyy/MM/dd")
 {
     var pc = new PersianCalendar();
     var year = pc.GetYear(date).ToString();
     var month = (pc.GetMonth(date) + 100).ToString().Substring(1);
     var day = (pc.GetDayOfMonth(date) + 100).ToString().Substring(1);
     var strdate = format;
     strdate = strdate.Replace("yyyy", year);
     strdate = strdate.Replace("MM", month);
     strdate = strdate.Replace("dd", day);
     return strdate;
 }
Пример #34
0
        public static DateTime ConvertToPersianDatetime(DateTime datetime)
        {
            var per = new PersianCalendar();

            var year = per.GetYear(datetime);
            var month = per.GetMonth(datetime);
            var day = per.GetDayOfMonth(datetime);
            var hour = per.GetHour(datetime);
            var minute = per.GetMinute(datetime);

            return new DateTime(year, month, day, hour, minute, 0);
        }
Пример #35
0
    //get Date in Persian
    public static string getPersianDate()
    {
        System.Globalization.PersianCalendar pc = new System.Globalization.PersianCalendar();

        int year  = pc.GetYear(DateTime.Now);
        int month = pc.GetMonth(DateTime.Now);
        int day   = pc.GetDayOfMonth(DateTime.Now);

        string persianDate = year.ToString("0#") + "/" + month.ToString("0#") + "/" + day.ToString("0#");

        return(persianDate);
    }
Пример #36
0
        public void TestCalendarConversion()
        {
            PersianCalendar cal = new PersianCalendar();
            int i = 0;

            while (i < s_dates.Length)
            {
                DateTime date = new DateTime(s_dates[i + 3], s_dates[i + 4], s_dates[i + 5]);

                Assert.True(cal.GetYear(date) == s_dates[i], String.Format("Calculated Persian Year {0} not equal the expected year {1}", cal.GetYear(date), s_dates[i]));
                Assert.True(cal.GetMonth(date) == s_dates[i + 1], String.Format("Calculated Persian Month {0} not equal the expected Month {1}", cal.GetMonth(date), s_dates[i + 1]));
                Assert.True(cal.GetDayOfMonth(date) == s_dates[i + 2], String.Format("Calculated Persian Day {0} not equal the expected Day {1}", cal.GetDayOfMonth(date), s_dates[i + 2]));

                DateTime result = cal.ToDateTime(s_dates[i], s_dates[i + 1], s_dates[i + 2], 0, 0, 0, 0);

                Assert.True(result.Year == s_dates[i + 3], String.Format("Calculated Gregorian Year {0} not equal the expected year {1}", result.Year, s_dates[i + 3]));
                Assert.True(result.Month == s_dates[i + 4], String.Format("Calculated Gregorian Month {0} not equal the expected Month {1}", result.Month, s_dates[i + 4]));
                Assert.True(result.Day == s_dates[i + 5], String.Format("Calculated Gregorian Day {0} not equal the expected Day {1}", result.Day, s_dates[i + 5]));

                i += 6;
            }
        }
Пример #37
0
		public static string ToPersianFullName(this DateTime date)
		{
			PersianCalendar persianCalendar = new PersianCalendar();
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(date.ToPersianWeekDayName());
			stringBuilder.Append(" ");
			stringBuilder.Append(persianCalendar.GetDayOfMonth(date));
			stringBuilder.Append(" ");
			stringBuilder.Append(date.ToPersianMonthName());
			stringBuilder.Append(" ");
			stringBuilder.Append(persianCalendar.GetYear(date));
			return stringBuilder.ToString();
		}
Пример #38
0
 /// <summary>
 /// تبدیل تاریخ میلادی به شمسی
 /// </summary>
 public static string ShamsiDateTime(this DateTime info, string separator = "/", bool includeHourMinute = true)
 {
     int ym = info.Year;
     int mm = info.Month;
     int dm = info.Day;
     PersianCalendar sss = new PersianCalendar();
     int ys = sss.GetYear(new DateTime(ym, mm, dm, new GregorianCalendar()));
     int ms = sss.GetMonth(new DateTime(ym, mm, dm, new GregorianCalendar()));
     int ds = sss.GetDayOfMonth(new DateTime(ym, mm, dm, new GregorianCalendar()));
     if (includeHourMinute)
         return ys + separator + ms.ToString("00", CultureInfo.InvariantCulture) + separator + ds.ToString("00", CultureInfo.InvariantCulture) + " " + info.Hour.ToString("00") + ":" + info.Minute.ToString("00");
     else
         return ys + separator + ms.ToString("00", CultureInfo.InvariantCulture) + separator + ds.ToString("00", CultureInfo.InvariantCulture);
 }
Пример #39
0
		public static string ToPersianDate(this DateTime date, string seperator)
		{
			PersianCalendar persianCalendar = new PersianCalendar();
			StringBuilder stringBuilder = new StringBuilder();
			int year = persianCalendar.GetYear(date);
			stringBuilder.Append(year.ToString("0000"));
			stringBuilder.Append(seperator);
			int month = persianCalendar.GetMonth(date);
			stringBuilder.Append(month.ToString("00"));
			stringBuilder.Append(seperator);
			int dayOfMonth = persianCalendar.GetDayOfMonth(date);
			stringBuilder.Append(dayOfMonth.ToString("00"));
			return stringBuilder.ToString();
		}
Пример #40
0
        private void login_Load(object sender, EventArgs e)
        {
            System.Globalization.PersianCalendar dtePersianCalendar = new System.Globalization.PersianCalendar();
            System.String Year, Month, Day, strResult;
            DateTime      Date_Now = DateTime.Now;

            //-----------------------------------------------------------------------------
            Year                      = dtePersianCalendar.GetYear(Date_Now).ToString();
            Month                     = dtePersianCalendar.GetMonth(Date_Now).ToString();
            Day                       = dtePersianCalendar.GetDayOfMonth(Date_Now).ToString();
            strResult                 = Year + "/" + Month + "/" + Day;
            buttonX1.Text             = strResult;
            comboBoxEx1.SelectedIndex = 0;
        }
Пример #41
0
        public static string WhichDayisToday()
        {
            var prCalendar = new PersianCalendar();

            int year = prCalendar.GetYear(DateTime.Now);
            int month = prCalendar.GetMonth(DateTime.Now);
            int dayofMonth = prCalendar.GetDayOfMonth(DateTime.Now);

            string returnValue = "[" + year.ToString(CultureInfo.InvariantCulture) + "." +
                                 month.ToString(CultureInfo.InvariantCulture) + "." +
                                 dayofMonth.ToString(CultureInfo.InvariantCulture) + "]";

            return returnValue;
        }
Пример #42
0
        private void FrmUpdate_Load(object sender, EventArgs e)
        {
            if (Session.LastUpdateDate != null)
            {
                DateTime date = Session.LastUpdateDate.Value;
                PersianCalendar pc = new PersianCalendar();
                lblLastUpdate.Text= pc.GetYear(date) + "/" + pc.GetMonth(date).ToString() + "/" + pc.GetDayOfMonth(date).ToString();
            }
            else
            {
                lblLastUpdate.Text = "-";
            }

            lblLicense.Text = Session.SoftwareSerial;
        }
Пример #43
0
        public string ConvertToPersianDate(DateTime? date)
        {
            if (date == null)
                return string.Empty;

            var calendar = new PersianCalendar();

            var day = calendar.GetDayOfMonth(date.Value);
            var month = calendar.GetMonth(date.Value);
            var year = calendar.GetYear(date.Value);

            var persian = string.Format("{0}/{1}/{2}", year, month, day);

            return persian;
        }
Пример #44
0
        public static string addDay(int n, int d)
        {
            var year  = Convert.ToInt32(n.ToString().Substring(0, 4));
            var month = Convert.ToInt32(n.ToString().Substring(4, 2));
            var day   = Convert.ToInt32(n.ToString().Substring(6, 2));

            var gdate = Convert.ToDateTime(formatDate(n.ToString()));
            var newdt = gdate.AddDays(d);

            System.Globalization.PersianCalendar pcal = new System.Globalization.PersianCalendar();
            string YY = pcal.GetYear(newdt).ToString();
            string MM = pcal.GetMonth(newdt).ToString();
            string DD = pcal.GetDayOfMonth(newdt).ToString();

            return(YY + MM.PadLeft(2, '0') + DD.PadLeft(2, '0'));
        }
public static System.Web.WebPages.HelperResult Initial() {
#line default
#line hidden
return new System.Web.WebPages.HelperResult(__razor_helper_writer => {

#line 4 "..\..\RazorHelpers\DatePickerInitial.cshtml"
                    
    Func<DateTime, string> toPersianDate = date =>
    {
        var dateTime = new DateTime(date.Year, date.Month, date.Day, new GregorianCalendar());
        var persianCalendar = new PersianCalendar();
        return string.Format("{0}/{1}/{2}",
            persianCalendar.GetYear(dateTime),
            persianCalendar.GetMonth(dateTime).ToString("00"),
            persianCalendar.GetDayOfMonth(dateTime).ToString("00"));
    };
    
    var today = toPersianDate(DateTime.Now);


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "<script>\r\n    $(function() {\r\n        $(document).on(\'focus\', \'input.datepicker\'," +
" function() {\r\n            $(this).datepicker({\r\n                \"setDate\": ");


#line 20 "..\..\RazorHelpers\DatePickerInitial.cshtml"
WriteTo(__razor_helper_writer, today);


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, ",\r\n                changeMonth: true, //\r\n                changeYear: true, // T\r" +
"\n                yearRange: \'c-100:c+0\'\r\n            });\r\n        });\r\n    });\r\n" +
"</script>\r\n");


#line 28 "..\..\RazorHelpers\DatePickerInitial.cshtml"


#line default
#line hidden
});

#line 28 "..\..\RazorHelpers\DatePickerInitial.cshtml"
}
Пример #46
0
        private void Form_kala_Load(object sender, EventArgs e)
        {
            System.Globalization.PersianCalendar dtePersianCalendar = new System.Globalization.PersianCalendar();
            System.String Year, Month, Day, strResult;
            DateTime      Date_Now = DateTime.Now;

            //-----------------------------------------------------------------------------
            Year           = dtePersianCalendar.GetYear(Date_Now).ToString();
            Month          = dtePersianCalendar.GetMonth(Date_Now).ToString();
            Day            = dtePersianCalendar.GetDayOfMonth(Date_Now).ToString();
            strResult      = Year + "/" + Month + "/" + Day;
            textBoxX3.Text = strResult;

            DataTable dt = new DataTable();
            DataBase  db = new DataBase();

            dt = db.MySelect("select * from kala");
            dataGridViewX1.DataSource            = dt;
            dataGridViewX1.Columns[0].HeaderText = "کد";
            dataGridViewX1.Columns[1].HeaderText = "نام ";
            dataGridViewX1.Columns[2].HeaderText = "توضیحات";
            dataGridViewX1.Columns[3].HeaderText = "کشور سازنده";
            dataGridViewX1.Columns[4].HeaderText = " نام انبار";
            dataGridViewX1.Columns[5].HeaderText = "تعداد";
            dataGridViewX1.Columns[6].HeaderText = "واحد";
            dataGridViewX1.Columns[7].HeaderText = "قیمت واحد";
            dataGridViewX1.Columns[8].HeaderText = "قیمت کل";
            dataGridViewX1.Columns[9].HeaderText = " تاریخ ثیت";
            dataGridViewX1.Columns[9].HeaderText = " شماره رسید";

            DataTable dt2 = new DataTable();
            DataBase  db2 = new DataBase();

            dt2 = db2.MySelect("select * from country");
            comboBoxEx1.DataSource    = dt2;
            comboBoxEx1.DisplayMember = "name";

            dt2 = db2.MySelect("select * from unit");
            comboBoxEx2.DataSource    = dt2;
            comboBoxEx2.DisplayMember = "name";

            dt2 = db2.MySelect("select name from anbar");
            comboBoxEx3.DataSource    = dt2;
            comboBoxEx3.DisplayMember = "name";
        }
Пример #47
0
 public static string getBeforeWeek()
 {
     System.Globalization.PersianCalendar p = new System.Globalization.PersianCalendar();
     DateTime date = DateTime.Today;
     int year = p.GetYear(date);
     int month = p.GetMonth(date);
     int day = p.GetDayOfMonth(date);
     if(day>7)
         return year + "/" + month.ToString("00") + "/" + (day-7).ToString("00");
     else
         if(month==1)
             return (year-1) + "/11/" + (22+day).ToString("00");
         else
             if(month<8)
                 return year + "/" + (month - 1).ToString("00") + "/" + (24+day).ToString("00");
             else
                 return year + "/" + (month - 1).ToString("00") + "/" + (23 + day).ToString("00");
 }
Пример #48
0
        /// <summary>
        /// گرفتن تاریخ شمسی جاری سیستم
        /// </summary>
        public static string CurrentSystemShamsiDate(string separator = "/", bool includeHourMinute = false)
        {
            var info = DateTime.Now;
            int ym = info.Year;
            int mm = info.Month;
            int dm = info.Day;

            PersianCalendar sss = new PersianCalendar();
            int ys = sss.GetYear(new DateTime(ym, mm, dm, new GregorianCalendar()));
            int ms = sss.GetMonth(new DateTime(ym, mm, dm, new GregorianCalendar()));
            int ds = sss.GetDayOfMonth(new DateTime(ym, mm, dm, new GregorianCalendar()));
            if (!includeHourMinute)
            {
                return ys + separator + ms.ToString("00", CultureInfo.InvariantCulture) + separator + ds.ToString("00", CultureInfo.InvariantCulture);
            }
            else
            {
                return ys + separator + ms.ToString("00", CultureInfo.InvariantCulture) + separator + ds.ToString("00", CultureInfo.InvariantCulture) + " " + info.Hour + ":" + info.Minute;
            }
        }
Пример #49
0
    public static string ShamsiDate()
    {
        System.Globalization.PersianCalendar p = new System.Globalization.PersianCalendar();
        DateTime d      = DateTime.Now;
        string   DayNow = p.GetDayOfMonth(d).ToString();

        if (DayNow.Length == 1)
        {
            DayNow = "0" + DayNow;
        }
        string MonthNow = p.GetMonth(d).ToString();

        if (MonthNow.Length == 1)
        {
            MonthNow = "0" + MonthNow;
        }
        string DateNow = p.GetYear(d).ToString() + "/" + MonthNow + "/" + DayNow;

        return(DateNow);
    }
Пример #50
0
 public static string ConvertToPersian(object obj)
 {
     if (obj.IsNull())
     {
         return null;
     }
     DateTime enDate;
     if (DateTime.TryParse(obj.ToString(), out enDate))
     {
         var calendar = new PersianCalendar();
         int year = calendar.GetYear(enDate);
         int month = calendar.GetMonth(enDate);
         int day = calendar.GetDayOfMonth(enDate);
         return String.Format("{0}/{1}/{2}", year, month, day);
     }
     else
     {
         return null;
     }
 }
Пример #51
0
    public static string GetPersianDate()
    {
        System.Globalization.PersianCalendar pc = new System.Globalization.PersianCalendar();

        DateTime dt = DateTime.Now;

        string y = pc.GetYear(dt).ToString();
        string m = pc.GetMonth(dt).ToString();
        string d = pc.GetDayOfMonth(dt).ToString();

        if (m.Length != 2)
            m = "0" + m;
        if (d.Length != 2)
            d = "0" + d;

        //{0} = Year
        //{1} = Month
        //{2} = Day
        return String.Format("{0}/{1}/{2}", y, m, d);
    }
Пример #52
0
 //private readonly string log_file = "Error_Log.txt";
 public static void WriteLog(String msg)
 {
     try
     {
         DateTime dt = DateTime.Now;
         PersianCalendar date = new PersianCalendar();
         StringBuilder sb = new StringBuilder(string.Format("{0}/{1}/{2} {3}:{4}", date.GetYear(dt), date.GetMonth(dt), date.GetDayOfMonth(dt),
             dt.Hour,dt.Minute));
         sb.Append("     ");
         sb.Append(msg);
         sb.Append("\r\n");
         FileStream fs = File.Open("Error_Log.txt", FileMode.Append, FileAccess.Write, FileShare.Read);
         byte[] txt = new byte[sb.Length * sizeof(char)];
         System.Buffer.BlockCopy(sb.ToString().ToCharArray(), 0, txt, 0, txt.Length);
         fs.Write(txt, 0, txt.Length);
         fs.Close();
     }
     catch (Exception)
     {
         return;
     }
 }
Пример #53
0
        public static string CurrentDateTime()
        {
            var pcal = new System.Globalization.PersianCalendar();

            return(string.Format("{0:0000}{1:00}{2:00}{3:00}{4:00}", pcal.GetYear(DateTime.Now), pcal.GetMonth(DateTime.Now), pcal.GetDayOfMonth(DateTime.Now), DateTime.Now.Hour, DateTime.Now.Minute));
        }
Пример #54
0
        private void Form1_Load(object sender, EventArgs e)
        {
            if (variable.i == 2)
            {
                labelX1.Text         = "کاربر عادی";
                buttonItem14.Enabled = false;
                buttonItem15.Enabled = false;
                buttonItem16.Enabled = false;
                buttonItem20.Enabled = false;
                buttonItem22.Enabled = false;
                buttonItem23.Enabled = false;
            }
            else
            {
                labelX1.Text = "مدیر";
            }

            System.Globalization.PersianCalendar dtePersianCalendar = new System.Globalization.PersianCalendar();
            System.String Year, Month, Day, strResult;
            DateTime      Date_Now = DateTime.Now;

            //-----------------------------------------------------------------------------
            Year          = dtePersianCalendar.GetYear(Date_Now).ToString();
            Month         = dtePersianCalendar.GetMonth(Date_Now).ToString();
            Day           = dtePersianCalendar.GetDayOfMonth(Date_Now).ToString();
            strResult     = Year + "/" + Month + "/" + Day;
            buttonX2.Text = strResult;
            DataTable dt = new DataTable();
            //'sakhte yek nemoone az class DataBase
            DataBase db = new DataBase();

            //'seda zadan function==>MySelect baraye jostejoo dar bank
            dt = db.MySelect("select top 6 * from foroshandeh");
            dataGridViewX1.DataSource            = dt;
            dataGridViewX1.Columns[0].HeaderText = "کد";
            dataGridViewX1.Columns[1].HeaderText = "نام";
            dataGridViewX1.Columns[2].HeaderText = "فامیلی";
            dataGridViewX1.Columns[3].HeaderText = "تلفن";
            dataGridViewX1.Columns[4].HeaderText = "ادرس";
            dt = db.MySelect("select top 6 * from tahvilgirandeh");
            dataGridViewX2.DataSource            = dt;
            dataGridViewX2.Columns[0].HeaderText = "کد";
            dataGridViewX2.Columns[1].HeaderText = "نام";
            dataGridViewX2.Columns[2].HeaderText = "فامیلی";
            dataGridViewX2.Columns[3].HeaderText = "تلفن";
            dataGridViewX2.Columns[4].HeaderText = "ادرس";
            dt = db.MySelect("select top 6 * from kala");
            dataGridViewX3.DataSource            = dt;
            dataGridViewX3.Columns[0].HeaderText = "کد";
            dataGridViewX3.Columns[1].HeaderText = "نام ";
            dataGridViewX3.Columns[2].HeaderText = "توضیحات";
            dataGridViewX3.Columns[3].HeaderText = "کشور سازنده";
            dataGridViewX3.Columns[4].HeaderText = " نام انبار";
            dataGridViewX3.Columns[5].HeaderText = "تعداد";
            dataGridViewX3.Columns[6].HeaderText = "واحد";
            dataGridViewX3.Columns[7].HeaderText = "قیمت واحد";
            dataGridViewX3.Columns[8].HeaderText = "قیمت کل";
            dataGridViewX3.Columns[9].HeaderText = " تاریخ ثیت";
            dt = db.MySelect("select top 6 * from anbar");
            dataGridViewX4.DataSource            = dt;
            dataGridViewX4.Columns[0].HeaderText = "کد";
            dataGridViewX4.Columns[1].HeaderText = "نام ";
            dataGridViewX4.Columns[2].HeaderText = "نوع انبار";
            dataGridViewX4.Columns[3].HeaderText = "انباردار";
        }
Пример #55
0
 public string PersianDat(DateTime Mdate)
 {
     PersianCalendar ps = new PersianCalendar();
     return string.Format(" {2}/{1}/{0}", ps.GetDayOfMonth(Mdate),
     ps.GetMonth(Mdate), ps.GetYear(Mdate), ps.GetDayOfWeek(Mdate));
 }
Пример #56
0
        public static string ayyam(DateTime date)
        {
            PersianCalendar persianCalender = new PersianCalendar();
            HijriCalendar hijriCalendar = new HijriCalendar();

            string ayyamName = "";
            string ayyamName2 = "";

            switch (persianCalender.GetMonth(date))
            {
                case 1:
                    switch (persianCalender.GetDayOfMonth(date))
                    {
                        case 1: ayyamName = "سال نو بر شما مبارک باد"; break;
                        case 2: ayyamName = "سال نو بر شما مبارک باد"; break;
                        case 3: ayyamName = "سال نو بر شما مبارک باد"; break;
                        case 4: ayyamName = "سال نو بر شما مبارک باد"; break;
                        case 5: ayyamName = "سال نو بر شما مبارک باد"; break;
                        case 12: ayyamName = "روز جمهوری اسلامی ایران -- تعطیل"; break;
                        case 13: ayyamName = "روز طبیعت -- تعطیل"; break;
                    }

                    break;

                case 3:
                    switch (persianCalender.GetDayOfMonth(date))
                    {
                        case 14: ayyamName = "رحلت حضرت امام خمینی -- تعطیل"; break;
                        case 15: ayyamName = "قیام خونین 15 خرداد -- تعطیل"; break;
                    }

                    break;

                case 11:
                    switch (persianCalender.GetDayOfMonth(date))
                    {
                        case 22: ayyamName = "پیروزی انقلاب و سقوط شاهنشاهی -- تعطیل"; break;

                    }
                    break;
                case 12:
                    switch (persianCalender.GetDayOfMonth(date))
                    {
                        case 29: ayyamName = "روز ملی شدن صنعت نفت ایران -- تعطیل"; break;
                    }
                    break;
            }
            /////////////////////////////////////////////////////////////////////////////////////////////////////////
            switch (hijriCalendar.GetMonth(date))
            {
                case 1:
                    switch (hijriCalendar.GetDayOfMonth(date))
                    {
                        case 9: ayyamName2 = "تاسوعای حسینی -- تعطیل"; break;
                        case 10: ayyamName2 = "عاشورای حسینی -- تعطیل"; break;

                    }
                    break;
                case 2:
                    switch (hijriCalendar.GetDayOfMonth(date))
                    {
                        case 20: ayyamName2 = "اربعین حسینی -- تعطیل"; break;
                        case 28: ayyamName2 = "رحلت حضرت رسول اکرم ص - شهادت حضرت امام حسن مجتبی ع -- تعطیل"; break;
                        case 30: ayyamName2 = "شهادت حضرت امام رضا ع - تعطیل"; break;
                    }
                    break;
                case 3:
                    switch (hijriCalendar.GetDayOfMonth(date))
                    {
                        case 17: ayyamName2 = "میلاد حضرت رسول اکرم و روز اخلاق و مهرورزی -- میلاد امام جعفر صادق -- تعطیل"; break;
                    }
                    break;

                case 6:
                    switch (hijriCalendar.GetDayOfMonth(date))
                    {
                        case 3: ayyamName2 = "شهادت حضرت فاطمه زهرا س -- تعطیل"; break;

                    }
                    break;
                case 7:
                    switch (hijriCalendar.GetDayOfMonth(date))
                    {
                        case 13: ayyamName2 = "ولادت حضرت امام علی  علیه السلام - آغاز ایام اعتکاف -- تعطیل"; break;
                        case 27: ayyamName2 = "مبعث رسول اکرم ص -- تعطیل"; break;
                    }
                    break;
                case 8:
                    switch (hijriCalendar.GetDayOfMonth(date))
                    {
                        case 15: ayyamName2 = "ولادت حضرت قائم عج روز جهانی مستضعفان -- تعطیل"; break;
                    }
                    break;
                case 9:
                    switch (hijriCalendar.GetDayOfMonth(date))
                    {
                        case 21: ayyamName2 = "شهادت حضرت علی علیه السلام -- تعطیل"; break;

                    }
                    break;
                case 10:
                    switch (hijriCalendar.GetDayOfMonth(date))
                    {
                        case 1: ayyamName2 = "عید سعید فطر -- تعطیل"; break;
                        case 25: ayyamName2 = "شهادت امام جعفر صادق ع -- تعطیل"; break;
                    }
                    break;

                case 12:
                    switch (hijriCalendar.GetDayOfMonth(date))
                    {
                        case 10: ayyamName2 = "عید سعید قربان -- تعطیل "; break;

                    }
                    break;

            }

            //////////////////////////////////////////////////////////////////////////////////////////////////
            return ayyamName2 + ((ayyamName2 != "" && ayyamName != "") ? " - " : "") + ayyamName;
        }
 public String getDateString(DateTime dt)
 {
     PersianCalendar pc = new PersianCalendar();
     StringBuilder sb = new StringBuilder();
     int month = pc.GetMonth(dt);
     int day = pc.GetDayOfMonth(dt);
     int year = pc.GetYear(dt);
     sb.Append(year);
     sb.Append("/");
     sb.Append(month);
     sb.Append("/");
     sb.Append(day);
     return sb.ToString();
 }
Пример #58
0
        //Format Persian Date
        internal static string ToPersianDateTimeString(this DateTime obj)
        {
            string retVal = null;
            var    pc     = new System.Globalization.PersianCalendar();

            try
            {
                retVal = string.Format("{0}/{1:0#}/{2:0#} {3}", pc.GetYear(obj), pc.GetMonth(obj), pc.GetDayOfMonth(obj), obj.ToString("HH:mm:ss", Util.EnglishCulture));
            }
            catch { /*Nothing*/ }
            return(retVal);
        }
Пример #59
0
        /// <summary>
        /// Convert DateTime to Shamsi String
        /// </summary>
        public static string ToShamsiDateString(this DateTime date)
        {
            System.Globalization.PersianCalendar PC = new System.Globalization.PersianCalendar();
            int       intYear = PC.GetYear(date);
            int       intMonth = PC.GetMonth(date);
            int       intDayOfMonth = PC.GetDayOfMonth(date);
            DayOfWeek enDayOfWeek = PC.GetDayOfWeek(date);
            string    strMonthName, strDayName;

            switch (intMonth)
            {
            case 1:
                strMonthName = "فروردین";
                break;

            case 2:
                strMonthName = "اردیبهشت";
                break;

            case 3:
                strMonthName = "خرداد";
                break;

            case 4:
                strMonthName = "تیر";
                break;

            case 5:
                strMonthName = "مرداد";
                break;

            case 6:
                strMonthName = "شهریور";
                break;

            case 7:
                strMonthName = "مهر";
                break;

            case 8:
                strMonthName = "آبان";
                break;

            case 9:
                strMonthName = "آذر";
                break;

            case 10:
                strMonthName = "دی";
                break;

            case 11:
                strMonthName = "بهمن";
                break;

            case 12:
                strMonthName = "اسفند";
                break;

            default:
                strMonthName = "";
                break;
            }

            switch (enDayOfWeek)
            {
            case DayOfWeek.Friday:
                strDayName = "جمعه";
                break;

            case DayOfWeek.Monday:
                strDayName = "دوشنبه";
                break;

            case DayOfWeek.Saturday:
                strDayName = "شنبه";
                break;

            case DayOfWeek.Sunday:
                strDayName = "یکشنبه";
                break;

            case DayOfWeek.Thursday:
                strDayName = "پنجشنبه";
                break;

            case DayOfWeek.Tuesday:
                strDayName = "سه شنبه";
                break;

            case DayOfWeek.Wednesday:
                strDayName = "چهارشنبه";
                break;

            default:
                strDayName = "";
                break;
            }

            return(string.Format("{0} {1} {2} {3}", strDayName, intDayOfMonth, strMonthName, intYear));
        }
Пример #60
0
        //------List-Actions-----\\
        //---Regions-List
        public ActionResult Regions(string search, string Combo, string Export)
        {
            System.Globalization.PersianCalendar pc = new System.Globalization.PersianCalendar();

            ViewBag.DateNow  = (pc.GetYear(DateTime.Now) + "/" + pc.GetMonth(DateTime.Now) + "/" + pc.GetDayOfMonth(DateTime.Now));
            ViewBag.AdminNum = database.Admins.Count();
            ViewBag.ProjNum  = database.Pers.Count();

            string ac = (string)Session["Access"];

            List <PerModel> perlist = new List <PerModel>();

            if ((string)Session["Access"] != null)
            {
                var per = database.Pers.OrderByDescending(x => x.ID).ToList();

                if ((string)Session["Access"] != "MainAdmin")
                {
                    per = database.Pers.OrderByDescending(x => x.ID).Where(x => x.RegionName == ac).ToList();
                }
                //---MainAdmin
                if (!String.IsNullOrWhiteSpace(search))
                {
                    if (Combo == "RN")
                    {
                        per = per.Where(x => x.RegionName == search).ToList();
                    }

                    if (Combo == "OD")
                    {
                        per = per.Where(x => x.OD.Contains(search)).ToList();
                    }

                    if (Combo == "NM")
                    {
                        per = per.Where(x => x.NMD.Contains(search)).ToList();
                    }

                    if (Combo == "MB")
                    {
                        per = per.Where(x => x.MBD.Contains(search)).ToList();
                    }

                    if (Combo == "TSH")
                    {
                        per = per.Where(x => x.TSHD == search).ToList();
                    }

                    if (Combo == "TP")
                    {
                        per = per.Where(x => x.TPD == search).ToList();
                    }

                    if (Combo == "RVSB")
                    {
                        per = per.Where(x => x.RVSBD == search).ToList();
                    }

                    if (Combo == "TA")
                    {
                        per = per.Where(x => x.TA == search).ToList();
                    }

                    if (Combo == "TF")
                    {
                        per = per.Where(x => x.TF == Int32.Parse(search)).ToList();
                    }

                    if (Combo == "DG")
                    {
                        per = per.Where(x => x.DG == Int32.Parse(search)).ToList();
                    }
                }

                foreach (var item in per)
                {
                    PerModel p = new PerModel();
                    p.ID         = item.ID;
                    p.RegionName = item.RegionName;
                    p.OD         = item.OD;
                    p.NMD        = item.NMD;
                    p.MBD        = item.MBD;
                    p.TSHD       = item.TSHD;
                    p.TPD        = item.TPD;
                    p.RVSBD      = item.RVSBD;
                    p.TA         = item.TA;
                    p.TF         = item.TF;
                    p.DG         = item.DG;
                    perlist.Add(p);
                }



                //---Export
                if (Export == "1")
                {
                    //var admins = database.Admins.ToList();

                    ExcelPackage   pck = new ExcelPackage();
                    ExcelWorksheet ws  = pck.Workbook.Worksheets.Add("Report");

                    ws.Cells["A1"].Value = "comm";
                    ws.Cells["B1"].Value = "com1";

                    ws.Cells["A2"].Value = "گزارش";
                    ws.Cells["B2"].Value = "لیست کاربران منطقه";

                    ws.Cells["A3"].Value = "تاریخ";
                    ws.Cells["B3"].Value = string.Format("{0:dd MMM yyyy} at {0:H mm tt})", pc.GetYear(DateTime.Now) + "/" + pc.GetMonth(DateTime.Now) + "/" + pc.GetDayOfMonth(DateTime.Now));

                    ws.Cells["A6"].Value = "منطقه";
                    ws.Cells["B6"].Value = "عنوان دوره";
                    ws.Cells["C6"].Value = "نام مدیر دوره";
                    ws.Cells["D6"].Value = "مکان برگذاری دوره";
                    ws.Cells["E6"].Value = "تاریخ شروع";
                    ws.Cells["F6"].Value = "تاریخ پایان";
                    ws.Cells["G6"].Value = "روز و ساعت برگذاری";
                    ws.Cells["H6"].Value = "تاریخ آزمون";
                    ws.Cells["I6"].Value = "تعداد فراگیر";
                    ws.Cells["J6"].Value = "درآمد گواهینامه";

                    int _i = 7;
                    foreach (var item in perlist)
                    {
                        ws.Row(_i).Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                        if (_i % 2 == 0)
                        {
                            ws.Row(_i).Style.Fill.BackgroundColor.SetColor(ColorTranslator.FromHtml(string.Format("GreenYellow")));
                        }

                        else
                        {
                            ws.Row(_i).Style.Fill.BackgroundColor.SetColor(ColorTranslator.FromHtml(string.Format("Pink")));
                        }

                        ws.Cells[string.Format("A{0}", _i)].Value = item.RegionName;
                        ws.Cells[string.Format("B{0}", _i)].Value = item.OD;
                        ws.Cells[string.Format("C{0}", _i)].Value = item.NMD;
                        ws.Cells[string.Format("D{0}", _i)].Value = item.MBD;
                        ws.Cells[string.Format("E{0}", _i)].Value = item.TSHD;
                        ws.Cells[string.Format("F{0}", _i)].Value = item.TPD;
                        ws.Cells[string.Format("G{0}", _i)].Value = item.RVSBD;
                        ws.Cells[string.Format("H{0}", _i)].Value = item.TA;
                        ws.Cells[string.Format("I{0}", _i)].Value = item.TF;
                        ws.Cells[string.Format("J{0}", _i)].Value = item.DG;

                        _i++;
                    }
                    ws.Cells["A:AZ"].AutoFitColumns();
                    Response.Clear();
                    Response.ContentType = "applicaton/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                    Response.AddHeader("Content-disposition", "attachment: filename=" + "ExportReport.xlsx");
                    Response.BinaryWrite(pck.GetAsByteArray());
                    Response.End();
                    string filename2 = AppDomain.CurrentDomain.BaseDirectory + "خروجی اکسل از جدول دوره های مناطق هلال احمر تهران" + DateTime.Now.Millisecond.ToString() + ".xlsx";
                }


                return(View(perlist));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }