protected override void updateCostAndProfit(ProductCirculation cir, ProductCirculationRecord record) { /*********更新数量和成本总价**********/ ProductStainlessDao stainlessDao = cirDao.getProductDao() as ProductStainlessDao; ProductStainless stainless = stainlessDao.FindByID(record.ProductID); double leftNum = stainless.Num + conf.productDirection * record.TotalNum; //只有采购入货才需要更新成本价,通过成本价重新计算来抵冲收付的差额 //销售、销售退货、采购退货通过利润的计算来抵消收付的差额 //采购退货之所以不重新计算成本价,是因为如果退货价格很高的话,可能导致成本价为负数 if (conf.type == ProductCirculation.CirculationType.purchase) { double totalCost = stainless.PriceCost * stainless.Num + conf.productDirection * record.Price * record.TotalNum; if (leftNum != 0) { double cost = totalCost / leftNum; stainless.PriceCost = cost; } } //double乘以int会出现0.9999999的问题 stainless.Num = (double)((decimal)stainless.Num + conf.productDirection * (decimal)record.TotalNum); stainlessDao.Update(stainless); /*************增加利润表记录**********/ if (conf.type == ProductCirculation.CirculationType.sell || conf.type == ProductCirculation.CirculationType.sellBack || conf.type == ProductCirculation.CirculationType.purchaseBack) { SellProfit profit = new SellProfit(cir, record, stainless.PriceCost); SellProfitDao.getInstance().Insert(profit); } }
/// <summary> /// 按产品统计 /// </summary> private void initProducts() { List <SellProfit> done_profit_ls = SellProfitDao.getInstance().FindList(this.start_time.Value, this.end_time.Value.AddDays(1), this.textBox_product.Text, this.textBox_customer.Text); SellProfit sell_profit_obj = new SellProfit(); // 根据货品进行分组 Dictionary <int, List <SellProfit> > group = SellProfitDao.getInstance().group_by_product_id(done_profit_ls); foreach (KeyValuePair <int, List <SellProfit> > one in group) { int product_id = one.Key; List <SellProfit> sell_profit_ls = one.Value; SellProfit merge = new SellProfit(); foreach (SellProfit sell in sell_profit_ls) { merge.type = sell.type; merge.product = sell.product; merge.unit = sell.unit; merge.cnt += sell.cnt; merge.sum_price += sell.sum_price; merge.sum_cost += sell.sum_cost; merge.profit += sell.profit; } //List<double> profit = sell_profit_obj.get_profit(merge.sum_cost, merge.sum_price); //这个地方没有考虑退货 merge.profit_margin = (merge.sum_price - merge.sum_cost) / merge.sum_cost * 100; int index = this.dataGridView1.Rows.Add(); sellprofit_to_grid(merge, index); } }
private void 全部数据清空ToolStripMenuItem_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("数据将全部被清除,建议先备份数据文件后再清除,是否备份?", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { 导出数据文件ToolStripMenuItem_Click(null, null); } else if (result == DialogResult.No) { if (MessageBox.Show("现有数据将全部被清除,是否继续?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK) { return; } else { CustomerDao.getInstance().ClearAllArrear(); PayReceiptDao.getInstance().DeleteAll(); ProductStainlessCirculationDao.getInstance().DeleteAll(); SellProfitDao.getInstance().DeleteAll(); ProductStainlessDao.getInstance().ClearAllNumAndCost(); MessageBox.Show("删除清空数据成功,系统将自动关闭,请重新启动软件!", "提示", MessageBoxButtons.OK); this.Close(); } } }
private void initListRecord() { statistic_record = new SellProfit(); this.dataGridView1.Rows.Clear(); List <SellProfit> done_profit_ls = SellProfitDao.getInstance().FindList(this.start_time.Value, this.end_time.Value.AddDays(1), this.textBox_product.Text, this.textBox_customer.Text); initRecords(done_profit_ls); initRecordStatisticLine(); }