You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ERP/TradeManageNew/TJ_CountServerNew.asmx.cs

344 lines
13 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using TradeModel;
using TradeData;
using System.Text;
using System.Data;
using System.Web.Script.Serialization;
namespace TradeManageNew
{
/// <summary>
/// TJ_CountServerNew 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
[System.Web.Script.Services.ScriptService]
public class TJ_CountServerNew : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
#region 报表27
[WebMethod(EnableSession = true)]
public string GetReportTable27(int PlatId, int ShopId, DateTime? SDate, DateTime? EDate, int StoreId)
{
var obj = new BaseService();
string CompanyId = Session["CompanyId"].ToString();
string tj = "";
if (StoreId > 0)
{
tj = " and b.StoreId=" + StoreId;
}
if (PlatId != 0)
tj += " and a.PlatId =" + PlatId;
if (ShopId != 0)
tj += " and a.ShopId =" + ShopId;
if (SDate != null)
tj += " and a.OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
if (EDate != null)
tj += " and a.OrderDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' ";
string sql = @"select a.PlatOrderCode,a.TotalPrice,shopName=dbo.GetShopName(a.shopId),b.CountryName,SKU=dbo.getGoodsSKU(a.OrderId),a.MoneyCode,a.OrderDate,a.GoodsNum from DT_OrderInfo a
inner join DT_OrderXXInfo b on a.OrderId=b.OrderId
where a.State<3 " + tj;
DataTable dt = obj.GetReportData(sql);
return GetReport(dt, 38);
}
#endregion
#region 报表
public string GetReport(DataTable dt, int ReportId)
{
PagesNew.Login(this.Session);
var obj = new BaseService();
var rmd = BaseService.GetReportModel(ReportId);
var rlist = obj.GetRepoartColsList(ReportId);
if (rmd == null || rlist == null)
return "";
StringBuilder html = new StringBuilder();
html.Append("<tr class='HeaderStyle'><th>序号</th>");
foreach (var md in rlist)
{
html.Append("<th>" + md.ColName + "</th>");
}
html.Append("</tr>");
if (dt != null)
{
DataRow row = null;
for (int i = 0; i < dt.Rows.Count; i++)
{
html.Append("<tr class='DataGridRowStyle'><td>" + (i + 1).ToString() + "</td>");
int rowindex = 1;
foreach (var md in rlist)
{
if (dt.Columns.Contains(md.ColValue) == false)
{
html.Append("<td rowindex='" + rowindex + "' rowtr='" + i + "'></td>");
rowindex++;
continue;
}
if (md.IsSum == 1 && i == 0)
{
if (row == null)
row = dt.NewRow();
if (md.ColType == "int")
{
try
{
row[md.ColValue] = Convert.ToInt32(dt.Compute("sum(" + md.ColValue + ")", "" + md.ColValue + " is not null"));
}
catch
{
row[md.ColValue] = 0;
}
}
else if (md.ColType == "dec")
{
try
{
row[md.ColValue] = Convert.ToDecimal(dt.Compute("sum(" + md.ColValue + ")", "" + md.ColValue + ">0"));
}
catch
{
row[md.ColValue] = 0;
}
}
}
if (dt.Rows[i][md.ColValue] != null && dt.Rows[i][md.ColValue].ToString() != "")
{
string csscolor = "";
if (md.ContionType == "=" && dt.Rows[i][md.ColValue].ToString() == md.SValue)
{
csscolor = md.ColColor;
}
else
if (md.ContionType == ">" && Convert.ToDecimal(dt.Rows[i][md.ColValue]) > Convert.ToDecimal(md.SValue) && Convert.ToDecimal(dt.Rows[i][md.ColValue]) < Convert.ToDecimal(md.EValue))
{
csscolor = md.ColColor;
}
else
if (md.ContionType == ">=" && Convert.ToDecimal(dt.Rows[i][md.ColValue]) >= Convert.ToDecimal(md.SValue) && Convert.ToDecimal(dt.Rows[i][md.ColValue]) <= Convert.ToDecimal(md.EValue))
{
csscolor = md.ColColor;
}
if (csscolor != "")
csscolor = "style='color:" + csscolor + "'";
string datav = "";
if (md.ColType == "date1")
datav = Convert.ToDateTime(dt.Rows[i][md.ColValue]).ToString("yyyy-MM-dd");
else
if (md.ColType == "date2")
datav = Convert.ToDateTime(dt.Rows[i][md.ColValue]).ToString("yyyy-MM-dd HH:mm");
else
datav = dt.Rows[i][md.ColValue].ToString();
html.Append("<td " + csscolor + " rowindex='" + rowindex + "' rowtr='" + i + "'>" + datav + "</td>");
}
else
html.Append("<td rowindex='" + rowindex + "' rowtr='" + i + "'></td>");
rowindex++;
}
html.Append("</tr>");
}
int hj = 0;
if (row != null)
{
html.Append("<tr class='DataGridRowStyle'><td>合计:</td>");
foreach (var md in rlist)
{
if (dt.Columns.Contains(md.ColValue) == false)
{
html.Append("<td></td>");
continue;
}
if (md.IsSum == 1 && row[md.ColValue] != null)
{
if (hj == 0)
{
hj = 1;
html.Append("<td>" + row[md.ColValue] + "</td>");
}
else
html.Append("<td>" + row[md.ColValue] + "</td>");
}
else
html.Append("<td></td>");
}
html.Append("</tr>");
}
}
return html.ToString();
}
#endregion
#region 首页订单统计
[WebMethod(EnableSession = true)]
public DT_OrderNum GetDefaultOrderCount1(List<DT_OrderCountContent> listshop, int Type, int Days)
{
PagesNew.Login(this.Session);
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
var obj = new DD_OrderData();
string Ids = "";
string[] categories = null;
DT_OrderNum md = new DT_OrderNum();
var list = new List<DT_OrderCountData>();
DateTime SDate = DateTime.Today.AddDays(-1 * Days);
DateTime EDate = DateTime.Today;
TimeSpan ts = EDate - SDate;
int days = ts.Days + 1;
List<DT_CountListFromDay> countlist = new List<DT_CountListFromDay>();
countlist = obj.GetDefaultCountListFromDay2(Type, Ids.Trim(','), SDate, EDate.AddDays(1), CompanyId);
List<DT_CountListFromDay> countlist2 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist3 = new List<DT_CountListFromDay>();
if (Type == 3)
{
countlist2 = obj.GetDefaultCountListFromDay2(4, Ids.Trim(','), SDate, EDate.AddDays(1), CompanyId);
countlist3 = obj.GetDefaultCountListFromDay2(4, Ids.Trim(','), SDate.AddYears(-1), EDate.AddDays(1).AddYears(-1), CompanyId);
}
categories = new string[days];
if (days > 0)
{
for (int i = 0; i < days; i++)
{
categories[i] = (SDate.AddDays(i)).ToString("MM月dd日");
}
}
if (Type == 3)
{
var smd = new DT_OrderCountContent();
smd.Id = 0;
smd.Name = "总销售额";
listshop.Insert(0, smd);
var _smd = new DT_OrderCountContent();
_smd.Id = -1;
_smd.Name = "去年总销售额";
listshop.Insert(0, _smd);
}
if (listshop != null && listshop.Count > 0)
{
for (int i = 0; i < listshop.Count; i++)
{
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (listshop[i].Id == 0 && Type == 3)
{
if (countlist2 != null)
{
var countmd2 = countlist2.Find(n => n.OrderDate == SDate.AddDays(j).ToString("yyyy-MM-dd"));
if (countmd2 != null)
data[j] = countmd2.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
else if (listshop[i].Id == -1 && Type == 3)
{
if (countlist3 != null)
{
var countmd2 = countlist3.Find(n => n.OrderDate == SDate.AddYears(-1).AddDays(j).ToString("yyyy-MM-dd"));
if (countmd2 != null)
data[j] = countmd2.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
else
{
if (countlist != null)
{
var countmd = countlist.Find(n => n.PlatId == listshop[i].Id && n.OrderDate == SDate.AddDays(j).ToString("yyyy-MM-dd"));
if (countmd != null && Type == 3)
data[j] = countmd.Price.Value;
else if (countmd != null)
data[j] = countmd.Num.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
}
var datamd = new DT_OrderCountData();
datamd.name = listshop[i].Name;
datamd.data = data;
list.Add(datamd);
}
}
md.categories = categories;
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
string postmessage = JsonConvert.Serialize(list);
md.Data = postmessage;
return md;
}
#endregion
}
}