public static bool SaveDB_AC(Dictionary <Variable.UserData, List <Variable.OutInTime> > DicUser) { try { Sys_ACLicense sysLicenseRecord = new Sys_ACLicense(); foreach (KeyValuePair <Variable.UserData, List <Variable.OutInTime> > kvp in DicUser) { foreach (Variable.OutInTime i in kvp.Value) { sysLicenseRecord.department = kvp.Key.Department; sysLicenseRecord.userChinese = kvp.Key.ChineseName; sysLicenseRecord.username = kvp.Key.EnglishName; sysLicenseRecord.login = i.OutTime; sysLicenseRecord.logout = i.InTime; sysLicenseRecord.workingtime = i.Duration; sysLicenseRecord.totaltime = i.TotalTime; sysLicenseRecord.date = DateTime.Today.ToLongDateString(); if (!SaveDB <Sys_ACLicense>(sysLicenseRecord)) { return(false); } } } } catch (System.Exception ex) { return(false); } return(true); }
public static bool GetOverAllData_AC(DateTime StartDate, int TotalDays, out Dictionary <string, List <OverAllValue> > DicOverAllData) { DicOverAllData = new Dictionary <string, List <OverAllValue> >(); try { //先整理日期區間有哪些人使用 List <UserData> ListUserName = new List <UserData>(); if (!GetUserName_AC(StartDate, TotalDays, out ListUserName)) { MessageBox.Show("取得【日期區間有哪些人使用】失敗"); return(false); } if (ListUserName.Count == 0) { MessageBox.Show("此日期區間沒有任何資料"); return(false); } for (int i = 0; i < TotalDays; i++) { foreach (UserData j in ListUserName) { IList <Sys_ACLicense> ListData = new List <Sys_ACLicense>(); using (ISession session = MyHibernateHelper.SessionFactory.OpenSession()) { ListData = session.QueryOver <Sys_ACLicense>().Where(x => x.username == j.EnglishName) .And(x => x.date == StartDate.AddDays(i).ToLongDateString()).List(); session.Close(); } Sys_ACLicense lastData = new Sys_ACLicense(); List <OverAllValue> ListOverAllValue = new List <OverAllValue>(); status = DicOverAllData.TryGetValue(StartDate.AddDays(i).ToLongDateString(), out ListOverAllValue); if (!status) { ListOverAllValue = new List <OverAllValue>(); } OverAllValue sOverAllValue = new OverAllValue(); sOverAllValue.EnglishName = j.EnglishName; sOverAllValue.Department = j.Department; sOverAllValue.ChineseName = j.ChineseName; if (ListData.Count == 0) { //此人在這個日期沒有用UG sOverAllValue.TotalTime = ""; } else { //取最後一筆紀錄 lastData = ListData[ListData.Count - 1]; if (lastData.totaltime == "使用中或未關閉NX") { sOverAllValue.TotalTime = "1440分0秒"; } else { sOverAllValue.TotalTime = lastData.totaltime; } } ListOverAllValue.Add(sOverAllValue); DicOverAllData[StartDate.AddDays(i).ToLongDateString()] = ListOverAllValue; /* * if (ListData.Count == 0) * { * //此人在這個日期沒有用UG * List<OverAllValue> ListOverAllValue = new List<OverAllValue>(); * status = DicOverAllData.TryGetValue(StartDate.AddDays(i).ToLongDateString(), out ListOverAllValue); * if (!status) * { * ListOverAllValue = new List<OverAllValue>(); * } * OverAllValue sOverAllValue = new OverAllValue(); * sOverAllValue.UserName = j; * sOverAllValue.TotalTime = ""; * ListOverAllValue.Add(sOverAllValue); * DicOverAllData[StartDate.AddDays(i).ToLongDateString()] = ListOverAllValue; * } * else * { * //取最後一筆紀錄 * Sys_ACLicense lastData = ListData[ListData.Count - 1]; * //此人在這個日期沒有用UG * List<OverAllValue> ListOverAllValue = new List<OverAllValue>(); * status = DicOverAllData.TryGetValue(StartDate.AddDays(i).ToLongDateString(), out ListOverAllValue); * if (!status) * { * ListOverAllValue = new List<OverAllValue>(); * } * OverAllValue sOverAllValue = new OverAllValue(); * sOverAllValue.UserName = j; * sOverAllValue.TotalTime = lastData.totaltime; * ListOverAllValue.Add(sOverAllValue); * DicOverAllData[StartDate.AddDays(i).ToLongDateString()] = ListOverAllValue; * } */ } } /* * for (int i = 0; i < TotalDays; i++) * { * IList<Sys_ACLicense> listData = new List<Sys_ACLicense>(); * using (ISession session = MyHibernateHelper.SessionFactory.OpenSession()) * { * listData = session.QueryOver<Sys_ACLicense>().Where(x => x.date == StartDate.AddDays(i).ToLongDateString()).List(); * session.Close(); * } * if (listData.Count == 0) * { * continue; * } * * foreach (Sys_ACLicense j in listData) * { * List<OverAllValue> ListOverAllValue = new List<OverAllValue>(); * status = DicOverAllData.TryGetValue(j.username, out ListOverAllValue); * if (!status) * { * * } * else * { * * } * } * } */ } catch (System.Exception ex) { return(false); } return(true); }