public List<ReportCommonEntity> GetOpportunityStageRate(string begintime, string endtime, string UserID, string TeamID, string agentid, string clientid, out decimal forecast) { forecast = 0; List<ReportCommonEntity> list = new List<ReportCommonEntity>(); DataSet ds = SalesRPTDAL.BaseProvider.GetOpportunityStageRate(begintime, endtime, UserID, TeamID, agentid, clientid); var stages = SystemBusiness.BaseBusiness.GetOpportunityStages(agentid, clientid); decimal total = 0;int prev = 0; foreach (var stage in stages) { ReportCommonEntity model = new ReportCommonEntity(); model.name = stage.StageName; DataRow[] drs = ds.Tables["Data"].Select("StageID='" + stage.StageID + "'"); if (drs.Count() > 0) { model.iValue = Convert.ToInt32(drs[0]["Value"]); model.dValue = Convert.ToDecimal(drs[0]["iValue"]); } else { model.dValue = 0; model.iValue = 0; } model.desc = "当前:" + model.iValue.ToString("f2"); total += model.iValue; forecast += model.iValue * stage.Probability; list.Add(model); } total = total > 0 ? total : 1; if (total > 0) { for (int i = list.Count - 1; i >= 0; i--) { list[i].iValue += prev; prev = list[i].iValue; list[i].value = (list[i].iValue / total * 100).ToString("f2"); //list[i].name += list[i].dValue.ToString("f2"); //list[i].name += " (" + list[i].desc + ") "; } } //else //{ // return new List<ReportCommonEntity>(); //} return list; }
public List<ReportCommonEntity> GetCustomerStageRate(string begintime, string endtime, int type, string clientid,string ownerid) { List<ReportCommonEntity> list = new List<ReportCommonEntity>(); DataSet ds = CustomerRPTDAL.BaseProvider.GetCustomerStageRPT(begintime, endtime, type, clientid, ownerid); int[] stages = { 1, 2, 3 }; int total = 0; foreach (var stage in stages) { ReportCommonEntity model = new ReportCommonEntity(); List<SourceItem> sourceItems = new List<SourceItem>(); model.name = stage == 1 ? "新客户" : stage == 2 ? "机会客户" : "成交客户"; if (ds.Tables["Data"].Select("StageStatus=" + stage).Count() > 0) { model.desc += model.name + ":" + ds.Tables["Data"].Select("StageStatus=" + stage)[0]["Value"].ToString(); model.iValue = Convert.ToInt32(ds.Tables["Data"].Select("StageStatus=" + stage)[0]["Value"]); } else { model.iValue = 0; model.desc = ""; } DataRow[] drRow = ds.Tables["Source"].Select("StageStatus=" + stage); if (stage == 2) { foreach (var source in SystemBusiness.BaseBusiness.GetOpportunityStages("", clientid)) { SourceItem item = new SourceItem(); item.Name = source.StageName; item.Value = 0; item.value = "0.00"; item.pvalue = "0.00"; item.cvalue = "0.00"; item.desc = ""; int[] oppstatus = { 1, 2, 3 }; foreach (var opstatus in oppstatus) { if (drRow.Any()) { DataRow[] row = drRow.Where(x => (x["SourceID"].ToString().ToLower() == source.StageID || string.IsNullOrEmpty(x["SourceID"].ToString())) && Convert.ToInt32(x["SourceName"]) == opstatus).ToArray(); if (row.Any() && row.Length > 0) { item.Value += Convert.ToInt32(row[0]["value"]); item.desc = item.desc + (opstatus == 1 ? "正常" : opstatus == 2 ? "已成单" : "已关闭") + "<br/>" + row[0]["value"].ToString() + "<br/>"; } else { item.desc = item.desc + (opstatus == 1 ? "正常" : opstatus == 2 ? "已成单" : "已关闭") + "<br/>0 <br/>"; } } else { item.desc = item.desc + (opstatus == 1 ? "正常" : opstatus == 2 ? "已成单" : "已关闭") + "<br/>0 <br/>"; } } item.cvalue = (Convert.ToDecimal(item.Value) / (model.iValue == 0 ? 1 : model.iValue) * 100).ToString( "f2"); if (list.Count > 0) { int value = list[0].iValue; int tempivalue = model.iValue == 0 ? 1 : model.iValue; item.value = (Convert.ToDecimal(item.Value) / (value == 0 ? 1 : tempivalue) * 100).ToString( "f2"); } sourceItems.Add(item); } } else if (stage == 1) { total = model.iValue; if (type == 1) { model.dValue = CustomerRPTDAL.BaseProvider.GetCustomerCountByTime(begintime, endtime, clientid, ownerid); model.desc = model.name + ":" + model.dValue; } foreach (var source in SystemBusiness.BaseBusiness.GetCustomSources("", clientid)) { SourceItem item = new SourceItem(); item.Name = source.SourceName; item.Value = 0; item.value = "0.00"; item.pvalue = "0.00"; item.cvalue = "0.00"; if (drRow.Any()) { DataRow[] row = drRow.Where(x => x["SourceID"].ToString().ToLower() == source.SourceID).ToArray(); if (row.Any() && row.Length > 0) { item.Value = Convert.ToInt32(row[0]["value"]); } item.cvalue = (Convert.ToDecimal(item.Value) / (model.iValue == 0 ? 1 : model.iValue) * 100).ToString("f2"); } sourceItems.Add(item); } } model.sourceItem = sourceItems; list.Add(model); } for (int i = list.Count - 1; i >= 0; i--) { if (total > 0) { list[i].value = (Convert.ToDecimal(list[i].iValue) / total * 100).ToString("f2"); } else { list[i].value = "0.00"; } list[i].name += list[i].iValue; if (list[i].desc.Length > 0) { list[i].name += " (" + list[i].desc + ") "; } } return list; }
public List<ReportCommonEntity> GetCustomerStageRate(string begintime, string endtime, string agentid, string clientid) { List<ReportCommonEntity> list = new List<ReportCommonEntity>(); DataSet ds = CustomerRPTDAL.BaseProvider.GetCustomerStageRate(begintime, endtime, agentid, clientid); var stages = SystemBusiness.BaseBusiness.GetCustomStages(agentid, clientid); int total = 0, prev = 0; foreach (var stage in stages) { ReportCommonEntity model = new ReportCommonEntity(); model.name = stage.StageName; model.iValue = 0; model.desc = ""; foreach (DataRow dr in ds.Tables["Data"].Select("StageID='" + stage.StageID + "'")) { model.desc += CommonBusiness.GetEnumDesc((EnumCustomStatus)Convert.ToInt32(dr["Status"])) + ":" + dr["Value"].ToString(); model.iValue += Convert.ToInt32(dr["Value"]); } total += model.iValue; list.Add(model); } if (total > 0) { for (int i = list.Count - 1; i >= 0; i--) { list[i].iValue += prev; prev = list[i].iValue; list[i].value = (Convert.ToDecimal(list[i].iValue) / total * 100).ToString("f2"); list[i].name += list[i].iValue; if (list[i].desc.Length > 0) { list[i].name += " (" + list[i].desc + ") "; } } } return list; }