public void AddDetail(_供应商类目详情 detail) { _详细信息.Add(detail); }
private void btnAnalyze_Click(object sender, EventArgs e) { SetButtonState(false); var d供应商详情金额下限 = ndLower.Value; var _商品明细List = new List <_商品明细Mapping>(); var _类目统计List = new List <_类目统计Model>(); var _供应商统计List = new List <_供应商统计Model>(); var _供应商详情List = new List <_供应商统计Model>(); var _采购员列表List = new List <string>(); #region 读取数据 var analyzeAct = new Action(() => { //ShowMsg("开始读取表格数据"); //#region 读取商品明细 //{ // var strCSVPath = txt商品明细.Text; // if (!string.IsNullOrEmpty(strCSVPath)) // { // using (var csv = new ExcelQueryFactory(strCSVPath)) // { // try // { // var tmp = from c in csv.Worksheet<_商品明细Mapping>() // select c; // _商品明细List.AddRange(tmp); // } // catch (Exception ex) // { // ShowMsg(ex.Message); // } // } // } //} //#endregion var strMsg = string.Empty; ShowMsg("开始读取商品明细数据"); FormHelper.ReadCSVFile <_商品明细Mapping>(txt商品明细.Text, ref _商品明细List, ref strMsg); var tmp = new List <_采购员Mapping>(); ShowMsg("开始读取采购员数据"); FormHelper.ReadCSVFile <_采购员Mapping>(txtBuyer.Text, ref tmp, ref strMsg); ShowMsg(strMsg); _采购员列表List = tmp.Select(x => x._采购员).Distinct().ToList(); }); #endregion #region 分析数据 analyzeAct.BeginInvoke((obj) => { var list类目列表 = _商品明细List.Where(x => !string.IsNullOrEmpty(x._商品类别)).Select(x => x._商品类别).Distinct().OrderBy(x => x).ToList(); var list供应商列表 = _商品明细List.Where(x => !string.IsNullOrEmpty(x._供应商)).Select(x => x._供应商).Distinct().OrderBy(x => x).ToList(); ShowMsg("正在统计类目信息"); list类目列表.ForEach(className => { var model = new _类目统计Model(); model._类目 = className; var refRecords = _商品明细List.Where(x => x._商品类别 == className).ToList(); model._供应商个数 = refRecords.Select(x => x._供应商).Distinct().Count(); model._SKU个数 = refRecords.Select(x => x._SKU码).Distinct().Count(); model._月销量 = refRecords.Sum(x => x._30天销量); model._月销售额 = refRecords.Sum(x => x._30销售金额); _类目统计List.Add(model); }); ShowMsg("正在统计供应商信息"); list供应商列表.ForEach(providerName => { var model = new _供应商统计Model(); model._供应商 = providerName; var refRecords = _商品明细List.Where(x => x._供应商 == providerName).ToList(); model._SKU个数 = refRecords.Select(x => x._SKU码).Distinct().Count(); model._类目个数 = refRecords.Select(x => x._商品类别).Distinct().Count(); model._月销量 = refRecords.Sum(x => x._30天销量); model._月销售额 = refRecords.Sum(x => x._30销售金额); var _采购员List = refRecords.Select(x => x._采购员).Distinct().ToList(); var _开发Array = refRecords.Select(x => x._业绩归属2).Distinct().ToArray(); var _类目Array = refRecords.Select(x => x._商品类别).Distinct().ToArray(); //model._采购详细 = _采购员List.Count() > 0 ? string.Join(",", Helper.RemoveUnBuyers(_采购员List).ToArray()) : ""; model._采购详细 = _采购员List.Count() > 0 ? string.Join(",", Helper.RemoveUnBuyersByList(_采购员List, _采购员列表List).ToArray()) : ""; model._开发详细 = _开发Array.Count() > 0 ? string.Join(",", _开发Array) : ""; model._类目详细 = _类目Array.Count() > 0 ? string.Join(",", _类目Array) : ""; #region 如果月销售额达到,加入 _供应商详情List,并且计算出详细信息 { if (model._月销售额 >= d供应商详情金额下限) { var _curRefClassNameList = refRecords.Select(x => x._商品类别).Distinct().ToList(); _curRefClassNameList.ForEach(curClass => { var detail = new _供应商类目详情(); detail._类目名称 = curClass; var curClassRefRecord = refRecords.Where(x => x._商品类别 == curClass).ToList(); detail._SKU个数 = curClassRefRecord.Select(x => x._SKU码).Distinct().Count(); detail._月销量 = curClassRefRecord.Sum(x => x._30天销量); detail._月销售额 = curClassRefRecord.Sum(x => x._30销售金额); model.AddDetail(detail); }); _供应商详情List.Add(model); } } #endregion _供应商统计List.Add(model); }); Export(_类目统计List.OrderByDescending(x => x._月销售额).ToList(), _供应商统计List.OrderByDescending(x => x._月销售额).ToList(), _供应商详情List.OrderByDescending(x => x._月销售额).ToList()); }, null); #endregion }