WorkStatisticalStoreOpenSingle.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. namespace LYFZ.Software.MainBusiness.StatisticalEmployeeWork
  10. {
  11. public partial class WorkStatisticalStoreOpenSingle : LYFZ.Software.UI.StatisticalEmployeeWork.WorkStatisticalStoreOpenSingle
  12. {
  13. LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
  14. public WorkStatisticalStoreOpenSingle()
  15. {
  16. this.Load += WorkStatisticalStoreOpenSingle_Load;
  17. this.Shown += WorkStatisticalStoreOpenSingle_Shown;
  18. this.dtDataTimeStart.Leave += dtDataTimeStart_Leave;
  19. this.btnQuery.Click += btnQuery_Click;
  20. this.btnExport.Click += btnExport_Click;
  21. this.btnClose.Click += btnClose_Click;
  22. }
  23. /// <summary>
  24. /// 窗体加载事件
  25. /// </summary>
  26. /// <param name="sender"></param>
  27. /// <param name="e"></param>
  28. void WorkStatisticalStoreOpenSingle_Load(object sender, EventArgs e)
  29. {
  30. this.dtDataTimeStart.DateValue = SDateTime.Now.ToString("yyyy-MM") + "-01";
  31. this.dtDataTimeEnd.DateValue = Convert.ToDateTime(this.dtDataTimeStart.DateValue).AddMonths(1).AddSeconds(-1).ToString("yyyy-MM-dd");
  32. }
  33. /// <summary>
  34. /// 窗体加载事件
  35. /// </summary>
  36. /// <param name="sender"></param>
  37. /// <param name="e"></param>
  38. void WorkStatisticalStoreOpenSingle_Shown(object sender, EventArgs e)
  39. {
  40. LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboBoxTreeView_DepartmentAndEmployee(this.cmbtreevperson, true, IsFirstNodeName: "全部", IsShowResign: false);
  41. cmbtreevperson.IsNodeMouseClick = true;
  42. cmbtreevperson.IsSelectParentNode = true;
  43. this.cmbtreevperson.TextFindTag("全部");
  44. LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboxTreeView(this.cmbtreevStatisticalType, "0:按订单套系统计,1:按订单收款统计", IsSplit: true);
  45. this.cmbtreevStatisticalType.TagFindText("0");
  46. this.btnQuery_Click(this, null);
  47. bool b = LYFZ.Software.MainBusiness.VersionControl.StaticVersion.UIFunctionVersion(VersionControl.VersionFunctionEnum.工作统计);
  48. if (!b)
  49. {
  50. this.Close();
  51. }
  52. }
  53. /// <summary>
  54. /// 开始日期离开事件
  55. /// </summary>
  56. /// <param name="sender"></param>
  57. /// <param name="e"></param>
  58. void dtDataTimeStart_Leave(object sender, EventArgs e)
  59. {
  60. this.dtDataTimeEnd.DateValue = Convert.ToDateTime(this.dtDataTimeStart.DateValue).AddMonths(1).AddSeconds(-1).ToString("yyyy-MM-dd");
  61. }
  62. /// <summary>
  63. /// 获取员工编号
  64. /// </summary>
  65. /// <returns></returns>
  66. string GetEmployeeDataInfo()
  67. {
  68. string strWhere = "";
  69. TreeNode tBode = this.cmbtreevperson.SelectedNode;
  70. if (tBode.Name == "StoreName")
  71. {
  72. if (tBode.Nodes.Count > 0)
  73. {
  74. foreach (TreeNode node in tBode.Nodes)
  75. {
  76. if (node.Nodes.Count > 0)
  77. {
  78. foreach (TreeNode userNode in node.Nodes)
  79. {
  80. if (strWhere != "")
  81. {
  82. strWhere += " or ";
  83. }
  84. strWhere += " Ord_OrderPersonNumber like '%" + userNode.Tag + "%'";
  85. }
  86. }
  87. }
  88. }
  89. }
  90. else if (tBode.Name == "Department")
  91. {
  92. if (tBode.Nodes.Count > 0)
  93. {
  94. foreach (TreeNode userNode in tBode.Nodes)
  95. {
  96. if (strWhere != "")
  97. {
  98. strWhere += " or ";
  99. }
  100. strWhere += " Ord_OrderPersonNumber like '%" + userNode.Tag + "%'";
  101. }
  102. }
  103. }
  104. else if (tBode.Name == "User")
  105. {
  106. if (strWhere != "")
  107. {
  108. strWhere += " or ";
  109. }
  110. strWhere += " Ord_OrderPersonNumber like '%" + tBode.Tag + "%'";
  111. //strWhere += tBode.Tag ;
  112. }
  113. if (string.IsNullOrEmpty(strWhere))
  114. {
  115. strWhere = " Ord_OrderPersonNumber = '-1'";
  116. }
  117. //strDepartment = "'" + string.Join("','", department.ToArray()) + "'";
  118. return strWhere;
  119. }
  120. /// <summary>
  121. /// 查询
  122. /// </summary>
  123. /// <param name="sender"></param>
  124. /// <param name="e"></param>
  125. void btnQuery_Click(object sender, EventArgs e)
  126. {
  127. if (string.IsNullOrEmpty(this.dtDataTimeStart.DateValue.Trim()) && string.IsNullOrEmpty(this.dtDataTimeEnd.DateValue.Trim()))
  128. { MessageBoxCustom.Show("日期段不能为空"); return; }
  129. if (Convert.ToDateTime(this.dtDataTimeEnd.DateValue) < Convert.ToDateTime(this.dtDataTimeStart.DateValue))
  130. { MessageBoxCustom.Show("开始日期不能大于结束日期"); return; }
  131. if (string.IsNullOrEmpty(this.cmbtreevperson.Text.Trim()))
  132. { MessageBoxCustom.Show("门市不能为空!"); return; }
  133. string StrWhere = "";
  134. DataTable dt = null;
  135. string StrStatisticalText = "";
  136. if (this.cmbtreevStatisticalType.Tag.ToString().Trim() == "0")
  137. {
  138. #region 按订单套系统计
  139. StrWhere += "Ord_Class = '1'";
  140. StrWhere += LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetDateTime("Ord_CreateDateTime", this.dtDataTimeStart.DateValue.Trim(), this.dtDataTimeEnd.DateValue.Trim());
  141. if (this.cmbtreevperson.Text.Trim() != "全部")
  142. { StrWhere += " And ("+ GetEmployeeDataInfo() + ")"; }
  143. else
  144. { StrWhere += " And Ord_OrderPersonNumber != ''"; }
  145. string StrTableName = "tb_ErpOrder Left Join tempTB_AggregationCustomer on Ord_Number = GP_OrderNumber Left Join dbo.BView_OrderAmount on Order_Number = Ord_Number Left Join OrderPhotographyData on Ordpg_Number = Ord_Number";
  146. string StrColumnName = "Ord_SinceOrderNumber AS 订单号,"+
  147. "dbo.fn_CheckOrderType(Ord_Type) AS 订单类型,"+
  148. "Cus_Name AS 客户姓名,"+
  149. "Cus_Sex_cs AS 客户性别,"+
  150. "Cus_Telephone AS 客户电话,"+
  151. "Ord_OrderPersonName AS 接单人,"+
  152. "Ord_SeriesName AS 套系名称,"+
  153. "Ord_SeriesPrice AS 套系价格,"+
  154. "dbo.fn_CheckDateTime(Ord_CreateDateTime) AS 订单日期,"+
  155. //"stuff((select ','+ Ords_SightsName from tb_ErpOrderDigitalStatus where Ords_OrdNumber = Ord_Number for xml path('')),1,1,'') AS 拍摄名称,"+
  156. "Ords_SightsName as 拍摄名称," +
  157. "isnull(收款金额,0) AS 收款金额,(套系金额 + isnull(加挑金额,0) - isnull(收款金额,0)) AS 欠款 ";
  158. string sql = @"with OrderPhotographyData as (
  159. select distinct
  160. Ordpg_Number,
  161. STUFF(
  162. (
  163. SELECT ',' + Ordpg_Sights
  164. FROM[dbo].tb_ErpOrdersPhotography
  165. WHERE Ordpg_Number = A.Ordpg_Number
  166. FOR XML PATH('')
  167. )
  168. ,1,1,''
  169. )AS Ords_SightsName
  170. from
  171. tb_ErpOrdersPhotography as A
  172. group by Ordpg_Number
  173. ) " + " select "+ StrColumnName + " from "+ StrTableName +" where "+ StrWhere;
  174. //dt = orbll.GetView_Custom(StrTableName, StrWhere: StrWhere, ShowColumnName: StrColumnName).Tables[0];
  175. dt = orbll.GetView_Custom(sql).Tables[0];
  176. if (dt.Rows.Count > 0)
  177. {
  178. dt = dt.AsEnumerable().OrderByDescending(p => p.Field<string>("订单日期")).CopyToDataTable();
  179. }
  180. this.dgvData.DataSource(dt, strHideField: "");
  181. this.dgvData.Columns["客户电话"].Width = 180;
  182. this.dgvData.Columns["拍摄名称"].Width = 200;
  183. this.dgvData.Columns["订单日期"].Width = 110;
  184. this.dgvData.FillLastColumn(isAddNullColumns: true);
  185. StrStatisticalText = "总数量:" + dt.Rows.Count;
  186. DataRow[] dtRow1 = dt.Select("订单类型 = '婚纱订单'");
  187. if (dtRow1.Length > 0)
  188. { StrStatisticalText += " 婚纱订单:" + dtRow1.Length; }
  189. DataRow[] dtRow2 = dt.Select("订单类型 = '儿童订单'");
  190. if (dtRow2.Length > 0)
  191. { StrStatisticalText += " 儿童订单:" + dtRow2.Length; }
  192. DataRow[] dtRow3 = dt.Select("订单类型 = '写真订单'");
  193. if (dtRow3.Length > 0)
  194. { StrStatisticalText += " 写真订单:" + dtRow3.Length; }
  195. #endregion
  196. }
  197. else
  198. {
  199. #region 按订单收款统计
  200. StrWhere += "Pay_Type = '0'";
  201. StrWhere += LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetDateTime("Pay_CreateDatetime", this.dtDataTimeStart.DateValue.Trim(), this.dtDataTimeEnd.DateValue.Trim());
  202. if (this.cmbtreevperson.Text.Trim() != "全部")
  203. { StrWhere += " And Pay_OpenSingle like '%" + this.cmbtreevperson.Tag.ToString().Trim() + "%'"; }
  204. else
  205. { StrWhere += " And Pay_OpenSingle != ''"; }
  206. string StrTableName = "tb_ErpPayment Left Join dbo.tb_ErpOrder on Ord_Number = Pay_OrdNumber Left Join tempTB_AggregationCustomer on Ord_Number = GP_OrderNumber " +
  207. "Left Join dbo.BView_OrderAmount on Order_Number = Ord_Number Left Join dbo.tb_ErpSystemCategory on Sc_ClassCode = Pay_PaymentMethod";
  208. string StrColumnName = "Ord_SinceOrderNumber AS 订单号," +
  209. "dbo.fn_CheckOrderType(Ord_Type) AS 订单类型," +
  210. "Cus_Name AS 客户姓名," +
  211. "dbo.fn_CheckUserIDGetUserName(Pay_OpenSingle) AS 接单人," +
  212. "Ord_SeriesName AS 套系名称," +
  213. "Ord_SeriesPrice AS 套系价格," +
  214. "dbo.fn_CheckDateTime(Ord_CreateDateTime) AS 订单日期," +
  215. "dbo.fn_CheckDateTime(Pay_CreateDatetime) AS 收款时间," +
  216. "Sc_ClassName AS 付款方式," +
  217. "Pay_AmountOf AS 收款金额," +
  218. "Pay_DiscountAmount AS 优惠金额," +
  219. "(套系金额 + isnull(加挑金额,0) - isnull(收款金额,0)) AS 欠款," +
  220. "case when Pay_Category = '后期收款' then '后期加挑' + (case when Pay_ShootingName != '' then '('+Pay_ShootingName+')' else Pay_ShootingName end) else Pay_Category end AS 收款类别," +
  221. "(case (len(rtrim(ltrim(Pay_OpenSingle))) - len(rtrim(ltrim(replace(Pay_OpenSingle,',',''))))) " +
  222. " when 0 then (Pay_AmountOf - Pay_DiscountAmount) else " +
  223. " cast(((Pay_AmountOf - Pay_DiscountAmount) / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') * (len(rtrim(ltrim(Pay_OpenSingle))) - len(rtrim(ltrim(replace(Pay_OpenSingle,',','')))))) ) * (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') as numeric(9,2)) " +
  224. " end) as '主门市金额' " +
  225. ",(case (len(rtrim(ltrim(Pay_OpenSingle))) - len(rtrim(ltrim(replace(Pay_OpenSingle,',',''))))) " +
  226. " when 0 then 0 else " +
  227. " cast(((Pay_AmountOf - Pay_DiscountAmount) / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') * (len(rtrim(ltrim(Pay_OpenSingle))) - len(rtrim(ltrim(replace(Pay_OpenSingle,',','')))))) ) * (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') as numeric(9,2)) " +
  228. " end) as '副门市金额'," +
  229. "Pay_OpenSingle";
  230. dt = orbll.GetView_Custom(StrTableName, StrWhere: StrWhere, ShowColumnName: StrColumnName).Tables[0];
  231. if (dt.Rows.Count > 0)
  232. {
  233. dt = dt.AsEnumerable().OrderByDescending(p => p.Field<string>("订单日期")).CopyToDataTable();
  234. }
  235. DataTable NewTable = new DataTable();
  236. for (int i = 0; i < dt.Columns.Count - 3; i++)
  237. { NewTable.Columns.Add(dt.Columns[i].ColumnName.Trim(), typeof(string)); }
  238. NewTable.Columns.Add("门市业绩", typeof(string));
  239. decimal TotalPerformance = 0;
  240. for (int i = 0; i < dt.Rows.Count; i++)
  241. {
  242. DataRow newRow = NewTable.NewRow();
  243. for (int j = 0; j < dt.Columns.Count - 3; j++)
  244. {
  245. newRow[dt.Columns[j].ColumnName.Trim()] = dt.Rows[i][j].ToString().Trim();
  246. }
  247. string strPerformance = "0";
  248. if (this.cmbtreevperson.Text.Trim() != "全部")
  249. {
  250. string[] StrArray = dt.Rows[i]["Pay_OpenSingle"].ToString().Trim().Split(',');
  251. for (int j = 0; j < StrArray.Length; j++)
  252. {
  253. if (!string.IsNullOrEmpty(StrArray[j].Trim()))
  254. {
  255. if (StrArray[j].Trim() == this.cmbtreevperson.Tag.ToString().Trim())
  256. {
  257. if (j == 0)
  258. { strPerformance = dt.Rows[i]["主门市金额"].ToString().Trim(); }
  259. else
  260. { strPerformance = dt.Rows[i]["副门市金额"].ToString().Trim(); }
  261. }
  262. }
  263. }
  264. }
  265. else
  266. { strPerformance = dt.Rows[i]["收款金额"].ToString().Trim(); }
  267. newRow["门市业绩"] = strPerformance;
  268. TotalPerformance += Convert.ToDecimal(strPerformance);
  269. NewTable.Rows.Add(newRow);
  270. }
  271. this.dgvData.DataSource(NewTable, strHideField: "");
  272. this.dgvData.Columns["订单日期"].Width = 110;
  273. this.dgvData.Columns["收款时间"].Width = 110;
  274. this.dgvData.Columns["收款类别"].Width = 180;
  275. this.dgvData.FillLastColumn(isAddNullColumns: true);
  276. StrStatisticalText = "总业绩:" + TotalPerformance.ToString("0.00").Trim();
  277. #endregion
  278. }
  279. // 套系价格列求和;
  280. try
  281. {
  282. double sumObject = Convert.ToDouble(dt.Compute("sum(套系价格)", "true"));
  283. StrStatisticalText += string.Format(" 套系总价:{0:N2}, 套系平均价:{1:N2}", sumObject, sumObject / dt.Rows.Count);
  284. }
  285. catch { }
  286. this.txtStatisticalText.Text = StrStatisticalText;
  287. }
  288. /// <summary>
  289. /// 导出
  290. /// </summary>
  291. /// <param name="sender"></param>
  292. /// <param name="e"></param>
  293. void btnExport_Click(object sender, EventArgs e)
  294. {
  295. this.dgvData.ExportDataTable(this.UcNavigationTool.LabTitle);
  296. }
  297. /// <summary>
  298. /// 关闭
  299. /// </summary>
  300. /// <param name="sender"></param>
  301. /// <param name="e"></param>
  302. void btnClose_Click(object sender, EventArgs e)
  303. {
  304. this.Close();
  305. }
  306. }
  307. }