提问人:Ali norouzi 提问时间:6/19/2023 更新时间:6/19/2023 访问量:39
要将公历日期转换为太阳日期-我显示有这样的错误
To convert Gregorian date to solar date-I showed with such errors
问:
我有这个将 DateTime 波斯语转换为英语的脚本 - 我有错误代码。
public ActionResult addvisit(int docid, int visitid, string visitdatetime, string pid) { int intpid = 0; if (pid != "") { var p = context.Table_Patient.Where(x => x.NationalCode == pid).SingleOrDefault(); if (p == null) { return Json(new { status = 2, nv = 0 }, JsonRequestBehavior.AllowGet); //no NashnalCode } else { intpid = p.pkID; } } string[] vdatetime = visitdatetime.Split(' '); string[] vdate = vdatetime[0].Split('/'); string[] vtime = vdatetime[1].Split(':'); int y = MyExtensions.PersianToEnglish(vdate[0]); int m = MyExtensions.PersianToEnglish(vdate[1]); int d = MyExtensions.PersianToEnglish(vdate[2]); int h = MyExtensions.PersianToEnglish(vtime[0]); int min = MyExtensions.PersianToEnglish(vtime[1]); PersianCalendar a = new PersianCalendar(); DateTime a = PC.ToDateTime(y, m, d, h, min, 0, 0); Double Duration = context.View_PerDoctorsID.Where(x => x.fkDocID == docid && x.fkVisitID == visitid).Select(x => x.Duration).Single(); Table_Visit nv = new Table_Visit(); nv.fkDocID = docid; nv.SDate = a; nv.EDate = a.AddMinutes(Duration); if (pid == null) { nv.fkPID = null; } else { nv.fkPID = intpid; } nv.fkVisitStatus = 1; nv.fkVTID = visitid; var thisvisit = context.View_Visit.Where(x => x.fkDocID == docid && x.fkVTID == visitid && x.SDate == nv.SDate && x.EDate == nv.EDate).SingleOrDefault();
我有错误 a =pc ?
所以我有部分错误列表这个错误。
严重性代码说明 项目文件行抑制状态
错误 CS0128 在此范围内已定义名为“a”的局部变量或函数 hospital D:\Cili\hospital\Controllers\HomeController.cs 266 活动
严重性代码说明 项目文件行抑制状态
错误 CS0103 名称“PC”在当前上下文中不存在 hospital D:\Cili\hospital\Controllers\HomeController.cs 266 活动
严重性代码说明 项目文件行抑制状态
错误 CS0029 无法隐式将类型“System.Globalization.PersianCalendar”转换为“System.DateTime” 医院 D:\Cili\hospital\Controllers\HomeController.cs 273 活动
严重性代码说明 项目文件行抑制状态
错误 CS7036 没有给出对应于“Calendar.AddMinutes(DateTime, int)”医院 D:\Cili\hospital\Controllers\HomeController.cs所需的正式参数“minutes”的参数 274 活动
我定义了将数字变量 persain 转换为英语的类
public static class MyExtensions
{
public static int PersianToEnglish(this string persianStr)
{
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 persianStr)
{
persianStr = persianStr.Replace(item, LettersDictionary[item]);
}
return int.Parse(persianStr);
}
}
答: 暂无答案
评论
a
PersianCalendar a = new PersianCalendar(); DateTime a = PC.ToDateTime(y, m, d, h, min, 0, 0);
a
PersianCalendar
DateTime
string
۱۴۰۲ یکشنبه ۲۸ خرداد
DateTime