//添加 public DataTable AddGoods(ConsumptionInfo _cinfo) { bool isexist = false; foreach (var item in cifo) { if (item.Goods == _cinfo.Goods) { isexist = true; break; } } if (isexist) { ConsumptionInfo ci = new ConsumptionInfo(); foreach (var item in cifo) { if (item.Goods == _cinfo.Goods) { ci = item; cifo.Remove(item); break; } } _cinfo.GoodsNumber = (Convert.ToInt32(_cinfo.GoodsNumber) + Convert.ToInt32(ci.GoodsNumber)).ToString(); _cinfo.TotalPrice = (Convert.ToInt32(_cinfo.TotalPrice) + Convert.ToInt32(ci.TotalPrice)).ToString(); } cifo.Add(_cinfo); return(ListToDatatableHelper.ToDataTable(cifo)); }
/// <summary> /// 添加购物车 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(comboBox1.Text)) { MessageBox.Show("请选择商品"); return; } ConsumptionInfo ci = new ConsumptionInfo(); ci.Goods = comboBox1.Text; ci.GoodsNumber = numericUpDown1.Value.ToString(); ci.UnitPrice = textBox6.Text; ci.TotalPrice = label10.Text; dataGridView1.DataSource = sp.AddGoods(ci); float s = 0; for (int i = 0; i < dataGridView1.RowCount; i++) { s += Convert.ToInt32(dataGridView1.Rows[i].Cells[3].Value); } label11.Text = s.ToString(); SetdataGridViewHeaderCell(); }
//结算 public void Settlement(DataTable dt, int TotalPrice) { //删除库存 Banlance bl = new Banlance(vinfo); vinfo.Balance -= TotalPrice; bl.ExecAdd(TotalPrice, BanlanceType.消费); vinfo.EditVipUser(vinfo); //写入文件 RecordsConsumption ls = new RecordsConsumption(); ls.VipCard = vinfo.VipCard; ls.Vtype = vinfo.VipType; ls.UserName = vinfo.UserName; ls.PhoneNumber = vinfo.PhoneNumber; ls.Banlance = vinfo.PhoneNumber; ls.ls = new List <ConsumptionInfo>(); ConsumptionInfo cinfo; for (int i = 0; i < dt.Rows.Count; i++) { cinfo = new ConsumptionInfo(); cinfo.Goods = dt.Rows[i]["Goods"].ToString(); cinfo.GoodsNumber = dt.Rows[i]["GoodsNumber"].ToString(); cinfo.TotalPrice = dt.Rows[i]["TotalPrice"].ToString(); cinfo.UnitPrice = dt.Rows[i]["UnitPrice"].ToString(); ls.ls.Add(cinfo); } ls.ConsumptionTime = DateTime.Now.ToLocalTime().ToString(); string filediry = filedir + @"/" + ls.VipCard; string fileurl = filediry + $"/{DateTime.Now.ToString("yyyyMMddhhmmss")}.txt"; FileCreate.FileAndDirCreate(FileType.directory, filediry); //FileCreate.FileAndDirCreate(FileType.File, fileurl); File.WriteAllText(fileurl, JsonConvert.SerializeObject(ls)); }