private bool TryParseDateTime(string datetime, out DateTime?dt)
        {
            dt = null;

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

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

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

                return(true);
            }
            catch
            {
                return(false);
            }
        }
 protected override void OnValueValidating(ValueValidatingEventArgs e)
 {
     try
     {
         string txt = e.Value.ToString();
         if (string.IsNullOrEmpty(txt) || txt == FALocalizeManager.GetLocalizerByCulture(Thread.CurrentThread.CurrentUICulture).GetLocalizedString(StringID.Validation_NullText))
         {
             e.HasError = false;
         }
         else if (mv.MonthViewControl.DefaultCulture.Equals(mv.MonthViewControl.PersianCulture))
         {
             PersianDate pd = PersianDate.Parse(txt, GetFormatByFormatInfo(FormatInfo));
             e.HasError = false;
             mv.MonthViewControl.IsNull = false;
             mv.MonthViewControl.SelectedDateTime = pd;
         }
         else if (mv.MonthViewControl.DefaultCulture.Equals(mv.MonthViewControl.InvariantCulture))
         {
             DateTime dt = DateTime.Parse(txt);
             e.HasError = false;
             mv.MonthViewControl.IsNull = false;
             mv.MonthViewControl.SelectedDateTime = dt;
         }
     }
     catch (Exception)
     {
         e.HasError = true;
         mv.MonthViewControl.IsNull = true;
     }
 }
示例#3
0
        private void SetWeek(IndexModel model)
        {
            DateTime now         = DateTime.Now;
            DateTime currentDate = new DateTime(now.Year, now.Month, now.Day, 23, 59, 59);

            var WeekIncome = unit.LastVisitedProduct.GetLastEntry(currentDate.AddDays(-7).ToUnix()).GroupBy(p => p.RegisterDate.PersianDay()).Select(p => new { p.Key, Orders = p.ToList() }).ToList();

            for (int i = 0; i < 7; i++)
            {
                WeekSales ws = new WeekSales();
                ws.Day    = PersianDate.Parse(DateTime.Now.AddDays(-i)).Day.ToString();
                ws.Income = 0;
                model.WeekUserEntry.Add(ws);
            }
            foreach (var item in WeekIncome)
            {
                for (int i = 0; i < model.WeekUserEntry.Count; i++)
                {
                    if (model.WeekUserEntry[i].Day == item.Key)
                    {
                        model.WeekUserEntry[i].Income += item.Orders.Count;
                    }
                }
            }
        }
示例#4
0
        private void SetUser(IndexModel model)
        {
            DateTime now         = DateTime.Now;
            DateTime currentDate = new DateTime(now.AddMonths(1).Year, now.AddMonths(1).Month, 1, 0, 0, 0);

            var WeekIncome = unit.User.GetLast(currentDate.AddMonths(-6).ToUnix()).GroupBy(p => p.RegisterDate.PersianMonth()).Select(p => new { p.Key, Users = p.ToList() }).ToList();

            for (int i = 0; i < 6; i++)
            {
                MonthRegister ws = new MonthRegister();
                ws.Month = PersianDate.Parse(DateTime.Now.AddMonths(-i)).Month.ToString();
                ws.No    = "0";
                model.MonthRegister.Add(ws);
            }
            foreach (var item in WeekIncome)
            {
                int income = item.Users.Count;
                for (int i = 0; i < model.MonthSales.Count; i++)
                {
                    if (model.MonthRegister[i].Month == item.Key)
                    {
                        model.MonthRegister[i].No = income.ToString();
                    }
                }
            }
        }
