internal ImportTime(string fileName, IEmployeeTimeService employeeTimeService, ImportTimeType importTimeType) : base(fileName, null) { _ImportTimeType = importTimeType; _EmployeeTimeService = employeeTimeService; _ImportRunning = true; _SaveDataResult = new SaveDataResult(); }
public SaveDataResult ImportLongTimeAbsence(List <ImportLongTimeAbsenceData> list) { SaveDataResult result = new SaveDataResult(); result.Success = true; if (list.Count > 0) { string query = @" create table #lta4insert ( PersID nvarchar (25), Code smallint, CodeName nvarchar (30), BeginTime smalldatetime, EndTime smalldatetime ) "; using (IDbCommand command = CreateCommand()) { command.CommandText = query; command.CommandTimeout = 60 * 3; command.ExecuteNonQuery(); foreach (ImportLongTimeAbsenceData value in list) { query = "insert into #lta4insert (PersID, Code, CodeName, BeginTime, EndTime) values(N'{0}',{1},N'{2}','{3}','{4}')"; command.CommandText = string.Format(query, value.PersID, value.Code, value.CodeName, value.BeginTime.ToString("yyyyMMdd"), value.EndTime.ToString("yyyyMMdd")); command.ExecuteNonQuery(); } command.CommandText = "spLongTimeAbsence_ImportData"; command.CommandType = CommandType.StoredProcedure; SqlParameter importResult = new SqlParameter("@result", SqlDbType.Int, 4); importResult.Direction = ParameterDirection.Output; command.Parameters.Add(importResult); using (IDataReader reader = command.ExecuteReader(CommandBehavior.SequentialAccess)) { list.Clear(); while (reader.Read()) { ImportLongTimeAbsenceData value = new ImportLongTimeAbsenceData(); value.PersID = reader.GetString(0); value.Code = reader.GetInt16(1); value.BeginTime = reader.GetDateTime(2); value.EndTime = reader.GetDateTime(3); list.Add(value); } reader.NextResult(); result.Success = ((int)importResult.Value > 0); } result.Data = list; } } OnDaoInvalidateWholeCache(); return(result); }
protected override void readCSVFile(CachedCsvReader csv) { #if (UseHeaders) #else int persIDIndex = _PersIDIndex; int codeIndex = _CodeIndex; int codeNameIndex = _CodeNameIndex; int beginTimeIndex = _BeginTimeIndex; int endTimeIndex = _EndTimeIndex; #endif Dictionary <string, ImportFileLongTimeAbsenceData> data = new Dictionary <string, ImportFileLongTimeAbsenceData>(); while (csv.ReadNextRecord()) { csvDataNextRow(); short code = short.Parse(csv[codeIndex]); string persID = csv[persIDIndex]; DateTime beginTime = DateTime.ParseExact(csv[beginTimeIndex], "yyyyMMdd", null); string endTimeStr = csv[endTimeIndex]; if (string.IsNullOrEmpty(endTimeStr)) { endTimeStr = DateTimeSql.SmallDatetimeMaxStr; } DateTime endTime = DateTime.ParseExact(endTimeStr, "yyyyMMdd", null); string key = persID + code.ToString() + beginTime.ToString() + endTime.ToString(); if (!data.ContainsKey(key)) { ImportLongTimeAbsenceData lta = new ImportLongTimeAbsenceData(); lta.PersID = persID; lta.BeginTime = beginTime; lta.EndTime = endTime; lta.Code = code; lta.CodeName = csv[codeNameIndex]; data.Add(key, new ImportFileLongTimeAbsenceData(_CurrentRow, lta)); } else { message(string.Format(GetLocalized("LongTimeAbsenceExists"), _CurrentRow, persID, code, beginTime, endTime)); } } csvDataEndRead(); List <ImportLongTimeAbsenceData> list = new List <ImportLongTimeAbsenceData>(data.Count); foreach (ImportFileLongTimeAbsenceData value in data.Values) { list.Add(value.Data); } SaveDataResult saveDataResult = _EmployeeService.LongTimeAbsenceService.ImportLongTimeAbsence(list); list = (List <ImportLongTimeAbsenceData>)saveDataResult.Data; foreach (ImportLongTimeAbsenceData value in list) { string key = value.PersID.ToString() + value.Code.ToString() + value.BeginTime.ToString() + value.EndTime.ToString(); message(string.Format(GetLocalized("LongTimeAbsenceNotAssignToEmployee"), data[key].RecordNumber, value.PersID)); } }
public SaveDataResult Save_HWGR_WGR_Values(List <HWGR_WGR_SysValuesShort> list) { SaveDataResult result = new SaveDataResult(); result.Success = true; if (list.Count > 0) { string query = @" create table #wgr4insert ( HWGR_SystemID int, World_SystemID int, WGR_SystemID int ) "; using (IDbCommand command = CreateCommand()) { command.CommandText = query; command.CommandTimeout = 60 * 3; command.ExecuteNonQuery(); foreach (HWGR_WGR_SysValuesShort value in list) { query = "insert into #wgr4insert (HWGR_SystemID, World_SystemID, WGR_SystemID) values({0},{1},{2})"; command.CommandText = string.Format(query, value.HWGR_SystemID, value.World_SystemID, value.WGR_SystemID); command.ExecuteNonQuery(); } command.CommandText = "spHWGR_WGR_ImportData"; command.CommandType = CommandType.StoredProcedure; SqlParameter importResult = new SqlParameter("@result", SqlDbType.Int, 4); importResult.Direction = ParameterDirection.Output; command.Parameters.Add(importResult); using (IDataReader reader = command.ExecuteReader(CommandBehavior.SequentialAccess)) { list.Clear(); while (reader.Read()) { HWGR_WGR_SysValuesShort value = new HWGR_WGR_SysValuesShort(); value.HWGR_SystemID = reader.GetInt32(0); value.World_SystemID = reader.GetInt32(1); value.WGR_SystemID = reader.GetInt32(2); list.Add(value); } reader.NextResult(); result.Success = ((int)importResult.Value > 0); } result.Data = list; } } OnDaoInvalidateWholeCache(); return(result); }
public SaveDataResult ImportAbsence(List <ImportAbsenceData> list) { SaveDataResult result = new SaveDataResult(); result.Success = true; if (list.Count > 0) { string query = @" create table #abs4insert ( SystemID int, CharID nvarchar (10), [Name] nvarchar (50) ) "; using (IDbCommand command = CreateCommand()) { command.CommandText = query; command.CommandTimeout = 60 * 3; command.ExecuteNonQuery(); foreach (ImportAbsenceData value in list) { query = @"insert into #abs4insert (SystemID, CharID, [Name]) values({0},'{1}',N'{2}')" ; command.CommandText = string.Format(query, value.SystemID, value.CharID, value.Name); command.ExecuteNonQuery(); } command.CommandText = "spAbsence_ImportData"; command.CommandType = CommandType.StoredProcedure; SqlParameter importResult = new SqlParameter("@result", SqlDbType.Int, 4); importResult.Direction = ParameterDirection.Output; command.Parameters.Add(importResult); using (IDataReader reader = command.ExecuteReader(CommandBehavior.SequentialAccess)) { list.Clear(); while (reader.Read()) { ImportAbsenceData value = new ImportAbsenceData(); value.SystemID = reader.GetInt32(0); list.Add(value); } reader.NextResult(); result.Success = ((int)importResult.Value > 0); } result.Data = list; } } OnDaoInvalidateWholeCache(); return(result); }
/* * public IList GetFeastsFiltered(long countryID, DateTime? from, DateTime? to) * { * ICriteria criteria = Session.CreateCriteria(typeof (Feast)); * criteria.Add(Expression.Eq("CountryID", countryID)); * if (from.HasValue) * { * criteria.Add(Expression.Ge("FeastDate", from.Value)); * if (to.HasValue) * { * criteria.Add(Expression.Le("FeastDate", to.Value)); * } * } * return ResolveCriteria(criteria); * }*/ public SaveDataResult ImportFeasts(List <ImportDaysData> list) { SaveDataResult result = new SaveDataResult(); result.Success = true; if (list.Count > 0) { string query = @" create table #feast4insert ( CountryID bigint, [Date] smalldatetime ) "; using (IDbCommand command = CreateCommand()) { command.CommandText = query; command.CommandTimeout = 60 * 3; command.ExecuteNonQuery(); foreach (ImportDaysData value in list) { query = "insert into #feast4insert (CountryID,[Date]) values({0},'{1}')"; command.CommandText = string.Format(query, value.CountryID, value.Date.ToString("yyyyMMdd")); command.ExecuteNonQuery(); } command.CommandText = "spFeasts_ImportData"; command.CommandType = CommandType.StoredProcedure; SqlParameter importResult = new SqlParameter("@result", SqlDbType.Int, 4); importResult.Direction = ParameterDirection.Output; command.Parameters.Add(importResult); using (IDataReader reader = command.ExecuteReader(CommandBehavior.SequentialAccess)) { list.Clear(); while (reader.Read()) { ImportDaysData value = new ImportDaysData(); value.CountryID = reader.GetInt64(0); value.Date = reader.GetDateTime(1); list.Add(value); } reader.NextResult(); result.Success = ((int)importResult.Value > 0); } result.Data = list; } } OnDaoInvalidateWholeCache(); return(result); }
protected override void readCSVFile(CachedCsvReader csv) { #if (UseHeaders) int worldIDIndex = csv.GetFieldIndex(_WorldID); int hwgr_IDIndex = csv.GetFieldIndex(_HWGR_ID); int hwgr_NameIndex = csv.GetFieldIndex(_HWGR_Name); #else int worldIDIndex = _WorldIDIndex; int hwgr_IDIndex = _HWGR_IDIndex; int hwgr_NameIndex = _HWGR_NameIndex; #endif Dictionary <string, ImportFileHWGRData> data = new Dictionary <string, ImportFileHWGRData>(); //Add HWGR while (csv.ReadNextRecord()) { csvDataNextRow(); int worldID = int.Parse(csv[worldIDIndex]); int hwgrID = int.Parse(csv[hwgr_IDIndex]); string hwgrName = csv[hwgr_NameIndex]; string key = worldID.ToString() + hwgrID.ToString(); if (!data.ContainsKey(key)) { data.Add(key, new ImportFileHWGRData(_CurrentRow, new ImportHWGRData(hwgrID, worldID, hwgrName))); } else { message(string.Format(GetLocalized("HWGRExists"), _CurrentRow, _WorldID, worldID, _HWGR_ID, hwgrID)); } } csvDataEndRead(); List <ImportHWGRData> list = new List <ImportHWGRData>(data.Count); foreach (ImportFileHWGRData value in data.Values) { list.Add(value.Data); } SaveDataResult saveDataResult = _StoreService.HWGRService.ImportHWGR(list); list = (List <ImportHWGRData>)saveDataResult.Data; foreach (ImportHWGRData value in list) { string key = value.World_SystemID.ToString() + value.HWGR_SystemID.ToString(); message(string.Format(GetLocalized("WorldNotExistsDB"), data[key].RecordNumber, _WorldID, value.World_SystemID)); } }
protected override void readCSVFile(CachedCsvReader csv) { #if (UseHeaders) int countryIDIndex = csv.GetFieldIndex(_VLID); int feastDateIndex = csv.GetFieldIndex(_FeastDate); #else int countryIDIndex = _VLIDIndex; int feastDateIndex = _FeastDateIndex; #endif Dictionary <string, ImportFeastsData> data = new Dictionary <string, ImportFeastsData>(); int i = 1; while (csv.ReadNextRecord()) { csvDataNextRow(); int countryID = int.Parse(csv[countryIDIndex]); DateTime feastDate = DateTime.ParseExact(csv[feastDateIndex], "yyyyMMdd", null); string key = countryID.ToString() + feastDate.ToString(); if (!data.ContainsKey(key)) { data.Add(key, new ImportFeastsData(i, new ImportDaysData(countryID, feastDate))); } else { message(string.Format(GetLocalized("FeastExists"), i, _CountryID, countryID, _FeastDate, feastDate)); } i++; } csvDataEndRead(); List <ImportDaysData> list = new List <ImportDaysData>(data.Count); foreach (ImportFeastsData value in data.Values) { list.Add(value.Data); } SaveDataResult saveDataResult = _FeastService.ImportFeasts(list); list = (List <ImportDaysData>)saveDataResult.Data; foreach (ImportDaysData value in list) { string key = value.CountryID.ToString() + value.Date.ToString(); message(string.Format(GetLocalized("CountryNotExistsDB"), data[key].RecordNumber, _VLID, value.CountryID)); } }
private void importTimePlanning(object param) { OperationCompleteEventArgs operationCompleteEventArgs = new OperationCompleteEventArgs(false); ImportParam importParam = (ImportParam)param; try { SaveDataResult saveDataResult = _EmployeeTimeDao.ImportTime(importParam.List, importParam.ImportTimeType); operationCompleteEventArgs.Success = saveDataResult.Success; //[0,0]- min date //[0,1]- max date DateTime?[,] minmaxDate = (DateTime?[, ])saveDataResult.Data; // calculate holidays absence - need change Time field if (minmaxDate != null && minmaxDate[0, 0] != null && minmaxDate[0, 1] != null) { DateTime minDate = minmaxDate[0, 0].Value; DateTime maxDate = minmaxDate[0, 1].Value; if (Log.IsDebugEnabled) { Log.Debug(minDate.ToShortDateString() + " " + maxDate.ToShortDateString() + " - start recalculation"); } EmployeeBusinessObject.RecalculateHolidaysTimeRanges(minDate, maxDate); if (Log.IsDebugEnabled) { Log.Debug(minDate.ToShortDateString() + " " + maxDate.ToShortDateString() + " - finished recalculation"); } } //operationCompleteEventArgs.Param = saveDataResult.Data; } catch (Exception ex) { operationCompleteEventArgs.Param = ex; } OnOperationComplete(null, operationCompleteEventArgs); }
protected override void readCSVFile(CachedCsvReader csv) { #if (UseHeaders) #else int absenceTypeIDIndex = _AbsenceTypeIDIndex; int absenceDescriptionIndex = _AbsenceDescriptionIndex; #endif Dictionary <int, ImportFileAbsenceData> data = new Dictionary <int, ImportFileAbsenceData>(); //Add Absence while (csv.ReadNextRecord()) { csvDataNextRow(); int systemID = int.Parse(csv[absenceTypeIDIndex]); string absenceName = csv[absenceDescriptionIndex]; if (!data.ContainsKey(systemID)) { data.Add(systemID, new ImportFileAbsenceData(_CurrentRow, new ImportAbsenceData(systemID, absenceName, csv[_AbsenceCharIDIndex]))); } else { message(string.Format(GetLocalized("AbsenceExists"), _CurrentRow, systemID)); } } csvDataEndRead(); List <ImportAbsenceData> list = new List <ImportAbsenceData>(data.Count); foreach (ImportFileAbsenceData value in data.Values) { list.Add(value.Data); } SaveDataResult saveDataResult = _AbsenceService.ImportAbsence(list); list = (List <ImportAbsenceData>)saveDataResult.Data; foreach (ImportAbsenceData value in list) { message(string.Format(GetLocalized("AbsenceNotImportedInDB"), data[value.SystemID].RecordNumber, value.SystemID)); } }
protected override void readCSVFile(CachedCsvReader csv) { #if (UseHeaders) int worldIDIndex = csv.GetFieldIndex(_WorldID); int hwgr_IDIndex = csv.GetFieldIndex(_HWGR_ID); int wgr_IDIndex = csv.GetFieldIndex(_WGR_ID); int wgr_NameIndex = csv.GetFieldIndex(_WGR_Name); #else int worldIDIndex = _WorldIDIndex; int hwgr_IDIndex = _HWGR_IDIndex; int wgr_IDIndex = _WGR_IDIndex; int wgr_NameIndex = _WGR_NameIndex; #endif Dictionary <string, ImportDataWGR> data = new Dictionary <string, ImportDataWGR>(); Dictionary <long, WGR> dbwgrHash = getDBwgrHash(); List <WGR> wgrSaveList = new List <WGR>(); //Add WGR int i = 1; while (csv.ReadNextRecord()) { csvDataNextRow(); int worldID = int.Parse(csv[worldIDIndex]); int hwgrID = int.Parse(csv[hwgr_IDIndex]); int wgrID = int.Parse(csv[wgr_IDIndex]); string wgrName = csv[wgr_NameIndex]; string key = worldID.ToString() + hwgrID.ToString() + wgrID.ToString(); if (!data.ContainsKey(key)) { data.Add(key, new ImportDataWGR(i, hwgrID, worldID, wgrID, wgrName, key)); if (!dbwgrHash.ContainsKey(wgrID)) { WGR wgr = new WGR(wgrID, SharedConsts.NeutralLangId, wgrName); wgr.Import = true; wgrSaveList.Add(wgr); dbwgrHash.Add(wgrID, wgr); } } else { message(string.Format(GetLocalized("WGRExists"), i, _WorldID, worldID, _HWGR_ID, hwgrID, _WGR_ID, wgrID)); } i++; } csvDataEndRead(); if (wgrSaveList.Count > 0) { SaveOrUpdateList <WGR>(_IStoreService.WGRService, wgrSaveList); } //Add HwgrToWgr List <HWGR_WGR_SysValuesShort> list = new List <HWGR_WGR_SysValuesShort>(data.Count); foreach (ImportDataWGR value in data.Values) { list.Add(new HWGR_WGR_SysValuesShort(value.HWGR_ID, value.WorldID, value.WGR_ID)); } SaveDataResult saveDataResult = _IStoreService.HwgrToWgrService.Save_HWGR_WGR_Values(list); list = (List <HWGR_WGR_SysValuesShort>)saveDataResult.Data; foreach (HWGR_WGR_SysValuesShort value in list) { string key = value.World_SystemID.ToString() + value.HWGR_SystemID.ToString() + value.WGR_SystemID.ToString(); message(string.Format(GetLocalized("HWGRNotExistsDB"), data[key].RecordNumber, _WorldID, value.World_SystemID, _HWGR_ID, value.HWGR_SystemID)); } }
public SaveDataResult ImportTime(List <ImportTimeData> list, ImportTimeType importTimeType) { SaveDataResult result = new SaveDataResult(); result.Success = true; if (list.Count > 0) { string query = @" create table #tp4insert ( [PersID] nvarchar (25), [Date] smalldatetime, [CharID] nvarchar (10), [Begin] smallint, [End] smallint ) "; using (IDbCommand command = Session.Connection.CreateCommand()) { Session.Transaction.Enlist(command); command.CommandText = query; command.CommandTimeout = 60 * 6; command.ExecuteNonQuery(); string[] queries = createQueriesForInsert(list); for (int i = 0; i < queries.Length; i++) { command.CommandText = queries[i]; command.ExecuteNonQuery(); } if (importTimeType == ImportTimeType.Planning) { command.CommandText = "spEmployeeTimePlanning_ImportData"; } else { command.CommandText = "spEmployeeTimeRecording_ImportData"; } command.CommandType = CommandType.StoredProcedure; SqlParameter importResult = new SqlParameter("@result", SqlDbType.Int, 4); importResult.Direction = ParameterDirection.Output; command.Parameters.Add(importResult); using (IDataReader reader = command.ExecuteReader(CommandBehavior.SequentialAccess)) { //list = Map.ToList<ImportTimeData>(reader); result.Data = GetResultFromTimeImport(reader); reader.NextResult(); result.Success = ((int)importResult.Value > 0); } } if (importTimeType == ImportTimeType.Planning) { _AbsenceTimePlanningDao.OnDaoInvalidateWholeCache(); _WorkingTimePlanningDao.OnDaoInvalidateWholeCache(); } else { _AbsenceTimeRecordingDao.OnDaoInvalidateWholeCache(); _WorkingTimeRecordingDao.OnDaoInvalidateWholeCache(); } } return(result); }