public override double Cacl() { CashNormal cn; for (int i = 0; i < ti.key_hour.Count; i++) { if (customer.begdatetime.Hour < ti.key_hour[i]) { DateTime key_time = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, ti.key_hour[i], 0, 0); if (customer.enddatetime.Hour <= ti.key_hour[i]) { cn = new CashNormal(customer.begdatetime, customer.enddatetime, ti.cph[i]); TotalMoney += cn.Cacl(); maxMoney = i >= ti.max_money.Count ? ti.max_money[ti.max_money.Count - 1] : ti.max_money[i]; minMoney = i >= ti.min_money.Count ? ti.min_money[ti.min_money.Count - 1] : ti.min_money[i]; } else { cn = new CashNormal(customer.begdatetime, key_time, ti.cph[i]); TotalMoney += cn.Cacl(); for (int j = 1; j < ti.key_hour.Count; j++) { if (customer.enddatetime.Hour <= ti.key_hour[j]) { cn = new CashNormal(key_time, customer.enddatetime, ti.cph[j]); TotalMoney += cn.Cacl(); maxMoney = j >= ti.max_money.Count?ti.max_money[ti.max_money.Count - 1]:ti.max_money[j]; minMoney = j >= ti.min_money.Count ? ti.min_money[ti.min_money.Count - 1] : ti.min_money[j]; break; } else { DateTime next_key_time = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, ti.key_hour[j], 0, 0); cn = new CashNormal(key_time, next_key_time, ti.cph[j + 1]); TotalMoney += cn.Cacl(); key_time = next_key_time; } } if (customer.enddatetime.Hour > ti.key_hour[ti.key_hour.Count - 1]) { maxMoney = ti.max_money[ti.max_money.Count - 1]; minMoney = ti.min_money[ti.min_money.Count - 1]; DateTime next_key_time = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, ti.key_hour[ti.key_hour.Count - 1], 0, 0); cn = new CashNormal(next_key_time, customer.enddatetime, ti.cph[ti.cph.Count - 1]); TotalMoney += cn.Cacl(); } } break; } } if (customer.begdatetime.Hour > ti.key_hour[ti.key_hour.Count - 1]) { maxMoney = ti.max_money[ti.max_money.Count - 1]; minMoney = ti.min_money[ti.min_money.Count - 1]; cn = new CashNormal(customer.begdatetime, customer.enddatetime, ti.cph[ti.cph.Count - 1]); TotalMoney += cn.Cacl(); } return(TotalMoney); }
private void jz()//结账 { TariffInfo ti = new TariffInfo(ismember()); //TariffInfo highti = new TariffInfo(ismember()); string commstr = "select begdatetime from card_consumption where cardid='" + CardNo + "' and begdatetime>='" + start_date.ToString() + "' and enddatetime is null"; begdatetime = Convert.ToDateTime(db.ExecuteScalar(commstr)); enddatetime = DateTime.Now; double xf_money = 0.0; commstr = "select isnull(sum(xf_point),0) from card_consumption where cardid='" + CardNo + "'and enddatetime>='" + DateTime.Now.Date + "' group by cardid"; int pay_already = Convert.ToInt16(db.ExecuteScalar(commstr)); CashSuper cs; if (ti.key_hour.IndexOf(-1) < 0) { cs = new CashTimeSharing(this, ti); xf_money = cs.Cacl(); } else { cs = new CashNormal(begdatetime, enddatetime, ti.cph[0], ti.max_money[0], ti.min_money[0]); xf_money = cs.Cacl(); } //if (DateTime.Now.Hour < ti.key_hour[0]) //{ // CashTimeSharing cts = new CashTimeSharing(this, ti); // xf_money = Math.Round(cts.Cacl()); //} //else //{ // if (!ismember()) // { // highti.cph = 8; // highti.min_money = 16; // } // if (begdatetime.Hour >= 17) // { // CashTimeSharing cts = new CashTimeSharing(this, highti); // xf_money = Math.Round(cts.Cacl()); // } // else // { // CashTimeSharing cts = new CashTimeSharing(this,ti,highti); // xf_money = Math.Round(cts.Cacl()); // } //} string filed = "xf_money"; if (ismember()) { filed = "xf_point"; xf_money = (xf_money + pay_already) > cs.maxMoney ? cs.maxMoney - pay_already : xf_money; } else { if (xf_money < cs.minMoney) { xf_money = cs.minMoney; } } commstr = "select top 1 ball_number from card_consumption where cardid='" + CardNo + "' order by enddatetime desc"; string ball_number = db.ExecuteScalar(commstr).ToString();//所借球号 string mes = "本次消费" + xf_money.ToString() + "元"; if (ball_number != "") { mes = mes + "\n\n" + "应归还" + ball_number + "号球"; } mes = mes + "\n\n是否要结账?"; if (MessageBox.Show(mes, "结账卡提醒", MessageBoxButtons.YesNo) == DialogResult.Yes) { string sql = "update card_consumption set enddatetime='" + DateTime.Now + "'," + filed + "='" + xf_money + "' where cardid='" + CardNo + "' and " + filed + " is null"; db.InsertUpdateDel(sql); if (filed == "xf_point") { if (xf_money > cs.maxMoney) { xf_money = cs.maxMoney; } double integral = xf_money * 1;//计算消费积分 sql = "update vipcard set point=point-" + xf_money + ",xf_integral=xf_integral+" + integral + " where cardid='" + CardNo + "'"; db.InsertUpdateDel(sql); sql = "select point,integral,xf_integral,shop_integral from vipcard where cardid='" + CardNo + "'"; SqlDataReader rs = db.ExecuteSqlDataReader(sql); rs.Read(); string point = rs[0].ToString(); integral = double.Parse(rs[1].ToString()) + double.Parse(rs[2].ToString()) + double.Parse(rs[3].ToString()); double user_point = double.Parse(point); mes = "本次消费" + xf_money.ToString() + "元\n\n"; if (user_point < 0) { mes = mes + "应收款" + Math.Abs(user_point).ToString() + "元\n\n"; sql = "update vipcard set point=0 where cardid='" + CardNo + "'"; db.InsertUpdateDel(sql); } else { mes = mes + "卡内还剩:" + point + "元\n\n"; } rs.Close(); mes = mes + "\n\n当前积分:" + integral.ToString(); if (ball_number != "") { mes = mes + "应归还" + ball_number + "号球"; } } else { double smoney = ti.deposit - xf_money; if (smoney > 1) { mes = "本次消费" + xf_money.ToString() + "元\n\n应找零" + smoney.ToString() + "元"; } else { mes = "本次消费" + xf_money.ToString() + "元\n\n应收款" + Math.Abs(smoney).ToString() + "元"; } if (ball_number != "") { mes = mes + "\n\n" + "应归还" + ball_number + "号球"; } } MessageBox.Show(mes, "刷卡消费", MessageBoxButtons.OK); } parametersf.dgf1 = true; parametersf.dgf2 = true; }