/// <summary> /// /// </summary> /// <param name="dgv"></param> /// <param name="year"></param> /// <param name="month"></param> /// <param name="mode"></param> public static void PayDiff(DataGridView dgv, int year, int month, int mode) { StringBuilder query = new StringBuilder(); DataTable dt = new DataTable(); // 基準月の末日 DateTime Startdt = new DateTime(year, month, 1); DateTime Enddt = Startdt.AddMonths(1); if (mode == (int)Remode.Reminder) { Enddt = Enddt.AddDays(-1); } query.AppendLine("select"); query.AppendLine(" AgreeID,"); query.AppendLine(" ClientSubID"); query.AppendLine(" FROM Agreement"); if (mode == (int)Remode.Reminder) { query.AppendLine(string.Format(" where (AgreeFrom <= '{0}' ", Enddt)); query.AppendLine(string.Format(" or AgreeTo >= '{0}') ", Startdt)); } else { query.AppendLine(string.Format(" where AgreeTo < '{0}' ", Enddt)); } dt = Util.QueryExecuteReturn(query.ToString()); foreach (DataRow dr in dt.Rows) { int AgreeID = int.Parse(dr["AgreeID"].ToString()); int SubID = int.Parse(dr["ClientSubID"].ToString()); AgreeInfo ai = new AgreeInfo(AgreeID); DateTime AgreeFrom = ai.AgreeFrom; DateTime AgreeTo = ai.AgreeTo; if (mode == (int)Remode.Reminder) { // 終了日が基準日より前ならToを終了日にする AgreeTo = ai.AgreeTo < Enddt ? ai.AgreeTo : Enddt; } int tp = Util.TotalPayment(AgreeID); // 合計支払額 int mp = Util.MonthlyPrice(AgreeID); // 月額 bool a16 = Util.From16toDateTime(AgreeFrom); string park = ""; double df = Util.MonthDiff(AgreeFrom, AgreeTo) - (a16 ? 0.5 : 0); // トータル契約月数 16日スタートの場合マイナス0.5か月 double a = tp - (df * mp); if (mode == (int)Remode.Reminder) { // 月数に対して支払額が大きければ問題なし 以降の処理は無し if (a >= 0) { continue; } } else { if (a <= 0) { continue; } } foreach (DataRow pdr in ai.dtParkingInfo.Rows) { park = park + pdr["ParkingName"].ToString() + "-" + pdr["SectionName"].ToString() + ","; } if (mode == (int)Remode.Reminder) { dgv.Rows.Add(new string[] { AgreeID.ToString(), ai.ClientName, park, (a * (-1)).ToString() }); } else { dgv.Rows.Add(new string[] { AgreeID.ToString(), ai.ClientName, park, a.ToString() }); } } }
public static string[] GetApportPay(int AgreeID, int SubID, int year) { string[] pay = new string[12]; AgreeInfo ai = new AgreeInfo(AgreeID); int mp = MonthlyPrice(AgreeID); double tp = TotalPayment(AgreeID); bool a16 = From16toDateTime(ai.AgreeFrom); // 処理しやすいように契約開始終了日を1日にしておく DateTime tmpFrom = new DateTime(ai.AgreeFrom.Year, ai.AgreeFrom.Month, 1); DateTime tmpTo = new DateTime(ai.AgreeTo.Year, ai.AgreeTo.Month, 1); DateTime bsDate = new DateTime(year, 4, 1); // 指定年度より前より契約してたら if (tmpFrom < bsDate) { tp = tp - ((MonthDiff(tmpFrom, bsDate) - (a16 ? 0.5 : 0)) * mp); a16 = false; // 既に半月の処理したので、falseにしておく tmpFrom = new DateTime(year, 4, 1); } // bsDateをプラス1カ月ずつしていき、開始日と終了日の間の支払いを配列に入れていく for (int i = 0; i < 12; i++) { if (tmpFrom == bsDate) { for (int j = i; j < 12; j++) { // 終了日を超えた場合 if (tmpTo < bsDate) { // 残高がある場合は!!で囲う、ない場合は「-」を入れる pay[j] = tp > 0 ? "!!" + mp.ToString() + "!!" : "-"; } else { // 残高がある場合 if (tp > 0) { // 残高が月額より小さい場合は残高を入れる(残高不足) pay[j] = tp < mp ? "!!" + tp.ToString() + "!!" : mp.ToString(); } else { pay[j] = "0"; } } // 支払残高から1カ月の料金を引く 16日開始の場合は半分引く if (a16) { tp = tp - (0.5 * mp); a16 = false; } else { tp = tp - mp; } // 基準月をプラス1する bsDate = bsDate.AddMonths(1); } break; } else { // 開始日が4/1から始まらならない場合は、「-」を入れる pay[i] = "-"; bsDate = bsDate.AddMonths(1); } } return(pay); }