private void Button1_Click(System.Object sender, System.EventArgs e) { if (dgSignPay.CurrentRowIndex == -1) { return; } //1、返回当前选中记录的 serialno,计算serialno的所有桌台应付金额 string SelectedPaySerialno; SelectedPaySerialno = dgSignPay[dgSignPay.CurrentRowIndex, 0].ToString(); //2、允许自由打折 int DiscountRate = 100; //默认打折率 if (rms_var.TheAppExt.Chk_op_dz) { frmFreeDiscount frmfd = new frmFreeDiscount(); frmfd.ShowDialog(); if (frmfd.DialogResult == DialogResult.OK) //存在,并设置了自由打折 { DiscountRate = System.Convert.ToInt32(frmfd.NumericUpDown1.Value); } else { return; } } //3、选择签单结帐的支付类型,并且更新 balancetype 表的相同 serialno 的支付类型 paytypecode string PayTypecode; double BalanceCost = 0; double AfterDiscountCost = 0; double AfterOddCost = 0; frmSelPayType frmspt = new frmSelPayType(); BalanceCost = System.Convert.ToDouble(dgSignPay[dgSignPay.CurrentRowIndex, 4]); AfterDiscountCost = BalanceCost * DiscountRate / 100; if (rms_var.FixCost()!="0") //允许自动抹零 { AfterOddCost =Math.Floor(AfterDiscountCost); } else { AfterOddCost = AfterDiscountCost; } frmspt.NumericUpDown1.ReadOnly = true; frmspt.NumericUpDown1.Value = (decimal) AfterOddCost; frmspt.ShowDialog(); if (frmspt.DialogResult == DialogResult.OK) { PayTypecode = rms_var.GetPayTypeCode(frmspt.ComboBox1.Text); if (PayTypecode != "4") //结帐时不能再是签单,必须选择除签单外的结账方式 { UpdateBalanceType(SelectedPaySerialno, rms_var.GetPayTypeCode(frmspt.ComboBox1.Text)); } else { MessageBox.Show("签单结帐的方式不能再选择签单!"); return; } } else { return; } //4、更新customer表 payingcost UpdateCustomerCost(dgSignPay[dgSignPay.CurrentRowIndex, 5].ToString(), AfterOddCost.ToString()); //5、向SignPayFor表添加签单结账记录 AddSignPayFor(SelectedPaySerialno,dgSignPay[dgSignPay.CurrentRowIndex, 5].ToString(), PayTypecode, AfterOddCost.ToString()); //6、更新balance表 UpdateBalance(SelectedPaySerialno, (BalanceCost - AfterDiscountCost).ToString(), (AfterDiscountCost - AfterOddCost).ToString(), AfterOddCost.ToString()); MessageBox.Show("签单结帐顺利完成!"); }
private void DoPay() { if (CurrentTableNo != "") { //检测是否有结帐权 if (rms_var.TheAppExt.Chk_op_jz) { frmPayFor frmpf = new frmPayFor(); //首先返回当前桌台的 serialno ,检测当前 serialno 下的桌台费用 string CurrentTableSerialno; CurrentTableSerialno = rms_var.GetCurrentTableSerialNo(CurrentTableNo); System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(); conn.ConnectionString = rms_var.ConnStr; try { SqlCommand selectCMD = new SqlCommand("SELECT tableno FROM balancetable_t where serialno='" + CurrentTableSerialno + "' group by serialno,tableno", conn); selectCMD.CommandTimeout = 30; SqlDataAdapter dbDA = new SqlDataAdapter(); dbDA.SelectCommand = selectCMD; conn.Open(); DataSet dbDS = new DataSet(); dbDA.Fill(dbDS, "TableList"); frmpf.TablePayFor = new frmPayFor.structTablePayFor[dbDS.Tables[0].Rows.Count - 1 + 1]; //获取所有需要结算的桌台 for (int i = 0; i <= dbDS.Tables[0].Rows.Count - 1; i++) { frmpf.TablePayFor[i].tableno = dbDS.Tables[0].Rows[i][0].ToString(); } //计算所有桌台的相关费用 for (int i = 0; i <= frmpf.TablePayFor.Length - 1; i++) { //计算菜品金额 frmpf.TablePayFor[i].foodcost = double.Parse(rms_var.GetTablePrice(frmpf.TablePayFor[i].tableno)); //菜品优惠金额(部门优惠) frmpf.TablePayFor[i].fooddiscountcost = double.Parse(rms_var.UpdateAndGetSaledFoodDiscountPrice(frmpf.TablePayFor[i].tableno)); //赠送单累计金额 frmpf.TablePayFor[i].presentcost = double.Parse(rms_var.GetPresentBillPrice(frmpf.TablePayFor[i].tableno)); //服务费 frmpf.TablePayFor[i].servercost = double.Parse(rms_var.GetTableServerPay(frmpf.TablePayFor[i].tableno, double.Parse(rms_var.GetTablePrice(frmpf.TablePayFor[i].tableno)))); //附加费/包房费 frmpf.TablePayFor[i].addcost = double.Parse(rms_var.GetTableRoomPay(frmpf.TablePayFor[i].tableno)); //超时费 frmpf.TablePayFor[i].overcost = double.Parse(rms_var.GetTableOverTimePay(frmpf.TablePayFor[i].tableno, double.Parse(rms_var.GetTablePrice(frmpf.TablePayFor[i].tableno)))); //最低消费 frmpf.TablePayFor[i].lowpay = double.Parse(rms_var.GetTableLowPay(frmpf.TablePayFor[i].tableno)); } frmpf.CreatePayForTable(); //frmpf.AddNewPayFor("1", "现金", CDbl(frmpf.lblTotal.Text)) //检测是否允许自由打折 frmFreeDiscount frmfd = new frmFreeDiscount(); if (!rms_var.TheAppExt.Chk_op_dz) //不存在自由打折 { frmfd.NumericUpDown1.Value = (decimal)(rms_var.GetEmplDiscount(rms_var.opinfo.EmpID)); frmfd.NumericUpDown1.Enabled = false; frmfd.ComboBox1.Items.Add("不打折"); frmfd.ComboBox1.Items.Add("99%"); frmfd.ComboBox1.Items.Add("98%"); frmfd.ComboBox1.Items.Add("97%"); frmfd.ComboBox1.Items.Add("96%"); frmfd.ComboBox1.Items.Add("95%"); frmfd.ComboBox1.Items.Add("94%"); frmfd.ComboBox1.Items.Add("93%"); frmfd.ComboBox1.Items.Add("92%"); frmfd.ComboBox1.Items.Add("91%"); frmfd.ComboBox1.Items.Add("90%"); frmfd.ComboBox1.Items.Add("89%"); frmfd.ComboBox1.Items.Add("88%"); frmfd.ComboBox1.Items.Add("87%"); frmfd.ComboBox1.Items.Add("86%"); frmfd.ComboBox1.Items.Add("85%"); frmfd.ComboBox1.Items.Add("84%"); frmfd.ComboBox1.Items.Add("83%"); frmfd.ComboBox1.Items.Add("82%"); frmfd.ComboBox1.Items.Add("81%"); frmfd.ComboBox1.Items.Add("80%"); frmfd.ComboBox1.Items.Add("79%"); frmfd.ComboBox1.Items.Add("78%"); frmfd.ComboBox1.Items.Add("77%"); frmfd.ComboBox1.Items.Add("76%"); frmfd.ComboBox1.Items.Add("75%"); frmfd.ComboBox1.Items.Add("74%"); frmfd.ComboBox1.Items.Add("73%"); frmfd.ComboBox1.Items.Add("72%"); frmfd.ComboBox1.Items.Add("71%"); frmfd.ComboBox1.Items.Add("70%"); frmfd.ComboBox1.Items.Add("69%"); frmfd.ComboBox1.Items.Add("68%"); frmfd.ComboBox1.Items.Add("67%"); frmfd.ComboBox1.Items.Add("66%"); frmfd.ComboBox1.Items.Add("65%"); frmfd.ComboBox1.Items.Add("64%"); frmfd.ComboBox1.Items.Add("63%"); frmfd.ComboBox1.Items.Add("62%"); frmfd.ComboBox1.Items.Add("61%"); frmfd.ComboBox1.Items.Add("60%"); frmfd.ComboBox1.Items.Add("59%"); frmfd.ComboBox1.Items.Add("58%"); frmfd.ComboBox1.Items.Add("57%"); frmfd.ComboBox1.Items.Add("56%"); frmfd.ComboBox1.Items.Add("54%"); frmfd.ComboBox1.Items.Add("53%"); frmfd.ComboBox1.Items.Add("52%"); frmfd.ComboBox1.Items.Add("51%"); frmfd.ComboBox1.Items.Add("50%"); frmfd.ComboBox1.Items.Add("49%"); frmfd.ComboBox1.Items.Add("48%"); frmfd.ComboBox1.Items.Add("47%"); frmfd.ComboBox1.Items.Add("46%"); frmfd.ComboBox1.Items.Add("45%"); frmfd.ComboBox1.Items.Add("44%"); frmfd.ComboBox1.Items.Add("43%"); frmfd.ComboBox1.Items.Add("42%"); frmfd.ComboBox1.Items.Add("41%"); frmfd.ComboBox1.Items.Add("40%"); frmfd.ComboBox1.Items.Add("39%"); frmfd.ComboBox1.Items.Add("38%"); frmfd.ComboBox1.Items.Add("37%"); frmfd.ComboBox1.Items.Add("36%"); frmfd.ComboBox1.Items.Add("35%"); frmfd.ComboBox1.Items.Add("34%"); frmfd.ComboBox1.Items.Add("33%"); frmfd.ComboBox1.Items.Add("32%"); frmfd.ComboBox1.Items.Add("31%"); frmfd.ComboBox1.Items.Add("30%"); frmfd.ComboBox1.Items.Add("29%"); frmfd.ComboBox1.Items.Add("28%"); frmfd.ComboBox1.Items.Add("27%"); frmfd.ComboBox1.Items.Add("26%"); frmfd.ComboBox1.Items.Add("25%"); frmfd.ComboBox1.Items.Add("24%"); frmfd.ComboBox1.Items.Add("23%"); frmfd.ComboBox1.Items.Add("22%"); frmfd.ComboBox1.Items.Add("21%"); frmfd.ComboBox1.Items.Add("20%"); frmfd.ComboBox1.Items.Add("10%"); } else //存在自由打折 { frmfd.ComboBox1.Items.Add("不打折"); frmfd.ComboBox1.Items.Add("99%"); frmfd.ComboBox1.Items.Add("98%"); frmfd.ComboBox1.Items.Add("97%"); frmfd.ComboBox1.Items.Add("96%"); frmfd.ComboBox1.Items.Add("95%"); frmfd.ComboBox1.Items.Add("94%"); frmfd.ComboBox1.Items.Add("93%"); frmfd.ComboBox1.Items.Add("92%"); frmfd.ComboBox1.Items.Add("91%"); frmfd.ComboBox1.Items.Add("90%"); frmfd.ComboBox1.Items.Add("89%"); frmfd.ComboBox1.Items.Add("88%"); frmfd.ComboBox1.Items.Add("87%"); frmfd.ComboBox1.Items.Add("86%"); frmfd.ComboBox1.Items.Add("85%"); frmfd.ComboBox1.Items.Add("84%"); frmfd.ComboBox1.Items.Add("83%"); frmfd.ComboBox1.Items.Add("82%"); frmfd.ComboBox1.Items.Add("81%"); frmfd.ComboBox1.Items.Add("80%"); frmfd.ComboBox1.Items.Add("79%"); frmfd.ComboBox1.Items.Add("78%"); frmfd.ComboBox1.Items.Add("77%"); frmfd.ComboBox1.Items.Add("76%"); frmfd.ComboBox1.Items.Add("75%"); frmfd.ComboBox1.Items.Add("74%"); frmfd.ComboBox1.Items.Add("73%"); frmfd.ComboBox1.Items.Add("72%"); frmfd.ComboBox1.Items.Add("71%"); frmfd.ComboBox1.Items.Add("70%"); frmfd.ComboBox1.Items.Add("69%"); frmfd.ComboBox1.Items.Add("68%"); frmfd.ComboBox1.Items.Add("67%"); frmfd.ComboBox1.Items.Add("66%"); frmfd.ComboBox1.Items.Add("65%"); frmfd.ComboBox1.Items.Add("64%"); frmfd.ComboBox1.Items.Add("63%"); frmfd.ComboBox1.Items.Add("62%"); frmfd.ComboBox1.Items.Add("61%"); frmfd.ComboBox1.Items.Add("60%"); frmfd.ComboBox1.Items.Add("59%"); frmfd.ComboBox1.Items.Add("58%"); frmfd.ComboBox1.Items.Add("57%"); frmfd.ComboBox1.Items.Add("56%"); frmfd.ComboBox1.Items.Add("54%"); frmfd.ComboBox1.Items.Add("53%"); frmfd.ComboBox1.Items.Add("52%"); frmfd.ComboBox1.Items.Add("51%"); frmfd.ComboBox1.Items.Add("50%"); frmfd.ComboBox1.Items.Add("49%"); frmfd.ComboBox1.Items.Add("48%"); frmfd.ComboBox1.Items.Add("47%"); frmfd.ComboBox1.Items.Add("46%"); frmfd.ComboBox1.Items.Add("45%"); frmfd.ComboBox1.Items.Add("44%"); frmfd.ComboBox1.Items.Add("43%"); frmfd.ComboBox1.Items.Add("42%"); frmfd.ComboBox1.Items.Add("41%"); frmfd.ComboBox1.Items.Add("40%"); frmfd.ComboBox1.Items.Add("39%"); frmfd.ComboBox1.Items.Add("38%"); frmfd.ComboBox1.Items.Add("37%"); frmfd.ComboBox1.Items.Add("36%"); frmfd.ComboBox1.Items.Add("35%"); frmfd.ComboBox1.Items.Add("34%"); frmfd.ComboBox1.Items.Add("33%"); frmfd.ComboBox1.Items.Add("32%"); frmfd.ComboBox1.Items.Add("31%"); frmfd.ComboBox1.Items.Add("30%"); frmfd.ComboBox1.Items.Add("29%"); frmfd.ComboBox1.Items.Add("28%"); frmfd.ComboBox1.Items.Add("27%"); frmfd.ComboBox1.Items.Add("26%"); frmfd.ComboBox1.Items.Add("25%"); frmfd.ComboBox1.Items.Add("24%"); frmfd.ComboBox1.Items.Add("23%"); frmfd.ComboBox1.Items.Add("22%"); frmfd.ComboBox1.Items.Add("21%"); frmfd.ComboBox1.Items.Add("20%"); frmfd.ComboBox1.Items.Add("10%"); } frmfd.ComboBox1.SelectedIndex = 0; frmfd.ShowDialog(); double blcCost = 0; //支付金额 int blcCostInt = 0; //优惠金额抹零后金额 170.2 ->170 double blcCostTmp = 0; //优惠金额的领头金额 0.2 if (frmfd.DialogResult == DialogResult.OK) //存在,并设置了自由打折 { for (int i = 0; i <= frmpf.TablePayFor.Length - 1; i++) { if (frmfd.ComboBox1.Text == "不打折") { frmpf.TablePayFor[i].discountrate = 1; } else if (frmfd.ComboBox1.Text == "99%") { frmpf.TablePayFor[i].discountrate = 0.99; } else if (frmfd.ComboBox1.Text == "98%") { frmpf.TablePayFor[i].discountrate = 0.98; } else if (frmfd.ComboBox1.Text == "97%") { frmpf.TablePayFor[i].discountrate = 0.97; } else if (frmfd.ComboBox1.Text == "96%") { frmpf.TablePayFor[i].discountrate = 0.96; } else if (frmfd.ComboBox1.Text == "95%") { frmpf.TablePayFor[i].discountrate = 0.95; } else if (frmfd.ComboBox1.Text == "94%") { frmpf.TablePayFor[i].discountrate = 0.94; } else if (frmfd.ComboBox1.Text == "93%") { frmpf.TablePayFor[i].discountrate = 0.93; } else if (frmfd.ComboBox1.Text == "92%") { frmpf.TablePayFor[i].discountrate = 0.92; } else if (frmfd.ComboBox1.Text == "91%") { frmpf.TablePayFor[i].discountrate = 0.91; } else if (frmfd.ComboBox1.Text == "90%") { frmpf.TablePayFor[i].discountrate = 0.9; } else if (frmfd.ComboBox1.Text == "89%") { frmpf.TablePayFor[i].discountrate = 0.89; } else if (frmfd.ComboBox1.Text == "88%") { frmpf.TablePayFor[i].discountrate = 0.88; } else if (frmfd.ComboBox1.Text == "87%") { frmpf.TablePayFor[i].discountrate = 0.87; } else if (frmfd.ComboBox1.Text == "86%") { frmpf.TablePayFor[i].discountrate = 0.86; } else if (frmfd.ComboBox1.Text == "85%") { frmpf.TablePayFor[i].discountrate = 0.85; } else if (frmfd.ComboBox1.Text == "84%") { frmpf.TablePayFor[i].discountrate = 0.84; } else if (frmfd.ComboBox1.Text == "83%") { frmpf.TablePayFor[i].discountrate = 0.83; } else if (frmfd.ComboBox1.Text == "82%") { frmpf.TablePayFor[i].discountrate = 0.82; } else if (frmfd.ComboBox1.Text == "81%") { frmpf.TablePayFor[i].discountrate = 0.81; } else if (frmfd.ComboBox1.Text == "80%") { frmpf.TablePayFor[i].discountrate = 0.8; } else if (frmfd.ComboBox1.Text == "79%") { frmpf.TablePayFor[i].discountrate = 0.79; } else if (frmfd.ComboBox1.Text == "78%") { frmpf.TablePayFor[i].discountrate = 0.78; } else if (frmfd.ComboBox1.Text == "77%") { frmpf.TablePayFor[i].discountrate = 0.77; } else if (frmfd.ComboBox1.Text == "76%") { frmpf.TablePayFor[i].discountrate = 0.76; } else if (frmfd.ComboBox1.Text == "75%") { frmpf.TablePayFor[i].discountrate = 0.75; } else if (frmfd.ComboBox1.Text == "74%") { frmpf.TablePayFor[i].discountrate = 0.74; } else if (frmfd.ComboBox1.Text == "73%") { frmpf.TablePayFor[i].discountrate = 0.73; } else if (frmfd.ComboBox1.Text == "72%") { frmpf.TablePayFor[i].discountrate = 0.72; } else if (frmfd.ComboBox1.Text == "71%") { frmpf.TablePayFor[i].discountrate = 0.71; } else if (frmfd.ComboBox1.Text == "70%") { frmpf.TablePayFor[i].discountrate = 0.7; } else if (frmfd.ComboBox1.Text == "69%") { frmpf.TablePayFor[i].discountrate = 0.69; } else if (frmfd.ComboBox1.Text == "68%") { frmpf.TablePayFor[i].discountrate = 0.68; } else if (frmfd.ComboBox1.Text == "67%") { frmpf.TablePayFor[i].discountrate = 0.67; } else if (frmfd.ComboBox1.Text == "66%") { frmpf.TablePayFor[i].discountrate = 0.66; } else if (frmfd.ComboBox1.Text == "65%") { frmpf.TablePayFor[i].discountrate = 0.65; } else if (frmfd.ComboBox1.Text == "64%") { frmpf.TablePayFor[i].discountrate = 0.64; } else if (frmfd.ComboBox1.Text == "63%") { frmpf.TablePayFor[i].discountrate = 0.63; } else if (frmfd.ComboBox1.Text == "62%") { frmpf.TablePayFor[i].discountrate = 0.62; } else if (frmfd.ComboBox1.Text == "61%") { frmpf.TablePayFor[i].discountrate = 0.61; } else if (frmfd.ComboBox1.Text == "60%") { frmpf.TablePayFor[i].discountrate = 0.6; } else if (frmfd.ComboBox1.Text == "59%") { frmpf.TablePayFor[i].discountrate = 0.59; } else if (frmfd.ComboBox1.Text == "58%") { frmpf.TablePayFor[i].discountrate = 0.58; } else if (frmfd.ComboBox1.Text == "57%") { frmpf.TablePayFor[i].discountrate = 0.57; } else if (frmfd.ComboBox1.Text == "56%") { frmpf.TablePayFor[i].discountrate = 0.56; } else if (frmfd.ComboBox1.Text == "55%") { frmpf.TablePayFor[i].discountrate = 0.55; } else if (frmfd.ComboBox1.Text == "54%") { frmpf.TablePayFor[i].discountrate = 0.54; } else if (frmfd.ComboBox1.Text == "53%") { frmpf.TablePayFor[i].discountrate = 0.53; } else if (frmfd.ComboBox1.Text == "52%") { frmpf.TablePayFor[i].discountrate = 0.52; } else if (frmfd.ComboBox1.Text == "51%") { frmpf.TablePayFor[i].discountrate = 0.51; } else if (frmfd.ComboBox1.Text == "50%") { frmpf.TablePayFor[i].discountrate = 0.5; } else if (frmfd.ComboBox1.Text == "49%") { frmpf.TablePayFor[i].discountrate = 0.49; } else if (frmfd.ComboBox1.Text == "48%") { frmpf.TablePayFor[i].discountrate = 0.48; } else if (frmfd.ComboBox1.Text == "47%") { frmpf.TablePayFor[i].discountrate = 0.47; } else if (frmfd.ComboBox1.Text == "46%") { frmpf.TablePayFor[i].discountrate = 0.46; } else if (frmfd.ComboBox1.Text == "45%") { frmpf.TablePayFor[i].discountrate = 0.45; } else if (frmfd.ComboBox1.Text == "44%") { frmpf.TablePayFor[i].discountrate = 0.44; } else if (frmfd.ComboBox1.Text == "43%") { frmpf.TablePayFor[i].discountrate = 0.43; } else if (frmfd.ComboBox1.Text == "42%") { frmpf.TablePayFor[i].discountrate = 0.42; } else if (frmfd.ComboBox1.Text == "41%") { frmpf.TablePayFor[i].discountrate = 0.41; } else if (frmfd.ComboBox1.Text == "40%") { frmpf.TablePayFor[i].discountrate = 0.4; } else if (frmfd.ComboBox1.Text == "39%") { frmpf.TablePayFor[i].discountrate = 0.39; } else if (frmfd.ComboBox1.Text == "38%") { frmpf.TablePayFor[i].discountrate = 0.38; } else if (frmfd.ComboBox1.Text == "37%") { frmpf.TablePayFor[i].discountrate = 0.37; } else if (frmfd.ComboBox1.Text == "36%") { frmpf.TablePayFor[i].discountrate = 0.36; } else if (frmfd.ComboBox1.Text == "35%") { frmpf.TablePayFor[i].discountrate = 0.35; } else if (frmfd.ComboBox1.Text == "34%") { frmpf.TablePayFor[i].discountrate = 0.34; } else if (frmfd.ComboBox1.Text == "33%") { frmpf.TablePayFor[i].discountrate = 0.33; } else if (frmfd.ComboBox1.Text == "32%") { frmpf.TablePayFor[i].discountrate = 0.32; } else if (frmfd.ComboBox1.Text == "31%") { frmpf.TablePayFor[i].discountrate = 0.31; } else if (frmfd.ComboBox1.Text == "30%") { frmpf.TablePayFor[i].discountrate = 0.3; } else if (frmfd.ComboBox1.Text == "29%") { frmpf.TablePayFor[i].discountrate = 0.29; } else if (frmfd.ComboBox1.Text == "28%") { frmpf.TablePayFor[i].discountrate = 0.28; } else if (frmfd.ComboBox1.Text == "27%") { frmpf.TablePayFor[i].discountrate = 0.27; } else if (frmfd.ComboBox1.Text == "26%") { frmpf.TablePayFor[i].discountrate = 0.26; } else if (frmfd.ComboBox1.Text == "25%") { frmpf.TablePayFor[i].discountrate = 0.25; } else if (frmfd.ComboBox1.Text == "24%") { frmpf.TablePayFor[i].discountrate = 0.24; } else if (frmfd.ComboBox1.Text == "23%") { frmpf.TablePayFor[i].discountrate = 0.23; } else if (frmfd.ComboBox1.Text == "22%") { frmpf.TablePayFor[i].discountrate = 0.22; } else if (frmfd.ComboBox1.Text == "21%") { frmpf.TablePayFor[i].discountrate = 0.21; } else if (frmfd.ComboBox1.Text == "20%") { frmpf.TablePayFor[i].discountrate = 0.2; } else if (frmfd.ComboBox1.Text == "10%") { frmpf.TablePayFor[i].discountrate = 0.1; } //frmpf.TablePayFor(i).discountrate = frmfd.NumericUpDown1.Value / 100 //根据自由打折率计算当前桌台所有菜品的优惠金额 //Dim DscntOnDscnt As String = GetSysSetup("DiscountOnDiscount") '允许折上折 string DscntOnDscnt = ""; if (frmfd.RadioButton2.Checked) { DscntOnDscnt = "1"; } //Dim blcCost As Double '支付金额 //Dim blcCostInt As Integer '优惠金额抹零后金额 170.2 ->170 //Dim blcCostTmp As Double '优惠金额的领头金额 0.2 blcCost = frmpf.TablePayFor[i].foodcost - frmpf.TablePayFor[i].presentcost; if (DscntOnDscnt == "1") { frmpf.TablePayFor[i].fooddiscountcost = blcCost * (1 - frmpf.TablePayFor[i].discountrate); } else { frmpf.TablePayFor[i].fooddiscountcost = double.Parse(rms_var.GetFoodsDiscountCost(frmpf.TablePayFor[i].tableno, blcCost, frmpf.TablePayFor[i].discountrate)); } blcCostInt = System.Convert.ToInt32(frmpf.TablePayFor[i].fooddiscountcost); blcCostTmp = System.Convert.ToDouble(frmpf.TablePayFor[i].fooddiscountcost - blcCostInt); frmpf.TablePayFor[i].fooddiscountcost = blcCostInt; //将差额加回应付金额 } } else { return; } //根据打折率,更新桌台支付金额 for (int i = 0; i <= frmpf.TablePayFor.Length - 1; i++) { frmpf.TablePayFor[i].needpayforcost = frmpf.TablePayFor[i].foodcost + frmpf.TablePayFor[i].addcost + frmpf.TablePayFor[i].overcost + frmpf.TablePayFor[i].servercost - frmpf.TablePayFor[i].fooddiscountcost - frmpf.TablePayFor[i].presentcost; frmpf.TablePayFor[i].endprice = frmpf.TablePayFor[i].needpayforcost; } //允许自动抹零 0:数值不变;1:自动抹零;2:四舍五入 string fixcostrtn = rms_var.FixCost(); if (fixcostrtn == "1") //自动抹零 { double afterfixprice = 0; for (int i = 0; i <= frmpf.TablePayFor.Length - 1; i++) { if (frmpf.TablePayFor[i].endprice >= frmpf.TablePayFor[i].lowpay) { //加上优惠抹零的金额 frmpf.TablePayFor[i].needpayforcost =Convert.ToDouble(frmpf.TablePayFor[i].needpayforcost + blcCostTmp); afterfixprice = Math.Floor(frmpf.TablePayFor[i].needpayforcost); frmpf.TablePayFor[i].oddcost =Convert.ToDouble(frmpf.TablePayFor[i].needpayforcost - afterfixprice); frmpf.TablePayFor[i].endprice = afterfixprice; } } } else if (fixcostrtn == "2") //四舍五入 { //Dim afterfixprice As Double = 0 string r="0"; for (int i = 0; i <= frmpf.TablePayFor.Length - 1; i++) { if (frmpf.TablePayFor[i].endprice >= frmpf.TablePayFor[i].lowpay) { //加上优惠抹零的金额 frmpf.TablePayFor[i].needpayforcost =Convert.ToDouble(frmpf.TablePayFor[i].needpayforcost + blcCostTmp); string s = string.Format("{###0:N2}",frmpf.TablePayFor[i].needpayforcost); int s_index = s.IndexOf("."); if (s_index != -1) { short n = short.Parse(s.ToString().Substring(s_index + 1, s.Length - s_index - 1)); if (n < 50) { r = s.Substring(0, s_index); } else { s=(Convert.ToInt32(s)+1).ToString(); r = s.ToString().Substring(0, s_index); } } frmpf.TablePayFor[i].endprice = double.Parse(r); } } } //更新该桌台最终支付金额 for (int i = 0; i <= frmpf.TablePayFor.Length - 1; i++) { if (frmpf.TablePayFor[i].endprice < frmpf.TablePayFor[i].lowpay) { frmpf.TablePayFor[i].balancecost = frmpf.TablePayFor[i].lowpay; } else { frmpf.TablePayFor[i].balancecost = frmpf.TablePayFor[i].endprice; } } //合计桌台消费金额,刷新结账窗口 double foodcost_sum = 0; double fooddiscountcost_sum = 0; double servercost_sum = 0; double presentcost_sum = 0; double addcost_sum = 0; double oddcost_sum = 0; double overcost_sum = 0; double balancecost_sum = 0; for (int i = 0; i <= frmpf.TablePayFor.Length - 1; i++) { foodcost_sum = foodcost_sum + frmpf.TablePayFor[i].foodcost; fooddiscountcost_sum = fooddiscountcost_sum + frmpf.TablePayFor[i].fooddiscountcost; servercost_sum = servercost_sum + frmpf.TablePayFor[i].servercost; presentcost_sum = presentcost_sum + frmpf.TablePayFor[i].presentcost; addcost_sum = addcost_sum + frmpf.TablePayFor[i].addcost; oddcost_sum = oddcost_sum + frmpf.TablePayFor[i].oddcost; overcost_sum = overcost_sum + frmpf.TablePayFor[i].overcost; balancecost_sum = balancecost_sum + frmpf.TablePayFor[i].balancecost; } frmpf.lblFoodCost.Text = string.Format("{0:N2}", foodcost_sum); frmpf.lblDiscountCost.Text = string.Format("{0:N2}", fooddiscountcost_sum); frmpf.lblServerCost.Text = string.Format("{0:N2}", servercost_sum); frmpf.lblPresentCost.Text = string.Format("{0:N2}", presentcost_sum); frmpf.lblAddCost.Text = string.Format("{0:N2}", addcost_sum); frmpf.lblOddCost.Text = string.Format("{0:N2}", oddcost_sum); frmpf.lblOverTimeCost.Text = string.Format("{0:N2}", overcost_sum); frmpf.lblNeedCost.Text = string.Format("{0:N2}", balancecost_sum); //在客显上显示应收金额 DevExt.PoleDisplayer.Display(frmpf.lblNeedCost.Text, DevExt.PoleDisplayType.Payment); //显示结账窗口 frmpf.ShowDialog(); if (frmpf.DialogResult == DialogResult.OK) { GetTableList(cbTableType.Text); CurrentTableNo = dgTableStatus[dgTableStatus.CurrentRowIndex, 0].ToString(); GetTableBills(CurrentTableNo); ShowBill(CurrentTableNo, "first"); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { conn.Close(); } } else { MessageBox.Show("您没有结帐权!"); return; } } }
private void Button1_Click(System.Object sender, System.EventArgs e) { if (dgSignPay.CurrentRowIndex == -1) { return; } //1、返回当前选中记录的 serialno,计算serialno的所有桌台应付金额 string SelectedPaySerialno; SelectedPaySerialno = dgSignPay[dgSignPay.CurrentRowIndex, 0].ToString(); //2、允许自由打折 int DiscountRate = 100; //默认打折率 if (rms_var.TheAppExt.Chk_op_dz) { frmFreeDiscount frmfd = new frmFreeDiscount(); frmfd.ShowDialog(); if (frmfd.DialogResult == DialogResult.OK) //存在,并设置了自由打折 { DiscountRate = System.Convert.ToInt32(frmfd.NumericUpDown1.Value); } else { return; } } //3、选择签单结帐的支付类型,并且更新 balancetype 表的相同 serialno 的支付类型 paytypecode string PayTypecode; double BalanceCost = 0; double AfterDiscountCost = 0; double AfterOddCost = 0; frmSelPayType frmspt = new frmSelPayType(); BalanceCost = System.Convert.ToDouble(dgSignPay[dgSignPay.CurrentRowIndex, 4]); AfterDiscountCost = BalanceCost * DiscountRate / 100; if (rms_var.FixCost() != "0") //允许自动抹零 { AfterOddCost = Math.Floor(AfterDiscountCost); } else { AfterOddCost = AfterDiscountCost; } frmspt.NumericUpDown1.ReadOnly = true; frmspt.NumericUpDown1.Value = (decimal)AfterOddCost; frmspt.ShowDialog(); if (frmspt.DialogResult == DialogResult.OK) { PayTypecode = rms_var.GetPayTypeCode(frmspt.ComboBox1.Text); if (PayTypecode != "4") //结帐时不能再是签单,必须选择除签单外的结账方式 { UpdateBalanceType(SelectedPaySerialno, rms_var.GetPayTypeCode(frmspt.ComboBox1.Text)); } else { MessageBox.Show("签单结帐的方式不能再选择签单!"); return; } } else { return; } //4、更新customer表 payingcost UpdateCustomerCost(dgSignPay[dgSignPay.CurrentRowIndex, 5].ToString(), AfterOddCost.ToString()); //5、向SignPayFor表添加签单结账记录 AddSignPayFor(SelectedPaySerialno, dgSignPay[dgSignPay.CurrentRowIndex, 5].ToString(), PayTypecode, AfterOddCost.ToString()); //6、更新balance表 UpdateBalance(SelectedPaySerialno, (BalanceCost - AfterDiscountCost).ToString(), (AfterDiscountCost - AfterOddCost).ToString(), AfterOddCost.ToString()); MessageBox.Show("签单结帐顺利完成!"); }