示例#5
0
        private void SetMonth(IndexModel model)
        {
            DateTime now         = DateTime.Now;
            DateTime currentDate = new DateTime(now.AddMonths(1).Year, now.AddMonths(1).Month, 1, 0, 0, 0);

            var WeekIncome = unit.LastVisitedProduct.GetLastEntry(currentDate.AddMonths(-6).ToUnix()).GroupBy(p => p.RegisterDate.PersianMonth()).Select(p => new { p.Key, Orders = p.ToList() }).ToList();

            for (int i = 0; i < 6; i++)
            {
                MonthSales ws = new MonthSales();
                ws.Month  = PersianDate.Parse(DateTime.Now.AddMonths(-i)).Month.ToString();
                ws.Income = 0;
                model.MonthSales.Add(ws);
            }
            foreach (var item in WeekIncome)
            {
                for (int i = 0; i < model.MonthSales.Count; i++)
                {
                    if (model.MonthSales[i].Month == item.Key)
                    {
                        model.MonthSales[i].Income += item.Orders.Count;
                    }
                }
            }
        }
 public void Parsing_30th_Of_Ordibehesht_Should_Not_Fail_When_Using_System_Persian_Culture()
 {
     using (new CultureSwitchContext(CultureHelper.FarsiCulture))
     {
         Assert.DoesNotThrow(() => PersianDate.Parse("1388/02/30"));
         Assert.DoesNotThrow(() => PersianDate.Parse("1388/02/31"));
     }
 }
示例#7
0
        private void MahView_SelectedDateChanged(object sender, RoutedEventArgs e)
        {
            TaView.DisplayDateStart = PersianDate.Parse(MahView.Text);

            int time;

            time = MahView.SelectedDate.Month;
            switch (time)
            {
            case 1: DateView.Content = "فروردین"; mahv = 1; break;

            case 2: DateView.Content = "اردیبهشت"; mahv = 2; break;

            case 3: DateView.Content = "خرداد"; mahv = 3; break;

            case 4: DateView.Content = "تیر"; mahv = 4; break;

            case 5:

                DateView.Content = "مرداد";
                mahv             = 5;
                break;

            case 6:
                DateView.Content = "شهریور";
                mahv             = 6;
                break;

            case 7:
                DateView.Content = "مهر";
                mahv             = 7;
                break;

            case 8:
                DateView.Content = "آبان";
                mahv             = 8;
                break;

            case 9:
                DateView.Content = "آذر";
                mahv             = 9;
                break;

            case 10:
                DateView.Content = "دی"; mahv = 10;
                break;

            case 11:
                mahv             = 11;
                DateView.Content = "بهمن";
                break;

            case 12:
                mahv             = 12;
                DateView.Content = "اسفند";
                break;
            }
        }
        public void Can_Parse_Short_Date_String()
        {
            var value = "1384/03/01";
            var pd    = PersianDate.Parse(value);

            Assert.AreEqual(1384, pd.Year);
            Assert.AreEqual(3, pd.Month);
            Assert.AreEqual(1, pd.Day);
        }
示例#9
0
        private PersianDate GetParsedDate(string formattedValue)
        {
            if (CultureHelper.IsBuiltinFarsiCulture)
            {
                return(PersianDate.Parse(formattedValue));
            }

            return(DateTime.Parse(formattedValue));
        }
示例#10
0
 private DateTime Parse(string value)
 {
     if (mv.MonthViewControl.DefaultCulture.Equals(mv.MonthViewControl.PersianCulture))
     {
         return(PersianDate.Parse(value));
     }
     else
     {
         return(DateTime.Parse(value));
     }
 }
示例#11
0
        public void Can_Parse_Date_Short_Time_String()
        {
            var value = "1394/05/01 12:33:00 AM";
            var pd    = PersianDate.Parse(value);

            Assert.AreEqual(1394, pd.Year);
            Assert.AreEqual(5, pd.Month);
            Assert.AreEqual(1, pd.Day);
            Assert.AreEqual(0, pd.Hour);
            Assert.AreEqual(33, pd.Minute);
        }
