Пример #1
0
        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);
        }
Пример #2
0
        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));
            }
        }
Пример #3
0
 internal ImportFileLongTimeAbsenceData(int recordNumber, ImportLongTimeAbsenceData data)
 {
     RecordNumber = recordNumber;
     Data         = data;
 }