/// <summary>
        /// 生成盈亏单
        /// </summary>
        /// <param name="brandID">一个仓库可能对应多个品牌,针对每个品牌生成各自的盈亏单</param>
        private DistributionCommonBillVM <BillStocktakeContrast, BillStocktakeContrastDetails> GenerateContrast(int brandID, IEnumerable <Stock> stocks, IEnumerable <StocktakeAggregationEntityForStockUpdate> stocktakeDatas)
        {
            var contrast = new DistributionCommonBillVM <BillStocktakeContrast, BillStocktakeContrastDetails>();
            var coMaster = contrast.Master;

            coMaster.Remark         = "盘点盈亏";
            coMaster.OrganizationID = VMGlobal.CurrentUser.OrganizationID;
            coMaster.StorageID      = (int)cbxStorage.SelectedValue;
            coMaster.BrandID        = brandID;

            var pids = stocks.Select(o => o.ProductID).Union(stocktakeDatas.Select(o => o.ProductID)).ToArray();//获取库存和盘点的成品ID并集
            List <BillStocktakeContrastDetails> coDetails = new List <BillStocktakeContrastDetails>();
            Stock stock = null;
            StocktakeAggregationEntityForStockUpdate st = null;

            foreach (var pid in pids)
            {
                stock = stocks.FirstOrDefault(o => o.ProductID == pid);
                st    = stocktakeDatas.FirstOrDefault(o => o.ProductID == pid);
                coDetails.Add(new BillStocktakeContrastDetails
                {
                    ProductID    = pid,
                    QuaStockOrig = stock == null ? 0 : stock.Quantity,
                    QuaStocktake = st == null ? 0 : st.Quantity
                });
            }
            coDetails.ForEach(o => o.Quantity = o.QuaStocktake - o.QuaStockOrig);
            coDetails.RemoveAll(o => o.Quantity == 0);
            contrast.Details = coDetails;

            return(contrast);
        }
Esempio n. 2
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            StylePictureAlbum album = this.DataContext as StylePictureAlbum;
            DistributionCommonBillVM <BillOrder, BillOrderDetails> orderVM = new DistributionCommonBillVM <BillOrder, BillOrderDetails>();

            var details            = orderVM.Details = new List <BillOrderDetails>();
            IEnumerable <int> sids = album.Styles.Select(o => o.ID).ToArray();
            var products           = VMGlobal.SysProcessQuery.LinqOP.Search <Product>(o => sids.Contains(o.StyleID)).ToList();

            foreach (var table in _tables)
            {
                var dv = table.DefaultView;
                foreach (DataRowView row in dv)
                {
                    ProSCPictureBO pic = (ProSCPictureBO)row[0];
                    for (int i = 1; i < dv.Table.Columns.Count; i++)
                    {
                        int qua = 0;
                        int.TryParse(row[i].ToString(), out qua);
                        if (qua > 0)
                        {
                            string sname = dv.Table.Columns[i].ColumnName;
                            var    sid   = VMGlobal.Sizes.Find(o => o.Name == sname).ID;
                            var    pid   = products.Find(o => o.StyleID == pic.StyleID && o.ColorID == pic.ColorID && o.SizeID == sid).ID;
                            details.Add(new BillOrderDetails {
                                ProductID = pid, Quantity = qua, QuaCancel = 0, QuaDelivered = 0, Status = (int)OrderStatusEnum.NotDelivered
                            });
                        }
                    }
                }
            }
            if (details.Count == 0)
            {
                MessageBox.Show("没有需要保存的数据");
                return;
            }
            orderVM.Master.BrandID        = album.BrandID;
            orderVM.Master.OrganizationID = VMGlobal.CurrentUser.OrganizationID;
            orderVM.Master.Remark         = txtRemark.Text;
            orderVM.Master.Status         = (int)OrderStatusEnum.NotDelivered;
            var result = orderVM.Save();

            if (result.IsSucceed)
            {
                MessageBox.Show("保存成功");
                foreach (var table in _tables)
                {
                    var dv = table.DefaultView;
                    foreach (DataRowView row in dv)
                    {
                        for (int i = 1; i < dv.Table.Columns.Count; i++)
                        {
                            int qua = 0;
                            int.TryParse(row[i].ToString(), out qua);
                            if (qua > 0)
                            {
                                row[i] = 0;
                            }
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("保存失败\n失败原因:" + result.Message);
            }
        }