示例#12
0
        public void Parsing_With_Years_Less_Than_Two_Digits_Will_Use_Four_Year_Digits()
        {
            using (new CultureSwitchContext(CultureHelper.FarsiCulture))
            {
                var pd = PersianDate.Parse("88/2/3");

                Assert.That(pd.Year, Is.EqualTo(1388));
                Assert.That(pd.Month, Is.EqualTo(2));
                Assert.That(pd.Day, Is.EqualTo(3));
            }
        }
    private void DisplayDateRange()
    {
        string year         = Request.QueryString["year"];
        string month        = Request.QueryString["month"];
        string specificDate = Request.QueryString["date"];

        if (!string.IsNullOrEmpty(year) && !string.IsNullOrEmpty(month) && BlogSettings.Instance.Culture != "fa")
        {
            DateTime dateFrom = DateTime.Parse(year + "-" + month + "-01", CultureInfo.InvariantCulture);
            DateTime dateTo   = dateFrom.AddMonths(1).AddMilliseconds(-1);
            PostList1.ContentBy = ServingContentBy.DateRange;
            PostList1.Posts     = Post.GetPostsByDate(dateFrom, dateTo).ConvertAll(new Converter <Post, IPublishable>(delegate(Post p) { return(p as IPublishable); }));
            Title = dateFrom.ToString("MMMM yyyy");
        }
        if (!string.IsNullOrEmpty(year) && !string.IsNullOrEmpty(month) && BlogSettings.Instance.Culture == "fa")
        {
            var dateFrom = PersianDate.Parse(year + "-" + month + "-01", '-');
            var dateTo   = dateFrom.AddMonths(1);
            PostList1.ContentBy = ServingContentBy.DateRange;
            PostList1.Posts     = Post.GetPostsByPersianDate(dateFrom, dateTo).ConvertAll(new Converter <Post, IPublishable>(delegate(Post p) { return(p as IPublishable); }));
            Title = dateFrom.ToStringYearMonthName();
        }
        else if (!string.IsNullOrEmpty(year) && BlogSettings.Instance.Culture != "fa")
        {
            DateTime dateFrom = DateTime.Parse(year + "-01-01", CultureInfo.InvariantCulture);
            DateTime dateTo   = dateFrom.AddYears(1).AddMilliseconds(-1);
            PostList1.ContentBy = ServingContentBy.DateRange;
            PostList1.Posts     = Post.GetPostsByDate(dateFrom, dateTo).ConvertAll(new Converter <Post, IPublishable>(delegate(Post p) { return(p as IPublishable); }));;
            Title = dateFrom.ToString("yyyy");
        }
        else if (!string.IsNullOrEmpty(year) && BlogSettings.Instance.Culture == "fa")
        {
            var dateFrom = PersianDate.Parse(year + "-01-01", '-');
            var dateTo   = dateFrom.AddYears(1);
            PostList1.ContentBy = ServingContentBy.DateRange;
            PostList1.Posts     = Post.GetPostsByPersianDate(dateFrom, dateTo).ConvertAll(new Converter <Post, IPublishable>(delegate(Post p) { return(p as IPublishable); }));;
            Title = dateFrom.Year.ToString();
        }
        else if (!string.IsNullOrEmpty(specificDate) && specificDate.Length == 10)
        {
            DateTime date = DateTime.Parse(specificDate, CultureInfo.InvariantCulture);
            PostList1.ContentBy = ServingContentBy.DateRange;
            PostList1.Posts     = Post.GetPostsByDate(date, date).ConvertAll(new Converter <Post, IPublishable>(delegate(Post p) { return(p as IPublishable); }));;
            Title = date.ToString("MMMM d. yyyy");
        }
        else if (!string.IsNullOrEmpty(Request.QueryString["calendar"]))
        {
            calendar.Visible  = true;
            PostList1.Visible = false;
            Title             = Server.HtmlEncode(Resources.labels.calendar);
        }
        AddMetaDescription(Title + " - " + BlogSettings.Instance.Description);
    }
示例#14
0
        public void Can_Parse_Date_From_String_Using_BuiltIn_CultureInfo()
        {
            using (new CultureSwitchContext(new CultureInfo("fa-ir")))
            {
                var dateString = "1388/06/17 12:00:00 ق.ظ";
                var pd         = PersianDate.Parse(dateString);

                Assert.That(pd.Year, Is.EqualTo(1388));
                Assert.That(pd.Month, Is.EqualTo(6));
                Assert.That(pd.Day, Is.EqualTo(17));
            }
        }
示例#15
0
        public void Can_Parse_Date_From_String()
        {
            using (new CultureSwitchContext(CultureHelper.PersianCulture))
            {
                var dateString = "1388/06/17 12:00:00 ق.ظ";
                var pd         = PersianDate.Parse(dateString);

                Assert.That(pd.Year, Is.EqualTo(1388));
                Assert.That(pd.Month, Is.EqualTo(6));
                Assert.That(pd.Day, Is.EqualTo(17));
            }
        }
