frmTimeStatistics.cs 96 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Data;
  6. using System.Data.SqlClient;
  7. using System.Windows.Forms;
  8. using System.Web.UI.WebControls;
  9. using System.Collections;
  10. using System.Threading;
  11. using LYFZ.Software.MainBusiness.DoorCityProcess;
  12. using System.Dynamic;
  13. namespace LYFZ.Software.MainBusiness.TimeAndAttendance
  14. {
  15. public class frmTimeStatistics : LYFZ.Software.UI.TimeAndAttendance.frmTimeStatistics
  16. {
  17. DataSet dsData = new DataSet();
  18. LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
  19. LYFZ.BLL.BLL_Loninbansets lonindansets = new BLL.BLL_Loninbansets();
  20. public frmTimeStatistics()
  21. {
  22. this.Load += frmTimeStatistics_Load;
  23. this.btnLastWeek.Click += btnLastWeek_Click;
  24. this.btnNextWeek.Click += btnNextWeek_Click;
  25. this.btnExport.Click += btnExport_Click;
  26. this.btnPrint.Click += btnPrint_Click;
  27. this.chkWeekMode.Click += chkWeekMode_Click;
  28. this.dgvData.CellMouseDoubleClick += dgvData_CellMouseDoubleClick;
  29. this.dtpYearMonth.ClickChengedValue += dtpYearMonth_ClickChengedValue;
  30. this.btnClose.Click += btnClose_Click;
  31. cbxCompanyList.ComboBoxTree_NodeMouseClick += CbxCompanyList_ComboBoxTree_NodeMouseClick;
  32. //BindCompanyList();
  33. //cbxCompanyList.SelectedIndexChanged += cbxCompanyList_SelectedIndexChanged;
  34. }
  35. private void CbxCompanyList_ComboBoxTree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
  36. {
  37. if (!this.chkWeekMode.Checked)
  38. { this.dtpYearMonth_ClickChengedValue(""); }
  39. else
  40. { this.GetWeekData(); }
  41. }
  42. void cbxCompanyList_SelectedIndexChanged(object sender, EventArgs e)
  43. {
  44. if (chkWeekMode.Checked)
  45. {
  46. GetWeekData();
  47. }
  48. else
  49. {
  50. dtpYearMonth_ClickChengedValue("");
  51. }
  52. }
  53. void BindCompanyList()
  54. {
  55. BLL.BLL_ErpCompanyInfo bllCompany = new BLL.BLL_ErpCompanyInfo();
  56. DataTable dt = bllCompany.GetAllList().Tables[0];
  57. cbxCompanyList.Items.Add(new ItemValue("", "全部"));
  58. foreach (DataRow dr in dt.Rows)
  59. {
  60. cbxCompanyList.Items.Add(new ItemValue(dr["Company_DividedShop"].ToString(), dr["Company_Name"].ToString_s()));
  61. }
  62. cbxCompanyList.SelectedIndex = 0;
  63. }
  64. DateTime WeekStartDate;
  65. DateTime WeekEndDate;
  66. /// <summary>
  67. /// 窗体加载事件
  68. /// </summary>
  69. /// <param name="sender"></param>
  70. /// <param name="e"></param>
  71. void frmTimeStatistics_Load(object sender, EventArgs e)
  72. {
  73. this.panelLastNextWeek.Visible = false;
  74. this.dgvData.dgvColumnHeadersHeight = 48;
  75. this.dgvData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;
  76. this.dgvData.ColumnHeadersHeight = 48;
  77. Control.CheckForIllegalCrossThreadCalls = false;
  78. this.dtpYearMonth.StrDateValue = SDateTime.Now.ToString("yyyy-MM");
  79. // 部门人员绑定
  80. LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboBoxTreeView_DepartmentAndEmployee(this.cbxCompanyList, IsFirstNodeNull: true, IsFirstNodeName: "全部", IsShowResign: false, IsShowAdmin: true, tb_User: LYFZ.DAL.DAL_ErpUser.SimpleUserDataTable);
  81. this.cbxCompanyList.AfterSelectLevelFirstNode = true;
  82. this.cbxCompanyList.IsNodeMouseClick = true;
  83. this.cbxCompanyList.IsSelectParentNode = true;
  84. cbxCompanyList.TextFindTag("全部");
  85. #region 获取本周
  86. this.WeekStartDate = SDateTime.Now.AddDays(Convert.ToInt32(SDateTime.Now.DayOfWeek) * -1);
  87. this.WeekEndDate = SDateTime.Now.AddDays(6 - Convert.ToInt32(SDateTime.Now.DayOfWeek));
  88. #endregion
  89. this.chkWeekMode.Checked = true;
  90. if (!this.chkWeekMode.Checked)
  91. { this.dtpYearMonth_ClickChengedValue(""); }
  92. else
  93. { this.GetWeekData(); }
  94. }
  95. /// <summary>
  96. /// 上一个星期
  97. /// </summary>
  98. /// <param name="sender"></param>
  99. /// <param name="e"></param>
  100. void btnLastWeek_Click(object sender, EventArgs e)
  101. {
  102. this.dgvData.Rows.Clear();
  103. this.WeekStartDate = this.WeekStartDate.AddDays(-7);
  104. this.WeekEndDate = this.WeekEndDate.AddDays(-7);
  105. this.GetWeekData();
  106. }
  107. /// <summary>
  108. /// 下一个星期
  109. /// </summary>
  110. /// <param name="sender"></param>
  111. /// <param name="e"></param>
  112. void btnNextWeek_Click(object sender, EventArgs e)
  113. {
  114. this.dgvData.Rows.Clear();
  115. this.WeekStartDate = this.WeekStartDate.AddDays(7);
  116. this.WeekEndDate = this.WeekEndDate.AddDays(7);
  117. this.GetWeekData();
  118. }
  119. /// <summary>
  120. /// 周模式
  121. /// </summary>
  122. /// <param name="sender"></param>
  123. /// <param name="e"></param>
  124. void chkWeekMode_Click(object sender, EventArgs e)
  125. {
  126. if (this.chkWeekMode.Checked)
  127. {
  128. this.GetWeekData();
  129. }
  130. else
  131. {
  132. this.dtpYearMonth_ClickChengedValue("");
  133. }
  134. }
  135. /// <summary>
  136. /// 导出Excel
  137. /// </summary>
  138. /// <param name="sender"></param>
  139. /// <param name="e"></param>
  140. void btnExport_Click(object sender, EventArgs e)
  141. {
  142. string StrModelName = "";
  143. if (this.chkWeekMode.Checked)
  144. { StrModelName = this.lblWhichWeek.Text.Trim(); }
  145. else
  146. { StrModelName = this.dtpYearMonth.StrDateValue.Trim(); }
  147. this.dgvData.ExportDataTable(StrModelName);
  148. }
  149. /// <summary>
  150. /// 打印
  151. /// </summary>
  152. /// <param name="sender"></param>
  153. /// <param name="e"></param>
  154. void btnPrint_Click(object sender, EventArgs e)
  155. {
  156. try
  157. {
  158. Hashtable htData = new Hashtable();
  159. htData["y"] = this.dgvData.CurrentCellAddress.Y;
  160. int yyyy = Convert.ToInt32(this.dtpYearMonth.StrYear);
  161. int MM = Convert.ToInt32(this.dtpYearMonth.StrMonth);
  162. int chk = 0;
  163. if (!this.chkWeekMode.Checked)
  164. { chk = 0; }
  165. else
  166. { chk = 1; }
  167. htData["chk"] = chk;
  168. htData["time1"] = this.dtpYearMonth.StrYear;
  169. htData["time2"] = this.dtpYearMonth.StrMonth;
  170. htData["dgvData"] = this.dgvData;
  171. LYFZ.Software.MainBusiness.ReportPrint.ReportFixedFormat.PrintFixedFormat(EnumPublic.PrintTypeEnum.考勤报表, htData);
  172. }
  173. catch (Exception ex)
  174. { MessageBoxCustom.Show(ex.Message); }
  175. }
  176. /// <summary>
  177. /// 关闭
  178. /// </summary>
  179. /// <param name="sender"></param>
  180. /// <param name="e"></param>
  181. void btnClose_Click(object sender, EventArgs e)
  182. {
  183. this.Close();
  184. }
  185. /// <summary>
  186. /// 双击查看考勤详情
  187. /// </summary>
  188. /// <param name="sender"></param>
  189. /// <param name="e"></param>
  190. void dgvData_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
  191. {
  192. if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
  193. {
  194. if (this.dgvData.Columns[e.ColumnIndex].Tag != null)
  195. {
  196. LYFZ.Software.MainBusiness.TimeAndAttendance.SetSmallForm.AttendanceDetailsSmallForm frm = new SetSmallForm.AttendanceDetailsSmallForm();
  197. frm.StrUserName = this.dgvData.Rows[e.RowIndex].Cells["姓名"].Value.ToString().Trim();
  198. frm.StrUserNumber = this.dgvData.Rows[e.RowIndex].Cells["编号"].Value.ToString().Trim();
  199. frm.StrDateTime = this.dgvData.Columns[e.ColumnIndex].Tag.ToString();
  200. frm.Show();
  201. }
  202. }
  203. }
  204. /// <summary>
  205. /// 获取工作数据
  206. /// </summary>
  207. /// <param name="StrWeekStartDate"></param>
  208. /// <param name="StrWeekEndDate"></param>
  209. /// <param name="WorkCount"></param>
  210. DataTable GetWorkData(string StrWeekStartDate, string StrWeekEndDate, int WorkCount,string companyWhere="")
  211. {
  212. DataTable newTable = new DataTable();
  213. newTable.Columns.Add("编号", typeof(string));
  214. newTable.Columns.Add("姓名", typeof(string));
  215. newTable.Columns.Add("迟到", typeof(string));
  216. newTable.Columns.Add("早退", typeof(string));
  217. newTable.Columns.Add("旷工", typeof(string));
  218. newTable.Columns.Add("漏打卡", typeof(string));
  219. newTable.Columns.Add("休息", typeof(string));
  220. newTable.Columns.Add("请假", typeof(string));
  221. for (int i = 0; i < WorkCount; i++)
  222. { newTable.Columns.Add(i.ToString().Trim(), typeof(string)); }
  223. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, System.ComponentModel.BackgroundWorker backgroundWorker)
  224. {
  225. string ExecuteSql = "select User_EmployeeID,User_Name,User_FirstFingerprintID,User_SecondaryFingerprintID from tb_ErpUser Where User_Status='在职' And User_Account <> 'admin' " + companyWhere + " ;";
  226. ExecuteSql += "select ID,User_ID,Time,fixed from loninbansets Where " + PublicCodeClasses.GetDateTime("Time", StrWeekStartDate, StrWeekEndDate, ConnectWord: "") + " and fixed !='' ;";
  227. ExecuteSql += "select no,dbo.fn_CheckDateTime(datetime) AS datetime from dbo.lonindata Where " + PublicCodeClasses.GetDateTime("datetime", StrWeekStartDate, StrWeekEndDate, ConnectWord: "") + " Group By no,dbo.fn_CheckDateTime(datetime);";
  228. ExecuteSql += "select type,date,user_id from loginsign Where " + PublicCodeClasses.GetDateTime("convert(datetime,date)", StrWeekStartDate, StrWeekEndDate, ConnectWord: "") + ";";
  229. ExecuteSql += "select time1,time2,time3,time4,name from lonintimeset;";
  230. DataSet dtSet = orbll.GetView_Custom(ExecuteSql);
  231. BindAttendanceStatistics(dtSet, newTable, StrWeekStartDate, WorkCount);
  232. #region 作废考勤统计
  233. //DataTable dt = dtSet.Tables["ds"];
  234. //DataTable dtPaibanSet = dtSet.Tables["ds1"];
  235. ////dtPaibanSet.PrimaryKey = new DataColumn[] { dtPaibanSet.Columns["User_ID"], dtPaibanSet.Columns["Time"] };
  236. //DataTable dtKaoqin = dtSet.Tables["ds2"];
  237. //DataTable dtQiandao = dtSet.Tables["ds3"];
  238. //DataTable dtBanchiSet = dtSet.Tables["ds4"];
  239. //dtBanchiSet.PrimaryKey = new DataColumn[] { dtBanchiSet.Columns["name"] };
  240. //for (int i = 0; i < dt.Rows.Count; i++)
  241. //{
  242. // string StrUserName = dt.Rows[i]["User_Name"].ToString().Trim();
  243. // DataRow newdtRow = newTable.NewRow();
  244. // int intLateToCount = 0;
  245. // int intEarlyGoCount = 0;
  246. // int intKuangGongCount = 0;
  247. // int intMissedPunch=0;
  248. // #region 处理一个星期的每天考勤情况
  249. // for (int j = 0; j < WorkCount; j++)
  250. // {
  251. // try
  252. // {
  253. // Dictionary<string, string> dataTimeList = new Dictionary<string, string>();
  254. // string StrDateTime = Convert.ToDateTime(StrWeekStartDate).AddDays(j).ToString("yyyy-MM-dd");
  255. // //排班
  256. // DataRow[] dtRow_PaibanSet = dtPaibanSet.Select( "User_ID = '"+ dt.Rows[i]["User_EmployeeID"].ToString().Trim() +"' and Time = '" + Convert.ToDateTime(StrDateTime).ToString("yyyy-MM-dd")+"'" );
  257. // //打卡
  258. // DataRow[] dtRows_Kaoqin = dtKaoqin.Select("no in ('" + dt.Rows[i]["User_FirstFingerprintID"].ToString().Trim() + "','" + dt.Rows[i]["User_SecondaryFingerprintID"].ToString().Trim() + "')" + PublicCodeClasses.GetDateTime2("datetime", StrDateTime, StrDateTime), sort: "datetime");
  259. // //签单
  260. // DataRow[] dtRows_Qiandao = dtQiandao.Select("user_id = '" + dt.Rows[i]["User_EmployeeID"].ToString().Trim() + "' And date = '" + StrDateTime + "'");
  261. // string StrTextString = "";
  262. // for (int k = 0; k < dtRows_Qiandao.Length; k++)
  263. // { StrTextString += dtRows_Qiandao[k]["type"].ToString().Trim() + ","; }
  264. // string StrValueText = "";
  265. // bool IsFindValueText = true;
  266. // if (dtRow_PaibanSet.Length>0)
  267. // {
  268. // #region 有安排班次
  269. // int forLateToCount = 0;
  270. // int forEarlyGoCount = 0;
  271. // StrValueText = dtRow_PaibanSet[0]["fixed"].ToString().Trim();
  272. // //班次设置
  273. // DataRow dtRow = dtBanchiSet.Rows.Find(dtRow_PaibanSet[0]["fixed"].ToString().Trim());
  274. // if (dtRow != null)
  275. // {
  276. // string StrText = "";
  277. // if (!string.IsNullOrEmpty(dtRow["time3"].ToString().Trim()))
  278. // { StrText = "[A-B][C-D]"; }
  279. // else
  280. // { StrText = "[A-B]"; }
  281. // #region 处理签到
  282. // if (StrTextString.IndexOf(LYFZ.EnumPublic.AttendanceSignType.StrAllDay.Trim()) != -1)
  283. // {
  284. // if (!string.IsNullOrEmpty(dtRow["time3"].ToString().Trim()))
  285. // {
  286. // dataTimeList.Add("time1", "签单");
  287. // dataTimeList.Add("time2", "签单");
  288. // dataTimeList.Add("time3", "签单");
  289. // dataTimeList.Add("time4", "签单");
  290. // StrText = StrText.Replace("A", "签单").Replace("B", "签单").Replace("C", "签单").Replace("D", "签单");
  291. // }
  292. // else
  293. // {
  294. // dataTimeList.Add("time1", "签单");
  295. // dataTimeList.Add("time2", "签单");
  296. // StrText = StrText.Replace("A", "签单").Replace("B", "签单");
  297. // }
  298. // }
  299. // if (StrTextString.IndexOf(LYFZ.EnumPublic.AttendanceSignType.StrFirstParagraph_GoToAndOffWork.Trim()) != -1)
  300. // {
  301. // dataTimeList.Add("time1", "签单");
  302. // dataTimeList.Add("time2", "签单");
  303. // StrText = StrText.Replace("A", "签单").Replace("B", "签单");
  304. // }
  305. // if (StrTextString.IndexOf(LYFZ.EnumPublic.AttendanceSignType.StrFirstParagraph_GoToAndOffWork.Trim()) != -1)
  306. // {
  307. // dataTimeList.Add("time3", "签单");
  308. // dataTimeList.Add("time4", "签单");
  309. // StrText = StrText.Replace("C", "签单").Replace("D", "签单");
  310. // }
  311. // if (StrTextString.IndexOf(LYFZ.EnumPublic.AttendanceSignType.StrFirstParagraph_GoToWork.Trim()) != -1)
  312. // {
  313. // dataTimeList.Add("time1", "签单");
  314. // StrText = StrText.Replace("A", "签单");
  315. // }
  316. // if (StrTextString.IndexOf(LYFZ.EnumPublic.AttendanceSignType.StrFirstParagraph_GoOffWork.Trim()) != -1)
  317. // {
  318. // dataTimeList.Add("time2", "签单");
  319. // StrText = StrText.Replace("B", "签单");
  320. // }
  321. // if (StrTextString.IndexOf(LYFZ.EnumPublic.AttendanceSignType.StrSecondParagraph_GoToWork.Trim()) != -1)
  322. // {
  323. // dataTimeList.Add("time3", "签单");
  324. // StrText = StrText.Replace("C", "签单");
  325. // }
  326. // if (StrTextString.IndexOf(LYFZ.EnumPublic.AttendanceSignType.StrSecondParagraph_GoOffWork.Trim()) != -1)
  327. // {
  328. // dataTimeList.Add("time4", "签单");
  329. // StrText = StrText.Replace("D", "签单");
  330. // }
  331. // #endregion
  332. // #region 获取每个班段的每个打卡的上班下班的时间点
  333. // string StrFirstParagraphDateTime = "";
  334. // string StrFirstParagraphDateTimeToMin = "";
  335. // string StrFirstParagraphDateTimeToMax = "";
  336. // string StrSecondParagraphDateTimeToMin = "";
  337. // string StrSecondParagraphDateTimeToMax = "";
  338. // for (int k = 0; k < dtRows_Kaoqin.Length; k++)
  339. // {
  340. // //遍历获取第一班段的上班时间的最先一次打卡记录,获取时间范围在第一班段的下班时间以前打的卡
  341. // if (Convert.ToDateTime(dtRows_Kaoqin[k]["datetime"]) <= Convert.ToDateTime(StrDateTime + " " + dtRow["time2"].ToString().Trim()))
  342. // {
  343. // if (!string.IsNullOrEmpty(StrFirstParagraphDateTime))
  344. // {
  345. // if (Convert.ToDateTime(dtRows_Kaoqin[k]["datetime"]) < Convert.ToDateTime(StrFirstParagraphDateTime))
  346. // { StrFirstParagraphDateTime = Convert.ToDateTime(dtRows_Kaoqin[k]["datetime"]).ToString("yyyy-MM-dd HH:mm"); }
  347. // }
  348. // else
  349. // {
  350. // StrFirstParagraphDateTime = Convert.ToDateTime(dtRows_Kaoqin[k]["datetime"]).ToString("yyyy-MM-dd HH:mm");
  351. // }
  352. // }
  353. // //1.获取第一班段的下班最小时间(范围大于第一班段下班时间并小于第二班段的上班时间)
  354. // //2.获取第一班段的下班最大时间(范围大于第一班段下班时间并小于第二班段的上班时间)
  355. // if (Convert.ToDateTime(dtRows_Kaoqin[k]["datetime"]) >= Convert.ToDateTime(StrDateTime + " " + dtRow["time2"].ToString().Trim()).AddMinutes(-30))
  356. // {
  357. // //如果没有第二班段,则获取最后打卡下班时间
  358. // if (!string.IsNullOrEmpty(dtRow["time3"].ToString().Trim()))
  359. // {
  360. // if (Convert.ToDateTime(dtRows_Kaoqin[k]["datetime"]) <= Convert.ToDateTime(StrDateTime + " " + dtRow["time3"].ToString().Trim()))
  361. // {
  362. // if (!string.IsNullOrEmpty(StrFirstParagraphDateTimeToMin))
  363. // {
  364. // if (Convert.ToDateTime(dtRows_Kaoqin[k]["datetime"]) < Convert.ToDateTime(StrFirstParagraphDateTimeToMin))
  365. // { StrFirstParagraphDateTimeToMin = Convert.ToDateTime(dtRows_Kaoqin[k]["datetime"]).ToString("yyyy-MM-dd HH:mm"); }
  366. // if (Convert.ToDateTime(dtRows_Kaoqin[k]["datetime"]) > Convert.ToDateTime(StrFirstParagraphDateTimeToMin))
  367. // { StrFirstParagraphDateTimeToMax = Convert.ToDateTime(dtRows_Kaoqin[k]["datetime"]).ToString("yyyy-MM-dd HH:mm"); }
  368. // }
  369. // else
  370. // {
  371. // StrFirstParagraphDateTimeToMin = Convert.ToDateTime(dtRows_Kaoqin[k]["datetime"]).ToString("yyyy-MM-dd HH:mm");
  372. // //StrFirstParagraphDateTimeToMax = StrFirstParagraphDateTimeToMin;
  373. // }
  374. // }
  375. // }
  376. // else if (!string.IsNullOrEmpty(StrFirstParagraphDateTimeToMin))
  377. // {
  378. // if (Convert.ToDateTime(dtRows_Kaoqin[k]["datetime"]) > Convert.ToDateTime(StrFirstParagraphDateTimeToMin))
  379. // { StrFirstParagraphDateTimeToMin = Convert.ToDateTime(dtRows_Kaoqin[k]["datetime"]).ToString("yyyy-MM-dd HH:mm"); }
  380. // }
  381. // else
  382. // { StrFirstParagraphDateTimeToMin = Convert.ToDateTime(dtRows_Kaoqin[k]["datetime"]).ToString("yyyy-MM-dd HH:mm"); }
  383. // }
  384. // //else if (Convert.ToDateTime(dtRows2[k]["datetime"]) < Convert.ToDateTime(StrDateTime + " " + dtRow["time2"].ToString().Trim()) && Convert.ToDateTime(dtRows2[k]["datetime"]) >= Convert.ToDateTime(StrDateTime + " " + dtRow["time1"].ToString().Trim()))
  385. // //{ StrFirstParagraphDateTimeToMax = Convert.ToDateTime(dtRows2[k]["datetime"]).ToString("yyyy-MM-dd HH:mm"); }
  386. // //获取大于第一班段下班时间并且小于第二班段下班时间(用于判断第二段上班卡是否迟到)
  387. // if (!string.IsNullOrEmpty(dtRow["time3"].ToString().Trim()))
  388. // {
  389. // if (Convert.ToDateTime(dtRows_Kaoqin[k]["datetime"]) > Convert.ToDateTime(StrDateTime + " " + dtRow["time3"].ToString().Trim()) &&
  390. // Convert.ToDateTime(dtRows_Kaoqin[k]["datetime"]) < Convert.ToDateTime(StrDateTime + " " + dtRow["time4"].ToString().Trim()))
  391. // {
  392. // if (!string.IsNullOrEmpty(StrSecondParagraphDateTimeToMin))
  393. // {
  394. // if (Convert.ToDateTime(dtRows_Kaoqin[k]["datetime"]) < Convert.ToDateTime(StrSecondParagraphDateTimeToMin))
  395. // { StrSecondParagraphDateTimeToMin = Convert.ToDateTime(dtRows_Kaoqin[k]["datetime"]).ToString("yyyy-MM-dd HH:mm"); }
  396. // }
  397. // else
  398. // { StrSecondParagraphDateTimeToMin = Convert.ToDateTime(dtRows_Kaoqin[k]["datetime"]).ToString("yyyy-MM-dd HH:mm"); }
  399. // }
  400. // //获取第二班段的最后下班打卡时间
  401. // if (Convert.ToDateTime(dtRows_Kaoqin[k]["datetime"]) >= Convert.ToDateTime(StrDateTime + " " + dtRow["time4"].ToString().Trim()).AddMinutes(-30))
  402. // {
  403. // if (!string.IsNullOrEmpty(StrSecondParagraphDateTimeToMax))
  404. // {
  405. // if (Convert.ToDateTime(dtRows_Kaoqin[k]["datetime"]) > Convert.ToDateTime(StrSecondParagraphDateTimeToMax))
  406. // { StrSecondParagraphDateTimeToMax = Convert.ToDateTime(dtRows_Kaoqin[k]["datetime"]).ToString("yyyy-MM-dd HH:mm"); }
  407. // }
  408. // else
  409. // { StrSecondParagraphDateTimeToMax = Convert.ToDateTime(dtRows_Kaoqin[k]["datetime"]).ToString("yyyy-MM-dd HH:mm"); }
  410. // }
  411. // }
  412. // }
  413. // #endregion
  414. // #region 第一班段的上班时间
  415. // if (StrText.Trim().IndexOf("A") != -1)
  416. // {
  417. // //如果获取到第一班段的上班打卡时间晚于第一班段设置的上班时间,则标迟到
  418. // if (!string.IsNullOrEmpty(StrFirstParagraphDateTime))
  419. // {
  420. // dataTimeList.Add("time1", StrFirstParagraphDateTime + "|" + StrDateTime + " " + dtRow["time1"].ToString().Trim());
  421. // //if (Convert.ToDateTime(StrFirstParagraphDateTime) > Convert.ToDateTime(StrDateTime + " " + dtRow["time1"].ToString().Trim()))
  422. // //{
  423. // // forLateToCount++;
  424. // //}
  425. // StrText = StrText.Replace("A", Convert.ToDateTime(StrFirstParagraphDateTime).ToString("HH:mm"));
  426. // }
  427. // //if (!string.IsNullOrEmpty(dtRow["time1"].ToString().Trim()))
  428. // //{
  429. // // StrText = StrText.Replace("A", Convert.ToDateTime(StrDateTime + " " + dtRow["time1"].ToString().Trim()).ToString("HH:mm"));
  430. // //}
  431. // else
  432. // {
  433. // dataTimeList.Add("time1", "");
  434. // StrText = StrText.Replace("A", "");
  435. // //forLateToCount++;
  436. // }
  437. // }
  438. // #endregion
  439. // #region 第一班段的下班时间
  440. // if (StrText.Trim().IndexOf("B") != -1)
  441. // {
  442. // //如果获取到的第一班段的下班打卡时间
  443. // if (!string.IsNullOrEmpty(StrFirstParagraphDateTimeToMin))
  444. // {
  445. // //如果不存在第二班段,则赋上第一班段下班的最小时间
  446. // if (string.IsNullOrEmpty(dtRow["time3"].ToString().Trim()))
  447. // {
  448. // dataTimeList.Add("time2", StrFirstParagraphDateTimeToMin + "|" + StrDateTime + " " + dtRow["time2"].ToString().Trim());
  449. // StrText = StrText.Replace("B", Convert.ToDateTime(StrFirstParagraphDateTimeToMin).ToString("HH:mm"));
  450. // }
  451. // //如果获取到的第一班段下班最大时间不等于最小时间
  452. // else if (StrFirstParagraphDateTimeToMin.Trim() != StrFirstParagraphDateTimeToMax.Trim())
  453. // {
  454. // dataTimeList.Add("time2", StrFirstParagraphDateTimeToMin + "|" + StrDateTime + " " + dtRow["time2"].ToString().Trim());
  455. // StrText = StrText.Replace("B", Convert.ToDateTime(StrFirstParagraphDateTimeToMin).ToString("HH:mm"));
  456. // //StrText = StrText.Replace("C", Convert.ToDateTime(StrFirstParagraphDateTimeToMax).ToString("HH:mm"));
  457. // }
  458. // else
  459. // {
  460. // //如果第一班段的打卡最小时间与最时间相同,离第二班段的时间的上班时间近,则为第二班段上班时间
  461. // if ((Convert.ToDateTime(StrFirstParagraphDateTimeToMin) - Convert.ToDateTime(dtRow["time2"])).Minutes < (Convert.ToDateTime(dtRow["time3"]) - Convert.ToDateTime(StrFirstParagraphDateTimeToMin)).Minutes)
  462. // { StrFirstParagraphDateTimeToMax = StrFirstParagraphDateTimeToMin; }
  463. // else
  464. // {
  465. // dataTimeList.Add("time2", StrFirstParagraphDateTimeToMin + "|" + StrDateTime + " " + dtRow["time2"].ToString().Trim());
  466. // StrText = StrText.Replace("B", Convert.ToDateTime(StrFirstParagraphDateTimeToMin).ToString("HH:mm"));
  467. // }
  468. // }
  469. // }
  470. // //else if (!string.IsNullOrEmpty(dtRow["time4"].ToString().Trim()))
  471. // //{
  472. // // StrText = StrText.Replace("B", Convert.ToDateTime(StrDateTime + " " + dtRow["time4"].ToString().Trim()).ToString("HH:mm"));
  473. // //}
  474. // //else if (!string.IsNullOrEmpty(dtRow["time3"].ToString().Trim()))
  475. // //{
  476. // // StrText = StrText.Replace("B", Convert.ToDateTime(StrDateTime + " " + dtRow["time3"].ToString().Trim()).ToString("HH:mm"));
  477. // //}
  478. // //else if (!string.IsNullOrEmpty(dtRow["time2"].ToString().Trim()))
  479. // //{
  480. // // StrText = StrText.Replace("B", Convert.ToDateTime(StrDateTime + " " + dtRow["time2"].ToString().Trim()).ToString("HH:mm"));
  481. // //}
  482. // else
  483. // {
  484. // dataTimeList.Add("time2", "");
  485. // //forEarlyGoCount++;
  486. // StrText = StrText.Replace("B", "");
  487. // }
  488. // }
  489. // #endregion
  490. // #region 第二班段上、下班时间
  491. // if (!string.IsNullOrEmpty(dtRow["time3"].ToString().Trim()))
  492. // {
  493. // //第二班段上班时间
  494. // if (StrText.Trim().IndexOf("C") != -1)
  495. // {
  496. // if (!string.IsNullOrEmpty(StrFirstParagraphDateTimeToMax) || !string.IsNullOrEmpty(StrSecondParagraphDateTimeToMin))
  497. // {
  498. // if (StrFirstParagraphDateTimeToMax != StrFirstParagraphDateTimeToMin)
  499. // {
  500. // if (!string.IsNullOrEmpty(StrFirstParagraphDateTimeToMax))
  501. // {
  502. // dataTimeList.Add("time3", StrFirstParagraphDateTimeToMax + "|" + StrDateTime + " " + dtRow["time3"].ToString().Trim());
  503. // StrText = StrText.Replace("C", Convert.ToDateTime(StrFirstParagraphDateTimeToMax).ToString("HH:mm"));
  504. // }
  505. // else if (!string.IsNullOrEmpty(StrSecondParagraphDateTimeToMin))
  506. // {
  507. // dataTimeList.Add("time3", StrSecondParagraphDateTimeToMin + "|" + StrDateTime + " " + dtRow["time3"].ToString().Trim());
  508. // StrText = StrText.Replace("C", Convert.ToDateTime(StrSecondParagraphDateTimeToMin).ToString("HH:mm"));
  509. // }
  510. // }
  511. // else if (!string.IsNullOrEmpty(StrFirstParagraphDateTimeToMax) || !string.IsNullOrEmpty(StrSecondParagraphDateTimeToMin))
  512. // {
  513. // if (!string.IsNullOrEmpty(StrFirstParagraphDateTimeToMax) && !string.IsNullOrEmpty(StrSecondParagraphDateTimeToMin))
  514. // {
  515. // if (Convert.ToDateTime(StrFirstParagraphDateTimeToMax) < Convert.ToDateTime(StrSecondParagraphDateTimeToMin))
  516. // {
  517. // //forLateToCount++;
  518. // dataTimeList.Add("time3", StrFirstParagraphDateTimeToMax + "|" + StrDateTime + " " + dtRow["time3"].ToString().Trim());
  519. // StrText = StrText.Replace("C", Convert.ToDateTime(StrFirstParagraphDateTimeToMax).ToString("HH:mm"));
  520. // }
  521. // }
  522. // else if (!string.IsNullOrEmpty(StrFirstParagraphDateTimeToMax) || string.IsNullOrEmpty(StrSecondParagraphDateTimeToMin))
  523. // {
  524. // //forLateToCount++;
  525. // dataTimeList.Add("time3", StrFirstParagraphDateTimeToMax + "|" + StrDateTime + " " + dtRow["tim3e"].ToString().Trim());
  526. // StrText = StrText.Replace("C", Convert.ToDateTime(StrFirstParagraphDateTimeToMax).ToString("HH:mm"));
  527. // }
  528. // else if (string.IsNullOrEmpty(StrFirstParagraphDateTimeToMax) || !string.IsNullOrEmpty(StrSecondParagraphDateTimeToMin))
  529. // {
  530. // //forLateToCount++;
  531. // dataTimeList.Add("time3", StrSecondParagraphDateTimeToMin + "|" + StrDateTime + " " + dtRow["time3"].ToString().Trim());
  532. // StrText = StrText.Replace("C", Convert.ToDateTime(StrSecondParagraphDateTimeToMin).ToString("HH:mm"));
  533. // }
  534. // }
  535. // }
  536. // else
  537. // {
  538. // //forLateToCount++;
  539. // dataTimeList.Add("time3", "");
  540. // StrText = StrText.Replace("C", "");
  541. // }
  542. // }
  543. // //第二班段下班时间
  544. // if (StrText.Trim().IndexOf("D") != -1)
  545. // {
  546. // if (!string.IsNullOrEmpty(StrSecondParagraphDateTimeToMax))
  547. // {
  548. // dataTimeList.Add("time4", StrSecondParagraphDateTimeToMax + "|" + StrDateTime + " " + dtRow["time4"].ToString().Trim());
  549. // StrText = StrText.Replace("D", Convert.ToDateTime(StrSecondParagraphDateTimeToMax).ToString("HH:mm"));
  550. // }
  551. // else
  552. // {
  553. // dataTimeList.Add("time4", "");
  554. // //forEarlyGoCount++;
  555. // StrText = StrText.Replace("D", "");
  556. // }
  557. // }
  558. // }
  559. // #endregion
  560. // //if (forLateToCount > 0)
  561. // //{
  562. // // if (Convert.ToDateTime(SDateTime.Now.ToString("yyyy-MM-dd")) >= Convert.ToDateTime(StrDateTime))
  563. // // { intLateToCount++; }
  564. // //}
  565. // //if (forEarlyGoCount > 0)
  566. // //{
  567. // // if (Convert.ToDateTime(SDateTime.Now.ToString("yyyy-MM-dd")) >= Convert.ToDateTime(StrDateTime))
  568. // // { intEarlyGoCount++; }
  569. // //}
  570. // //if (!string.IsNullOrEmpty(dtRow["time3"].ToString().Trim()))
  571. // //{
  572. // // if (StrText.Trim().IndexOf("A") != -1 && StrText.Trim().IndexOf("B") != -1 && StrText.Trim().IndexOf("C") != -1 && StrText.Trim().IndexOf("D") != -1)
  573. // // { intKuangGongCount++; }
  574. // //}
  575. // //else if (StrText.Trim().IndexOf("A") != -1 && StrText.Trim().IndexOf("B") != -1)
  576. // //{ intKuangGongCount++; }
  577. // StrValueText += StrText.Trim();
  578. // IsFindValueText = false;
  579. // }
  580. // #endregion
  581. // }
  582. // if (IsFindValueText)
  583. // {
  584. // #region 没有安排班次
  585. // #region 处理签到
  586. // string StrText = "[A-B]";
  587. // if (StrTextString.IndexOf(LYFZ.EnumPublic.AttendanceSignType.StrAllDay.Trim()) != -1 || StrTextString.IndexOf(LYFZ.EnumPublic.AttendanceSignType.StrFirstParagraph_GoToAndOffWork.Trim()) != -1 || StrTextString.IndexOf(LYFZ.EnumPublic.AttendanceSignType.StrFirstParagraph_GoToAndOffWork.Trim()) != -1)
  588. // {
  589. // dataTimeList.Add("time1", "签单");
  590. // dataTimeList.Add("time2", "签单");
  591. // StrText = StrText.Replace("A", "签单").Replace("B", "签单");
  592. // }
  593. // if (StrTextString.IndexOf(LYFZ.EnumPublic.AttendanceSignType.StrFirstParagraph_GoToWork.Trim()) != -1 || StrTextString.IndexOf(LYFZ.EnumPublic.AttendanceSignType.StrSecondParagraph_GoToWork.Trim()) != -1)
  594. // {
  595. // dataTimeList.Add("time1", "签单");
  596. // StrText = StrText.Replace("A", "签单");
  597. // }
  598. // if (StrTextString.IndexOf(LYFZ.EnumPublic.AttendanceSignType.StrFirstParagraph_GoOffWork.Trim()) != -1 || StrTextString.IndexOf(LYFZ.EnumPublic.AttendanceSignType.StrSecondParagraph_GoOffWork.Trim()) != -1)
  599. // {
  600. // dataTimeList.Add("time2", "签单");
  601. // StrText = StrText.Replace("B", "签单");
  602. // }
  603. // #endregion
  604. // #region 获取一天的最早的打卡上班时间与最晚的打卡下班时间
  605. // if (StrText.Trim().IndexOf("A") != -1 || StrText.Trim().IndexOf("B") != -1)
  606. // {
  607. // //获取一天的最早的打卡上班时间与最晚的打卡下班时间
  608. // string StrFirstParagraphDateTimeGoUp = "";
  609. // string StrFirstParagraphDateTimeDown = "";
  610. // for (int k = 0; k < dtRows_Kaoqin.Length; k++)
  611. // {
  612. // if (!string.IsNullOrEmpty(StrFirstParagraphDateTimeGoUp))
  613. // {
  614. // if (Convert.ToDateTime(dtRows_Kaoqin[k]["datetime"]) < Convert.ToDateTime(StrFirstParagraphDateTimeGoUp))
  615. // { StrFirstParagraphDateTimeGoUp = Convert.ToDateTime(dtRows_Kaoqin[k]["datetime"]).ToString("yyyy-MM-dd HH:mm"); }
  616. // }
  617. // else
  618. // { StrFirstParagraphDateTimeGoUp = Convert.ToDateTime(dtRows_Kaoqin[k]["datetime"]).ToString("yyyy-MM-dd HH:mm"); }
  619. // if (!string.IsNullOrEmpty(StrFirstParagraphDateTimeDown))
  620. // {
  621. // if (Convert.ToDateTime(dtRows_Kaoqin[k]["datetime"]) > Convert.ToDateTime(StrFirstParagraphDateTimeDown))
  622. // { StrFirstParagraphDateTimeDown = Convert.ToDateTime(dtRows_Kaoqin[k]["datetime"]).ToString("yyyy-MM-dd HH:mm"); }
  623. // }
  624. // else
  625. // { StrFirstParagraphDateTimeDown = Convert.ToDateTime(dtRows_Kaoqin[k]["datetime"]).ToString("yyyy-MM-dd HH:mm"); }
  626. // }
  627. // //替换打卡时间点
  628. // if (!string.IsNullOrEmpty(StrFirstParagraphDateTimeGoUp))
  629. // {
  630. // if (StrFirstParagraphDateTimeGoUp == StrFirstParagraphDateTimeDown)
  631. // {
  632. // if (StrText.Trim().IndexOf("A") != -1 && StrText.Trim().IndexOf("B") != -1)
  633. // {
  634. // dataTimeList.Add("time1", StrFirstParagraphDateTimeGoUp );
  635. // StrText = StrText.Trim().Replace("A", Convert.ToDateTime(StrFirstParagraphDateTimeGoUp).ToString("HH:mm"));
  636. // }
  637. // else if (StrText.Trim().IndexOf("A") != -1 && StrText.Trim().IndexOf("B") == -1)
  638. // {
  639. // dataTimeList.Add("time1", StrFirstParagraphDateTimeGoUp);
  640. // StrText = StrText.Trim().Replace("A", Convert.ToDateTime(StrFirstParagraphDateTimeGoUp).ToString("HH:mm"));
  641. // }
  642. // else if (StrText.Trim().IndexOf("A") == -1 && StrText.Trim().IndexOf("B") != -1)
  643. // {
  644. // dataTimeList.Add("time2", StrFirstParagraphDateTimeGoUp);
  645. // StrText = StrText.Trim().Replace("B", Convert.ToDateTime(StrFirstParagraphDateTimeGoUp).ToString("HH:mm"));
  646. // }
  647. // }
  648. // else
  649. // {
  650. // dataTimeList.Add("time1", StrFirstParagraphDateTimeGoUp);
  651. // dataTimeList.Add("time2", StrFirstParagraphDateTimeDown);
  652. // StrText = StrText.Trim().Replace("A", Convert.ToDateTime(StrFirstParagraphDateTimeGoUp).ToString("HH:mm"));
  653. // StrText = StrText.Trim().Replace("B", Convert.ToDateTime(StrFirstParagraphDateTimeDown).ToString("HH:mm"));
  654. // }
  655. // }
  656. // if (StrText.Trim().IndexOf("A") != -1 && StrText.Trim().IndexOf("B") != -1)
  657. // {
  658. // //intKuangGongCount++;
  659. // dataTimeList.Add("time1", "");
  660. // dataTimeList.Add("time2", "");
  661. // StrText = StrText.Trim().Replace("A", "");
  662. // StrText = StrText.Trim().Replace("B", "");
  663. // }
  664. // if (StrText.Trim().IndexOf("A") != -1 && StrText.Trim().IndexOf("B") == -1)
  665. // {
  666. // //if (Convert.ToDateTime(SDateTime.Now.ToString("yyyy-MM-dd")) >= Convert.ToDateTime(StrDateTime))
  667. // //{ intLateToCount++; }
  668. // dataTimeList.Add("time1", "");
  669. // StrText = StrText.Trim().Replace("A", "");
  670. // }
  671. // if (StrText.Trim().IndexOf("A") == -1 && StrText.Trim().IndexOf("B") != -1)
  672. // {
  673. // //if (Convert.ToDateTime(SDateTime.Now.ToString("yyyy-MM-dd")) >= Convert.ToDateTime(StrDateTime))
  674. // //{ intEarlyGoCount++; }
  675. // dataTimeList.Add("time2", "");
  676. // StrText = StrText.Trim().Replace("B", "");
  677. // }
  678. // }
  679. // #endregion
  680. // StrValueText = StrText.Trim();
  681. // #endregion
  682. // }
  683. // newdtRow[j.ToString().Trim()] = StrValueText.Trim();
  684. // #region 考勤情况统计
  685. // var values = dataTimeList.Values;
  686. // List<string> vals = new List<string>(values);
  687. // string[] strVals = (from val in vals where val != "" select val).ToArray();
  688. // if(strVals.Length==0)
  689. // {
  690. // intKuangGongCount++;
  691. // }
  692. // else
  693. // {
  694. // if(strVals.Length>0&&vals.Count!=strVals.Length)
  695. // {
  696. // intMissedPunch++;
  697. // }
  698. // else
  699. // {
  700. // if(strVals.Length==2)
  701. // {
  702. // string[] stvalus = strVals[0].Split('|');
  703. // string[] envalus = strVals[1].Split('|');
  704. // if (stvalus.Length > 1)
  705. // {
  706. // if(Convert.ToDateTime(stvalus[0])>Convert.ToDateTime(stvalus[1]))
  707. // {
  708. // intLateToCount++;
  709. // }
  710. // }
  711. // if (envalus.Length > 1)
  712. // {
  713. // if (Convert.ToDateTime(envalus[0]) < Convert.ToDateTime(envalus[1]))
  714. // {
  715. // intEarlyGoCount++;
  716. // }
  717. // }
  718. // }
  719. // else if (strVals.Length == 4)
  720. // {
  721. // string[] stvalus1 = strVals[0].Split('|');
  722. // string[] envalus1 = strVals[1].Split('|');
  723. // string[] stvalus2 = strVals[2].Split('|');
  724. // string[] envalus2 = strVals[3].Split('|');
  725. // if (stvalus1.Length > 1)
  726. // {
  727. // if (Convert.ToDateTime(stvalus1[0]) > Convert.ToDateTime(stvalus1[1]))
  728. // {
  729. // intLateToCount++;
  730. // }
  731. // }
  732. // if (stvalus1.Length > 1)
  733. // {
  734. // if (Convert.ToDateTime(stvalus1[0]) < Convert.ToDateTime(stvalus1[1]))
  735. // {
  736. // intEarlyGoCount++;
  737. // }
  738. // }
  739. // if (stvalus2.Length > 1)
  740. // {
  741. // if (Convert.ToDateTime(stvalus2[0]) > Convert.ToDateTime(stvalus2[1]))
  742. // {
  743. // intLateToCount++;
  744. // }
  745. // }
  746. // if (stvalus2.Length > 1)
  747. // {
  748. // if (Convert.ToDateTime(stvalus2[0]) < Convert.ToDateTime(stvalus2[1]))
  749. // {
  750. // intEarlyGoCount++;
  751. // }
  752. // }
  753. // }
  754. // }
  755. // }
  756. // #endregion
  757. // //switch (j)
  758. // //{
  759. // // case 0: newdtRow["星期日"] = StrValueText; break;
  760. // // case 1: newdtRow["星期一"] = StrValueText; break;
  761. // // case 2: newdtRow["星期二"] = StrValueText; break;
  762. // // case 3: newdtRow["星期三"] = StrValueText; break;
  763. // // case 4: newdtRow["星期四"] = StrValueText; break;
  764. // // case 5: newdtRow["星期五"] = StrValueText; break;
  765. // // case 6: newdtRow["星期六"] = StrValueText; break;
  766. // //}
  767. // }
  768. // catch { MessageBoxCustom.Show(i.ToString() + " " + j.ToString() + " " + new System.Diagnostics.StackTrace(new System.Diagnostics.StackFrame(true)).ToString()); }
  769. // }
  770. // #endregion
  771. // newdtRow["编号"] = dt.Rows[i]["User_EmployeeID"].ToString().Trim();
  772. // newdtRow["姓名"] = dt.Rows[i]["User_Name"].ToString().Trim();
  773. // newdtRow["迟到"] = intLateToCount.ToString().Trim();
  774. // newdtRow["早退"] = intEarlyGoCount.ToString().Trim();
  775. // newdtRow["旷工"] = intKuangGongCount.ToString().Trim();
  776. // newdtRow["漏打卡"] = intMissedPunch.ToString().Trim();
  777. // newTable.Rows.Add(newdtRow);
  778. //}
  779. #endregion
  780. });
  781. return newTable;
  782. }
  783. /// <summary>
  784. /// 新考勤统计
  785. /// </summary>
  786. /// <param name="dtSet"></param>
  787. /// <param name="newTable"></param>
  788. void BindAttendanceStatistics(DataSet dtSet, DataTable newTable, string StrWeekStartDate ,int WorkCount)
  789. {
  790. DataTable dt = dtSet.Tables["ds"];
  791. DataTable dtPaibanSet = dtSet.Tables["ds1"];
  792. //dtPaibanSet.PrimaryKey = new DataColumn[] { dtPaibanSet.Columns["User_ID"], dtPaibanSet.Columns["Time"] };
  793. DataTable dtKaoqin = dtSet.Tables["ds2"];
  794. DataTable dtQiandao = dtSet.Tables["ds3"];
  795. DataTable dtBanchiSet = dtSet.Tables["ds4"];
  796. Dictionary<string, dynamic> userCheckWork = new Dictionary<string, dynamic>();
  797. foreach (DataRow dr in dt.Rows)
  798. {
  799. string StrUserName = dr["User_Name"].ToString().Trim();
  800. string EmployeeID = dr["User_EmployeeID"].ToString().Trim();
  801. List<string> fingers = new List<string>();
  802. if(!string.IsNullOrEmpty(dr["User_FirstFingerprintID"].ToString().Trim()))
  803. {
  804. fingers.Add(dr["User_FirstFingerprintID"].ToString());
  805. }
  806. if (!string.IsNullOrEmpty(dr["User_SecondaryFingerprintID"].ToString().Trim()))
  807. {
  808. fingers.Add(dr["User_SecondaryFingerprintID"].ToString());
  809. }
  810. DataRow newdtRow = newTable.NewRow();
  811. int intLateToCount = 0;
  812. int intEarlyGoCount = 0;
  813. int intKuangGongCount = 0;
  814. int intMissedPunch = 0;
  815. int restCount = 0;
  816. int leaveCount = 0;
  817. #region 处理一个星期的每天考勤情况
  818. for (int j = 0; j < WorkCount; j++)
  819. {
  820. try
  821. {
  822. ///获取当前时间
  823. DateTime staWeekTime = Convert.ToDateTime(StrWeekStartDate).AddDays(j);
  824. ///休息数据
  825. List<DataRow> restConfigList = dtPaibanSet.AsEnumerable().Where(
  826. p =>
  827. p.Field<string>("User_ID") == EmployeeID &&
  828. p.Field<DateTime>("Time").ToString("yyyy-MM-dd") == staWeekTime.ToString("yyyy-MM-dd") &&
  829. p.Field<string>("fixed").ToString()=="休息").ToList();
  830. List<DataRow> leaveConfigList = dtPaibanSet.AsEnumerable().Where(
  831. p =>
  832. p.Field<string>("User_ID") == EmployeeID &&
  833. p.Field<DateTime>("Time").ToString("yyyy-MM-dd") == staWeekTime.ToString("yyyy-MM-dd") &&
  834. p.Field<string>("fixed") == "请假").ToList();
  835. ///获取配置的时间段
  836. List<DataRow> workConfig = dtPaibanSet.AsEnumerable().Where(p => p.Field<string>("User_ID") == EmployeeID && p.Field<DateTime>("Time").ToString("yyyy-MM-dd") == staWeekTime.ToString("yyyy-MM-dd")).ToList();
  837. if (workConfig.Count > 0)
  838. {
  839. workConfig = dtBanchiSet.AsEnumerable().Where(p => p.Field<string>("name") == workConfig[0]["fixed"].ToString()).ToList();
  840. }
  841. ///获取会员当天配置好的打卡时间段
  842. List<dynamic> dySignList = new List<dynamic>();
  843. List<DataRow> dtKaoqinDr = dtKaoqin.AsEnumerable().Where(p =>
  844. ("," + string.Join(",", fingers.ToArray()) + ",").IndexOf("," + p.Field<string>("no") + ",") != -1
  845. && p.Field<string>("datetime").Trim().Split(' ')[0] == staWeekTime.ToString("yyyy-MM-dd")
  846. ).ToList();
  847. foreach (DataRow kqDr in dtKaoqinDr)
  848. {
  849. DateTime tempDateTime;
  850. if (DateTime.TryParse(kqDr["datetime"].ToLowerString(), out tempDateTime))
  851. {
  852. dynamic dyObj = new ExpandoObject();
  853. dyObj.TypeName = "";
  854. dyObj.DateTime = tempDateTime;
  855. dySignList.Add(dyObj);
  856. }
  857. }
  858. if(restConfigList.Count>0)
  859. {
  860. restCount++;
  861. }
  862. if(leaveConfigList.Count>0)
  863. {
  864. leaveCount++;
  865. }
  866. //获取签卡的时间段
  867. dtKaoqinDr = dtQiandao.AsEnumerable().Where(p =>
  868. p.Field<string>("user_id")== EmployeeID
  869. && p.Field<string>("date").Trim().Split(' ')[0] == staWeekTime.ToString("yyyy-MM-dd")
  870. ).ToList();
  871. foreach (DataRow kqDr in dtKaoqinDr)
  872. {
  873. DateTime tempDateTime;
  874. if (DateTime.TryParse(kqDr["date"].ToLowerString(), out tempDateTime))
  875. {
  876. dynamic dyObj = new ExpandoObject();
  877. dyObj.TypeName = kqDr["type"].ToString_s();
  878. dyObj.DateTime = tempDateTime;
  879. dySignList.Add(dyObj);
  880. }
  881. }
  882. ///签到时间排序,升序
  883. dySignList = dySignList.OrderBy(a => a.DateTime).ToList();
  884. if (dySignList.Count > 0)
  885. {
  886. ///存在排班
  887. if (workConfig.Count > 0)
  888. {
  889. List<dynamic> dyList = new List<dynamic>();
  890. ///排班阶段数据提取
  891. if(!string.IsNullOrEmpty(workConfig[0]["time1"].ToString_s()))
  892. {
  893. dynamic dyObj = new ExpandoObject();
  894. dyObj.StartTime = Convert.ToDateTime(staWeekTime.ToString("yyyy-MM-dd")+" " + workConfig[0]["time1"].ToString_s());
  895. dyObj.EndTime = Convert.ToDateTime(staWeekTime.ToString("yyyy-MM-dd") + " " + workConfig[0]["time2"].ToString_s());
  896. dyList.Add(dyObj);
  897. }
  898. if (!string.IsNullOrEmpty(workConfig[0]["time3"].ToString_s()))
  899. {
  900. dynamic dyObj = new ExpandoObject();
  901. dyObj.StartTime = Convert.ToDateTime(staWeekTime.ToString("yyyy-MM-dd") + " " + workConfig[0]["time3"].ToString_s());
  902. dyObj.EndTime = Convert.ToDateTime(staWeekTime.ToString("yyyy-MM-dd") + " " + workConfig[0]["time4"].ToString_s());
  903. dyList.Add(dyObj);
  904. }
  905. string typeText = "";
  906. ///存在排班数据
  907. if(dyList.Count>0)
  908. {
  909. ///只有一个阶段的排班
  910. if(dyList.Count==1)
  911. {
  912. ///获取开始时间和结束时间,开始时间和结束时间对排班数据进行
  913. string stimeDatet = "";
  914. string etimeDatet = "";
  915. TimeSpan timeSpan = dyList[0].EndTime - dyList[0].StartTime;
  916. int hourValue = timeSpan.Hours;
  917. if(dySignList[0].DateTime> dyList[0].StartTime.AddHours(-2)&& dySignList[0].DateTime< dyList[0].StartTime.AddHours(hourValue/2))
  918. {
  919. }
  920. else
  921. {
  922. dynamic dyObj = new ExpandoObject();
  923. dyObj.TypeName = "无数据";
  924. dyObj.DateTime = null;
  925. dySignList.Insert(0,dyObj);
  926. }
  927. //排班对打卡时间进行比较判断是否迟到
  928. if (dySignList[0].TypeName != "无数据")
  929. {
  930. if (dyList[0].StartTime < dySignList[0].DateTime)
  931. {
  932. if (restConfigList.Count == 0 && leaveConfigList.Count == 0)
  933. {
  934. intLateToCount++;
  935. typeText = "迟到";
  936. }
  937. }
  938. stimeDatet = string.IsNullOrEmpty(dySignList[0].TypeName) ? dySignList[0].DateTime.ToString("HH:mm") : dySignList[0].TypeName;
  939. }
  940. else
  941. {
  942. intMissedPunch++;
  943. typeText = "漏";
  944. stimeDatet = "";
  945. }
  946. //排班对打卡时间进行比较判断早退还是漏打卡
  947. if (dyList[0].EndTime > dySignList[dySignList.Count-1].DateTime )
  948. {
  949. if ((dySignList.Count - 1) > 0)
  950. {
  951. if (restConfigList.Count == 0 && leaveConfigList.Count == 0)
  952. {
  953. intEarlyGoCount++;
  954. typeText = "早退";
  955. }
  956. }
  957. else
  958. {
  959. if (restConfigList.Count == 0 && leaveConfigList.Count == 0)
  960. {
  961. intMissedPunch++;
  962. typeText = "漏";
  963. }
  964. }
  965. }
  966. if ((dySignList.Count - 1) > 0)
  967. {
  968. etimeDatet = string.IsNullOrEmpty(dySignList[dySignList.Count - 1].TypeName) ? dySignList[dySignList.Count - 1].DateTime.ToString("HH:mm") : dySignList[dySignList.Count - 1].TypeName;
  969. }
  970. else
  971. {
  972. etimeDatet = "";
  973. }
  974. newdtRow[j.ToString()] = workConfig[0]["name"]+"[" + stimeDatet + "-" + etimeDatet + "]"+(string.IsNullOrEmpty(typeText)?"":"("+ typeText + ")");
  975. }
  976. else
  977. {
  978. ///将排班信息进行分组,分成3组
  979. List<dynamic> group1 = dySignList.Where(p => p.DateTime < dyList[0].EndTime).ToList();
  980. List<dynamic> group2 = dySignList.Where(p => p.DateTime >= dyList[0].EndTime && p.DateTime <= dyList[1].StartTime).ToList();
  981. List<dynamic> group3 = dySignList.Where(p => p.DateTime > dyList[1].StartTime).ToList();
  982. string stime1 = "";
  983. string etime1 = "";
  984. string stime2 = "";
  985. string etime2 = "";
  986. if(group1.Count>0)
  987. {
  988. stime1 = group1[0].DateTime.ToString("HH:mm");
  989. //if(dyList[0].StartTime< group1[0].DateTime)
  990. //{
  991. //}
  992. }
  993. if (group2.Count == 0)
  994. {
  995. etime1 = (group1.Count > 1 ? group1[group1.Count - 1].DateTime.ToString("HH:mm") : "");
  996. stime2 = (group3.Count > 0) ? group3[0].DateTime.ToString("HH:mm") : "";
  997. }
  998. else if (group2.Count == 1)
  999. {
  1000. TimeSpan timeSpan = dyList[1].StartTime - dyList[0].EndTime;
  1001. double halfMinu = timeSpan.TotalMinutes / 2;
  1002. if (dyList[0].EndTime.AddMinutes(Convert.ToInt32(halfMinu)) >= group2[0].DateTime)
  1003. {
  1004. etime1 = group2[0].DateTime.ToString("HH:mm");
  1005. if (group3.Count == 1)
  1006. {
  1007. timeSpan = dyList[1].EndTime - dyList[1].StartTime;
  1008. halfMinu = timeSpan.TotalMinutes / 2;
  1009. if (dyList[1].StartTime.AddMinutes(Convert.ToInt32(halfMinu)) >= group3[0].DateTime)
  1010. {
  1011. stime2 = group3[0].DateTime.ToString("HH:mm");
  1012. }
  1013. else
  1014. {
  1015. etime2 = group3[0].DateTime.ToString("HH:mm");
  1016. }
  1017. }
  1018. else
  1019. {
  1020. stime2 = group3[0].DateTime.ToString("HH:mm");
  1021. }
  1022. }
  1023. else
  1024. {
  1025. stime2 = group2[0].DateTime.ToString("HH:mm");
  1026. if (group1.Count > 1)
  1027. {
  1028. DateTime tempEndTime = group1[group1.Count - 1].DateTime;
  1029. if (tempEndTime > dyList[0].EndTime.AddMinutes(-Convert.ToInt32(halfMinu)))
  1030. {
  1031. etime1= tempEndTime.ToString("HH:mm");
  1032. }
  1033. }
  1034. }
  1035. }
  1036. else
  1037. {
  1038. etime1 = group2[0].DateTime.ToString("HH:mm");
  1039. stime2 = group2[group2.Count - 1].DateTime.ToString("HH:mm");
  1040. if (group3.Count == 1)
  1041. {
  1042. TimeSpan timeSpan = dyList[1].EndTime - dyList[1].StartTime;
  1043. double halfMinu = timeSpan.TotalMinutes / 2;
  1044. if (dyList[1].StartTime.AddMinutes(Convert.ToInt32(halfMinu)) < group3[0].DateTime)
  1045. {
  1046. etime2 = group3[0].DateTime.ToString("HH:mm");
  1047. }
  1048. }
  1049. }
  1050. if (group3.Count > 0)
  1051. {
  1052. etime2 = group3[group3.Count - 1].DateTime.ToString("HH:mm");
  1053. if (etime2 == stime2)
  1054. {
  1055. stime2 = "";
  1056. }
  1057. }
  1058. if (string.IsNullOrEmpty(stime1) && string.IsNullOrEmpty(etime1) && string.IsNullOrEmpty(stime2) && string.IsNullOrEmpty(etime2))
  1059. {
  1060. if (restConfigList.Count == 0 && leaveConfigList.Count == 0)
  1061. {
  1062. intKuangGongCount++;
  1063. typeText = "旷";
  1064. }
  1065. }
  1066. else if (string.IsNullOrEmpty(stime1)|| string.IsNullOrEmpty(etime1) || string.IsNullOrEmpty(stime2) || string.IsNullOrEmpty(etime2))
  1067. {
  1068. if (restConfigList.Count == 0 && leaveConfigList.Count == 0)
  1069. {
  1070. intMissedPunch++;
  1071. typeText = "漏";
  1072. }
  1073. }
  1074. if(!string.IsNullOrEmpty(workConfig[0]["time3"].ToString_s()))
  1075. {
  1076. if (Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " " + workConfig[0]["time1"]) <
  1077. Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " " + stime1) ||
  1078. Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " " + workConfig[0]["time3"]) <
  1079. Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " " + stime2))
  1080. {
  1081. if (restConfigList.Count == 0 && leaveConfigList.Count == 0)
  1082. {
  1083. intLateToCount++;
  1084. typeText = "迟到";
  1085. }
  1086. }
  1087. }
  1088. else
  1089. {
  1090. if (Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " " + workConfig[0]["time1"]) <
  1091. Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " " + stime1))
  1092. {
  1093. if (restConfigList.Count == 0 && leaveConfigList.Count == 0)
  1094. {
  1095. intLateToCount++;
  1096. typeText = "迟到";
  1097. }
  1098. }
  1099. }
  1100. if (!string.IsNullOrEmpty(workConfig[0]["time3"].ToString_s()))
  1101. {
  1102. if (Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " " + workConfig[0]["time2"]) >
  1103. Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " " + etime1) ||
  1104. Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " " + workConfig[0]["time4"]) >
  1105. Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " " + etime2))
  1106. {
  1107. if (restConfigList.Count == 0 && leaveConfigList.Count == 0)
  1108. {
  1109. intEarlyGoCount++;
  1110. typeText = "早退";
  1111. }
  1112. }
  1113. }
  1114. else
  1115. {
  1116. if (Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " " + workConfig[0]["time2"]) >
  1117. Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " " + etime1))
  1118. {
  1119. if (restConfigList.Count == 0 && leaveConfigList.Count == 0)
  1120. {
  1121. intEarlyGoCount++;
  1122. typeText = "早退";
  1123. }
  1124. }
  1125. }
  1126. if (restConfigList.Count > 0 || leaveConfigList.Count > 0)
  1127. {
  1128. newdtRow[j.ToString()] = workConfig[0]["name"].ToString_s() + "[" + stime1 + " -" + etime1 + "]" + "[" + stime2 + " -" + etime2 + "]"
  1129. + (restConfigList.Count > 0 ? "(休)" : "") + (leaveConfigList.Count > 0 ? "(假)" : "");
  1130. }
  1131. else
  1132. {
  1133. newdtRow[j.ToString()] = workConfig[0]["name"].ToString_s() + "[" + stime1 + " -" + etime1 + "]" + "[" + stime2 + " -" + etime2 + "]"
  1134. + (string.IsNullOrEmpty(typeText) ? "" : "(" + typeText + ")");
  1135. }
  1136. }
  1137. }
  1138. else
  1139. {
  1140. TimeSpan timeSpan = dyList[0].EndTime - dyList[0].StartTime;
  1141. int hourValue = timeSpan.Hours;
  1142. if (dySignList[0].DateTime > dyList[0].StartTime.AddHours(-2) && dySignList[0].DateTime < dyList[0].StartTime.AddHours(hourValue / 2))
  1143. {
  1144. }
  1145. else
  1146. {
  1147. dynamic dyObj = new ExpandoObject();
  1148. dyObj.TypeName = "无数据";
  1149. dyObj.DateTime = null;
  1150. dySignList.Insert(0, dyObj);
  1151. }
  1152. string timeDatet = "";
  1153. if (dySignList[0].TypeName != "无数据")
  1154. {
  1155. timeDatet = string.IsNullOrEmpty(dySignList[0].TypeName) ? dySignList[0].DateTime.ToString("HH:mm") : dySignList[0].TypeName;
  1156. }
  1157. if (dySignList.Count > 1)
  1158. {
  1159. newdtRow[j.ToString()] = "[" + timeDatet + " - " + (string.IsNullOrEmpty(dySignList[dySignList.Count - 1].TypeName) ?
  1160. dySignList[dySignList.Count - 1].DateTime.ToString("HH:mm") :
  1161. dySignList[dySignList.Count - 1].TypeName) + "]" +
  1162. (restConfigList.Count > 0 ? "(休)" : "") + (leaveConfigList.Count > 0 ? "(假)" : "");
  1163. }
  1164. else
  1165. {
  1166. if (restConfigList.Count == 0 && leaveConfigList.Count == 0)
  1167. {
  1168. intMissedPunch++;
  1169. }
  1170. if (restConfigList.Count > 0 || leaveConfigList.Count > 0)
  1171. {
  1172. newdtRow[j.ToString()] = "[" + timeDatet + " -" + "]" + (restConfigList.Count > 0 ? "(休)" : "") + (leaveConfigList.Count > 0 ? "(假)" : "");
  1173. }
  1174. else
  1175. {
  1176. newdtRow[j.ToString()] = "[" + timeDatet + " -" + "](漏)";
  1177. }
  1178. }
  1179. }
  1180. }
  1181. else
  1182. {
  1183. string timeDatet = string.IsNullOrEmpty(dySignList[0].TypeName) ? dySignList[0].DateTime.ToString("HH:mm") : dySignList[0].TypeName;
  1184. if(dySignList.Count>1)
  1185. {
  1186. newdtRow[j.ToString()] ="["+ timeDatet + " - " + (string.IsNullOrEmpty(dySignList[dySignList.Count - 1].TypeName) ?
  1187. dySignList[dySignList.Count - 1].DateTime.ToString("HH:mm") :
  1188. dySignList[dySignList.Count - 1].TypeName)+"]" + (restConfigList.Count > 0 ? "(休)" : "") + (leaveConfigList.Count > 0 ? "(假)" : "");
  1189. }
  1190. else
  1191. {
  1192. if (restConfigList.Count == 0 && leaveConfigList.Count == 0)
  1193. {
  1194. intMissedPunch++;
  1195. }
  1196. if (restConfigList.Count > 0 || leaveConfigList.Count > 0)
  1197. {
  1198. newdtRow[j.ToString()] = "[" + timeDatet + " -" + "]" + (restConfigList.Count > 0 ? "(休)" : "") + (leaveConfigList.Count > 0 ? "(假)" : "");
  1199. }
  1200. else
  1201. {
  1202. newdtRow[j.ToString()] = "[" + timeDatet + " -" + "](漏)";
  1203. }
  1204. }
  1205. }
  1206. }
  1207. else
  1208. {
  1209. if (restConfigList.Count == 0 && leaveConfigList.Count == 0)
  1210. {
  1211. intKuangGongCount++;
  1212. }
  1213. if (restConfigList.Count > 0 || leaveConfigList.Count > 0)
  1214. {
  1215. newdtRow[j.ToString()] = "[" + "-" + "]" + (restConfigList.Count > 0 ? "(休)" : "") + (leaveConfigList.Count > 0 ? "(假)" : "");
  1216. }
  1217. else
  1218. {
  1219. newdtRow[j.ToString()] = "[" + "-" + "](旷)";
  1220. }
  1221. }
  1222. }
  1223. catch (Exception e)
  1224. {
  1225. intKuangGongCount++;
  1226. newdtRow[j.ToString()] = "[" + "-" + "](旷)";
  1227. }
  1228. }
  1229. newdtRow["编号"] = EmployeeID.Trim();
  1230. newdtRow["姓名"] = StrUserName.Trim();
  1231. newdtRow["迟到"] = intLateToCount.ToString().Trim();
  1232. newdtRow["早退"] = intEarlyGoCount.ToString().Trim();
  1233. newdtRow["旷工"] = intKuangGongCount.ToString().Trim();
  1234. newdtRow["漏打卡"] = intMissedPunch.ToString().Trim();
  1235. newdtRow["休息"] = restCount.ToString().Trim();
  1236. newdtRow["请假"] = leaveCount.ToString().Trim();
  1237. newTable.Rows.Add(newdtRow);
  1238. #endregion
  1239. }
  1240. }
  1241. /// <summary>
  1242. /// 更改日期
  1243. /// </summary>
  1244. /// <param name="SelectValue"></param>
  1245. void dtpYearMonth_ClickChengedValue(string SelectValue)
  1246. {
  1247. this.dtpYearMonth.Visible = true;
  1248. this.panelLastNextWeek.Visible = false;
  1249. if (string.IsNullOrEmpty(this.dtpYearMonth.StrDateValue.Trim()))
  1250. { MessageBoxCustom.Show("请选择要排班的月份!"); return; }
  1251. int IntMonthDay = DateTime.DaysInMonth(this.dtpYearMonth.StrYear, this.dtpYearMonth.StrMonth);
  1252. string StrWeekStartDate = this.dtpYearMonth.StrDateValue + "-01";
  1253. string StrWeekEndDate = Convert.ToDateTime(StrWeekStartDate).AddMonths(1).AddSeconds(-1).ToString("yyyy-MM-dd");
  1254. DataTable newTable = this.GetWorkData(StrWeekStartDate, StrWeekEndDate, IntMonthDay,((ItemValue)GetCompanyDataInfo()).Value.ToString_s());
  1255. this.dgvData.Rows.Clear();
  1256. string StrColumnName = "编号,姓名,迟到,早退,旷工,漏打卡,休息,请假";
  1257. this.dgvData.DataColumns(StrColumnName, strHideField: "编号");
  1258. DataGridViewColumn column = null;
  1259. for (int i = 1; i <= IntMonthDay; i++)
  1260. {
  1261. StrColumnName = i + "日\r\n" + Convert.ToDateTime(this.dtpYearMonth.StrDateValue + "-01").AddDays(i - 1).ToString("dddd") + "";
  1262. column = new DataGridViewColumn();
  1263. column.ReadOnly = true;
  1264. column.Name = StrColumnName;
  1265. column.HeaderText = StrColumnName;
  1266. column.Tag = Convert.ToDateTime(this.dtpYearMonth.StrDateValue + "-01").AddDays(i - 1).ToString("yyyy-MM-dd");
  1267. this.dgvData.Columns.Add(column);
  1268. }
  1269. //this.dgvData.DataColumns(StrColumnName);
  1270. this.dgvData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  1271. this.dgvData.Columns["姓名"].Frozen = true;
  1272. for (int i = 0; i < this.dgvData.Columns.Count; i++)
  1273. {
  1274. switch (this.dgvData.Columns[i].Name.Trim())
  1275. {
  1276. case "姓名":
  1277. case "迟到":
  1278. case "早退":
  1279. case "旷工":
  1280. case "漏打卡":
  1281. case "休息":
  1282. case "请假":
  1283. this.dgvData.Columns[i].Width = 70;
  1284. break;
  1285. default:
  1286. this.dgvData.Columns[i].Width = 100;
  1287. break;
  1288. }
  1289. }
  1290. DataGridViewRow dgvr = null;
  1291. DataGridViewCell cell = null;
  1292. for (int i = 0; i < newTable.Rows.Count; i++)
  1293. {
  1294. dgvr = new DataGridViewRow();
  1295. dgvr.Height = 48;
  1296. for (int j = 0; j < newTable.Columns.Count; j++)
  1297. {
  1298. cell = new DataGridViewTextBoxCell();
  1299. cell.Style.BackColor = System.Drawing.Color.White;
  1300. string cellValue = newTable.Rows[i][j].ToString().Trim();
  1301. SetCellBackColor(cell,ref cellValue);
  1302. cell.Value = cellValue;
  1303. dgvr.Cells.Add(cell);
  1304. }
  1305. this.dgvData.Rows.Add(dgvr);
  1306. string[] columnsList = "迟到,早退,旷工,漏打卡,休息,请假".Split(',');
  1307. foreach (string strColumn in columnsList)
  1308. {
  1309. string cellText = "";
  1310. switch (strColumn)
  1311. {
  1312. case "迟到":
  1313. case "早退":
  1314. cellText = "(" + strColumn + ")";
  1315. break;
  1316. case "请假":
  1317. cellText = "(假)";
  1318. break;
  1319. default:
  1320. cellText = "(" + strColumn.ToCharArray()[0] + ")";
  1321. break;
  1322. }
  1323. dgvr.Cells[strColumn].Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
  1324. if (Convert.ToDecimal(dgvr.Cells[strColumn].Value) > 0)
  1325. {
  1326. SetCellBackColor(dgvr.Cells[strColumn], ref cellText);
  1327. }
  1328. }
  1329. }
  1330. }
  1331. ///修改单元格的颜色
  1332. void SetCellBackColor(DataGridViewCell cell,ref string cellText)
  1333. {
  1334. if(cellText.Contains("(休)"))
  1335. {
  1336. cell.Style.BackColor = System.Drawing.Color.Green;
  1337. }
  1338. else if (cellText.Contains("(假)"))
  1339. {
  1340. cell.Style.BackColor = System.Drawing.Color.BlueViolet;
  1341. }
  1342. else if (cellText.Contains("(迟到)"))
  1343. {
  1344. cell.Style.BackColor = System.Drawing.Color.Yellow;
  1345. cellText = cellText.Replace("(迟到)", "");
  1346. }
  1347. else if (cellText.Contains("(早退)"))
  1348. {
  1349. cell.Style.BackColor = System.Drawing.Color.YellowGreen;
  1350. cellText = cellText.Replace("(早退)", "");
  1351. }
  1352. else if (cellText.Contains("(漏)"))
  1353. {
  1354. cell.Style.BackColor = System.Drawing.Color.Red;
  1355. cellText = cellText.Replace("(漏)", "");
  1356. }
  1357. else if (cellText.Contains("(旷)"))
  1358. {
  1359. cell.Style.BackColor = System.Drawing.Color.DarkOrange;
  1360. cellText = cellText.Replace("(旷)", "");
  1361. }
  1362. }
  1363. /// <summary>
  1364. /// 周统计
  1365. /// </summary>
  1366. void GetWeekData()
  1367. {
  1368. this.panelLastNextWeek.Visible = true;
  1369. this.dtpYearMonth.Visible = false;
  1370. DataTable newTable = this.GetWorkData(this.WeekStartDate.ToString("yyyy-MM-dd"), this.WeekEndDate.ToString("yyyy-MM-dd"), 7,((ItemValue)GetCompanyDataInfo()).Value.ToString_s());
  1371. this.dgvData.Rows.Clear();
  1372. string StrColumnName = "编号,姓名,迟到,早退,旷工,漏打卡,休息,请假";
  1373. this.dgvData.DataColumns(StrColumnName, strHideField: "编号");
  1374. DataGridViewColumn column = null;
  1375. for (int i = 0; i < 7; i++)
  1376. {
  1377. string StrMonthDay = this.WeekStartDate.AddDays(i).ToString("MM月dd日");
  1378. switch (i)
  1379. {
  1380. case 0: StrColumnName = "星期日\r\n";
  1381. break;
  1382. case 1: StrColumnName = "星期一\r\n";
  1383. break;
  1384. case 2: StrColumnName = "星期二\r\n";
  1385. break;
  1386. case 3: StrColumnName = "星期三\r\n";
  1387. break;
  1388. case 4: StrColumnName = "星期四\r\n";
  1389. break;
  1390. case 5: StrColumnName = "星期五\r\n";
  1391. break;
  1392. case 6: StrColumnName = "星期六\r\n";
  1393. break;
  1394. }
  1395. StrColumnName += StrMonthDay;
  1396. column = new DataGridViewColumn();
  1397. column.ReadOnly = true;
  1398. column.Name = StrColumnName;
  1399. column.HeaderText = StrColumnName;
  1400. column.Tag = this.WeekStartDate.AddDays(i).ToString("yyyy-MM-dd");
  1401. this.dgvData.Columns.Add(column);
  1402. }
  1403. this.dgvData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  1404. //this.dgvData.DataColumns(StrColumnName);
  1405. this.dgvData.Columns["姓名"].Frozen = true;
  1406. int IntdgvDataColumnsCount = this.dgvData.Columns.GetColumnCount(DataGridViewElementStates.Visible);
  1407. int intdgvDataWidth = (this.dgvData.Width - 50 - 280) / (IntdgvDataColumnsCount - 4);
  1408. for (int i = 0; i < this.dgvData.Columns.Count; i++)
  1409. {
  1410. if (i > 7)
  1411. {
  1412. if (intdgvDataWidth < 170)
  1413. { this.dgvData.Columns[i].Width = 170; }
  1414. else
  1415. { this.dgvData.Columns[i].Width = intdgvDataWidth; }
  1416. }
  1417. else
  1418. { this.dgvData.Columns[i].Width = 70; }
  1419. }
  1420. DataGridViewRow dgvr = null;
  1421. DataGridViewCell cell = null;
  1422. for (int i = 0; i < newTable.Rows.Count; i++)
  1423. {
  1424. dgvr = new DataGridViewRow();
  1425. dgvr.Height = 48;
  1426. for (int j = 0; j < newTable.Columns.Count; j++)
  1427. {
  1428. cell = new DataGridViewTextBoxCell();
  1429. cell.Style.BackColor = System.Drawing.Color.White;
  1430. string cellValue = newTable.Rows[i][j].ToString().Trim();
  1431. SetCellBackColor(cell,ref cellValue);
  1432. cell.Value = cellValue;
  1433. dgvr.Cells.Add(cell);
  1434. }
  1435. this.dgvData.Rows.Add(dgvr);
  1436. string[] columnsList = "迟到,早退,旷工,漏打卡,休息,请假".Split(',');
  1437. foreach(string strColumn in columnsList)
  1438. {
  1439. string cellText = "";
  1440. switch(strColumn)
  1441. {
  1442. case "迟到":
  1443. case "早退":
  1444. cellText = "("+ strColumn + ")";
  1445. break;
  1446. case "请假":
  1447. cellText = "(假)";
  1448. break;
  1449. default:
  1450. cellText = "("+ strColumn.ToCharArray()[0] + ")";
  1451. break;
  1452. }
  1453. dgvr.Cells[strColumn].Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
  1454. if (Convert.ToDecimal(dgvr.Cells[strColumn].Value) > 0)
  1455. {
  1456. SetCellBackColor(dgvr.Cells[strColumn],ref cellText);
  1457. }
  1458. }
  1459. }
  1460. }
  1461. ItemValue GetCompanyDataInfo()
  1462. {
  1463. ItemValue itemValue = new ItemValue("", "");
  1464. if (this.cbxCompanyList.Tag != null && this.cbxCompanyList.TreeView.SelectedNode != null)
  1465. {
  1466. string dataValue = this.cbxCompanyList.Tag.ToString();
  1467. string dataType = this.cbxCompanyList.StrGetName.Trim();
  1468. if (dataType.Length > 0)
  1469. {
  1470. switch (dataType.ToLower())
  1471. {
  1472. case "storename":
  1473. itemValue.Value = "and User_DividedShop = '" + dataValue + "'";
  1474. break;
  1475. case "department":
  1476. itemValue.Value = "and User_Department = '" + dataValue + "'";
  1477. break;
  1478. case "user":
  1479. itemValue.Value = "and User_EmployeeID = '" + dataValue + "'";
  1480. break;
  1481. }
  1482. }
  1483. }
  1484. return itemValue;
  1485. }
  1486. }
  1487. }