WorkStatisticalPhotographer.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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 WorkStatisticalPhotographer : LYFZ.Software.UI.StatisticalEmployeeWork.WorkStatisticalPhotographer
  12. {
  13. LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
  14. public WorkStatisticalPhotographer()
  15. {
  16. this.Load += WorkStatisticalPhotographer_Load;
  17. this.Shown += WorkStatisticalPhotographer_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 WorkStatisticalPhotographer_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. cbx_SearchUser.SelectedIndex = 0;
  33. }
  34. /// <summary>
  35. /// 窗体加载事件
  36. /// </summary>
  37. /// <param name="sender"></param>
  38. /// <param name="e"></param>
  39. void WorkStatisticalPhotographer_Shown(object sender, EventArgs e)
  40. {
  41. LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboBoxTreeView_DepartmentAndEmployee(this.cmbtreevperson, true, IsFirstNodeName: "全部", IsShowResign: false);
  42. cmbtreevperson.IsNodeMouseClick = true;
  43. cmbtreevperson.IsSelectParentNode = true;
  44. this.cmbtreevperson.TextFindTag("全部");
  45. this.btnQuery_Click(this, null);
  46. bool b = LYFZ.Software.MainBusiness.VersionControl.StaticVersion.UIFunctionVersion(VersionControl.VersionFunctionEnum.工作统计);
  47. if (!b)
  48. {
  49. this.Close();
  50. }
  51. }
  52. /// <summary>
  53. /// 开始日期离开事件
  54. /// </summary>
  55. /// <param name="sender"></param>
  56. /// <param name="e"></param>
  57. void dtDataTimeStart_Leave(object sender, EventArgs e)
  58. {
  59. this.dtDataTimeEnd.DateValue = Convert.ToDateTime(this.dtDataTimeStart.DateValue).AddMonths(1).AddSeconds(-1).ToString("yyyy-MM-dd");
  60. }
  61. /// <summary>
  62. /// 获取员工编号
  63. /// </summary>
  64. /// <returns></returns>
  65. string GetEmployeeDataInfo()
  66. {
  67. string strWhere = "";
  68. TreeNode tBode = this.cmbtreevperson.SelectedNode;
  69. string searchSqlKey = "Ords_Photographer";
  70. switch(cbx_SearchUser.Text)
  71. {
  72. case "接单人":
  73. searchSqlKey = "Ord_OrderPersonNumber";
  74. break;
  75. case "摄影师":
  76. searchSqlKey = "Ords_Photographer";
  77. break;
  78. case "客服人员":
  79. searchSqlKey = "客服人员";
  80. break;
  81. }
  82. if (tBode.Name == "StoreName")
  83. {
  84. if (tBode.Nodes.Count > 0)
  85. {
  86. foreach (TreeNode node in tBode.Nodes)
  87. {
  88. if (node.Nodes.Count > 0)
  89. {
  90. foreach (TreeNode userNode in node.Nodes)
  91. {
  92. if (strWhere != "")
  93. {
  94. strWhere += " or ";
  95. }
  96. strWhere += " "+ searchSqlKey + " like '%" + userNode.Tag + "%'";
  97. }
  98. }
  99. }
  100. }
  101. }
  102. else if (tBode.Name == "Department")
  103. {
  104. if (tBode.Nodes.Count > 0)
  105. {
  106. foreach (TreeNode userNode in tBode.Nodes)
  107. {
  108. if (strWhere != "")
  109. {
  110. strWhere += " or ";
  111. }
  112. strWhere += " " + searchSqlKey + " like '%" + userNode.Tag + "%'";
  113. }
  114. }
  115. }
  116. else if (tBode.Name == "User")
  117. {
  118. if (strWhere != "")
  119. {
  120. strWhere += " or ";
  121. }
  122. strWhere += " " + searchSqlKey + " like '%" + tBode.Tag + "%'";
  123. //strWhere += tBode.Tag ;
  124. }
  125. if (string.IsNullOrEmpty(strWhere))
  126. {
  127. strWhere = " " + searchSqlKey + " = '-1'";
  128. }
  129. //strDepartment = "'" + string.Join("','", department.ToArray()) + "'";
  130. return strWhere;
  131. }
  132. /// <summary>
  133. /// 查询
  134. /// </summary>
  135. /// <param name="sender"></param>
  136. /// <param name="e"></param>
  137. void btnQuery_Click(object sender, EventArgs e)
  138. {
  139. DAL.DAL_ErpOrdersPhotography bLLErpOrdersPhotography = new DAL.DAL_ErpOrdersPhotography();
  140. if (string.IsNullOrEmpty(this.dtDataTimeStart.DateValue.Trim()) && string.IsNullOrEmpty(this.dtDataTimeEnd.DateValue.Trim()))
  141. { MessageBoxCustom.Show("日期段不能为空"); return; }
  142. if (Convert.ToDateTime(this.dtDataTimeEnd.DateValue) < Convert.ToDateTime(this.dtDataTimeStart.DateValue))
  143. { MessageBoxCustom.Show("开始日期不能大于结束日期"); return; }
  144. if (string.IsNullOrEmpty(this.cmbtreevperson.Text.Trim()))
  145. { MessageBoxCustom.Show("摄影师不能为空!"); return; }
  146. string StrWhere = "Ords_PhotographStatus = '1'";
  147. StrWhere += LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetDateTime("Ords_PhotographMaxTime", this.dtDataTimeStart.DateValue.Trim(), this.dtDataTimeEnd.DateValue.Trim());
  148. if (this.cmbtreevperson.Text.Trim() != "全部")
  149. { StrWhere += " And ("+ GetEmployeeDataInfo() + ")"; }
  150. else
  151. { StrWhere += " And Ords_Photographer != ''"; }
  152. DataTable dt = bLLErpOrdersPhotography.GetStatisticalPhotographerData(StrWhere, " Ords_Photographer as 摄影师 ");
  153. DataTable useDt = new BLL.BLL_ErpUser().GetAllList().Tables[0];
  154. foreach (DataRow dr in dt.Rows)
  155. {
  156. List<DataRow> useDr = useDt.AsEnumerable().Where(p => p.Field<string>("User_EmployeeID") == dr["摄影师"].ToString_s()).ToList();
  157. if (useDr.Count > 0)
  158. {
  159. dr["摄影师"] = useDr[0]["User_Name"];
  160. }
  161. useDr = useDt.AsEnumerable().Where(p => p.Field<string>("User_EmployeeID") == dr["客服人员"].ToString_s()).ToList();
  162. if (useDr.Count > 0)
  163. {
  164. dr["客服人员"] = useDr[0]["User_Name"];
  165. }
  166. }
  167. if (dt.Rows.Count > 0)
  168. {
  169. dt = dt.AsEnumerable().OrderByDescending(p => p.Field<string>("拍摄日期")).CopyToDataTable();
  170. }
  171. /*string StrTableName = "tb_ErpOrderDigital Left Join dbo.tb_ErpOrder on Ord_Number = Ordv_Number Left Join tempTB_AggregationCustomer on Ord_Number = GP_OrderNumber " +
  172. "Left Join dbo.BView_OrderAmount on Order_Number = Ord_Number Left Join OrderPhotographyData on Ords_ViceNumber = Ordv_ViceNumber ";
  173. string StrColumnName = "Ord_SinceOrderNumber AS 订单号," +
  174. "dbo.fn_CheckOrderType(Ord_Type) AS 订单类型," +
  175. "Cus_Name AS 客户姓名," +
  176. "Cus_Sex_cs AS 客户性别," +
  177. "Cus_Telephone AS 客户电话," +
  178. "Ord_OrderPersonName AS 接单人," +
  179. "Ord_SeriesName AS 套系名称," +
  180. "Ord_SeriesPrice AS 套系价格," +
  181. "Ords_Photographer AS 摄影师," +
  182. "dbo.fn_CheckDateTime(Ords_PhotographMaxTime) AS 拍摄日期," +
  183. "Ords_SightsName AS 拍摄名称," +
  184. "(case Ords_PhotographStatus when '1' then 'OK' else '未拍' end ) AS 拍照状态," +
  185. "(套系金额 + isnull(加挑金额,0) - isnull(收款金额,0)) AS 欠款";
  186. string sql = @"with OrderPhotographyData as (
  187. select distinct
  188. Ordpg_PhotographyStatus as Ords_PhotographStatus,
  189. max(Ordpg_PhotographyTime) as Ords_PhotographMaxTime,
  190. Ordpg_Photographer as Ords_Photographer ,
  191. Ordpg_Number,
  192. Ordpg_ViceNumber as Ords_ViceNumber,
  193. STUFF(
  194. (
  195. SELECT ',' + Ordpg_Sights
  196. FROM[dbo].tb_ErpOrdersPhotography
  197. WHERE Ordpg_ViceNumber = A.Ordpg_ViceNumber
  198. FOR XML PATH('')
  199. )
  200. ,1,1,''
  201. )AS Ords_SightsName
  202. from
  203. tb_ErpOrdersPhotography as A
  204. group by Ordpg_Number,Ordpg_ViceNumber,Ordpg_PhotographyStatus,Ordpg_PhotographyTime,Ordpg_Photographer
  205. )" +
  206. "select " + StrColumnName + " from " + StrTableName + " where " + StrWhere;*/
  207. //DataTable dt = orbll.GetView_Custom(StrTableName, StrWhere: StrWhere, ShowColumnName: StrColumnName).Tables[0];
  208. //DataTable dt = orbll.GetView_Custom(sql).Tables[0];
  209. this.dgvData.DataSource(dt, strHideField: "");
  210. this.dgvData.Columns["客户电话"].Width = 180;
  211. this.dgvData.Columns["拍摄名称"].Width = 200;
  212. this.dgvData.Columns["拍摄日期"].Width = 110;
  213. this.dgvData.FillLastColumn(isAddNullColumns: true);
  214. string StrStatisticalText = "总数量:" + dt.Rows.Count;
  215. DataRow[] dtRow1 = dt.Select("订单类型 = '婚纱订单'");
  216. if (dtRow1.Length > 0)
  217. { StrStatisticalText += " 婚纱订单:" + dtRow1.Length; }
  218. DataRow[] dtRow2 = dt.Select("订单类型 = '儿童订单'");
  219. if (dtRow2.Length > 0)
  220. { StrStatisticalText += " 儿童订单:" + dtRow2.Length; }
  221. DataRow[] dtRow3 = dt.Select("订单类型 = '写真订单'");
  222. if (dtRow3.Length > 0)
  223. { StrStatisticalText += " 写真订单:" + dtRow3.Length; }
  224. // 套系价格列求和;
  225. try
  226. {
  227. double sumObject = Convert.ToDouble(dt.Compute("sum(套系价格)", "true"));
  228. StrStatisticalText += string.Format(" 套系总价:{0:N2}, 套系平均价:{1:N2}", sumObject, sumObject / dt.Rows.Count);
  229. }
  230. catch { }
  231. this.txtStatisticalText.Text = StrStatisticalText;
  232. }
  233. /// <summary>
  234. /// 导出
  235. /// </summary>
  236. /// <param name="sender"></param>
  237. /// <param name="e"></param>
  238. void btnExport_Click(object sender, EventArgs e)
  239. {
  240. this.dgvData.ExportDataTable(this.UcNavigationTool.LabTitle);
  241. }
  242. /// <summary>
  243. /// 关闭
  244. /// </summary>
  245. /// <param name="sender"></param>
  246. /// <param name="e"></param>
  247. void btnClose_Click(object sender, EventArgs e)
  248. {
  249. this.Close();
  250. }
  251. }
  252. }