private void CalCurrentAllGZ(int day, string jd, string jm, string jy, string jnd, string jnm) { int g = DyadicArrayHelper.GetArrayIndexByValue(ganArr, jd.Substring(0, 1)); int z = DyadicArrayHelper.GetArrayIndexByValue(zhiArr, jd.Substring(1, 1)); day = day - 1;//约一个记时日,因交节气时间不可能是24:00,时家奇门,如果有刻奇门,或分奇门理论上要比时家奇门要精确。 for (int i = 0; i <= day; i++) { g++; if (g > 9) { g = g - 10; } z++; if (z > 11) { z = z - 12; } } dayGZ = ganArr[g] + zhiArr[z];//得到日干支 yearGZ = jy; monthGZ = jm; int monthIndex = DyadicArrayHelper.GetArrayIndexByValue(JieQiHelper.Days(true).ToArray(), jnd.Replace("日", "")); int mdays = 30; if (jnm.IndexOf("小") > 0) { mdays = 29; } if (monthIndex + day > mdays) //跨月 { SQLiteDataReader reader = SelectJieQI.GetReadData((-1) * day + 10); //因节气在上个月,时间回本月,取节气前一个月的月干支,年干支 if (reader != null) { while (reader.Read()) { monthGZ = reader["MonthGZ"].ToString(); yearGZ = reader["YearGZ"].ToString(); } } reader.Close(); reader.Dispose(); } }
private void GetAllGZ() { //if (1==2) { //string sql = "select [gzDay],[gzMonth],[gzYear],DateValue=([DateValue])+' '+ substring(JieQi,4,5),[weekDay],[constellation],JieQi,[nlMonth],[nlDay] from [ChineseTenThousandCalendar] where left(ltrim(JieQi),2) in (" + JieQiHelper.GetInJieQis() + ")"; //string datasource = Application.StartupPath + "/JieQi.db"; //SqlLiteHelper.SqlServerToSqlLite(datasource, sql); } int myDiffday = 0; string jd = string.Empty; string jm = string.Empty; string jy = string.Empty; string jnd = string.Empty; string jnm = string.Empty; int day = 0; System.Data.SQLite.SQLiteDataReader reader = SelectJieQI.GetReadData(myDiffday); if (reader != null) { while (reader.Read()) { jieQi = reader["jieQi"].ToString().Trim() + " " + reader["DayGZ"].ToString().Trim() + "日" + reader["DateValue"].ToString(); jd = reader["DayGZ"].ToString(); jm = reader["MonthGZ"].ToString(); jy = reader["YearGZ"].ToString(); jnd = reader["NongLiDay"].ToString(); jnm = reader["NongLiMonth"].ToString();; DateTime nowdate = DateTime.Now.AddDays(myDiffday); DateTime jqt = DateTime.Parse(reader["DateValue"].ToString()); TimeSpan ts = nowdate - jqt; day = ts.Days; } reader.Close(); reader.Dispose(); } CalCurrentAllGZ(day, jd, jm, jy, jnd, jnm); }