Exemplo n.º 1
0
        public void PersianDateTimeTests()
        {
            //PersianDateTime is utility data type for GregorianDateTime to/from PersianDateTime conversions.

            var pNow = PersianDateTime.Now;

            var clrDate = DateTime.Now;
            //Convert an instance of CLR-DateTime to PersianDateTime
            PersianDateTime faDateTime = clrDate.ToPersianDateTime();

            //Convert an instance of PersianDateTime to CLR-DateTime
            clrDate = faDateTime.ToDateTime();

            Debug.WriteLine(faDateTime.Hour12);      // Hour based on 12Hours
            Debug.WriteLine(faDateTime.IsAfternoon); // ...

            //Convert persian date time string to PersianDateTime
            faDateTime = PersianDateTime.Parse("1395/10/1 5:1 ب.ظ");

            //writes name of week day
            Debug.WriteLine("MonthName: {0}\nDayName: {1}", faDateTime.MonthName, faDateTime.DayName);

            //well form date time display :-)
            Debug.WriteLine(PersianDateTime.Parse("1395/10/19").ToString("dddd d MMMM yyyy")); // یکشنبه 19 دی 1395

            Debugger.Break();
        }
Exemplo n.º 2
0
        private DateTime FromOldExcelDateTime(string InDate)
        {
            string persianDate = InDate;

            string[] userDateParts   = persianDate.Split(new[] { "/" }, System.StringSplitOptions.None);
            int      Year            = int.Parse(userDateParts[2]);
            int      Month           = int.Parse(userDateParts[1]);
            int      Day             = int.Parse(userDateParts[0]);
            var      persianDateTime = new PersianDateTime(Year, Month, Day);

            return(persianDateTime.ToDateTime());
        }
        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.º 4
