private void ResetForm() { this.mainSaleList = new SalesList(); this.dgvProdutList.DataSource = null; this.lblSerialNum.Text = string.Empty; this.txtProductId.Focus(); }
/// <summary> /// 结算,更新销售主表、明细、会员积分 /// </summary> /// <param name="objSalesList"></param> /// <param name="objMember"></param> /// <returns></returns> public bool SaveSaleInfo(SalesList objSalesList, Member objMember) { List <string> sqlList = new List <string>(); StringBuilder sqlBuilder = new StringBuilder(); //添加主表信息 sqlBuilder.AppendFormat("INSERT INTO SalesList (SeriaNum,TotalMoney,RealReceive,ReturnMoney,SalesPersonId) VALUES ('{0}',{1},{2},{3},{4})", objSalesList.SeriaNum, objSalesList.TotalMoney, objSalesList.RealReceive, objSalesList.ReturnMoney, objSalesList.SalesPersonId); sqlList.Add(sqlBuilder.ToString()); //添加明细信息 foreach (SalesListDetail detailItem in objSalesList.SalesListDetail) { sqlBuilder.Clear(); sqlBuilder.AppendFormat("INSERT INTO SalesListDetail (SerialNum,ProductId,ProductName,UnitPrice,Discount,Quantity,SubTotalMoney) VALUES('{0}', '{1}', '{2}',{3},{4},{5},{6})", detailItem.SerialNum, detailItem.ProductId, detailItem.ProductFullName, detailItem.UnitPrice, detailItem.Discount, detailItem.Quantity, detailItem.SubTotalMoney); sqlList.Add(sqlBuilder.ToString()); //减少库存 sqlBuilder.Clear(); sqlBuilder.AppendFormat("UPDATE ProductInventory SET TotalCount = TotalCount - {0} WHERE ProductId = '{1}'", detailItem.Quantity, detailItem.ProductId); sqlList.Add(sqlBuilder.ToString()); } //有会员信息的话,更新会员积分 if (objMember != null) { sqlBuilder.Clear(); sqlBuilder.AppendFormat("UPDATE SMMembers SET Points = Points + {0} WHERE MemberId = {1}", objMember.Points, objMember.MemberId); sqlList.Add(sqlBuilder.ToString()); } return(SqlHelper.UpdateByTran(sqlList)); }
/// <summary> /// 结算 /// </summary> /// <param name="sales"></param> /// <param name="members"></param> /// <returns></returns> public bool SaveSalerInfo(SalesList sales, SMMembers members) { List <string> procList = new List <string>(); List <SqlParameter[]> psList = new List <SqlParameter[]>(); //给消费主表中添加数据 procList.Add("AddSalesList"); SqlParameter[] saleSp = new SqlParameter[] { new SqlParameter("@SerialNum", SqlDbType.NVarChar, 50), new SqlParameter("@TotalMoney", SqlDbType.Decimal), new SqlParameter("@RealReceive", SqlDbType.Decimal), new SqlParameter("@ReturnMoney", SqlDbType.Decimal), new SqlParameter("@SalesPersonId", SqlDbType.Int) }; saleSp[0].Value = sales.SerialNum; saleSp[1].Value = sales.TotalMoney; saleSp[2].Value = sales.RealReceive; saleSp[3].Value = sales.ReturnMoney; saleSp[4].Value = sales.SalesPersonId; psList.Add(saleSp); //给消费明细表中添加每次购物的详细数据 foreach (SalesListDetail item in sales.salesLists) { procList.Add("AddSalesListDetail"); SqlParameter[] sp = new SqlParameter[] { new SqlParameter("@SerialNum", SqlDbType.NVarChar, 50), new SqlParameter("@ProductId", SqlDbType.NVarChar, 50), new SqlParameter("@ProductName", SqlDbType.NVarChar, 50), new SqlParameter("@UnitPrice", SqlDbType.Decimal), new SqlParameter("@Discount", SqlDbType.Int), new SqlParameter("@Quantity", SqlDbType.Int), new SqlParameter("@SubTotalMoney", SqlDbType.Decimal) }; sp[0].Value = item.SerialNum; sp[1].Value = item.ProductId; sp[2].Value = item.ProductName; sp[3].Value = item.UnitPrice; sp[4].Value = item.Discount; sp[5].Value = item.Quantity; sp[6].Value = item.SubTotalMoney; psList.Add(sp); } //更新会员的积分 if (members != null) { procList.Add("RefreshMemberPoint"); SqlParameter[] sp = new SqlParameter[] { new SqlParameter("@point", SqlDbType.Int), new SqlParameter("@memberId", SqlDbType.Int) }; sp[0].Value = members.Points; sp[1].Value = members.MemberId; psList.Add(sp); } return(SQLHelper.UpdateByTran(procList, psList)); }
public static SalesList ParseToSalesList(string[] file_content) { var result = new SalesList(); for (int i = 1; i < file_content.Length; i++) { result.Add(ParseToSalesPosition(file_content[i])); } return(result); }
//结算时需要更新的数据 //1.在销售主表中添加一条记录 //2.在销售明细表中添加若干条记录 //3.更新库存 public bool SaveSaleInfo(SalesList objSaleList, List <SalesListDetail> objDetailList) { //定义一个结合,用来存储多条SQL语句 List <string> sqlList = new List <string>(); List <SqlParameter[]> paramList = new List <SqlParameter[]>(); //【1】组合插入主表的SQL语句 string sql = "insert into SalesList"; sql += " (SerialNumber,TotalMoney,RealReceive,ReturnMone,SalesPersonId)"; sql += " values(@SerialNumber,@TotalMoney,@RealReceive,@ReturnMone,@SalesPersonId);"; SqlParameter[] param = new SqlParameter[] { new SqlParameter("@SerialNumber", objSaleList.SerialNumber), new SqlParameter("@TotalMoney", objSaleList.TotalMoney), new SqlParameter("@RealReceive", objSaleList.RealReceive), new SqlParameter("@ReturnMone", objSaleList.ReturnMoney), new SqlParameter("@SalesPersonId", objSaleList.SalesPersonId) }; sqlList.Add(sql); paramList.Add(param); //【2】组合插入明细表的SQL语句 foreach (var item in objDetailList) { string sqlDetail = "insert into SalesListDetail"; sqlDetail += " (SerialNumber,ProductId,ProductName,UnitPrice,Discount,Quantity,SubTotalMoney)"; sqlDetail += " values(@SerialNumber,@ProductId,@ProductName,@UnitPrice,@Discount,@Quantity,@SubTotalMoney);"; SqlParameter[] paramDetail = new SqlParameter[] { new SqlParameter("@SerialNumber", item.SerialNumber), new SqlParameter("@ProductId", item.ProductId), new SqlParameter("@ProductName", item.ProductName), new SqlParameter("@UnitPrice", item.UnitPrice), new SqlParameter("@Discount", item.Discount), new SqlParameter("@Quantity", item.Quantity), new SqlParameter("@SubTotalMoney", item.SubTotalMoney) }; sqlList.Add(sqlDetail); paramList.Add(paramDetail); //更新库存信息 string sqlInventory = "update ProductInventory set TotalCount=TotalCount-@Quantity where ProductId=@ProductId;"; SqlParameter[] paramInventory = new SqlParameter[] { new SqlParameter("@Quantity", item.Quantity), new SqlParameter("@ProductId", item.ProductId) }; sqlList.Add(sqlInventory); paramList.Add(paramInventory); } //【3】启用事务并执行放回结果 return(Helper.SqlHelper.UpdateByTran(sqlList, paramList)); }
private void SalesListReloaded(object sender, EventArgs e) { _salesSumary.Clear(); IQueryable <ChartDataDto> chartDataQuery = from i in SalesList.GetFilteredQuery() group i by i.Category into gr select new ChartDataDto { Area = gr.Key, TotalSales = gr.Sum(s => s.SalesOrderRowAmount) }; _salesSumary.AddRange(chartDataQuery.ToList()); }
protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { // TODO: dispose managed state (managed objects) SalesList?.Clear(); SalesList = null; SalesGridParameters?.Dispose(); } // TODO: free unmanaged resources (unmanaged objects) and override finalizer // TODO: set large fields to null disposedValue = true; } }
private void Balance() { //显示结算窗口,考虑支付被取消或修改 FrmBalance frm = new FrmBalance(txtPay.Text); if (frm.ShowDialog() != DialogResult.OK) { if (frm.Tag.ToString() == "Esc")//客户放弃购买(忘记带钱等) { RestForm(); } } else//正式进入结算环节 { SMMembers members = null; if (frm.Tag.ToString().Contains("&"))//输入了会员卡号 { string[] info = frm.Tag.ToString().Split('&'); txtAmount.Text = info[0]; members = new SMMembers() { MemberId = Convert.ToInt32(info[1]), Points = (int)(Convert.ToDouble(txtPay.Text) / 10.0) }; } else { txtAmount.Text = frm.Tag.ToString(); } //找零 txtChange.Text = (Convert.ToDecimal(txtPay.Text) - Convert.ToDecimal(txtAmount.Text)).ToString(); //创建消费对象 SalesList saleObj = new SalesList() { SerialNum = txtSerialNum.Text, TotalMoney = Convert.ToDecimal(txtPay.Text.Trim()), RealReceive = Convert.ToDecimal(txtAmount.Text.Trim()), ReturnMoney = Convert.ToDecimal(txtChange.Text.Trim()), SalesPersonId = Program.Sale.SalePersonId }; //封装消费明细列表 foreach (Produts item in productList) { saleObj.ListDetail.Add( new SalesListDetail() { SerialNum = txtSerialNum.Text, ProductId = item.ProductId, ProductName = item.ProductName, Quantity = item.Quantity, UnitPrice = item.UnitPrice, Discount = item.Discount, SubTotalMoney = item.SubTotal } ); } try { productManager.SaveSalerInfo(saleObj, members); } catch (Exception ex) { MessageBox.Show($"保存销售数据的时候发生异常!{ex.Message}", "异常提示"); return; } //小票打印 printDocument.Print(); PrintPriview(); //重置主界面 RestForm(); } }
/// <summary> /// 在主窗口里按键 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FormMain_KeyDown(object sender, KeyEventArgs e) { // 按下F1 if (e.KeyCode == Keys.F1) { // 封装销售对象 SalesList saleList = new SalesList() { SerialNumber = this.textBoxSerialNumber.Text, TotalMoney = Convert.ToDouble(this.textBoxShouldPay.Text), SalesPersonId = Program.LoginSalePerson.SalesPersonId }; // 打开结算对象窗口 FormBalance dlg = new FormBalance(saleList); if (DialogResult.OK != dlg.ShowDialog()) { if (((KeyEventArgs)dlg.Tag).KeyCode == Keys.F4) { ResetForm(); // 更新主窗口的实收、找零 this.textBoxRealReceived.Text = NumericUtility.ToMoneyFormat(saleList.RealReceive); this.textBoxReturnChange.Text = NumericUtility.ToMoneyFormat(saleList.ReturnMoney); } return; } saleList = dlg.salesList; try { // 保存销售信息、明细 objSalesManager.SaveSaleInfo(saleList, salesListDetailList); } // 访问数据库出错 catch (Exception ex) { MessageBoxEx.Show("保存商品明细时出错!", Program.MessageBoxTitle[Program.MessageBoxTitleType.Error], ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error); } // 有会员卡,则更新积分 if (dlg.salesList.VipCardNo != 0) { try { objSalesManager.UpdateVipPoint(dlg.salesList.VipCardNo, (int)(Math.Floor(Convert.ToDouble(this.textBoxShouldPay.Text) / 10))); } // 更新积分时,数据库出错 catch (Exception ex) { MessageBoxEx.Show("更新会员积分时出错!", Program.MessageBoxTitle[Program.MessageBoxTitleType.Error], ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error); } } // 打印小票 // TODO //printDocumentMain.Print(); ResetForm(); // 更新主窗口的实收、找零 this.textBoxRealReceived.Text = NumericUtility.ToMoneyFormat(saleList.RealReceive); this.textBoxReturnChange.Text = NumericUtility.ToMoneyFormat(saleList.ReturnMoney); } }
private void ApplyBalance() { FrmBalance frmBalance = new FrmBalance(this.lblTotalMoney.Text); DialogResult result = frmBalance.ShowDialog(); if (result == DialogResult.OK) { string returnInfo = frmBalance.Tag.ToString(); Member objMember = null; //输入了正确的会员号 if (returnInfo.Contains("|")) { string[] infoSplit = returnInfo.Split('|'); this.lblReceivedMoney.Text = infoSplit[0]; objMember = new Member() { MemberId = Convert.ToInt32(infoSplit[1]), Points = (int)(Convert.ToDecimal(this.lblTotalMoney.Text) / 10) }; } else { this.lblReceivedMoney.Text = returnInfo; } this.lblReturnMoney.Text = (Convert.ToDecimal(this.lblReceivedMoney.Text) - Convert.ToDecimal(this.lblTotalMoney.Text)).ToString(); //封装销售主表 SalesList objSalesList = new SalesList() { SeriaNum = this.lblSerialNum.Text, TotalMoney = Convert.ToDecimal(this.lblTotalMoney.Text), RealReceive = Convert.ToDecimal(this.lblReceivedMoney.Text), ReturnMoney = Convert.ToDecimal(this.lblReturnMoney.Text), SalesPersonId = Program.currentSalesPerson.SalesPersonId }; //封装销售明细 foreach (SalesListDetail item in this.mainSaleList.SalesListDetail) { objSalesList.SalesListDetail.Add(new SalesListDetail() { SerialNum = objSalesList.SeriaNum, ProductId = item.ProductId, ProductFullName = item.ProductFullName, UnitPrice = item.UnitPrice, Discount = item.Discount, Quantity = item.Quantity, SubTotalMoney = item.SubTotalMoney }); } try { //调用后台方法保存数据 objProductService.SaveSaleInfo(objSalesList, objMember); } catch (Exception ex) { MessageBox.Show("结算过程出现异常,请检查:" + ex.Message); return; } //打印小票(电脑蓝屏。。) //this.mainSaleList = objSalesList; //this.printDocument.Print(); //界面刷新 ResetForm(); } else { if (frmBalance.Tag.ToString().Equals("F4"))//修改商品列表 { this.lblReceivedMoney.Text = "0.00"; this.lblReturnMoney.Text = "0.00"; this.txtProductId.Focus(); } else if (frmBalance.Tag.ToString().Equals("F5")) { this.lblTotalMoney.Text = "0.00"; this.lblReceivedMoney.Text = "0.00"; this.lblReturnMoney.Text = "0.00"; ResetForm(); } } }
public FormBalance(SalesList objSalesList) : this() { salesList = objSalesList; this.textBoxTotal.Text = NumericUtility.ToMoneyFormat(salesList.TotalMoney); }
public bool SaveSaleInfo(SalesList objSaleList, List <SalesListDetail> objDetailList) { return(objSalesListService.SaveSaleInfo(objSaleList, objDetailList)); }
public bool SaveSalerInfo(SalesList sales, SMMembers members) { return(server.SaveSalerInfo(sales, members)); }
private void GoToSalesList(object sender, RoutedEventArgs e) { var salesList = new SalesList(); NavigationService.Navigate(salesList); }
public static void Print(System.Drawing.Printing.PrintPageEventArgs e, SalesList salesList, List <SalesListDetail> detailList, SalesPerson sp) { //生成票据 float left = 2; //打印区域的左边界 float top = 10; //打印区域的上边界 Font titleFont = new Font("楷体_gb2312", 12); //标题字体 Font contentFont = new Font("仿宋", 8); //正文字体 e.Graphics.DrawString(" 实惠到家超市", titleFont, Brushes.Blue, left + 10, top - 5, new StringFormat()); //打印标题 e.Graphics.DrawString(" 购物凭证", titleFont, Brushes.Blue, left + 10, top + 15, new StringFormat()); //打印标题 //画一条分界线 Pen pen = new Pen(Color.Green, 1); e.Graphics.DrawLine(pen, new Point((int)left - 2, (int)top + 35), new Point((int)left + 180, (int)top + 36)); //打印内容 double totalMoney = 0; //商品总计金额 e.Graphics.DrawString("商品名称 单价 数量 金额", contentFont, Brushes.Blue, left, top + titleFont.GetHeight(e.Graphics) + 12 + 12, new StringFormat()); //打印内容表头标题 for (int i = 1; i <= detailList.Count; i++) { //调整间距 string sp1 = string.Empty; if (detailList[i - 1].ProductName.Length == 4) { sp1 = " "; } else if (detailList[i - 1].ProductName.Length == 3) { sp1 = " "; } else if (detailList[i - 1].ProductName.Length == 5) { sp1 = " "; } string sp2 = string.Empty; if (detailList[i - 1].UnitPrice.ToString().Length == 3) { sp1 = " "; } else if (detailList[i - 1].UnitPrice.ToString().Length == 4) { sp1 = " "; } else if (detailList[i - 1].UnitPrice.ToString().Length == 5) { sp1 = " "; } string sp3 = string.Empty; if (detailList[i - 1].Quantity.ToString().Length == 1) { sp1 = " "; } else if (detailList[i - 1].Quantity.ToString().Length == 2) { sp1 = " "; } else if (detailList[i - 1].Quantity.ToString().Length == 3) { sp1 = " "; } e.Graphics.DrawString(detailList[i - 1].ProductName + sp1 + NumericUtility.ToMoneyFormat(detailList[i - 1].UnitPrice) + sp2 + detailList[i - 1].Quantity.ToString() + sp3 + NumericUtility.ToMoneyFormat(detailList[i - 1].SubTotalMoney), contentFont, Brushes.Blue, left, top + titleFont.GetHeight(e.Graphics) + contentFont.GetHeight(e.Graphics) * i + 12 + 12, new StringFormat());//打印明细内容 } //画一条分界线 e.Graphics.DrawLine(pen, new Point((int)left - 2, (int)top + 125), new Point((int)left + 180, (int)top + 36)); //打印备注 e.Graphics.DrawString("总计: ", contentFont, Brushes.Blue, left + 10, top + 15, new StringFormat()); e.Graphics.DrawString("实收: ", contentFont, Brushes.Blue, left + 10, top + 15, new StringFormat()); e.Graphics.DrawString("找零: ", contentFont, Brushes.Blue, left + 10, top + 15, new StringFormat()); e.Graphics.DrawString("流水号: ", contentFont, Brushes.Blue, left + 10, top + 15, new StringFormat()); e.Graphics.DrawString("收银员", contentFont, Brushes.Blue, left + 10, top + 15, new StringFormat()); e.Graphics.DrawString("在30日内凭小票可开具购物发票", contentFont, Brushes.Blue, left + 10, top + 15, new StringFormat()); e.Graphics.DrawString(" 欢迎再次光临", contentFont, Brushes.Blue, left + 10, top + 15, new StringFormat()); }
public bool SaveSalerInfo(SalesList sales, SMMembers members) { List <string> procList = new List <string>(); List <SqlParameter[]> psList = new List <SqlParameter[]>(); //给消费主表中添加数据 procList.Add("AddSalesList"); SqlParameter[] saleSp = new SqlParameter[] { new SqlParameter("@SerialNum", SqlDbType.NVarChar, 50), new SqlParameter("@TotalMoney", SqlDbType.Decimal), new SqlParameter("@RealReceive", SqlDbType.Decimal), new SqlParameter("@ReturnMoney", SqlDbType.Decimal), new SqlParameter("@SalesPersonid", SqlDbType.Int) }; saleSp[0].Value = sales.SerialNum; saleSp[1].Value = sales.TotalMoney; saleSp[2].Value = sales.RealReceive; saleSp[3].Value = sales.ReturnMoney; saleSp[4].Value = sales.SalesPersonId; psList.Add(saleSp); //给消费明细表中添加每次购物的详细数据 foreach (SalesListDetail detail in sales.ListDetail) { procList.Add("AddSalesListDetail"); SqlParameter[] detailList = new SqlParameter[] { new SqlParameter("@SerialNum", SqlDbType.NVarChar, 50), new SqlParameter("@Productid", SqlDbType.NVarChar, 50), new SqlParameter("@ProductName", SqlDbType.NVarChar, 50), new SqlParameter("@UnitPrice", SqlDbType.Decimal), new SqlParameter("@Discount", SqlDbType.Float), new SqlParameter("@Quantity", SqlDbType.Int), new SqlParameter("@SubTotalMoney", SqlDbType.Decimal) }; detailList[0].Value = detail.SerialNum; detailList[1].Value = detail.ProductId; detailList[2].Value = detail.ProductName; detailList[3].Value = detail.UnitPrice; detailList[4].Value = detail.Discount; detailList[5].Value = detail.Quantity; detailList[6].Value = detail.SubTotalMoney; psList.Add(detailList); //更新库存数据 procList.Add("InventoryOut"); SqlParameter[] inventorySp = new SqlParameter[] { new SqlParameter("@Productid", SqlDbType.NVarChar, 50), new SqlParameter("@TotalCount", SqlDbType.Int) }; inventorySp[0].Value = detail.ProductId; inventorySp[1].Value = detail.Quantity; psList.Add(inventorySp); } //更新会员的积分 if (members != null) { procList.Add("RefreshMemberPoint"); SqlParameter[] memberSp = new SqlParameter[] { new SqlParameter("@Points", SqlDbType.Int), new SqlParameter("@Memberid", SqlDbType.Int) }; memberSp[0].Value = members.Points; memberSp[1].Value = members.Memberid; psList.Add(memberSp); } return(SQLHelper.UpdateByTran(procList, psList)); }