FrmOrdersCustomer.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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.Web.UI.WebControls;
  9. using System.Windows.Forms;
  10. using System.Globalization;
  11. using LYFZ.ComponentLibrary;
  12. using System.Collections;
  13. namespace LYFZ.Software.MainBusiness.Customers
  14. {
  15. public partial class FrmOrdersCustomer : LYFZ.Software.UI.Customers.FrmOrdersCustomer
  16. {
  17. List<LYFZ.Software.MainBusiness.EnumPermissions.BusinessType> Versions = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetBusinessTypeList();
  18. LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
  19. private delegate void UpdateControl();
  20. public FrmOrdersCustomer()
  21. {
  22. this.ucOld.EventPaging += ucOld_EventPaging;
  23. this.dgvData.CellDoubleClick += dgvData_CellDoubleClick;
  24. this.dgvData.RowsAdded += dgvData_RowsAdded;
  25. this.btnConditionQuery.Click += btnConditionQuery_Click;
  26. foreach (Control chkBtn in flowLayoutPanel1.Controls)
  27. { chkBtn.Click += chkBtn_Click; }
  28. orbll.UpdateNullDataToLunar();
  29. }
  30. Hashtable htData = new Hashtable();
  31. /// <summary>
  32. /// 当前订单类型
  33. /// </summary>
  34. string Ord_Type = "";
  35. void chkBtn_Click(object sender, EventArgs e)
  36. {
  37. this.Ord_Type = "";
  38. CheckBoxEx chkSender = (CheckBoxEx)sender;
  39. if (chkSender.Checked)
  40. { this.Ord_Type = chkSender.Tag.ToString(); }
  41. foreach (Control chkBtn in this.flowLayoutPanel1.Controls)
  42. {
  43. if (!chkBtn.Equals(sender))
  44. {
  45. CheckBoxEx chkObj = (CheckBoxEx)chkBtn;
  46. chkObj.Checked = false;
  47. }
  48. }
  49. this.PublicFunctionRows();
  50. }
  51. /// <summary>
  52. /// 窗体加载事件
  53. /// </summary>
  54. /// <param name="sender"></param>
  55. /// <param name="e"></param>
  56. protected override void FrmOrdersCustomer_Shown(object sender, EventArgs e)
  57. {
  58. try
  59. {
  60. this.chkEt.Visible = false;
  61. this.chkXz.Visible = false;
  62. this.chkHs.Visible = false;
  63. for (int i = 0; i < this.Versions.Count; i++)
  64. {
  65. LYFZ.Software.MainBusiness.EnumPermissions.BusinessType Version = this.Versions[i];
  66. if (Version.ToString() == EnumPermissions.BusinessType.写真版.ToString())
  67. { this.chkXz.Visible = true; }
  68. if (Version.ToString() == EnumPermissions.BusinessType.婚纱版.ToString())
  69. { this.chkHs.Visible = true; }
  70. if (Version.ToString() == EnumPermissions.BusinessType.儿童版.ToString())
  71. { this.chkEt.Visible = true; }
  72. }
  73. this.PublicFunctionRows();
  74. this.btnUpdate.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.OrdersCustomerCompetence, CustomAttributes.OperatingAuthority.Update);
  75. this.btnExport.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.OrdersCustomerCompetence, CustomAttributes.OperatingAuthority.DataExport);
  76. }
  77. catch (Exception ex)
  78. { MessageBoxCustom.Show(ex.Message); }
  79. }
  80. /// <summary>
  81. /// 获取订单客户表
  82. /// </summary>
  83. public void PublicFunctionRows()
  84. {
  85. this.ucOld.PageCurrent = 1;
  86. this.ucOld.PageSize = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetPageSize();//3;分页条数
  87. this.ucOld.Bind();
  88. }
  89. /// <summary>
  90. /// 查询
  91. /// </summary>
  92. /// <param name="sender"></param>
  93. /// <param name="e"></param>
  94. protected override void btnSlect_Click(object sender, EventArgs e)
  95. {
  96. try
  97. { PublicFunctionRows(); }
  98. catch (Exception ex)
  99. { MessageBoxCustom.Show(ex.Message); }
  100. }
  101. /// <summary>
  102. /// 条件查询
  103. /// </summary>
  104. /// <param name="sender"></param>
  105. /// <param name="e"></param>
  106. void btnConditionQuery_Click(object sender, EventArgs e)
  107. {
  108. LYFZ.Software.MainBusiness.Customers.SetSmallForm.ConditionQuerySamllForm frm = new SetSmallForm.ConditionQuerySamllForm();
  109. frm.StrLoadType = this.Ord_Type;
  110. frm.ShowDialog();
  111. if (frm.IsSaveed)
  112. {
  113. htData = frm.htData;
  114. this.PublicFunctionRows();
  115. }
  116. }
  117. /// <summary>
  118. /// 关闭
  119. /// </summary>
  120. /// <param name="sender"></param>
  121. /// <param name="e"></param>
  122. protected override void btnClose_Click(object sender, EventArgs e)
  123. {
  124. this.Close();
  125. }
  126. /// <summary>
  127. /// 导出
  128. /// </summary>
  129. /// <param name="sender"></param>
  130. /// <param name="e"></param>
  131. protected override void btnExport_Click(object sender, EventArgs e)
  132. {
  133. try
  134. { this.dgvData.ExportDataTable(); }
  135. catch (Exception ex)
  136. { MessageBoxCustom.Show(ex.Message); }
  137. }
  138. /// <summary>
  139. /// 查看订单记录数据
  140. /// </summary>
  141. /// <param name="sender"></param>
  142. /// <param name="e"></param>
  143. void dgvData_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  144. {
  145. if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
  146. {
  147. this.btnUpdate_Click(this, null);
  148. }
  149. }
  150. /// <summary>
  151. /// 更新
  152. /// </summary>
  153. /// <param name="sender"></param>
  154. /// <param name="e"></param>
  155. protected override void btnUpdate_Click(object sender, EventArgs e)
  156. {
  157. if (this.dgvData.SelectedRows.Count == 0)
  158. { MessageBoxCustom.Show("请选择你要修改的客户!"); return; }
  159. if (this.dgvData.Rows.Count > 0)
  160. {
  161. if (this.dgvData.CurrentRow != null)
  162. {
  163. if (this.dgvData.CurrentRow.Index >= 0 && this.dgvData.CurrentCell.RowIndex >= 0)
  164. {
  165. if (!LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.OrdersCustomerCompetence, CustomAttributes.OperatingAuthority.Update))
  166. { return; }
  167. if (this.dgvData.Rows[this.dgvData.CurrentRow.Index].Cells["订单类型"].Value.ToString().Trim() == "婚纱订单" ||
  168. this.dgvData.Rows[this.dgvData.CurrentRow.Index].Cells["订单类型"].Value.ToString().Trim() == "写真订单" ||
  169. this.dgvData.Rows[this.dgvData.CurrentRow.Index].Cells["订单类型"].Value.ToString().Trim() == "服务订单" ||
  170. this.dgvData.Rows[this.dgvData.CurrentRow.Index].Cells["订单类型"].Value.ToString().Trim() == "写真订单")
  171. {
  172. FrmOldCustomerRecord from_HS = new FrmOldCustomerRecord();
  173. from_HS.Theorderno = this.dgvData.Rows[this.dgvData.CurrentRow.Index].Cells["Ord_Number"].Value.ToString();
  174. from_HS.Owner = this;
  175. from_HS.ShowDialog();
  176. if (from_HS.IsSaved)
  177. { this.PublicFunctionRows(); }
  178. return;
  179. }
  180. else if (this.dgvData.Rows[this.dgvData.CurrentRow.Index].Cells["订单类型"].Value.ToString() == "儿童订单")
  181. {
  182. FrmOldCustomerRecordBaby from_Et = new FrmOldCustomerRecordBaby();
  183. from_Et.Theorderno = this.dgvData.Rows[this.dgvData.CurrentRow.Index].Cells["Ord_Number"].Value.ToString();
  184. from_Et.Owner = this;
  185. from_Et.ShowDialog();
  186. if (from_Et.IsSaved)
  187. { this.PublicFunctionRows(); }
  188. }
  189. }
  190. }
  191. }
  192. }
  193. /// <summary>
  194. /// 列表添加行时发生事件
  195. /// </summary>
  196. /// <param name="sender"></param>
  197. /// <param name="e"></param>
  198. void dgvData_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
  199. {
  200. /*
  201. if (!string.IsNullOrEmpty(this.dgvData.Rows[e.RowIndex].Cells["客户类型"].Value.ToString().Trim()))
  202. { this.dgvData.Rows[e.RowIndex].Cells["客户类型"].Value = GroupType(this.dgvData.Rows[e.RowIndex].Cells["客户类型"].Value.ToString().Trim()); }
  203. if (!string.IsNullOrEmpty(this.dgvData.Rows[e.RowIndex].Cells["婚期"].Value.ToString().Trim()))
  204. { this.dgvData.Rows[e.RowIndex].Cells["婚期"].Value = LYFZ.Command.Command_Validate.DateTimeToString(this.dgvData.Rows[e.RowIndex].Cells["婚期"].Value, "yyyy-MM-dd"); }
  205. if (!string.IsNullOrEmpty(this.dgvData.Rows[e.RowIndex].Cells["生日"].Value.ToString().Trim()))
  206. { this.dgvData.Rows[e.RowIndex].Cells["生日"].Value = LYFZ.Command.Command_Validate.DateTimeToString(this.dgvData.Rows[e.RowIndex].Cells["生日"].Value, "yyyy-MM-dd"); }
  207. if (!string.IsNullOrEmpty(this.dgvData.Rows[e.RowIndex].Cells["订单时间"].Value.ToString().Trim()))
  208. { this.dgvData.Rows[e.RowIndex].Cells["订单时间"].Value = LYFZ.Command.Command_Validate.DateTimeToString(this.dgvData.Rows[e.RowIndex].Cells["订单时间"].Value, "yyyy-MM-dd HH:mm"); }
  209. */
  210. }
  211. /// <summary>
  212. /// 画分页
  213. /// </summary>
  214. /// <param name="e"></param>
  215. /// <returns></returns>
  216. private int ucOld_EventPaging(UCPager.EventPagingArg e)
  217. {
  218. this.dgvData.Rows.Clear();
  219. DataTable dt = new DataTable();
  220. StringBuilder str = new StringBuilder();
  221. str.Append(" 1=1 and GP_GroupType=0 ");
  222. if (this.Ord_Type.Trim().Length > 0)
  223. { str.Append(" and Ord_Type='" + Ord_Type.Trim() + "' "); }
  224. if (htData.Count > 0)
  225. {
  226. if (htData.ContainsKey("ClientRegion") && htData["ClientRegion"].ToString().Trim().Length > 0)
  227. { str.Append(" and Cus_Region like '%" + htData["ClientRegion"].ToString().Trim() + "%' "); }
  228. if (htData.ContainsKey("AgesStart") && htData["AgesStart"].ToString().Trim().Length > 0 && htData.ContainsKey("AgesEnd") && htData["AgesEnd"].ToString().Trim().Length > 0)
  229. {
  230. if (htData["AgesType"].ToString().Trim() == "Order")
  231. {
  232. if (htData["OrderAges"].ToString().Trim() == "岁")
  233. { str.Append(" and (DATEDIFF(year, GregorianCalendar_Birthday, Ord_CreateDateTime) between '" + htData["AgesStart"].ToString().Trim() + "' And '" + htData["AgesEnd"].ToString().Trim() + "')"); }
  234. else if (htData["OrderAges"].ToString().Trim() == "天")
  235. { str.Append(" and (DATEDIFF(day, GregorianCalendar_Birthday, Ord_CreateDateTime) between '" + htData["AgesStart"].ToString().Trim() + "' And '" + htData["AgesEnd"].ToString().Trim() + "')"); }
  236. }
  237. else if (htData["AgesType"].ToString().Trim() == "Grow")
  238. { str.Append(" and (" + htData["GrowAges"].ToString().Trim() + " between '" + htData["AgesStart"].ToString().Trim() + "' And '" + htData["AgesEnd"].ToString().Trim() + "')"); }
  239. }
  240. else if (htData.ContainsKey("AgesStart") && !htData.ContainsKey("AgesEnd"))
  241. {
  242. if (htData["AgesType"].ToString().Trim() == "Order")
  243. {
  244. if (htData["OrderAges"].ToString().Trim() == "岁")
  245. { str.Append(" and DATEDIFF(year, GregorianCalendar_Birthday, Ord_CreateDateTime) = '" + htData["AgesStart"].ToString().Trim() + "' "); }
  246. else if (htData["OrderAges"].ToString().Trim() == "天")
  247. { str.Append(" and DATEDIFF(day, GregorianCalendar_Birthday, Ord_CreateDateTime) = '" + htData["AgesStart"].ToString().Trim() + "' "); }
  248. }
  249. else if (htData["AgesType"].ToString().Trim() == "Grow")
  250. { str.Append(" and " + htData["GrowAges"].ToString().Trim() + " = '" + htData["AgesStart"].ToString().Trim() + "'"); }
  251. }
  252. else if (!htData.ContainsKey("AgesStart") && htData.ContainsKey("AgesEnd"))
  253. {
  254. if (htData["AgesType"].ToString().Trim() == "Order")
  255. {
  256. if (htData["OrderAges"].ToString().Trim() == "岁")
  257. { str.Append(" and DATEDIFF(year, GregorianCalendar_Birthday, Ord_CreateDateTime) = '" + htData["AgesEnd"].ToString().Trim() + "')"); }
  258. else if (htData["OrderAges"].ToString().Trim() == "天")
  259. { str.Append(" and DATEDIFF(day, GregorianCalendar_Birthday, Ord_CreateDateTime) = '" + htData["AgesEnd"].ToString().Trim() + "')"); }
  260. }
  261. else if (htData["AgesType"].ToString().Trim() == "Grow")
  262. { str.Append(" and " + htData["GrowAges"].ToString().Trim() + " = '" + htData["AgesEnd"].ToString().Trim() + "'"); }
  263. }
  264. }
  265. string keyword = this.txtContent.Text.Trim();
  266. if (!string.IsNullOrEmpty(keyword))
  267. { str.Append("and (Ord_Number like '%" + keyword + "%' or Cus_Name like '%" + keyword + "%' or Cus_Sex_cs like '%" + keyword + "%' or Cus_Telephone like '%" + keyword + "%' or Cus_Region like '%" + keyword + "%' ) "); }
  268. this.htData.Clear();
  269. this.dgvData.DataColumns("Ord_Number,订单号,客户类型,客户名称,客户电话,性别,区域,婚期,生日,岁(订单),天(订单),岁(成长),天(成长),套系类别,套系名称,套系价格,消费总额,订单类型,订单时间,客户组ID", strHideField: "Ord_Number,客户组ID");
  270. LYFZ.UCPager.PageData pageData = new LYFZ.UCPager.PageData();
  271. string StrStatistics = "";
  272. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
  273. {
  274. pageData.TableName = "Vw_OrderCustomerList";
  275. pageData.QueryCondition = str.ToString();
  276. DataTable tbl = orbll.GetView_Custom(pageData.TableName,
  277. StrWhere: pageData.QueryCondition,
  278. ShowColumnName: "Count(ID) AS 总订单量,(sum(Ord_SeriesPrice)/Count(ID)) AS 套系平均值,(sum(OrderLateConsume)/Count(ID)) AS 后期消费平均值,(sum(yingFuPrice)/Count(ID)) AS 总消费平均值").Tables[0];
  279. if (tbl.Rows.Count > 0)
  280. {
  281. StrStatistics = "总订单量:"
  282. + tbl.Rows[0]["总订单量"].ToString().Trim()
  283. + " 套系平均值:"
  284. + tbl.Rows[0]["套系平均值"].ToString().Trim()
  285. + " 后期消费平均值:"
  286. + tbl.Rows[0]["后期消费平均值"].ToString().Trim()
  287. + " 总消费平均值:"
  288. + tbl.Rows[0]["总消费平均值"].ToString().Trim() + "";
  289. }
  290. else
  291. {
  292. StrStatistics = "总订单量:0 套系平均值:0 后期消费平均值:0 总消费平均值:0";
  293. }
  294. pageData.PageIndex = this.ucOld.PageCurrent;
  295. pageData.PageSize = this.ucOld.PageSize;
  296. pageData.QueryFieldName = "Ord_Number"+
  297. ", Ord_SinceOrderNumber"+
  298. ", (case [GP_GroupType] when '0' then '订单客户' when '1' then '老客户' else '意向客户' end) as [GP_GroupType]" +
  299. ", Cus_Name"+
  300. ", Cus_Telephone"+
  301. ", Cus_Sex_cs"+
  302. ", Cus_Region"+
  303. ", convert(char(10),dbo.fn_CheckDateTime(Gregoriancalendar_DayForMarriage),120) as Gregoriancalendar_DayForMarriage" +
  304. ", convert(char(10),dbo.fn_CheckDateTime(GregorianCalendar_Birthday),120) as GregorianCalendar_Birthday" +
  305. ", OrderAgesYear"+
  306. ", OrderAgesDay"+
  307. ", Age_Year"+
  308. ", Age_Day"+
  309. ", Ord_PhotographyCategory"+
  310. ", Ord_SeriesName"+
  311. ", Ord_SeriesPrice"+
  312. ", yingFuPrice"+
  313. ", Ord_Type_CH"+
  314. ", Ord_CreateDateTime"+
  315. ",GM_CustomerGroupID";
  316. pageData.OrderStr = "ID desc";
  317. pageData.OrderType = 1;
  318. DataSet da = pageData.QueryDataTable();
  319. dt = da.Tables[0];
  320. if (dt.Rows.Count > 0)
  321. {
  322. this.Invoke(new UpdateControl(delegate()
  323. {
  324. this.dgvData.DataSource(dt, IsBindColumns: false);
  325. this.dgvData.ClearSelection();
  326. }));
  327. }
  328. });
  329. this.txtStatistics.Text = StrStatistics;
  330. try
  331. { this.ucOld.TbDataSource = dt; }
  332. catch
  333. { }
  334. this.dgvData.Columns["订单时间"].Width = 110;
  335. return pageData.TotalCount;
  336. }
  337. /// <summary>
  338. /// 客户类型 客户组类型 0 为其它客户/订单客户 1 为老客户 2 为意向客户
  339. /// </summary>
  340. /// <param name="Type"></param>
  341. /// <returns></returns>
  342. string GroupType(string Type)
  343. {
  344. string type = "";
  345. switch (Type)
  346. {
  347. case "0":
  348. type = "订单客户";
  349. break;
  350. case "1":
  351. type = "老客户";
  352. break;
  353. case "2":
  354. type = "意向客户";
  355. break;
  356. case null:
  357. break;
  358. }
  359. return type;
  360. }
  361. }
  362. }