示例#16
0
        protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
                                      DataGridViewElementStates cellState, object value, object formattedValue,
                                      string errorText, DataGridViewCellStyle cellStyle,
                                      DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                      DataGridViewPaintParts paintParts)
        {
            if (DataGridView == null)
            {
                return;
            }


            // First paint the borders and background of the cell.
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts & ~(DataGridViewPaintParts.ErrorIcon | DataGridViewPaintParts.ContentForeground));

            Point ptCurrentCell = DataGridView.CurrentCellAddress;
            bool  cellCurrent   = ptCurrentCell.X == ColumnIndex && ptCurrentCell.Y == rowIndex;
            bool  cellEdited    = cellCurrent && DataGridView.EditingControl != null;

            // If the cell is in editing mode, there is nothing else to paint
            if (!cellEdited && value != null && !string.IsNullOrEmpty(value.ToString()))
            {
                PersianDate pd = null;
                if (value is DateTime)
                {
                    pd = (DateTime)value;
                }
                else if (value is string)
                {
                    pd = PersianDate.Parse(value.ToString());
                }

                if (pd != null)
                {
                    using (SolidBrush brFG = new SolidBrush(cellStyle.ForeColor))
                        using (SolidBrush brSelected = new SolidBrush(cellStyle.SelectionForeColor))
                            using (StringFormat fmt = new StringFormat())
                            {
                                fmt.LineAlignment = HorizontalAlignment;
                                fmt.Alignment     = VerticalAlignment;
                                fmt.Trimming      = StringTrimming.None;
                                fmt.FormatFlags   = StringFormatFlags.LineLimit;

                                graphics.DrawString(pd.ToString(), cellStyle.Font, IsInState(cellState, DataGridViewElementStates.Selected) ? brSelected : brFG, cellBounds, fmt);
                            }
                }
            }

            if (PartPainted(paintParts, DataGridViewPaintParts.ErrorIcon))
            {
                base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, DataGridViewPaintParts.ErrorIcon);
            }
        }
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value is string)
            {
                return(PersianDate.Parse(value as string));
            }

            if (value is DateTime)
            {
                return(new PersianDate((DateTime)value));
            }

            return(base.ConvertFrom(context, culture, value));
        }
示例#18
0
        private void DataGrid_Members_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
        {
            object itemOne = DataGrid_Members.SelectedItem;

            try
            {
                var content = (DataGrid_Members.SelectedCells[2].Column.GetCellContent(itemOne) as TextBlock).Text;


                NamayeshTarikh.Text          = String.Format("{0:yyyy/M/d}", Convert.ToDateTime(Convert.ToString(content)));
                NamayeshTarikh1.SelectedDate = PersianDate.Parse(content);



                TarikhMah.Content        = NamayeshTarikh1.SelectedDate.MonthAsPersianMonth;
                TarikhRoz.Content        = NamayeshTarikh1.SelectedDate.Day;
                TarikhRoozeFarsi.Content = NamayeshTarikh1.SelectedDate.PersianDayOfWeek;
            }
            catch

            {
            }
        }
