AnalyzedOrderDetailSmallForm.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. using LYFZ.Model;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Text.RegularExpressions;
  10. using System.Windows.Forms;
  11. namespace LYFZ.Software.MainBusiness.DecisionAssistant.SetSmallForm
  12. {
  13. public partial class AnalyzedOrderDetailSmallForm : UI.DecisionAssistant.SetSmallForm.AnalyzedOrderDetailSmallForm
  14. {
  15. LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
  16. public AnalyzedOrderDetailSmallForm()
  17. {
  18. InitializeComponent();
  19. this.Load += AnalyzedOrderDetailSmallForm_Load;
  20. }
  21. void AnalyzedOrderDetailSmallForm_Load(object sender, EventArgs e)
  22. {
  23. this.btn_Export.Click += btn_Export_Click;
  24. }
  25. void btn_Export_Click(object sender, EventArgs e)
  26. {
  27. this.gridViewDetail.ExportDataTable();
  28. }
  29. void SetDataTablePaymentNull( DataTable DataTableDb)
  30. {
  31. foreach(DataRow dr in DataTableDb.Rows)
  32. {
  33. if(DataTableDb.Columns.Contains("付款方式"))
  34. {
  35. if (string.IsNullOrEmpty(dr["付款方式"].ToString()))
  36. {
  37. dr["付款方式"] = "";
  38. }
  39. }
  40. }
  41. }
  42. public void BindDataGridView(ModelImagePostionAction modelImagePostionAction)
  43. {
  44. DataTable DataTableDb = orbll.GetView_Custom(modelImagePostionAction.SqlData).Tables[0];
  45. SetDataTablePaymentNull(DataTableDb);
  46. BindDataGridView(modelImagePostionAction, DataTableDb);
  47. }
  48. public void BindDataGridView2(ModelImagePostionAction modelImagePostionAction)
  49. {
  50. DataSet ds=orbll.GetView_Custom(modelImagePostionAction.SqlData);
  51. DataTable DataTableDb = ds.Tables[0];
  52. DataTable DataTableDb1 = ds.Tables[1];
  53. SetDataTablePaymentNull(DataTableDb);
  54. SetDataTablePaymentNull(DataTableDb1);
  55. for (int j = 0; j < DataTableDb.Rows.Count; j++)
  56. {
  57. DataRow dr = DataTableDb.Rows[j];
  58. if (dr["OrdersPerson"].ToString().Trim().Length != dr["OrdersPerson"].ToString().Trim().Replace(",", "").Length)
  59. {
  60. string[] StrArrayPerson = dr["OrdersPerson"].ToString().Trim().Split(',');
  61. if (StrArrayPerson[0].Trim() == modelImagePostionAction.ColumType)
  62. {
  63. dr["订单号"] = dr["订单号"] + "(主门市)";
  64. }
  65. else
  66. {
  67. dr["订单号"] = dr["订单号"] + "(副门市)";
  68. }
  69. }
  70. else
  71. {
  72. dr["订单号"] = dr["订单号"] + "(主门市)";
  73. }
  74. }
  75. for (int j = 0; j < DataTableDb1.Rows.Count; j++)
  76. {
  77. DataRow tempDataRow = DataTableDb1.Rows[j];
  78. DataRow dataRow = DataTableDb.NewRow();
  79. foreach (DataColumn header in DataTableDb1.Columns)
  80. {
  81. if (header.ColumnName == "订单号")
  82. {
  83. dataRow[header.ColumnName] = tempDataRow[header.ColumnName] + "(二销)";
  84. }
  85. else
  86. {
  87. dataRow[header.ColumnName] = tempDataRow[header.ColumnName];
  88. }
  89. }
  90. DataTableDb.Rows.Add(dataRow);
  91. }
  92. DataTableDb.Columns.Remove("OrdersPerson");
  93. BindDataGridView(modelImagePostionAction, DataTableDb);
  94. this.Width = 850;
  95. }
  96. public void BindDataGridView3(ModelImagePostionAction modelImagePostionAction)
  97. {
  98. DataSet ds = orbll.GetView_Custom(modelImagePostionAction.SqlData);
  99. DataTable DataTableDb = ds.Tables[0];
  100. SetDataTablePaymentNull(DataTableDb);
  101. List<string> strWhereList = new List<string>();
  102. string strWhere = "";
  103. foreach(DataRow dr in DataTableDb.Rows)
  104. {
  105. if(!strWhereList.Contains(Convert.ToString(dr["摄影师"].ToString())))
  106. {
  107. strWhereList.Add(dr["摄影师"].ToString());
  108. }
  109. if (!strWhereList.Contains(Convert.ToString(dr["摄影助理"].ToString())))
  110. {
  111. strWhereList.Add(dr["摄影助理"].ToString());
  112. }
  113. if (!strWhereList.Contains(Convert.ToString(dr["化妆师"].ToString())))
  114. {
  115. strWhereList.Add(dr["化妆师"].ToString());
  116. }
  117. if (!strWhereList.Contains(Convert.ToString(dr["化妆助理"].ToString())))
  118. {
  119. strWhereList.Add(dr["化妆助理"].ToString());
  120. }
  121. if (!strWhereList.Contains(Convert.ToString(dr["引导师"])))
  122. {
  123. strWhereList.Add(dr["引导师"].ToString());
  124. }
  125. if (!strWhereList.Contains(Convert.ToString(dr["引导助理"])))
  126. {
  127. strWhereList.Add(dr["引导助理"].ToString());
  128. }
  129. }
  130. LYFZ.BLL.BLL_ErpUser userBll = new BLL.BLL_ErpUser();
  131. DataTable userTb = userBll.GetList(" User_EmployeeID in ('" + string.Join("','", strWhereList.ToArray()) + "') ").Tables[0];
  132. foreach(DataRow dr in DataTableDb.Rows)
  133. {
  134. if(!string.IsNullOrEmpty(Convert.ToString(dr["摄影师"])))
  135. {
  136. DataRow[] tempUserRow = userTb.Select( " User_EmployeeID ='"+dr["摄影师"].ToString()+"' ");
  137. if(tempUserRow.Length>0)
  138. {
  139. dr["摄影师"] = tempUserRow[0]["User_Name"].ToString();
  140. }
  141. }
  142. if (!string.IsNullOrEmpty(Convert.ToString(dr["摄影助理"]).ToString()))
  143. {
  144. DataRow[] tempUserRow = userTb.Select(" User_EmployeeID ='" + dr["摄影助理"].ToString() + "' ");
  145. if (tempUserRow.Length > 0)
  146. {
  147. dr["摄影助理"] = tempUserRow[0]["User_Name"].ToString();
  148. }
  149. }
  150. if (!string.IsNullOrEmpty(Convert.ToString(dr["化妆师"]).ToString()))
  151. {
  152. DataRow[] tempUserRow = userTb.Select(" User_EmployeeID ='" + dr["化妆师"].ToString() + "' ");
  153. if (tempUserRow.Length > 0)
  154. {
  155. dr["化妆师"] = tempUserRow[0]["User_Name"].ToString();
  156. }
  157. }
  158. if (!string.IsNullOrEmpty(Convert.ToString(dr["化妆助理"]).ToString()))
  159. {
  160. DataRow[] tempUserRow = userTb.Select(" User_EmployeeID ='" + dr["化妆助理"].ToString() + "' ");
  161. if (tempUserRow.Length > 0)
  162. {
  163. dr["化妆助理"] = tempUserRow[0]["User_Name"].ToString();
  164. }
  165. }
  166. if (!string.IsNullOrEmpty(Convert.ToString(dr["引导师"]).ToString()))
  167. {
  168. DataRow[] tempUserRow = userTb.Select(" User_EmployeeID ='" + dr["引导师"].ToString() + "' ");
  169. if (tempUserRow.Length > 0)
  170. {
  171. dr["引导师"] = tempUserRow[0]["User_Name"].ToString();
  172. }
  173. }
  174. if (!string.IsNullOrEmpty(Convert.ToString(dr["引导助理"]).ToString()))
  175. {
  176. DataRow[] tempUserRow = userTb.Select(" User_EmployeeID ='" + dr["引导助理"].ToString() + "' ");
  177. if (tempUserRow.Length > 0)
  178. {
  179. dr["引导助理"] = tempUserRow[0]["User_Name"].ToString();
  180. }
  181. }
  182. if (!string.IsNullOrEmpty(Convert.ToString(dr["重拍责任人"]).ToString()))
  183. {
  184. DataRow[] tempUserRow = userTb.Select(" User_EmployeeID in ('" + dr["重拍责任人"].ToString() + "') ");
  185. string userName = "";
  186. foreach (DataRow tempUser in tempUserRow)
  187. {
  188. if(!string.IsNullOrEmpty(userName))
  189. {
  190. userName += ",";
  191. }
  192. userName += tempUser["User_Name"].ToString();
  193. }
  194. if (tempUserRow.Length > 0)
  195. {
  196. dr["重拍责任人"] = userName;
  197. }
  198. }
  199. }
  200. BindDataGridView(modelImagePostionAction, DataTableDb);
  201. }
  202. void BindDataGridView(ModelImagePostionAction modelImagePostionAction, DataTable DataTableDb)
  203. {
  204. Dictionary<string, decimal> dicList = new Dictionary<string, decimal>();
  205. if (string.IsNullOrEmpty(modelImagePostionAction.OrdType))
  206. {
  207. this.Text = modelImagePostionAction.OrdTitle;
  208. }
  209. else
  210. {
  211. this.Text = modelImagePostionAction.OrdTitle + " (" + modelImagePostionAction.OrdType + ")";
  212. }
  213. foreach (DataColumn columText in DataTableDb.Columns)
  214. {
  215. this.gridViewDetail.Columns.Add(columText.ColumnName, columText.ColumnName);
  216. if(columText.ColumnName=="订单号")
  217. {
  218. this.gridViewDetail.Columns[0].Width = 160;
  219. }
  220. }
  221. string ordNumber = "";
  222. bool bNowData = false;
  223. List<decimal> payTotalValue = new List<decimal>();
  224. foreach (DataRow dr in DataTableDb.Rows)
  225. {
  226. if (modelImagePostionAction.OrdTitle.Equals("营收分析"))
  227. {
  228. if (ordNumber != dr["订单号"].ToString_s())
  229. {
  230. bNowData = false;
  231. ordNumber = dr["订单号"].ToString_s();
  232. payTotalValue = new List<decimal>();
  233. payTotalValue.Add(Convert.ToDecimal(dr["实收"]));
  234. }
  235. else
  236. {
  237. bNowData = true;
  238. payTotalValue.Add(Convert.ToDecimal(dr["实收"]));
  239. }
  240. }
  241. int rowIndex = this.gridViewDetail.Rows.Add();
  242. if (modelImagePostionAction.OrdTitle.Equals("营收分析") )
  243. {
  244. this.gridViewDetail.Rows[rowIndex].Cells["余款"].Value = Convert.ToDecimal(dr["业绩"]) - Convert.ToDecimal(dr["实收"]);
  245. }
  246. foreach (DataColumn columText in DataTableDb.Columns)
  247. {
  248. if (modelImagePostionAction.OrdTitle.Equals("营收分析") && columText.ColumnName.Equals("余款")&& !bNowData)
  249. {
  250. continue;
  251. }
  252. this.gridViewDetail.Rows[rowIndex].Cells[columText.ColumnName].Value = dr[columText.ColumnName];
  253. if (modelImagePostionAction.OrdTitle.Equals("营收分析") )
  254. {
  255. if (bNowData)
  256. {
  257. if (!columText.ColumnName.Equals("付款方式") && !columText.ColumnName.Equals("实收") )
  258. {
  259. this.gridViewDetail.Rows[rowIndex].Cells[columText.ColumnName].Value = "";
  260. }
  261. decimal totalValue = payTotalValue.Sum();
  262. //for (int i = 0; i < payTotalValue.Count; i++)
  263. //{
  264. this.gridViewDetail.Rows[rowIndex - (payTotalValue.Count-1)].Cells["余款"].Value = Convert.ToDecimal(dr["业绩"]) - totalValue;
  265. //}
  266. }
  267. }
  268. /*if (dr[columText.ColumnName] != null)
  269. {
  270. if (IsNumeric(dr[columText.ColumnName].ToString()))
  271. {
  272. if (!dicList.ContainsKey(columText.ColumnName))
  273. {
  274. if (string.IsNullOrEmpty(dr[columText.ColumnName].ToString()))
  275. {
  276. dr[columText.ColumnName] = "0";
  277. }
  278. dicList.Add(columText.ColumnName, Convert.ToDecimal(dr[columText.ColumnName].ToString()));
  279. }
  280. else
  281. {
  282. if (string.IsNullOrEmpty(dr[columText.ColumnName].ToString()))
  283. {
  284. dr[columText.ColumnName] = "0";
  285. }
  286. dicList[columText.ColumnName] += Convert.ToDecimal(dr[columText.ColumnName].ToString());
  287. }
  288. }
  289. }*/
  290. }
  291. }
  292. Dictionary<string, decimal> pluAmountList = new Dictionary<string, decimal>();
  293. foreach(DataGridViewRow row in gridViewDetail.Rows)
  294. {
  295. foreach(DataGridViewColumn colum in gridViewDetail.Columns)
  296. {
  297. if (IsNumeric(row.Cells[colum.Name].Value.ToString()))
  298. {
  299. if (!dicList.ContainsKey(colum.Name))
  300. {
  301. if (!string.IsNullOrEmpty(row.Cells[colum.Name].Value.ToString()))
  302. {
  303. dicList.Add(colum.Name, Convert.ToDecimal(row.Cells[colum.Name].Value.ToString()));
  304. //row.Cells[colum.Name].Value = "0";
  305. }
  306. }
  307. else
  308. {
  309. if (!string.IsNullOrEmpty(row.Cells[colum.Name].Value.ToString()))
  310. {
  311. decimal tempValue = 0;
  312. if (decimal.TryParse(row.Cells[colum.Name].Value.ToString(), out tempValue))
  313. {
  314. dicList[colum.Name] += Convert.ToDecimal(row.Cells[colum.Name].Value.ToString());
  315. //row.Cells[colum.Name].Value = "0";
  316. }
  317. }
  318. }
  319. if(colum.Name=="加挑金额")
  320. {
  321. if (gridViewDetail.Columns.Contains("订单号"))
  322. {
  323. if(!pluAmountList.ContainsKey(row.Cells["订单号"].Value.ToString_s()))
  324. {
  325. pluAmountList.Add(row.Cells["订单号"].Value.ToString_s(), Convert.ToDecimal(row.Cells["加挑金额"].Value.ToString_s()));
  326. }
  327. }
  328. }
  329. }
  330. }
  331. }
  332. if(dicList.ContainsKey("加挑金额"))
  333. {
  334. dicList["加挑金额"] = pluAmountList.Values.Sum();
  335. }
  336. string msg = "";
  337. foreach (string key in dicList.Keys)
  338. {
  339. if (!string.IsNullOrEmpty(msg))
  340. {
  341. msg += " ";
  342. }
  343. msg += key + ":" + dicList[key];
  344. }
  345. labelMsg.Text = msg;
  346. }
  347. public bool IsNumeric(string value)
  348. {
  349. return Regex.IsMatch(value, @"^[+-]?\d*[.]?\d*$");
  350. }
  351. }
  352. }