public override DateTime GetDateTime(int ordinal) { return(rdr.GetDateTime(ordinal).ToLocalTime()); }
/// <summary> /// Create a MembershipUser object from a data reader. /// </summary> /// <param name="sqlDataReader">Data reader.</param> /// <returns>MembershipUser object.</returns> private MembershipUser GetUserFromReader( OracleDataReader oracleDataReader ) { object idPersonne = oracleDataReader.GetValue(0); string courriel = oracleDataReader.GetString(1); string motDePasse = oracleDataReader.GetString(2); string username = String.Empty; string passwordQuestion = String.Empty; if (oracleDataReader.GetValue(3) != DBNull.Value) { passwordQuestion = oracleDataReader.GetString(3); } string comment = String.Empty; if (oracleDataReader.GetValue(4) != DBNull.Value) { comment = oracleDataReader.GetString(4); } bool isApproved = true; if (oracleDataReader.GetBoolean(5) != null) { isApproved = oracleDataReader.GetBoolean(5); } bool isLockedOut = oracleDataReader.GetBoolean(6); if (oracleDataReader.GetBoolean(6) != null) { isLockedOut = oracleDataReader.GetBoolean(6); } DateTime creationDate = new DateTime(); if (oracleDataReader.GetValue(7) != DBNull.Value) { creationDate = oracleDataReader.GetDateTime(7); } DateTime lastLoginDate = new DateTime(); if (oracleDataReader.GetValue(8) != DBNull.Value) { lastLoginDate = oracleDataReader.GetDateTime(8); } DateTime lastActivityDate = new DateTime(); if (oracleDataReader.GetValue(9) != DBNull.Value) { lastActivityDate = oracleDataReader.GetDateTime(9); } DateTime lastPasswordChangedDate = new DateTime(); if (oracleDataReader.GetValue(10) != DBNull.Value) { lastPasswordChangedDate = oracleDataReader.GetDateTime(10); } DateTime lastLockedOutDate = new DateTime(); if (oracleDataReader.GetValue(11) != DBNull.Value) { lastLockedOutDate = oracleDataReader.GetDateTime(11); } MembershipUser membershipUser = new MembershipUser( this.Name, username, idPersonne, courriel, passwordQuestion, comment, isApproved, isLockedOut, creationDate, lastLoginDate, lastActivityDate, lastPasswordChangedDate, lastLockedOutDate ); return membershipUser; }
public void SimpleValue() { try { BeginCase("check simple value"); //prepare data base.PrepareDataForTesting(connectionString); con = new OracleConnection (connectionString); con.Open(); cmd = new OracleCommand("Select BirthDate From Employees where EmployeeID = 100", con); rdr = cmd.ExecuteReader(); rdr.Read(); DateTime dt = rdr.GetDateTime(0); //will be 1988-May-31 15:33:44 Compare(dt,new DateTime(1988,5,31,15,33,44,00)); } catch(Exception ex) { exp = ex; } finally { EndCase(exp); if (rdr != null && !rdr.IsClosed) rdr.Close(); exp = null; } }
public CWarehouseTask GetTask2(int channel) { if (channel == 4) channel = 0; bool sucess = false; CWarehouseTask newTask = null; if (Connection.State != ConnectionState.Open) { return null; } try { using (OracleCommand cmd = new OracleCommand()) { cmd.Connection = Connection; //MessageBox.Show(GetTaskSQLCommand2); cmd.CommandText = string.Format(GetTaskSQLCommand2, channel); cmd.CommandType = CommandType.Text; using (dataReader = cmd.ExecuteReader()) { if (dataReader.Read()) {//如果有任务 OprationState = "正在读取任务"; #region 读取 //#region task_id,task_type,status,from_addr,to_addr,create_time,product_id,pack_unit,pack_num,pallet_id CWarehouseTask tmpTask = new CWarehouseTask(); tmpTask.TaskID = dataReader.GetInt32(0); tmpTask.TaskType = (CWarehouseTask.ETaskType)int.Parse(dataReader.GetString(1)); tmpTask.State = int.Parse(dataReader.GetString(2)); //调整地址格式 string tmp = dataReader.GetString(3); tmp = tmp.Replace("LF00", "WH01"); tmpTask.SourceAddress = tmp; tmp = dataReader.GetString(4); tmp = tmp.Replace("LF00", "WH01"); tmp = tmp.Replace("CR0115", "CR0105"); tmpTask.DestinationAddress = tmp; //调整空托盘直出任务类型 if ((tmpTask.TaskType == CWarehouseTask.ETaskType.空托盘返库) && (tmpTask.DestinationAddress == "CR0105")) { tmpTask.TaskType = CWarehouseTask.ETaskType.空托盘直出; } tmpTask.CreateTime = dataReader.GetDateTime(5); tmpTask.ProductID = dataReader.GetString(6); tmpTask.PackingUnit = dataReader.GetString(7); tmpTask.PackingNumber = dataReader.GetInt32(8); tmpTask.PalletID = dataReader.GetString(9); tmpTask.ProductName = dataReader.GetString(10); if (dataReader[11] != null) { int ch = dataReader.GetInt32(11); tmpTask.ChannelID = (ch == 0) ? (4) : (ch); } else { tmpTask.ChannelID = 4; } tmpTask.Priority = dataReader.GetInt32(12); //tmpTask.RunningState = CWarehouseTask.EState.创建; #endregion #region 创建 try { newTask = new CWarehouseTask(tmpTask.TaskID, tmpTask.Req_ID, (int)tmpTask.TaskType, tmpTask.State, tmpTask.SourceAddress, tmpTask.DestinationAddress, tmpTask.CreateTime, tmpTask.ProductID, tmpTask.PackingUnit, tmpTask.PackingNumber, tmpTask.Num, tmpTask.Priority, tmpTask.PalletID, tmpTask.ProductName, tmpTask.ChannelID); sucess = true; } catch (Exception ex1) { sucess = false; Program.ErrorManager.Add(new RuntimeError(oprationState, RuntimeError.EVisibility.Programer, new Exception("生成任务实例出现异常,此异常并不会影响程序执行结果。", ex1))); } #endregion } else {//无任务 sucess = false; } } } } catch (Exception ex) // catches any other error { sucess = false; OprationState = "读取任务过程中出现数据库相关的操作错误"; Program.ErrorManager.Add(new RuntimeError(oprationState, RuntimeError.EVisibility.Programer, ex)); } //如果无错误,返回newTask,否则返回null return ((sucess) && newTask != null) ? (newTask) : (null); }