示例#19
0
        public ActionResult SaveComments(string sdate, string edate)
        {
            //string sdate = "1397/03/06";
            //string edate = "1397/04/06";
            PersianDate ssdate = PersianDate.Parse(Convert.ToDateTime(sdate).ToString("yyyy/MM/dd HH:mm:ss"));
            DateTime    Sdate  = PersianDateConverter.ToGregorianDateTime(ssdate);
            PersianDate eedate = PersianDate.Parse(Convert.ToDateTime(edate).ToString("yyyy/MM/dd HH:mm:ss"));
            DateTime    Edate  = PersianDateConverter.ToGregorianDateTime(eedate);



            //PersianDate pd= PersianDateConverter.ToPersianDate(dt);

            var select = db.users.Where(q => q.birth >= Sdate && q.birth <= Edate).ToList();

            //foreach(var item in select)
            //{

            //    //dt.Add(Convert.ToDateTime(item));
            //}

            return(Content(""));
        }
    //TODO Does the old URL redirect still needed with BE 2.9 and above?
    /// <summary>
    /// Permanently redirects to the correct URL format if the page is requested with
    /// the old URL: /default.aspx?year=2007&month=12
    /// <remarks>
    /// The redirection is important so that we don't end up having 2 URLs
    /// to the same resource. It's for SEO purposes.
    /// </remarks>
    /// </summary>
    private void Redirect()
    {
        string year    = Request.QueryString["year"];
        string month   = Request.QueryString["month"];
        string date    = Request.QueryString["date"];
        string page    = string.IsNullOrEmpty(Request.QueryString["page"]) ? string.Empty : "?page=" + Request.QueryString["page"];
        string rewrite = null;

        if (!string.IsNullOrEmpty(date) && BlogSettings.Instance.Culture != "fa")
        {
            DateTime dateParsed = DateTime.Parse(date);
            rewrite = Utils.RelativeWebRoot + dateParsed.Year + "/" + dateParsed.Month + "/" + dateParsed.Day + "/default.aspx";
        }
        else if (!string.IsNullOrEmpty(date) && BlogSettings.Instance.Culture == "fa")
        {
            var dateParsed = PersianDate.Parse(date);
            rewrite = Utils.RelativeWebRoot + dateParsed.Year + "/" + dateParsed.Month + "/" + dateParsed.Day + "/default.aspx";
        }
        else if (!string.IsNullOrEmpty(year) && !string.IsNullOrEmpty(month))
        {
            rewrite = Utils.RelativeWebRoot + year + "/" + month + "/default.aspx";
        }
        else if (!string.IsNullOrEmpty(year))
        {
            rewrite = Utils.RelativeWebRoot + year + "/default.aspx";
        }

        if (rewrite != null)
        {
            //TODO Replace this Block of code with Response.RedirectPermanent?  Since Asp.net 4.0 has new method saves on code.
            Response.Clear();
            Response.StatusCode = 301;
            Response.AppendHeader("location", rewrite + page);
            Response.End();
        }
    }
示例#21
0
        private void Grid_Loaded_1(object sender, RoutedEventArgs e)
        {
            TaView.DisplayDateStart = PersianDate.Parse(MahView.Text);
            TaView.SelectedDate     = PersianDate.Today.AddDays(30);



            Random rnd  = new Random();
            int    card = rnd.Next(100000000, 999999999);

            TextBoxFactor.Text = Convert.ToString(card);
            Lbl_Name.Content   = "" + MemberName + " " + MemberFamily;
            txt_username.Text  = Convert.ToString(memberid);



            int Today;

            Today = MahView.SelectedDate.Day;


            mah  = MahView.SelectedDate.Month;
            mahv = mah;

            sal = MahView.SelectedDate.Year;


            newdate = mah + 1;



            TextBoxAz.Text = sal + "/" + mah + "/" + Today;
            TextBoxTa.Text = sal + "/" + newdate + "/" + Today;
            // mah bayad 00 | 1 = 01



            switch (mah)
            {
            case 1:
                DateView.Content = "فروردین";
                break;

            case 2:
                DateView.Content = "اردیبهشت";
                break;

            case 3:
                DateView.Content = "خرداد";
                break;

            case 4:
                DateView.Content = "تیر";
                break;

            case 5:
                DateView.Content = "مرداد";
                break;

            case 6:
                DateView.Content = "شهریور";
                break;

            case 7:
                DateView.Content = "مهر";
                break;

            case 8:
                DateView.Content = "آبان";
                break;

            case 9:
                DateView.Content = "آذر";
                break;

            case 10:
                DateView.Content = "دی";
                break;

            case 11:
                DateView.Content = "بهمن";
                break;

            case 12:
                DateView.Content = "اسفند";
                break;
            }
        }
示例#22
0
 public void Parse_With_Invalid_Or_Null_Values_Throws()
 {
     Assert.Throws <InvalidPersianDateFormatException>(() => PersianDate.Parse(null));
     Assert.Throws <InvalidPersianDateFormatException>(() => PersianDate.Parse(string.Empty));
     Assert.Throws <InvalidPersianDateFormatException>(() => PersianDate.Parse("1234"));
 }
示例#23
0
 public void Parsing_Empty_String_Will_Throw()
 {
     Assert.Throws <InvalidPersianDateFormatException>(() => PersianDate.Parse(string.Empty));
 }
示例#24
0
 public void Parsing_30th_Of_Ordibehesht_Should_Not_Fail_When_Using_Invariant_Thread_Culture()
 {
     Assert.DoesNotThrow(() => PersianDate.Parse("1388/02/30"));
 }