private void btnDate_Click(object sender, EventArgs e) { List <dWorker> ldWorker = new List <dWorker>(); ldWorker.Clear(); List <worker> listWorker = new List <worker>(); listWorker.Clear(); try { string strqry = "select count(*) from Logs"; server.GetDBTable(strqry); server.sdr.Read(); Int32 nInLastRow = server.sdr.GetInt32(0); server.sdr.Close(); DateTime ot = new DateTime(); strqry = "select * from Logs ORDER BY row"; server.GetDBTable(strqry); int row = 0, rowf = 0; string status = null, tag = null, gate = null; string date = null, pdate = null, pname = null, name = null, job = null; bool isFound = false, isInit = false; lvDate.Items.Clear(); it = Convert.ToDateTime(lblInit.Text); ft = Convert.ToDateTime(lblFinal.Text); if (it.CompareTo(ft) > 0) { it = Convert.ToDateTime(lblFinal.Text); ft = Convert.ToDateTime(lblInit.Text); } for (int i = 0; i < nInLastRow; i++) { server.sdr.Read(); date = server.sdr.GetString(1); ot = DateTime.ParseExact(date, "yyyy-MM-dd-HH:mm:ss", CultureInfo.InvariantCulture); if (ot.CompareTo(it) >= 0) { row = i; break; } } isInit = true; for (int i = row + 1; i < nInLastRow; i++) { server.sdr.Read(); date = server.sdr.GetString(1); ot = DateTime.ParseExact(date, "yyyy-MM-dd-HH:mm:ss", CultureInfo.InvariantCulture); if (isInit) { System.TimeSpan span = new System.TimeSpan(1, 0, 0, 0); ft = ft + span; isInit = false; } if (ot.CompareTo(ft) != -1) { rowf = i; isFound = true; break; } } server.sdr.Close(); if (!isFound) { rowf = nInLastRow; } strqry = "SELECT* FROM Logs where row > " + row + " AND row<" + (rowf) + "order by row"; server.GetDBTable(strqry); for (int i = row; i < rowf; i++) { server.sdr.Read(); date = server.sdr.GetString(1); name = server.sdr.GetString(3); tag = server.sdr.GetString(4); gate = server.sdr.GetString(5); status = server.sdr.GetString(2); //IN/OUT job = server.sdr.GetString(6); //공종 worker wk = new worker(name, job, date, status, tag, gate); listWorker.Add(wk); dWorker dw = new dWorker(name, tag, job, 0, 0); ldWorker.Add(dw); } } catch { } for (int i = ldWorker.Count - 1; i >= 0; i--) { for (int j = i - 1; j >= 0; j--) { if (ldWorker[i].tag == ldWorker[j].tag) { ldWorker.RemoveAt(j); i--; } } } server.sdr.Close(); string[] pday = new string[ldWorker.Count]; bool[] dayflag = new bool[ldWorker.Count]; string ppname = null; string pptag = null; int cnt = ldWorker.Count; for (int i = 0; i < listWorker.Count; i++) { bool foundEnd = false; string Dname = null; string day = null, time = null, day2 = null, time2 = null; string[] gateSplit = listWorker[i].gate.Split('-'); int dt = 0; if (listWorker[i].status.Substring(0, 1) == "입" && gateSplit.Length == 1) //MG 들어오는거 발견 { //Dname = listWorker[i].name; //if (listWorker[i].name != Dname) pday = null; day = listWorker[i].date.Substring(0, 10); time = listWorker[i].date.Substring(11, 5); //출근했으면 for (int j = i + 1; j < listWorker.Count; j++) { string[] gateSplit2 = listWorker[j].gate.Split('-'); //메인게이트 if (listWorker[i].date.Substring(0, 10) == listWorker[j].date.Substring(0, 10)) { if (listWorker[i].name == listWorker[j].name && listWorker[j].status.Substring(0, 1) == "출" && gateSplit2.Length == 1) { time2 = listWorker[j].date.Substring(11, 5); foreach (dWorker dw in ldWorker) { if (dw.tag == listWorker[i].tag && cnt >= 1) //&& listWorker[i].date.Substring(0, 10) == listWorker[j].date.Substring(0, 10)) { if (day != pday[cnt - 1]) { dw.cnt++; cnt--; break; } } } break; } } else { time2 = "18:00"; foreach (dWorker dw in ldWorker) { if (dw.tag == listWorker[i].tag) { dw.cnt++; break; } } break; } } if (cnt >= 0 && cnt < ldWorker.Count) { pday[cnt] = day; } } if (time != null && time2 != null) { DateTime itime = Convert.ToDateTime(time); DateTime ftime = Convert.ToDateTime(time2); if (itime == ftime) { dt = 0; } else { TimeSpan dtime = ftime - itime; dt = dtime.Hours * 60 + dtime.Minutes; } foundEnd = false; } foreach (dWorker dw in ldWorker) { if (dw.tag == listWorker[i].tag) { dw.time += dt; break; } } } foreach (dWorker dw in ldWorker) { ListViewItem item = new ListViewItem(dw.name); item.SubItems.Add(dw.job); item.SubItems.Add(dw.cnt.ToString()); item.SubItems.Add((dw.time / 60).ToString()); lvDate.Items.Add(item); } /* for (int k = lvDate.Items.Count - 1; k >= 0; k--) * { * string na = lvDate.Items[k].SubItems[0].Text; * string ti = lvDate.Items[k].SubItems[2].Text; * for (int l = k - 1; l >= 0; l--) * { * if (na == lvDate.Items[l].SubItems[0].Text && ti == lvDate.Items[l].SubItems[2].Text) * { * lvDate.Items.RemoveAt(l); * k--; * } * } * }*/ }
public TabbedPage1(List <TodoItem> GridTodoItems) { InitializeComponent(); manager = TodoItemManager.DefaultManager; LTodoItem.Clear(); Lwhole.Clear(); Lworker.Clear(); ldWorker.Clear(); DateTime today = DateTime.Now; //today = DateTime.ParseExact(today, "yyyy-MM-dd-HH:mm:ss", CultureInfo.InvariantCulture); List <TodoItem> GridTodoItem = GridTodoItems.OrderBy(x => x.row).ToList(); List <TodoItem> GridDateTodoItem = new List <TodoItem>(); //List<TodoItem> GateTodoItem = new List<TodoItem>(); WholeList.ItemsSource = Lwhole; foreach (TodoItem a in GridTodoItem) { DateTime TodoItemday = DateTime.ParseExact(a.dates, "yyyy-MM-dd-HH:mm:ss", System.Globalization.CultureInfo.CurrentCulture); if (today.Year == TodoItemday.Year && today.Month == TodoItemday.Month && today.Day == TodoItemday.Day) { GridDateTodoItem.Add(a); dWorker dw = new dWorker(a.names, a.tags, a.works, 0, 0); ldWorker.Add(dw); } } for (int i = ldWorker.Count - 1; i >= 0; i--) { for (int j = i - 1; j >= 0; j--) { if (ldWorker[i].tag == ldWorker[j].tag) { ldWorker.RemoveAt(j); i--; } } } List <string> GateList = GridDateTodoItem.Select(x => x.gates).Distinct().ToList(); List <string> JobList = GridDateTodoItem.Select(x => x.works).Distinct().ToList(); int cnt = GridDateTodoItem.Count; string[] pday = new string[cnt]; for (int i = 0; i < GridDateTodoItem.Count; i++) { string day = null, time = null, time2 = null; string[] gateSplit = GridDateTodoItem[i].gates.Split('-'); int dt = 0; if (GridDateTodoItem[i].inout.Substring(0, 1) == "입" && gateSplit.Length == 1) //MG 들어오는거 발견 { //Dname = listWorker[i].name; //if (listWorker[i].name != Dname) pday = null; day = GridDateTodoItem[i].dates.Substring(0, 10); time = GridDateTodoItem[i].dates.Substring(11, 5); //출근했으면 for (int j = i + 1; j < GridDateTodoItem.Count; j++) { string[] gateSplit2 = GridDateTodoItem[j].gates.Split('-'); //메인게이트 if (GridDateTodoItem[i].dates.Substring(0, 10) == GridDateTodoItem[j].dates.Substring(0, 10)) { if (GridDateTodoItem[i].names == GridDateTodoItem[j].names && GridDateTodoItem[j].inout.Substring(0, 1) == "출" && gateSplit2.Length == 1) { time2 = GridDateTodoItem[j].dates.Substring(11, 5); foreach (dWorker dw in ldWorker) { if (dw.tag == GridDateTodoItem[i].tags && cnt >= 1) //&& listWorker[i].date.Substring(0, 10) == listWorker[j].date.Substring(0, 10)) { if (day != pday[cnt - 1]) { dw.cnt++; cnt--; break; } } } break; } } else { time2 = "18:00"; foreach (dWorker dw in ldWorker) { if (dw.tag == GridDateTodoItem[i].tags) { dw.cnt++; break; } } break; } } if (cnt >= 0 && cnt < ldWorker.Count) { pday[cnt] = day; } } if (time != null && time2 != null) { DateTime itime = Convert.ToDateTime(time); DateTime ftime = Convert.ToDateTime(time2); if (itime == ftime) { dt = 0; } else { TimeSpan dtime = ftime - itime; dt = dtime.Hours * 60 + dtime.Minutes; } //foundEnd = false; } foreach (dWorker dw in ldWorker) { if (dw.tag == GridDateTodoItem[i].tags) { dw.time += dt; break; } } } int GatesumIn = 0, GatesumOut = 0; for (int i = 0; i < GateList.Count; i++) { // string comp = formMain.listCompany[i]; int cntIn = 0, cntOut = 0; foreach (TodoItem TodoItems in GridDateTodoItem) { if (TodoItems.gates == GridDateTodoItem[i].gates && TodoItems.inout == "입") { cntIn++; } else if (TodoItems.gates == GridDateTodoItem[i].gates && TodoItems.inout == "출") { cntOut++; } } Lwhole.Add(new WholeWorker { WhGate = GridDateTodoItem[i].gates, WhIn = cntIn.ToString(), WhOut = cntOut.ToString(), Whleft = (cntIn - cntOut).ToString() }); GatesumIn += cntIn; GatesumOut += cntOut; } Allin.Text = GatesumIn.ToString(); Allout.Text = GatesumOut.ToString(); Manleft.Text = (GatesumIn - GatesumOut).ToString(); WholeList.ItemsSource = Lwhole; int JobsumIn = 0, JobsumOut = 0; for (int i = 0; i < JobList.Count; i++) { string zob = JobList[i]; int cntIn = 0, cntOut = 0; foreach (TodoItem TodoItems in GridDateTodoItem) { if (TodoItems.works == zob && TodoItems.inout == "입") { cntIn++; } else if (TodoItems.works == zob && TodoItems.inout == "출") { cntOut++; } } Lworker.Add(new Worker { WGate = JobList[i], WIn = cntIn.ToString(), WOut = cntOut.ToString(), Wleft = (cntIn - cntOut).ToString() }); //Worker a = new Worker(JobList[i], cntIn, cntOut); //Lworker.Add(a); JobsumIn += cntIn; JobsumOut += cntOut; } Workin.Text = JobsumIn.ToString(); Workout.Text = JobsumOut.ToString(); Workleft.Text = (JobsumIn - JobsumOut).ToString(); }