0
        public static DateTime ToGeorgianDateTime(this string dateTime)
        {
            var date = (dateTime.Split('/')).Select(s => int.Parse(s)).ToArray();

            try
            {
                PersianDateTime persianDate = new PersianDateTime(date[0], date[1], date[2]);
                var             x           = persianDate.ToDateTime();
                return(x);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemplo n.º 5
0
        public ActionResult AddAuction(AuctionAddViewModel model)
        {
            TimeSpan tooBig = new TimeSpan(2, 8, 8, 8);


            //yourDbEntity.timeValue = temp;



            PersianDateTime persianDate = new PersianDateTime();
            var             dd          = model.Date.Split('-');

            persianDate = new PersianDateTime(int.Parse(dd[0]), int.Parse(dd[1]), int.Parse(dd[2]), model.Auction_Time.Hours, model.Auction_Time.Minutes, 0);
            var dateMi       = persianDate.ToDateTime();                      //convert datetime Persian  to miladi
            var cur          = DateTime.Now.AddSeconds(-DateTime.Now.Second); //datetime without seconde
            var def          = dateMi.Subtract(cur);                          //get def
            var auction_Time = new TimeSpan(def.Days, def.Hours, def.Minutes, 0, 0);
            var h            = auction_Time.Days * 24;
            var hh           = h + auction_Time.Hours;
            var timestring   = auction_Time.TotalHours;
            //to database
            Int64    tooBigBits = auction_Time.Ticks;
            Int64    truncated  = tooBigBits >> 24;
            TimeSpan temp       = TimeSpan.FromTicks(truncated);

            //from database
            //Int64 truncated1 = temp.Ticks;
            //Int64 adjusted = truncated1 << 24;
            //TimeSpan actual = TimeSpan.FromTicks(adjusted);


            model.Auction_Time = temp;
            var result = repo.AddAuction(model);

            if (result)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                var allProduct = ProRepo.GetProForDop();
                return(View(allProduct));
            }
        }
Exemplo n.º 6
0
        public ActionResult UsersSellInfoList(int?i, string FromDate, string ToDate)
        {
            if (Session["UserId"] != null)
            {
                Dictionary <char, char> LettersDictionary = new Dictionary <char, char>
                {
                    ['/'] = '/', ['۰'] = '0', ['۱'] = '1', ['۲'] = '2', ['۳'] = '3', ['۴'] = '4', ['۵'] = '5', ['۶'] = '6', ['۷'] = '7', ['۸'] = '8', ['۹'] = '9', ['0'] = '0', ['1'] = '1', ['2'] = '2', ['3'] = '3', ['4'] = '4', ['5'] = '5', ['6'] = '6', ['7'] = '7', ['8'] = '8', ['9'] = '9'
                };
                foreach (var item in FromDate)
                {
                    FromDate = FromDate.Replace(item, LettersDictionary[item]);
                }
                foreach (var item in ToDate)
                {
                    ToDate = ToDate.Replace(item, LettersDictionary[item]);
                }

                PersianDateTime FromD       = PersianDateTime.Parse(FromDate);
                DateTime        miladiFromD = FromD.ToDateTime();

                PersianDateTime ToD       = PersianDateTime.Parse(ToDate);
                DateTime        miladiToD = ToD.ToDateTime();

                List <UserShopingInfo> UserList = (_context.Database.SqlQuery <UserShopingInfo>(@"select Tbl_User.Name , Tbl_User.Id , Tbl_User.BIZCode ,sum(CAST(Tbl_SirjanPurchase.Price AS bigint)) AS [TotalPurchase] from Tbl_User inner join Tbl_SirjanPurchase on Tbl_User.Id = Tbl_SirjanPurchase.UserId WHERE Tbl_SirjanPurchase.PurchaseId = 1 and Tbl_SirjanPurchase.MiladiDate > '" + miladiFromD + "' and Tbl_SirjanPurchase.MiladiDate< '" + miladiToD + "' group by Tbl_User.Name,Tbl_User.Id,Tbl_User.BIZCode")).ToList();

                string TotalPrice = (_context.Database.SqlQuery <string>(@"SELECT CAST(sum(CAST(Tbl_SirjanPurchase.Price AS int))AS varchar) AS [TotalPrice] from Tbl_User inner join Tbl_SirjanPurchase on Tbl_User.Id = Tbl_SirjanPurchase.UserId WHERE Tbl_SirjanPurchase.PurchaseId = 1 and Tbl_SirjanPurchase.MiladiDate > '" + miladiFromD + "' and Tbl_SirjanPurchase.MiladiDate< '" + miladiToD + "'")).FirstOrDefault <string>();

                ViewBag.TotalPrice = TotalPrice;

                var viewmodel = new UserInformationsIpagedList
                {
                    IpagedListUserInfo = UserList.ToList().ToPagedList(i ?? 1, 100000)
                };
                return(View(viewmodel));
            }
            else
            {
                return(RedirectToAction("Login", "Home"));
            }
        }
        public async Task <IActionResult> GetDayData(int personnelId, string shamsiDayDate)
        {
            try
            {
                PersianDateTime prsDt = PersianDateTime.Parse(shamsiDayDate.Replace("-", "/"));

                var obj = (await dayRep.GetDayData(personnelId, prsDt.ToDateTime()));

                if (obj.Successed)
                {
                    return(Ok(obj.ResultObject));
                }
                else
                {
                    return(NotFound(obj));
                }
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
        public JsonResult GetVaredeAndSadere(ProductInStockpileModelView SenderObj)
        {
            if (ModelState.IsValid)
            {
                if (SenderObj != null)
                {
                    int id_Mpc = 0;
                    if (Int32.TryParse(SenderObj.InOutStructures.id_Mpc, out id_Mpc))
                    {
                        string id_CreatedByAdmin = "0";
                        if (Session["AdministratorRegistery"] != null)
                        {
                            id_CreatedByAdmin = ((Administrator)Session["AdministratorRegistery"]).id_Admin;
                        }
                        else
                        {
                            var           coockie          = HttpContext.Request.Cookies.Get(ProjectProperies.AuthCoockieCode());
                            Administrator administratorobj = CoockieController.SayMyName(coockie.Value);
                            id_CreatedByAdmin = administratorobj.id_Admin;
                        }
                        PDBC db = new PDBC();
                        db.Connect();
                        using (DataTable dt = db.Select("SELECT [id_PQT] ,[PriceModule] FROM [tlb_Product_MainProductConnector] WHERE [id_MPC] = " + id_Mpc))
                        {
                            using (DataTable dtStockpile = db.Select("SELECT [id_Stockpile]  FROM [tbl_Modules_StockpileMainTable] WHERE [id_MPC] = " + id_Mpc))
                            {
                                db.DC();
                                if (dtStockpile.Rows.Count > 0)
                                {
                                    if (dt.Rows.Count > 0)
                                    {
                                        List <ExcParameters> allpars = new List <ExcParameters>();
                                        ExcParameters        par     = new ExcParameters()
                                        {
                                            _KEY   = "@id_TransactionType",
                                            _VALUE = SenderObj.InOutStructures.Whichone
                                        };
                                        allpars.Add(par);
                                        par = new ExcParameters()
                                        {
                                            _KEY   = "@id_Stockpile",
                                            _VALUE = dtStockpile.Rows[0]["id_Stockpile"].ToString()
                                        };
                                        allpars.Add(par);
                                        if (SenderObj.InOutStructures.Whichone == "1")
                                        {
                                            par = new ExcParameters()
                                            {
                                                _KEY   = "@shop_id",
                                                _VALUE = SenderObj.InOutStructures.Shopid1
                                            };
                                            allpars.Add(par);
                                        }
                                        else
                                        {
                                            par = new ExcParameters()
                                            {
                                                _KEY   = "@shop_id",
                                                _VALUE = SenderObj.InOutStructures.shopid2
                                            };
                                            allpars.Add(par);
                                        }
                                        string[]        dates           = SenderObj.InOutStructures.ActionDate.Split('/');
                                        string[]        times           = SenderObj.InOutStructures.Time.Split(':');
                                        PersianDateTime persianDateTime = new PersianDateTime(Convert.ToInt32(dates[0]), Convert.ToInt32(dates[1]), Convert.ToInt32(dates[2]), Convert.ToInt32(times[0]), Convert.ToInt32(times[1]), 0);


                                        par = new ExcParameters()
                                        {
                                            _KEY   = "@StockpileDate_Transaction",
                                            _VALUE = persianDateTime.ToDateTime()
                                        };
                                        allpars.Add(par);
                                        par = new ExcParameters()
                                        {
                                            _KEY   = "@StockpileTime_Transaction",
                                            _VALUE = SenderObj.InOutStructures.Time
                                        };
                                        allpars.Add(par);
                                        par = new ExcParameters()
                                        {
                                            _KEY   = "@id_PQT",
                                            _VALUE = dt.Rows[0]["id_PQT"].ToString()
                                        };
                                        allpars.Add(par);
                                        par = new ExcParameters()
                                        {
                                            _KEY   = "@MoneyId",
                                            _VALUE = dt.Rows[0]["PriceModule"].ToString()
                                        };
                                        allpars.Add(par);
                                        par = new ExcParameters()
                                        {
                                            _KEY   = "@PriceOf_Transaction",
                                            _VALUE = SenderObj.InOutStructures.INOUTPrice
                                        };
                                        allpars.Add(par);
                                        par = new ExcParameters()
                                        {
                                            _KEY   = "@PQTValueOf_Transaction",
                                            _VALUE = SenderObj.InOutStructures.INOUTValue
                                        };
                                        allpars.Add(par);
                                        if (!string.IsNullOrEmpty(SenderObj.InOutStructures.Description))
                                        {
                                            par = new ExcParameters()
                                            {
                                                _KEY   = "@Description_Transaction",
                                                _VALUE = SenderObj.InOutStructures.Description
                                            };
                                            allpars.Add(par);
                                        }
                                        else
                                        {
                                            par = new ExcParameters()
                                            {
                                                _KEY   = "@Description_Transaction",
                                                _VALUE = ""
                                            };
                                            allpars.Add(par);
                                        }
                                        par = new ExcParameters()
                                        {
                                            _KEY   = "@id_SubmiterAdmin",
                                            _VALUE = id_CreatedByAdmin
                                        };
                                        allpars.Add(par);


                                        db.Connect();
                                        string result = db.Script("INSERT INTO [tbl_Modules_StockpileTransactionMainTable]([id_TransactionType],[id_Stockpile],[shop_id],[StockpileDate_Transaction],[StockpileTime_Transaction],[id_PQT],[MoneyId],[PriceOf_Transaction],[PQTValueOf_Transaction],[Description_Transaction],[id_SubmiterAdmin]) VALUES(@id_TransactionType,@id_Stockpile,@shop_id,@StockpileDate_Transaction,@StockpileTime_Transaction,@id_PQT,@MoneyId,@PriceOf_Transaction,@PQTValueOf_Transaction,@Description_Transaction,@id_SubmiterAdmin)", allpars);
                                        db.DC();
                                        if (result == "1")
                                        {
                                            var ModelSender = new ErrorReporterModel
                                            {
                                                ErrorID      = "SX1645605",
                                                Errormessage = $"اطلاعات با موفقیت ثبت شد!",
                                                Errortype    = "Success"
                                            };
                                            return(Json(ModelSender));
                                        }
                                        else
                                        {
                                            PPBugReporter rep         = new PPBugReporter(BugTypeFrom.SQL, "IN Controller : {AdministratorStockpileController}\nMethod : {public JsonResult GetVarede(ProductInStockpileModelView senderObj)  Script : INSERT INTO [tbl_Modules_StockpileTransactionMainTable]([id_TransactionType],[id_Stockpile],[shop_id],[Submitdate_Transaction],[StockpileDate_Transaction],[StockpileTime_Transaction],[id_PQT],[MoneyId],[PriceOf_Transaction],[PQTValueOf_Transaction],[Description_Transaction],[id_SubmiterAdmin]) VALUES(@id_TransactionType,@id_Stockpile,@shop_id,@Submitdate_Transaction,@StockpileDate_Transaction,@StockpileTime_Transaction,@id_PQT,@MoneyId,@PriceOf_Transaction,@PQTValueOf_Transaction,@Description_Transaction,@id_SubmiterAdmin) ||| Result :" + result);
                                            var           ModelSender = new ErrorReporterModel
                                            {
                                                ErrorID      = "EX1186781",
                                                Errormessage = $"عدم توانایی در ثبت اطلاعات",
                                                Errortype    = "Error"
                                            };
                                            return(Json(ModelSender));
                                        }
                                    }
                                    else
                                    {
                                        var ModelSender = new ErrorReporterModel
                                        {
                                            ErrorID      = "EX645756697",
                                            Errormessage = $"محصول مورد نظر یافت نشد",
                                            Errortype    = "Error"
                                        };
                                        return(Json(ModelSender));
                                    }
                                }
                                else
                                {
                                    var ModelSender = new ErrorReporterModel
                                    {
                                        ErrorID      = "EX645697",
                                        Errormessage = $"محصول مورد نظر یافت نشد",
                                        Errortype    = "Error"
                                    };
                                    return(Json(ModelSender));
                                }
                            }
                        }
                    }
                    else
                    {
                        var ModelSender = new ErrorReporterModel
                        {
                            ErrorID      = "EX1897",
                            Errormessage = $"اطلاعات وارده خلاف متغیر های قانونی میباشد!",
                            Errortype    = "Error"
                        };
                        return(Json(ModelSender));
                    }
                }
                else
                {
                    PPBugReporter rep         = new PPBugReporter(BugTypeFrom.SQL, "IN Controller : {AdministratorStockpileController}\nMethod : {public JsonResult GetVarede(ProductInStockpileModelView senderObj)  (senderObj == null)");
                    var           ModelSender = new ErrorReporterModel
                    {
                        ErrorID      = "EX111",
                        Errormessage = $"ورود متغیر خلاف پروتکل های امنیتی",
                        Errortype    = "Error"
                    };
                    return(Json(ModelSender));
                }
            }
            else
            {
                List <ModelErrorReporter> allErrors = new List <ModelErrorReporter>();
                //foreach (ModelError error in ModelState.Values.)
                var AllValues   = ModelState.Values.ToList();
                var AllKeys     = ModelState.Keys.ToList();
                int errorsCount = AllValues.Count;
                for (int i = 0; i < errorsCount; i++)
                {
                    if (AllValues[i].Errors.Count > 0)
                    {
                        ModelErrorReporter er = new ModelErrorReporter()
                        {
                            IdOfProperty = AllKeys[i].Replace("InOutStructures.", "InOutStructures_"),
                            ErrorMessage = AllValues[i].Errors[0].ErrorMessage
                        };
                        allErrors.Add(er);
                    }
                }
                var ModelSender = new ErrorReporterModel
                {
                    ErrorID      = "EX115",
                    Errormessage = $"عدم رعایت استاندارد ها!",
                    Errortype    = "ErrorWithList",
                    AllErrors    = allErrors
                };
                return(Json(ModelSender));
            }



            return(Json(""));
        }
        public static DateTime ConvertShamsiToMiladi(this string date)
        {
            PersianDateTime persianDateTime = PersianDateTime.Parse(date);

            return(persianDateTime.ToDateTime());
        }
Exemplo n.º 10
0
        public static string ToPersianRelativeDate(this PersianDateTime date)
        {
            var gDate = date.ToDateTime();

            return(gDate.ToPersianRelativeDate());
        }
Exemplo n.º 11
0
        public DateTime ConvertShamsiToMiladi(string Date)
        {
            PersianDateTime persianDateTime = PersianDateTime.Parse(Date);

            return(persianDateTime.ToDateTime());
        }
Exemplo n.º 12
0
        public static DateTime ConvertPersianToGeorgian(this string date)
        {
            PersianDateTime persianDateTime = PersianDateTime.Parse(date);

            return(persianDateTime.ToDateTime());
        }
Exemplo n.º 13
0
        public DateTime ShamsiToMilade(string date)
        {
            PersianDateTime persianDateTime = PersianDateTime.Parse(date);

            return(persianDateTime.ToDateTime());
        }
Exemplo n.º 14
0
 /// <summary>
 /// تبدیل تاریخ شمسی به میلادی
 /// </summary>
 /// <param name="dt">تاریخ شمسی</param>
 /// <returns> 9/3/2017 3:16:29 PM </returns>
 public static DateTime ToDateTime(this PersianDateTime dt)
 {
     return(dt.ToDateTime());
 }
Exemplo n.º 15
0
 /// <summary>
 /// تبدیل تاریخ شمسی به میلادی
 /// </summary>
 /// <param name="dt">تاریخ شمسی</param>
 /// <returns>Sunday 3 September 2017 </returns>
 public static string ToDateString(this PersianDateTime dt)
 {
     return(dt.ToDateTime().ToString("dddd d MMMM yyyy"));
 }
Exemplo n.º 16
0
        public static string MakeCalender(int year)
        {
            if (year == 0)
            {
                year = new PersianDateTime(DateTime.Now).Year;
            }
            var persiandate = new PersianDateTime(year, 1, 1);
            string res = "";
            for (int i = 1; i < 5; i++)
            {
                res += "<div class='row'>";
                for (int j = 1; j < 4; j++)
                {

                    res += "<div class='col-md-4' style='text-align: center'>";
                    res += "<div class='cal'>";
                    res += " <table class='cal-table'>";
                    res += "<caption class='cal-caption'>";
                    res += persiandate.GetLongMonthName;
                    //res += monthCounter.ToString();
                    res += "</caption>";
                    res += "<tbody class='cal-body'>";
                    int emptyCells = ((int)persiandate.DayOfWeek + 7 - 6) % 7;
                    int days = persiandate.GetMonthDays;
                    for (int k = 0; k != 42; k++)
                    {
                        if (k % 7 == 0)
                        {
                            res += "<tr>";
                            if (k > 0) res += "</tr>";
                        }

                        if (k < emptyCells || k >= emptyCells + days)
                        {
                            res += "<td class='cal-off'><a href='#'>";
                            res += "-";
                            res += "</a></td>";
                        }
                        else
                        {
                            if (!string.IsNullOrWhiteSpace(TodayVM.GetPersianEvent(persiandate.Month, persiandate.Day)))
                                res += "<td title='" + TodayVM.GetPersianEvent(persiandate.Month, persiandate.Day)
                                       + "'" + " class='cal-check'>";
                            else
                            {
                                if (persiandate.ToDateTime().Date == DateTime.Now.Date)
                                    res += "<td class='cal-today'>";
                                else
                                    res += "<td >";
                            }

                            if (persiandate.DayOfWeek == DayOfWeek.Friday)
                                res += "<a style='color:red;'>";
                            else
                                res += "<a>";


                            var dayNo = "12";
                            res += TodayVM.ToPersianDigit(persiandate.Day.ToString());
                            res += "</a></td>";
                            persiandate = persiandate.AddDays(1);
                        }
                    }
                    res += "</tbody>";
                    res += "</table>";
                    res += "</div>";
                    res += "</div>";
                    persiandate.AddMonths(1);
                }
                res += "</div>";
            }
            return res;
        }