ReportModelService.cs 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Models;
  6. using System.Data.SqlClient;
  7. using System.Data;
  8. using System.IO;
  9. using System.Text.RegularExpressions;
  10. namespace DAL
  11. {
  12. public class ReportModelService
  13. {
  14. /// <summary>
  15. /// 查询所有
  16. /// </summary>
  17. /// <param name="sql">sql语句</param>
  18. /// <param name="param">可变参数数组</param>
  19. /// <returns>返回集合</returns>
  20. List<ReportModel> excuteReportModelSql(string sql, params SqlParameter[] param)
  21. {
  22. return ServiceBase<ReportModel>.excuteSql(new ReportModel(), "reportModel", sql, CommandType.Text, param);
  23. }
  24. /// <summary>
  25. /// LiuChengYi 2014/4/25
  26. /// 用于报表模型的绑定
  27. /// </summary>
  28. /// <returns></returns>
  29. public List<ReportModel> ReportGetAll()
  30. {
  31. return excuteReportModelSql(@"SELECT count([VisitCountry]) as num,
  32. [VisitCountry] as Category,
  33. '出访国家数据统计图' as sequence
  34. from DelegationInfo
  35. where [VisitCountry] is not null
  36. group by [VisitCountry]");
  37. }
  38. /// <summary>
  39. /// LiuChengYi 2014/4/25
  40. /// 用于团组和非团组利润的统计
  41. /// </summary>
  42. /// <returns></returns>
  43. public DataTable ReportProfitStatistics(string startTime, string endTime)
  44. {
  45. double tzIncome = 0.00;
  46. double tzOutlay = 0.00;
  47. double ftzIncome = 0.00;
  48. double ftzOutlay = 0.00;
  49. //收入
  50. DataTable IncomeDt = IncomeMoney(startTime, endTime);
  51. for (int i = 0; i < IncomeDt.Rows.Count; i++)
  52. {
  53. if (IncomeDt.Rows[i]["Category"].ToString().Equals("团组"))
  54. {
  55. tzIncome += Convert.ToDouble(IncomeDt.Rows[i]["num"]);
  56. }
  57. else
  58. {
  59. ftzIncome += Convert.ToDouble(IncomeDt.Rows[i]["num"]);
  60. }
  61. }
  62. //支出
  63. DataTable OutlayDt = OutlayMoney(startTime, endTime);
  64. for (int j = 0; j < OutlayDt.Rows.Count; j++)
  65. {
  66. if (OutlayDt.Rows[j]["Category"].ToString().Equals("团组"))
  67. {
  68. tzOutlay += Convert.ToDouble(OutlayDt.Rows[j]["num"]);
  69. }
  70. else
  71. {
  72. ftzOutlay += Convert.ToDouble(OutlayDt.Rows[j]["num"]);
  73. }
  74. }
  75. //团组总利润
  76. tzIncome = tzIncome - tzOutlay;
  77. //非团组总利润
  78. ftzIncome = ftzIncome - ftzOutlay;
  79. DataTable dt = IncomeDt.Copy();
  80. dt.Clear();
  81. DataRow dr = dt.NewRow();
  82. dt.Rows.Add(dr);
  83. dt.Rows[0]["num"] = Convert.ToDouble(tzIncome.ToString("F2"));
  84. dt.Rows[0]["CateGory"] = "团组";
  85. DataRow dr1 = dt.NewRow();
  86. dt.Rows.Add(dr1);
  87. dt.Rows[1]["num"] =Convert.ToDouble(ftzIncome.ToString("F2"));
  88. dt.Rows[1]["CateGory"] = "非团组";
  89. return dt;
  90. }
  91. /// <summary>
  92. /// LiuChengYi 2014/4/29
  93. /// 构造月份的数据字典
  94. /// 用于日常报表统计
  95. /// </summary>
  96. /// <returns></returns>
  97. public Dictionary<string, string> GetListMonth()
  98. {
  99. Dictionary<string, string> ListMonth = new Dictionary<string, string>();
  100. ListMonth.Add("1", "0");
  101. ListMonth.Add("2", "0");
  102. ListMonth.Add("3", "0");
  103. ListMonth.Add("4", "0");
  104. ListMonth.Add("5", "0");
  105. ListMonth.Add("6", "0");
  106. ListMonth.Add("7", "0");
  107. ListMonth.Add("8", "0");
  108. ListMonth.Add("9", "0");
  109. ListMonth.Add("10", "0");
  110. ListMonth.Add("11", "0");
  111. ListMonth.Add("12", "0");
  112. return ListMonth;
  113. }
  114. /// <summary>
  115. /// LiuChengYi 2014/4/29
  116. /// 日常支付统计
  117. /// </summary>
  118. /// <returns></returns>
  119. public DataTable GetDailyDay(string companyId)
  120. {
  121. int year = Convert.ToInt32(DateTime.Now.ToString("yyyy"));
  122. SqlParameter[] pars =
  123. {
  124. new SqlParameter("@companyId",companyId),
  125. new SqlParameter("@year",year)
  126. };
  127. DataTable dt = SqlHelper.TransferProcedure("DailyDay_Report", CommandType.StoredProcedure,pars);
  128. Dictionary<string, string> ListMonth = GetListMonth();
  129. for (int i = 0; i <dt.Rows.Count; i++)
  130. {
  131. ListMonth[dt.Rows[i]["Category"].ToString()] = dt.Rows[i]["Num"].ToString();
  132. }
  133. DataTable table = new DataTable();
  134. table = dt.Copy();
  135. table.Clear();
  136. foreach (KeyValuePair<string, string> category in ListMonth)
  137. {
  138. table.Rows.Add(category.Value,category.Key ,"日常支付报表");
  139. }
  140. return table;
  141. }
  142. /// <summary>
  143. /// 统计总利润 LiuChengYi 2014/07/29
  144. /// </summary>
  145. public DataTable GetCompanyProfitStatisticsReport(string companyId,string year)
  146. {
  147. //公司利润=团组收入-(团组支出-日常支出)
  148. #region 四川公司团组和非团组的每月利润
  149. SqlParameter[] pars =
  150. {
  151. new SqlParameter("companyId",companyId)
  152. };
  153. //团组和非团组收入
  154. DataTable dt = IncomeMoneyByMonth(year);
  155. //构造每月收入集合
  156. Dictionary<string, string> ListMonth = GetListMonth();
  157. for (int i = 0; i < dt.Rows.Count; i++)
  158. {
  159. ListMonth[dt.Rows[i]["Category"].ToString()] = dt.Rows[i]["Num"].ToString();
  160. }
  161. DataTable table = new DataTable();
  162. table = dt.Copy();
  163. table.Clear();
  164. foreach (KeyValuePair<string, string> category in ListMonth)
  165. {
  166. table.Rows.Add(category.Value, category.Key, "企业利润报表");
  167. }
  168. #endregion
  169. #region 每月支出 ,日常支出除外
  170. //团组和非团组支出
  171. DataTable OutlayDt = OutlayMoneyByMonth(year);
  172. //构造每月支出集合
  173. Dictionary<string, string> outlay = GetListMonth();
  174. for (int j = 0; j < OutlayDt.Rows.Count; j++)
  175. {
  176. outlay[OutlayDt.Rows[j]["Category"].ToString()] = OutlayDt.Rows[j]["Num"].ToString();
  177. }
  178. OutlayDt.Clear();
  179. foreach (KeyValuePair<string, string> category in outlay)
  180. {
  181. OutlayDt.Rows.Add(category.Value, category.Key, "企业利润报表");
  182. }
  183. #endregion
  184. #region 四川公司日常支付
  185. DataTable DailyDayTable = GetDailyDay("114");
  186. #endregion
  187. for (int i = 0; i < DailyDayTable.Rows.Count; i++)
  188. {
  189. //double d1 = Convert.ToDouble(table.Rows[i]["Num"]);
  190. //double d2 = Convert.ToDouble(DailyDayTable.Rows[i]["Num"]);
  191. //double d3 = d1 - d2;
  192. table.Rows[i]["Num"] = (Convert.ToDouble(table.Rows[i]["Num"]) - Convert.ToDouble(DailyDayTable.Rows[i]["Num"])-Convert.ToDouble(OutlayDt.Rows[i]["Num"])).ToString();
  193. }
  194. return table;
  195. }
  196. /// <summary>
  197. /// LiuChengYi 2014/5/5
  198. /// 构造天数的集合
  199. /// </summary>
  200. /// <param name="Months"></param>
  201. /// <returns></returns>
  202. public Dictionary<string, string> GetListDay(string startDate, string endDate)
  203. {
  204. List<Calendars> ListMonths = new CalendarsService().GetCalendarMonths(startDate,endDate);
  205. Dictionary<string, string> dictMonth = new Dictionary<string, string>();
  206. for (int i = 0; i < ListMonths.Count; i++)
  207. {
  208. dictMonth.Add(Convert.ToDateTime(ListMonths[i].CalendarDate).ToString("yyyy-MM-dd"),"");
  209. }
  210. return dictMonth;
  211. }
  212. /// <summary>
  213. /// LiuChengYi
  214. /// 员工考勤报表
  215. /// </summary>
  216. /// <param name="employeeId"></param>
  217. /// <param name="months"></param>
  218. /// <returns></returns>
  219. public DataTable EmployeeAttendance(int employeeId, string startDate, string endDate)
  220. {
  221. DataTable table = new DataTable();
  222. //根据员工Id和考勤月份获取员工考勤
  223. SqlParameter[] pars =
  224. {
  225. new SqlParameter("@startDate",startDate),
  226. new SqlParameter("@endDate",endDate),
  227. new SqlParameter("@EmployeeId",employeeId)
  228. };
  229. DataTable dt = SqlHelper.TransferProcedure("EmployeeAttendance_Report", CommandType.StoredProcedure, pars);
  230. //填充已构造好的日期结合
  231. Dictionary<string, string> dictDay = GetListDay(startDate,endDate);
  232. if (dt.Rows.Count>0)
  233. {
  234. for (int i = 0; i < dt.Rows.Count; i++)
  235. {
  236. string c = dt.Rows[i]["Num"].ToString().Replace(":", ".");
  237. string b = Convert.ToDouble(c).ToString();
  238. dictDay[dt.Rows[i]["Category"].ToString()] = b;
  239. }
  240. //构造报表的数据集
  241. table = dt.Copy();
  242. table.Clear();
  243. foreach (KeyValuePair<string, string> category in dictDay)
  244. {
  245. if (category.Value == "")
  246. {
  247. table.Rows.Add("0.00", category.Key, "打卡时间");
  248. }
  249. else
  250. {
  251. table.Rows.Add(category.Value, category.Key, "打卡时间");
  252. }
  253. }
  254. }
  255. return table;
  256. }
  257. /// <summary>
  258. /// LiuChengYi
  259. /// </summary>
  260. /// <param name="startDate"></param>
  261. /// <param name="endDate"></param>
  262. /// <param name="employeeId"></param>
  263. /// <returns></returns>
  264. public DataTable EmployeesRated(string startDate, string endDate, int employeeId)
  265. {
  266. DataTable table = new DataTable();
  267. //根据员工Id和考勤月份获取员工考勤
  268. SqlParameter[] pars =
  269. {
  270. new SqlParameter("@startTime",startDate),
  271. new SqlParameter("@endTime",endDate),
  272. new SqlParameter("@EmployeeId",employeeId)
  273. };
  274. DataTable dt = SqlHelper.TransferProcedure("EmployeesRated_Report", CommandType.StoredProcedure, pars);
  275. //填充已构造好的日期结合
  276. Dictionary<string, string> dictDay = GetListDay(startDate, endDate);
  277. //构造报表的数据集
  278. if (dt.Rows.Count > 0)
  279. {
  280. table = dt.Copy();
  281. table.Clear();
  282. for (int i = 0; i < dt.Rows.Count; i++)
  283. {
  284. dictDay[dt.Rows[i]["Category"].ToString()] = dt.Rows[i]["Num"].ToString();
  285. foreach (KeyValuePair<string, string> category in dictDay)
  286. {
  287. string Time = Convert.ToDateTime(category.Key).ToString("yyyy-MM-dd");
  288. if (category.Value == "")
  289. {
  290. table.Rows.Add("0", Time, dt.Rows[i]["Sequence"].ToString());
  291. }
  292. else
  293. {
  294. table.Rows.Add(category.Value, Time, dt.Rows[i]["Sequence"].ToString());
  295. }
  296. }
  297. }
  298. }
  299. return table;
  300. }
  301. /// <summary>
  302. /// 团组与非团组的收入合计 LiuChengYi 2014/07/29
  303. /// </summary>
  304. /// <param name="startTime"></param>
  305. /// <param name="endTime"></param>
  306. /// <returns></returns>
  307. public DataTable IncomeMoney(string startTime, string endTime)
  308. {
  309. SqlParameter[] pars =
  310. {
  311. new SqlParameter("@startTime",startTime),
  312. new SqlParameter("@endTime",endTime)
  313. };
  314. return SqlHelper.TransferProcedure("IncomeMoney", CommandType.StoredProcedure, pars);
  315. }
  316. /// <summary>
  317. /// 团组与非团组的支出合计 LiuChengYi 2014/07/29
  318. /// </summary>
  319. /// <param name="startTime"></param>
  320. /// <param name="endTime"></param>
  321. /// <returns></returns>
  322. public DataTable OutlayMoney(string startTime, string endTime)
  323. {
  324. SqlParameter[] pars =
  325. {
  326. new SqlParameter("@startTime",startTime),
  327. new SqlParameter("@endTime",endTime)
  328. };
  329. return SqlHelper.TransferProcedure("OutlayMoney", CommandType.StoredProcedure, pars);
  330. }
  331. /// <summary>
  332. /// LiuChengYi 2014/07/29
  333. /// 获取每月的企业利润(团组利润和非团组利润)
  334. /// </summary>
  335. /// <returns></returns>
  336. public DataTable IncomeMoneyByMonth(string year)
  337. {
  338. SqlParameter[] pars =
  339. {
  340. new SqlParameter("@year",year)
  341. };
  342. return SqlHelper.TransferProcedure("IncomeMoneyByMonth", CommandType.StoredProcedure, pars);
  343. }
  344. /// <summary>
  345. /// LiuChengYi 2014/07/29
  346. /// 获取每月支出(团组利润和非团组利润,日常支付除外)
  347. /// </summary>
  348. /// <returns></returns>
  349. public DataTable OutlayMoneyByMonth(string year)
  350. {
  351. SqlParameter[] pars =
  352. {
  353. new SqlParameter("@year",year)
  354. };
  355. return SqlHelper.TransferProcedure("OutlayMoneyByMonth", CommandType.StoredProcedure, pars);
  356. }
  357. /// <summary>
  358. /// LiuChengYi 2014/07/30
  359. /// 团组利润月份对比统计图
  360. /// </summary>
  361. /// <returns></returns>
  362. public DataTable MissionsProfitByMOnth(string year)
  363. {
  364. //公司利润=团组收入-(团组支出-日常支出)
  365. #region 四川公司团组和非团组的每月利润
  366. //团组和非团组收入
  367. DataTable Profitdt = IncomeMoneyByMonth(year);
  368. //构造每月收入集合
  369. Dictionary<string, string> zhenFuMonth = GetListMonth();
  370. Dictionary<string, string> FZFMonth = GetListMonth();
  371. for (int i = 0; i < Profitdt.Rows.Count; i++)
  372. {
  373. if (!Profitdt.Rows[i]["name"].ToString().Equals("非团组"))
  374. {
  375. zhenFuMonth[Profitdt.Rows[i]["Category"].ToString()] = Profitdt.Rows[i]["Num"].ToString();
  376. }
  377. else
  378. {
  379. FZFMonth[Profitdt.Rows[i]["Category"].ToString()] = Profitdt.Rows[i]["Num"].ToString();
  380. }
  381. }
  382. #endregion
  383. #region 每月支出 ,日常支出除外
  384. //团组和非团组支出
  385. DataTable OutlayDt = OutlayMoneyByMonth(year);
  386. //构造每月支出集合
  387. Dictionary<string, string> ZFoutlay = GetListMonth();
  388. Dictionary<string, string> FZFoutlay = GetListMonth();
  389. for (int j = 0; j < OutlayDt.Rows.Count; j++)
  390. {
  391. if (!Profitdt.Rows[j]["name"].ToString().Equals("非团组"))
  392. {
  393. ZFoutlay[OutlayDt.Rows[j]["Category"].ToString()] = OutlayDt.Rows[j]["Num"].ToString();
  394. }
  395. else
  396. {
  397. FZFoutlay[OutlayDt.Rows[j]["Category"].ToString()] = OutlayDt.Rows[j]["Num"].ToString();
  398. }
  399. }
  400. DataTable table = new DataTable();
  401. table = Profitdt.Copy();
  402. table.Clear();
  403. foreach (KeyValuePair<string, string> category in zhenFuMonth)
  404. {
  405. foreach (KeyValuePair<string, string> zfoutlayDic in ZFoutlay)
  406. {
  407. if (category.Key.ToString().Equals(zfoutlayDic.Key.ToString()))
  408. {
  409. table.Rows.Add((Convert.ToDouble(category.Value.ToString()) - Convert.ToDouble(zfoutlayDic.Value.ToString())).ToString("F2"), category.Key, "企业利润报表", "团组");
  410. }
  411. }
  412. }
  413. foreach (KeyValuePair<string, string> category in FZFMonth)
  414. {
  415. foreach (KeyValuePair<string, string> FzfoutlayDic in FZFoutlay)
  416. {
  417. if (category.Key.ToString().Equals(FzfoutlayDic.Key.ToString()))
  418. {
  419. table.Rows.Add((Convert.ToDouble(category.Value.ToString()) - Convert.ToDouble(FzfoutlayDic.Value.ToString())).ToString("F2"), category.Key, "企业利润报表", "非团组");
  420. }
  421. }
  422. }
  423. OutlayDt.Clear();
  424. #endregion
  425. return table;
  426. }
  427. /// <summary>
  428. /// 团组利润年对比图
  429. /// </summary>
  430. /// <param name="year"></param>
  431. /// <returns></returns>
  432. public DataTable MissionsProfitByYear(string year)
  433. {
  434. SqlParameter[] pars =
  435. {
  436. new SqlParameter("@year",year)
  437. };
  438. DataTable dtIncome = SqlHelper.TransferProcedure("IncomeMoneyByYear", CommandType.StoredProcedure, pars);
  439. SqlParameter[] pras =
  440. {
  441. new SqlParameter("@year",year)
  442. };
  443. DataTable dtOutlay = SqlHelper.TransferProcedure("OutlayMoneyByYear", CommandType.StoredProcedure, pras);
  444. //测试所用
  445. //DataRow dr = dtIncome.NewRow();
  446. //dr["num"] = "1500000";
  447. //dr["Category"] = "2013";
  448. //dr["name"] = "非团组";
  449. //dtIncome.Rows.Add(dr);
  450. DataTable dt = new DataTable();
  451. dt = dtIncome.Copy();
  452. dt.Clear();
  453. for (int i = 2; i >=0; i--)
  454. {
  455. DataRow dr1 = dt.NewRow();
  456. dr1["num"] = "0";
  457. dr1["Category"] =( Convert.ToInt32(year)-i).ToString();
  458. dr1["name"] = "团组";
  459. dt.Rows.Add(dr1);
  460. DataRow dr2 = dt.NewRow();
  461. dr2["num"] = "0";
  462. dr2["Category"] =( Convert.ToInt32(year)-i).ToString();
  463. dr2["name"] = "非团组";
  464. dt.Rows.Add(dr2);
  465. }
  466. try
  467. {
  468. for (int i = 0; i < dtIncome.Rows.Count; i++)
  469. {
  470. if(!dtIncome.Rows[i]["name"].Equals("非团组"))
  471. dtIncome.Rows[i]["name"] = "团组";
  472. for (int j = 0; j < dtOutlay.Rows.Count; j++)
  473. {
  474. if (!dtOutlay.Rows[j]["name"].Equals("非团组"))
  475. dtOutlay.Rows[j]["name"] = "团组";
  476. if (dtIncome.Rows[i]["name"].ToString().Equals(dtOutlay.Rows[j]["name"].ToString()))
  477. {
  478. if (dtIncome.Rows[i]["Category"].ToString().Equals(dtOutlay.Rows[j]["Category"].ToString()))
  479. {
  480. for (int h = 0; h < dt.Rows.Count; h++)
  481. {
  482. if (dtIncome.Rows[i]["name"].ToString().Equals(dt.Rows[h]["name"].ToString()) && dtIncome.Rows[i]["Category"].ToString().Equals(dt.Rows[h]["Category"].ToString()))
  483. {
  484. dt.Rows[h]["num"] = ((Convert.ToDouble(dtIncome.Rows[i]["num"].ToString()) - (Convert.ToDouble(dtOutlay.Rows[j]["num"].ToString()))).ToString());
  485. }
  486. }
  487. }
  488. else
  489. {
  490. for (int h = 0; h < dt.Rows.Count; h++)
  491. {
  492. if (dtIncome.Rows[i]["name"].ToString().Equals(dt.Rows[h]["name"].ToString()) && dtIncome.Rows[i]["Category"].ToString().Equals(dt.Rows[h]["Category"].ToString()))
  493. {
  494. dt.Rows[h]["num"] = (Convert.ToDouble(dtIncome.Rows[i]["num"].ToString()));
  495. }
  496. }
  497. }
  498. }
  499. }
  500. }
  501. }
  502. catch (Exception ex)
  503. {
  504. throw;
  505. }
  506. return dt;
  507. }
  508. /// <summary>
  509. /// 团组总利润
  510. /// </summary>
  511. /// <param name="year"></param>
  512. /// <returns></returns>
  513. public DataTable Total_MissionsProfitByYear(string year)
  514. {
  515. DataTable dt = MissionsProfitByYear(year);
  516. //重新构造DataTable
  517. DataTable dtTotal = new DataTable();
  518. DataColumn dc =null;
  519. dc = dtTotal.Columns.Add("Category", Type.GetType("System.String"));
  520. dc = dtTotal.Columns.Add("num", Type.GetType("System.String"));
  521. DataRow dr = dtTotal.NewRow();
  522. dr["Category"] = (Convert.ToInt32(year) - 2).ToString();
  523. dr["num"] = "";
  524. DataRow dr1 = dtTotal.NewRow();
  525. dr1["Category"] = (Convert.ToInt32(year) - 1).ToString(); ;
  526. dr1["num"] = "";
  527. DataRow dr2 = dtTotal.NewRow();
  528. dr2["Category"] = year;
  529. dr2["num"] = "";
  530. dtTotal.Rows.Add(dr);
  531. dtTotal.Rows.Add(dr1);
  532. dtTotal.Rows.Add(dr2);
  533. Double total=0.00;
  534. //循环填充数据
  535. for (int i = 0; i < dtTotal.Rows.Count; i++)
  536. {
  537. total = 0.00;
  538. for (int j = 0; j < dt.Rows.Count; j++)
  539. {
  540. if(dt.Rows[j]["Category"].ToString().Equals(dtTotal.Rows[i]["Category"].ToString()))
  541. {
  542. total +=Convert.ToDouble(dt.Rows[j]["num"].ToString());
  543. }
  544. }
  545. dtTotal.Rows[i]["num"] = total.ToString();
  546. }
  547. return dtTotal;
  548. }
  549. /// <summary>
  550. /// LiuChengYi 2014/7/31
  551. /// 出访国家统计
  552. /// </summary>
  553. /// <returns></returns>
  554. public DataTable DelegationByCount(string year)
  555. {
  556. DelegationInfoService difs = new DelegationInfoService();
  557. DataTable dt =difs.ReportDelegationInfo(year);
  558. return HotelbyDelegionsbySort(dt);
  559. }
  560. /// <summary>
  561. /// LiuChengYi 2014/7/31
  562. /// 用于预定酒店统计
  563. /// </summary>
  564. /// <returns></returns>
  565. public DataTable HotelReservationsListByCount(string year)
  566. {
  567. DelegationInfoService difs = new DelegationInfoService();
  568. HotelReservationsService hrs = new HotelReservationsService();
  569. DataTable dt = hrs.ReportHotelReservationsInfo(year);
  570. return HotelbyDelegionsbySort(dt);
  571. }
  572. /// <summary>
  573. /// 排序
  574. /// </summary>
  575. /// <param name="dt"></param>
  576. /// <param name="type"></param>
  577. /// <param name="year"></param>
  578. /// <returns></returns>
  579. public DataTable HotelbyDelegionsbySort(DataTable dt )
  580. {
  581. DataView dv = dt.DefaultView;
  582. dv.Sort = "num desc";
  583. dt = dv.ToTable();
  584. return dt;
  585. }
  586. public string XmlReport(DataTable dt,string type,int year)
  587. {
  588. string xmlStr = "";
  589. #region 初始化月份数据
  590. //for (int i = 0; i < dt.Rows.Count; i++)
  591. //{
  592. // if(dt.Rows[i][1].ToString().Equals("1"))
  593. // {
  594. // dt.Rows[i][1] = "一月";
  595. // }
  596. // if (dt.Rows[i][1].ToString().Equals("2"))
  597. // {
  598. // dt.Rows[i][1] = "二月";
  599. // }
  600. // if (dt.Rows[i][1].ToString().Equals("3"))
  601. // {
  602. // dt.Rows[i][1] = "三月";
  603. // }
  604. // if (dt.Rows[i][1].ToString().Equals("4"))
  605. // {
  606. // dt.Rows[i][1] = "四月";
  607. // }
  608. // if (dt.Rows[i][1].ToString().Equals("5"))
  609. // {
  610. // dt.Rows[i][1] = "五月";
  611. // }
  612. // if (dt.Rows[i][1].ToString().Equals("6"))
  613. // {
  614. // dt.Rows[i][1] = "六月";
  615. // }
  616. // if (dt.Rows[i][1].ToString().Equals("7"))
  617. // {
  618. // dt.Rows[i][1] = "七月";
  619. // }
  620. // if (dt.Rows[i][1].ToString().Equals("8"))
  621. // {
  622. // dt.Rows[i][1] = "八月";
  623. // }
  624. // if (dt.Rows[i][1].ToString().Equals("9"))
  625. // {
  626. // dt.Rows[i][1] = "九月";
  627. // }
  628. // if (dt.Rows[i][1].ToString().Equals("10"))
  629. // {
  630. // dt.Rows[i][1] = "十月";
  631. // }
  632. // if (dt.Rows[i][1].ToString().Equals("11"))
  633. // {
  634. // dt.Rows[i][1] = "十一月";
  635. // }
  636. // if (dt.Rows[i][1].ToString().Equals("12"))
  637. // {
  638. // dt.Rows[i][1] = "十二月";
  639. // }
  640. //}
  641. #endregion
  642. switch (type)
  643. {
  644. case "团组月份利润":
  645. xmlStr = MissionsProfitDToXmlByMonthOrLine(dt);
  646. break;
  647. case "团/非团组年利润":
  648. xmlStr = MissionsProfitDToXmlByYearOrLine(dt, year);
  649. break;
  650. case "查询团组年利润":
  651. xmlStr = Total_MissionsProfitByYearDtToXmlByBar(dt);
  652. break;
  653. case "出访国家统计":
  654. xmlStr = DataTableToXmlByBar(dt);
  655. break;
  656. case "预订酒店统计":
  657. xmlStr = DataTableToXmlByBar(dt);
  658. break;
  659. default:
  660. break;
  661. }
  662. return xmlStr;
  663. }
  664. /// <summary>
  665. /// LiuChengYi 2014/07/29
  666. /// 转换成XML格式字符串 应用于报表柱状图
  667. /// </summary>
  668. /// <param name="dt"></param>
  669. /// <returns></returns>
  670. public string DataTableToXmlByBar(DataTable dt)
  671. {
  672. StringBuilder strXml = new StringBuilder();
  673. strXml.AppendLine("<JSChart>");
  674. strXml.AppendLine("<dataset type=\"bar\">");
  675. for (int i = 0; i < dt.Rows.Count; i++ )
  676. {
  677. //dt.Rows[i]["Category"].ToString().Replace("&", " ")
  678. if (i<10)
  679. {
  680. if (dt.Rows[i]["Category"].ToString().Length > 5)
  681. {
  682. dt.Rows[i]["Category"] = dt.Rows[i]["Category"].ToString().Substring(0, 5);
  683. dt.Rows[i]["Category"] = "" + (i + 1) + "" + "." + dt.Rows[i]["Category"].ToString() + "...";
  684. }
  685. else
  686. {
  687. dt.Rows[i]["Category"] = "" + (i + 1) + "" + "." + dt.Rows[i]["Category"].ToString();
  688. }
  689. strXml.AppendLine("<data unit=" + "\"" + dt.Rows[i]["Category"].ToString().Replace("&", " ") + "\" " + "value=" + "\"" + dt.Rows[i]["num"].ToString() + "\"/>");
  690. }
  691. }
  692. strXml.AppendLine("</dataset>");
  693. //strXml.AppendLine("<colorset>");
  694. //strXml.AppendLine("<color value= \"#49A5EC\" />");
  695. //strXml.AppendLine("<color value= \"#61B320\" />");
  696. //strXml.AppendLine("</colorset>");
  697. strXml.AppendLine("<optionset>");
  698. strXml.AppendLine("<option set=\"setSize\" value=\"800,300\" />");
  699. strXml.AppendLine("<option set=\"setBarSpacingRatio\" value=\"20\" />");
  700. strXml.AppendLine("<option set=\"setBarValues\" value=\"true\" />");
  701. strXml.AppendLine("<option set=\"setTitle\" value=\"'出访国家/预订酒店统计报表'\" />");
  702. strXml.AppendLine("<option set=\"setAxisNameX\" value=\"' '\" />");
  703. //strXml.AppendLine("<option set=\"setTextPaddingBottom\" value=\"0\" />");
  704. strXml.AppendLine("<option set=\"setAxisNameY\" value=\"'次数'\" />");
  705. strXml.AppendLine("<option set=\"setAxisPaddingLeft\" value=\"80\" />");
  706. strXml.AppendLine("</optionset>");
  707. strXml.AppendLine("</JSChart>");
  708. return strXml.ToString();
  709. }
  710. /// <summary>
  711. /// LiuChengYi 2014/07/31
  712. /// 用于团组利润统计
  713. /// </summary>
  714. /// <param name="dt"></param>
  715. /// <param name="year"></param>
  716. /// <returns></returns>
  717. public string Total_MissionsProfitByYearDtToXmlByBar(DataTable dt)
  718. {
  719. StringBuilder strXml = new StringBuilder();
  720. strXml.AppendLine("<JSChart>");
  721. strXml.AppendLine("<dataset type=\"bar\">");
  722. for (int i = 0; i < dt.Rows.Count; i++)
  723. {
  724. strXml.AppendLine("<data unit=" + "\"" + dt.Rows[i]["Category"].ToString() + "\" " + "value=" + "\"" + dt.Rows[i]["num"].ToString() + "\"/>");
  725. }
  726. strXml.AppendLine("</dataset>");
  727. strXml.AppendLine("<colorset>");
  728. strXml.AppendLine("<color value= \"#49A5EC\" />");
  729. strXml.AppendLine("<color value= \"#61B320\" />");
  730. strXml.AppendLine("<color value= \"#ECB075\" />");
  731. strXml.AppendLine("</colorset>");
  732. strXml.AppendLine("<optionset>");
  733. strXml.AppendLine("<option set=\"setTitle\" value=\"'团组年份统计报表'\" />");
  734. strXml.AppendLine("<option set=\"setAxisNameX\" value=\"'年份'\" />");
  735. strXml.AppendLine("<option set=\"setAxisNameY\" value=\"'¥'\" />");
  736. strXml.AppendLine("<option set=\"setAxisPaddingLeft\" value=\"80\" />");
  737. strXml.AppendLine("<option set=\"setAxisPaddingBottom\" value=\"80\" />");
  738. strXml.AppendLine("</optionset>");
  739. strXml.AppendLine("</JSChart>");
  740. return strXml.ToString();
  741. }
  742. /// <summary>
  743. /// LiuChengYi 2014/07/29
  744. /// 转换成四川公司团组月份统计图XML格式字符串 应用于报表折线图
  745. /// </summary>
  746. /// <param name="dt"></param>
  747. /// <returns></returns>
  748. public string MissionsProfitDToXmlByMonthOrLine(DataTable dt)
  749. {
  750. StringBuilder strXml = new StringBuilder();
  751. strXml.AppendLine("<JSChart>");
  752. string strName = "";
  753. for (int i = 0; i < dt.Rows.Count; i++)
  754. {
  755. if (!strName.Equals(dt.Rows[i]["name"].ToString())) {
  756. strName = dt.Rows[i]["name"].ToString();
  757. if (!strName.Equals("非团组"))
  758. {
  759. strXml.AppendLine("<dataset type=\"line\" id=\"blue\"> ");
  760. for (int j = 0; j < dt.Rows.Count; j++)
  761. {
  762. if (!dt.Rows[j]["name"].ToString().Equals("非团组")) {
  763. strXml.AppendLine("<data unit=" + "\"" + dt.Rows[j]["Category"].ToString() + "\" " + "value=" + "\"" + dt.Rows[j]["num"].ToString() + "\"/>");
  764. }
  765. }
  766. strXml.AppendLine("</dataset>");
  767. }
  768. else
  769. {
  770. strXml.AppendLine("<dataset type=\"line\" id=\"green\"> ");
  771. for (int j = 0; j < dt.Rows.Count; j++)
  772. {
  773. if (dt.Rows[j]["name"].ToString().Equals("非团组"))
  774. {
  775. strXml.AppendLine("<data unit=" + "\"" + dt.Rows[j]["Category"].ToString() + "\" " + "value=" + "\"" + dt.Rows[j]["num"].ToString() + "\"/>");
  776. }
  777. }
  778. strXml.AppendLine("</dataset>");
  779. }
  780. }
  781. }
  782. strXml.AppendLine("<colorset>");
  783. strXml.AppendLine("<color value= \"#0070C0\" />");
  784. strXml.AppendLine("<color value= \"#C55A11\" />");
  785. strXml.AppendLine("</colorset>");
  786. strXml.AppendLine("<optionset>");
  787. strXml.AppendLine("<option set=\"setSize\" value=\"500,300\" />");
  788. strXml.AppendLine("<option set=\"setAxisPaddingLeft\" value=\"100\" />");
  789. strXml.AppendLine("<option set=\"setAxisPaddingBottom\" value=\"50\" />");
  790. strXml.AppendLine("<option set=\"setTitle\" value=\"'团组月份统计报表'\" />");
  791. strXml.AppendLine("<option set=\"setGraphExtend\" value=\"true\" />");
  792. strXml.AppendLine("<option set=\"setShowXValues\" value=\"false\" />");
  793. strXml.AppendLine("<option set=\"setLabelX\" value=\"[1,'一月']\" />");
  794. strXml.AppendLine("<option set=\"setLabelX\" value=\"[2,'二月']\" />");
  795. strXml.AppendLine("<option set=\"setLabelX\" value=\"[3,'三月']\" />");
  796. strXml.AppendLine("<option set=\"setLabelX\" value=\"[4,'四月']\" />");
  797. strXml.AppendLine("<option set=\"setLabelX\" value=\"[5,'五月']\" />");
  798. strXml.AppendLine("<option set=\"setLabelX\" value=\"[6,'六月']\" />");
  799. strXml.AppendLine("<option set=\"setLabelX\" value=\"[7,'七月']\" />");
  800. strXml.AppendLine("<option set=\"setLabelX\" value=\"[8,'八月']\" />");
  801. strXml.AppendLine("<option set=\"setLabelX\" value=\"[9,'九月']\" />");
  802. strXml.AppendLine("<option set=\"setLabelX\" value=\"[10,'十月']\" />");
  803. strXml.AppendLine("<option set=\"setLabelX\" value=\"[11,'十一月']\" />");
  804. strXml.AppendLine("<option set=\"setLabelX\" value=\"[12,'十二月']\" />");
  805. strXml.AppendLine("<option set=\"setTooltip\" value=\"[1,' ']\" />");
  806. strXml.AppendLine("<option set=\"setTooltip\" value=\"[2,' ']\" />");
  807. strXml.AppendLine("<option set=\"setTooltip\" value=\"[3,' ']\" />");
  808. strXml.AppendLine("<option set=\"setTooltip\" value=\"[4,' ']\" />");
  809. strXml.AppendLine("<option set=\"setTooltip\" value=\"[5,' ']\" />");
  810. strXml.AppendLine("<option set=\"setTooltip\" value=\"[6,' ']\" />");
  811. strXml.AppendLine("<option set=\"setTooltip\" value=\"[7,' ']\" />");
  812. strXml.AppendLine("<option set=\"setTooltip\" value=\"[8,' ']\" />");
  813. strXml.AppendLine("<option set=\"setTooltip\" value=\"[9,' ']\" />");
  814. strXml.AppendLine("<option set=\"setTooltip\" value=\"[10,' ']\" />");
  815. strXml.AppendLine("<option set=\"setTooltip\" value=\"[11,' ']\" />");
  816. strXml.AppendLine("<option set=\"setTooltip\" value=\"[12,' ']\" />");
  817. //strXml.AppendLine("<option set=\"setGraphLabel\" value=\"'团组'\" />");
  818. //strXml.AppendLine("<option set=\"setLegendShow\" value=\"true\" />");
  819. strXml.AppendLine("<option set=\"setFlagColor\" value=\"'#9D16FC'\" />");
  820. strXml.AppendLine("<option set=\"setLineColor\" value=\"'#0070C0','blue'\" />");
  821. strXml.AppendLine("<option set=\"setLineColor\" value=\"'#C55A11','green'\" />");
  822. //strXml.AppendLine("<option set=\"setLegendForLine\" value=\"'blue','团组'\" />");
  823. //strXml.AppendLine("<option set=\"setLegendForLine\" value=\"'green' ,'非团组'\"/>");
  824. strXml.AppendLine("<option set=\"setAxisNameX\" value=\"'月份'\" />");
  825. strXml.AppendLine("<option set=\"setAxisNameY\" value=\"'¥'\" />");
  826. strXml.AppendLine("</optionset>");
  827. strXml.AppendLine("</JSChart>");
  828. return strXml.ToString();
  829. }
  830. /// <summary>
  831. /// LiuChengYi 2014/07/29
  832. /// 转换成四川公司团组(团组/非团组)年份统计图XML格式字符串 应用于报表折线图
  833. /// </summary>
  834. /// <param name="dt"></param>
  835. /// <returns></returns>
  836. public string MissionsProfitDToXmlByYearOrLine(DataTable dt,int year)
  837. {
  838. StringBuilder strXml = new StringBuilder();
  839. strXml.AppendLine("<JSChart>");
  840. string strName = "";
  841. for (int i = 0; i < dt.Rows.Count; i++)
  842. {
  843. if (!strName.Equals(dt.Rows[i]["name"].ToString()))
  844. {
  845. strName = dt.Rows[i]["name"].ToString();
  846. if (!strName.Equals("非团组"))
  847. {
  848. strXml.AppendLine("<dataset type=\"line\" id=\"blue\"> ");
  849. for (int j = 0; j < dt.Rows.Count; j++)
  850. {
  851. if (!dt.Rows[j]["name"].ToString().Equals("非团组"))
  852. {
  853. strXml.AppendLine("<data unit=" + "\"" + dt.Rows[j]["Category"].ToString() + "\" " + "value=" + "\"" + dt.Rows[j]["num"].ToString() + "\"/>");
  854. }
  855. }
  856. strXml.AppendLine("</dataset>");
  857. }
  858. else
  859. {
  860. strXml.AppendLine("<dataset type=\"line\" id=\"green\"> ");
  861. for (int j = 0; j < dt.Rows.Count; j++)
  862. {
  863. if (dt.Rows[j]["name"].ToString().Equals("非团组"))
  864. {
  865. strXml.AppendLine("<data unit=" + "\"" + dt.Rows[j]["Category"].ToString() + "\" " + "value=" + "\"" + dt.Rows[j]["num"].ToString() + "\"/>");
  866. }
  867. }
  868. strXml.AppendLine("</dataset>");
  869. }
  870. }
  871. }
  872. strXml.AppendLine("<colorset>");
  873. strXml.AppendLine("<color value= \"#0070C0\" />");
  874. strXml.AppendLine("<color value= \"#C55A11\" />");
  875. strXml.AppendLine("</colorset>");
  876. strXml.AppendLine("<optionset>");
  877. strXml.AppendLine("<option set=\"setSize\" value=\"500,300\" />");
  878. strXml.AppendLine("<option set=\"setAxisPaddingLeft\" value=\"100\" />");
  879. strXml.AppendLine("<option set=\"setAxisPaddingBottom\" value=\"50\" />");
  880. strXml.AppendLine("<option set=\"setTitle\" value=\"'团组年利润统计报表'\" />");
  881. strXml.AppendLine("<option set=\"setGraphExtend\" value=\"true\" />");
  882. strXml.AppendLine("<option set=\"setShowXValues\" value=\"false\" />");
  883. strXml.AppendLine("<option set=\"setLabelX\" value=\"[2012,'2012年']\" />");
  884. strXml.AppendLine("<option set=\"setLabelX\" value=\"[2013,'2013年']\" />");
  885. strXml.AppendLine("<option set=\"setLabelX\" value=\"[2014,'2014年']\" />");
  886. strXml.AppendLine("<option set=\"setTooltip\" value=\"[2012,' ']\" />");
  887. strXml.AppendLine("<option set=\"setTooltip\" value=\"[2013,' ']\" />");
  888. strXml.AppendLine("<option set=\"setTooltip\" value=\"[2014,' ']\" />");
  889. //strXml.AppendLine("<option set=\"setGraphLabel\" value=\"'团组'\" />");
  890. //strXml.AppendLine("<option set=\"setLegendShow\" value=\"true\" />");
  891. strXml.AppendLine("<option set=\"setFlagColor\" value=\"'#9D16FC'\" />");
  892. strXml.AppendLine("<option set=\"setLineColor\" value=\"'#0070C0','blue'\" />");
  893. strXml.AppendLine("<option set=\"setLineColor\" value=\"'#C55A11','green'\" />");
  894. //strXml.AppendLine("<option set=\"setLegendForLine\" value=\"'blue','团组'\" />");
  895. //strXml.AppendLine("<option set=\"setLegendForLine\" value=\"'green' ,'非团组'\"/>");
  896. strXml.AppendLine("<option set=\"setAxisNameX\" value=\"'年份'\" />");
  897. strXml.AppendLine("<option set=\"setAxisNameY\" value=\"'¥'\" />");
  898. strXml.AppendLine("</optionset>");
  899. strXml.AppendLine("</JSChart>");
  900. return strXml.ToString();
  901. }
  902. #region dataTable转换成Json格式
  903. /// <summary>
  904. /// dataTable转换成Json格式
  905. /// </summary>
  906. /// <param name="dt"></param>
  907. /// <returns></returns>
  908. public string ToJson(DataTable dt)
  909. {
  910. StringBuilder jsonBuilder = new StringBuilder();
  911. jsonBuilder.Append("{\"report");
  912. jsonBuilder.Append(dt.TableName.ToString());
  913. jsonBuilder.Append("\":[");
  914. for (int i = 0; i < dt.Rows.Count; i++)
  915. {
  916. jsonBuilder.Append("{");
  917. for (int j = 0; j < dt.Columns.Count; j++)
  918. {
  919. jsonBuilder.Append("\"");
  920. jsonBuilder.Append(dt.Columns[j].ColumnName);
  921. jsonBuilder.Append("\":\"");
  922. jsonBuilder.Append(dt.Rows[i][j].ToString());
  923. jsonBuilder.Append("\",");
  924. }
  925. jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
  926. jsonBuilder.Append("},");
  927. }
  928. jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
  929. jsonBuilder.Append("]");
  930. jsonBuilder.Append("}");
  931. return jsonBuilder.ToString();
  932. }
  933. #endregion dataTable转换成Json格式
  934. }
  935. }