public List <Object> getDatosParaEmail() { string sql = "select p.Nombre as [Proyecto],c.Nombre as [Componente],f.Nombre as [Fase],cr.Fecha_Inicio,cr.Fecha_Conclusion" + " from Fase_Componente fc,Fase f,Componente c, Proyecto p,Cronograma cr, Usuario u" + " where fc.CodComponente=c.Codigo and fc.IDFase=f.ID and c.CodProyecto=p.Codigo" + " and fc.IDCronograma=cr.Id and fc.AliasPers=u.AliasPers and u.ID='" + this.AliasPers.Alias + "' and f.ID='" + this.IDFase.ID + "' and c.Codigo='" + this.CodComponente.Codigo + "';"; List <Object> datosGet = new List <Object>(); try { Conexion.abrirConexion(); OdbcDataReader dr = Conexion.ObtenerTuplas(sql); if (dr.Read()) { datosGet.Add(dr.GetString(0)); datosGet.Add(dr.GetString(1)); datosGet.Add(dr.GetString(2)); datosGet.Add(dr.GetDateTime(3)); datosGet.Add(dr.GetDateTime(4)); } dr.Close(); return(datosGet); } catch (Exception ex) { string error = ex.Message; return(null); //throw; } finally { Conexion.cerrarConexion(); } }
public static Cronograma getIDCronograma_desdeSubcomponente(string codsubcomp) { try { Conexion.abrirConexion(); string sql = "select cr.Fecha_Inicio,cr.Fecha_Conclusion from Componente c,Cronograma cr" + " where c.IDCronograma=cr.Id and c.Codigo= (select c.CodComponente " + " from Componente c" + " where c.Codigo='" + codsubcomp + "')"; OdbcDataReader dr = Conexion.ObtenerTuplas(sql); Cronograma x = null; if (dr.Read()) { x = new Cronograma(int.MaxValue, dr.GetDateTime(0), dr.GetDateTime(1)); } return(x); } catch (Exception) { return(null); } finally { Conexion.cerrarConexion(); } }
public static Cronograma obtenerCronograma(string codComp) { try { Conexion.abrirConexion(); string sql = "select cr.Fecha_Inicio,cr.Fecha_Conclusion from Componente c, Cronograma cr where c.IDCronograma=cr.ID and c.Codigo='" + codComp + "'"; OdbcDataReader dr = Conexion.ObtenerTuplas(sql); if (dr.Read()) { Cronograma x = new Cronograma(int.MaxValue, dr.GetDateTime(0), dr.GetDateTime(1)); return(x); } return(null); /*else * { * //Conexion.cerrarConexion(); * return null; * }*/ } catch (Exception) { return(null); } finally { Conexion.cerrarConexion(); } }
// // GetProfileInfoFromReader // Takes the current row from the OdbcDataReader // and populates a ProfileInfo object from the values. // private ProfileInfo GetProfileInfoFromReader(OdbcDataReader reader) { string username = reader.GetString(0); DateTime lastActivityDate = new DateTime(); if (reader.GetValue(1) != DBNull.Value) { lastActivityDate = reader.GetDateTime(1); } DateTime lastUpdatedDate = new DateTime(); if (reader.GetValue(2) != DBNull.Value) { lastUpdatedDate = reader.GetDateTime(2); } bool isAnonymous = reader.GetBoolean(3); // ProfileInfo.Size not currently implemented. ProfileInfo p = new ProfileInfo(username, isAnonymous, lastActivityDate, lastUpdatedDate, 0); return(p); }
////compere two date and determind lagest date(not use at this time) //public bool DateValidate(int fyear, int fmonth, int fday, int lyear, int lmonth, int lday) //{ // try // { // DateTime dt1; //= new DateTime(fyear, fmonth, fday); // dt1 = DateTime.Parse(fyear + "," + fmonth + "," + fday); // DateTime dt2; //= new DateTime(lyear, lmonth, lday); // dt2 = DateTime.Parse(lyear + "," + lmonth + "," + lday); // if (DateTime.Compare(dt1, dt2) <= 0) // { // return true; // } // else // { // return false; // } // } // catch (FormatException) // { // return false; // } //} ////validate single date from year,month and day(not use at this time) //public bool SingleDateValidate(int year, int month, int day) //{ // try // { // DateTime dt1 = DateTime.Parse(year + "," + month + "," + day); // return true; // } // catch (FormatException) // { // return false; // } //} ////time validate (not use this time) //public bool TimeValidate(string time) //{ // try // { // if (time.Length == 5) // { // string[] timeParts = time.Split('.'); // if (timeParts.Length == 2) // { // if (Convert.ToInt32(timeParts[0]) >= 0 && Convert.ToInt32(timeParts[0]) <= 25 && Convert.ToInt32(timeParts[1]) >= 0 && Convert.ToInt32(timeParts[1]) <= 59) // { // return true; // } // else // { // return false; // } // } // else // { // return false; // } // } // else // { // return false; // } // } // catch (FormatException) // { // return false; // } //} //check allocate same date or time allocate at same time public bool checkItem(DateTime sd1, DateTime sd2, string txtcommand) { bool check = true; DateTime dt1, dt2; if (DateTime.Compare(sd1, sd2) < 0) { using (OdbcCommand MyCommand = new OdbcCommand(txtcommand, Connection.MyConnection)) { MyDataReader = MyCommand.ExecuteReader(); while (MyDataReader.Read()) { dt1 = MyDataReader.GetDateTime(0); dt2 = MyDataReader.GetDateTime(1); if (!(((DateTime.Compare(dt1, sd1) > 0) && (DateTime.Compare(dt1, sd2) > 0)) || ((DateTime.Compare(dt2, sd1) < 0) && (DateTime.Compare(dt2, sd2) < 0)))) { check = false; } } MyDataReader.Close(); } } else { check = false; } return(check); }
public static Cronograma obtenerCronograma(string codigo) { try { Conexion.abrirConexion(); string sql = "Select cr.Fecha_Inicio,cr.Fecha_Conclusion from Proyecto p,Cronograma cr where p.IDCronograma=cr.ID and p.Codigo='" + codigo + "'"; OdbcDataReader dr = Conexion.ObtenerTuplas(sql); if (dr.Read()) { //Conexion.DesconectarBD(); Cronograma x = new Cronograma(int.MaxValue, dr.GetDateTime(0), dr.GetDateTime(1)); return(x); } else { return(null); } } catch (Exception) { return(null); } finally { Conexion.cerrarConexion(); } }
public static Cronograma getCronograma(string idfase, string codsubcomp) { try { Conexion.abrirConexion(); string sql = "select fc.ID,fc.IDFase,fc.CodComponente,fc.IDCronograma,cr.Fecha_Inicio,cr.Fecha_Conclusion,fc.AliasPers" + " from Fase_Componente fc,Cronograma cr" + " where fc.IDCronograma=cr.Id and fc.CodComponente='" + codsubcomp + "' and fc.IDFase='" + idfase + "';"; OdbcDataReader dr = Conexion.ObtenerTuplas(sql); Cronograma x = null; if (dr.Read()) { x = new Cronograma(dr.GetInt32(3), dr.GetDateTime(4), dr.GetDateTime(5)); } return(x); } catch (Exception) { return(null); } finally { Conexion.cerrarConexion(); } }
// // GetUserFromReader // A helper function that takes the current row from the OdbcDataReader // and hydrates a MembershiUser from the values. Called by the // MembershipUser.GetUser implementation. // private MembershipUser GetUserFromReader(OdbcDataReader reader) { object providerUserKey = reader.GetValue(0); string username = reader.GetString(1); string email = reader.GetString(2); string passwordQuestion = ""; if (reader.GetValue(3) != DBNull.Value) { passwordQuestion = reader.GetString(3); } string comment = ""; if (reader.GetValue(4) != DBNull.Value) { comment = reader.GetString(4); } bool isApproved = reader.GetBoolean(5); bool isLockedOut = reader.GetBoolean(6); DateTime creationDate = reader.GetDateTime(7); DateTime lastLoginDate = new DateTime(); if (reader.GetValue(8) != DBNull.Value) { lastLoginDate = reader.GetDateTime(8); } DateTime lastActivityDate = reader.GetDateTime(9); DateTime lastPasswordChangedDate = reader.GetDateTime(10); DateTime lastLockedOutDate = new DateTime(); if (reader.GetValue(11) != DBNull.Value) { lastLockedOutDate = reader.GetDateTime(11); } MembershipUser u = new MembershipUser(this.Name, username, providerUserKey, email, passwordQuestion, comment, isApproved, isLockedOut, creationDate, lastLoginDate, lastActivityDate, lastPasswordChangedDate, lastLockedOutDate); return(u); }
public static Order FindOrderByOrderID(int orderID) { Order order = null; string connectionString = DataUtilities.ConnectionString; if (orderID > 0) { if ((connectionString != null) && (connectionString.Length > 0)) { try { OdbcConnection dataConnection = new OdbcConnection(); dataConnection.ConnectionString = connectionString; dataConnection.Open(); OdbcCommand dataCommand = new OdbcCommand(); dataCommand.Connection = dataConnection; // Build Command String StringBuilder commandText = new StringBuilder("SELECT * FROM Orders WHERE OrdersID = "); commandText.Append(orderID); dataCommand.CommandText = commandText.ToString(); OdbcDataReader dataReader = dataCommand.ExecuteReader(); while (dataReader.Read()) { order = new Order(); order.OrderID = dataReader.GetInt32(0); order.CustomerID = dataReader.GetString(1); order.OrderDate = dataReader.GetDateTime(3); order.ShipDate = dataReader.GetDateTime(5); order.ShipName = dataReader.GetString(8); order.ShipAddress = dataReader.GetString(9); order.ShipCity = dataReader.GetString(10); order.ShipPostalCode = dataReader.GetString(12); order.ShipCountry = dataReader.GetString(13); } dataConnection.Close(); } catch (Exception e) { Console.WriteLine("error: " + e.Message); } } } return(order); }
// Map ODBC row to source member public static SrcMbr RowToSrcMbr(OdbcDataReader reader) { var mbr = new SrcMbr(); mbr.Name = reader.GetString(0).Trim(); // TABLE_PARTITION mbr.Attribute = reader.GetString(1).Trim(); // SOURCE_TYPE mbr.LineCount = reader.GetInt32(2); // NUMBER_ROWS mbr.Text = reader.GetString(3).Trim(); // PARTITION_TEXT mbr.RecordLength = reader.GetInt32(4); // AVGROWSIZE mbr.DataSize = reader.GetInt32(5); // DATA_SIZE mbr.Created = reader.GetDateTime(6); // CREATE_TIMESTAMP mbr.Updated = reader.GetDateTime(7); // LAST_CHANGE_TIMESTAMP return(mbr); }
public Cotization Read_once(string id) { Cotization cotization = new Cotization(); try { //Console.WriteLine("Conexion Cotizacion: " + Database.GetConn().State); if (!Database.GetConn().State.ToString().Equals("Open")) { Database.Connect(); } command = new OdbcCommand { Connection = Database.GetConn(), CommandType = CommandType.StoredProcedure, CommandText = "{call csg.Cotization_ReadOnce(?)}" }; command.Parameters.Add("Id", OdbcType.VarChar, 50).Value = id; dataReader = command.ExecuteReader(); if (dataReader.Read()) { cotization = new Cotization { Cotization_id = dataReader.GetString(0), Cotization_generation_date = dataReader.GetDateTime(1), Cotization_expiration_date = dataReader.GetDateTime(2), Cotization_quantity = dataReader.GetByte(3), Cotization_comentarys = dataReader.GetString(4), Cotization_subtotal = dataReader.GetString(5), Cotization_discount = dataReader.GetString(6), Cotization_iva = dataReader.GetString(7), Cotization_total = dataReader.GetString(8) }; } else { cotization = null; } } catch (Exception ex) { MessageBox.Show("Excepción controlada en CotizationDAO->Read_once: " + ex.Message, "Excepción", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { Database.Disconnect(); } return(cotization); }
private DateTime GetDateTimeValue(OdbcDataReader reader, int column) { try { if (reader.IsDBNull(column)) { logger.Debug("Reader column {column} is DbNull. Returning default value.", column); return(new DateTime()); } else { return(reader.GetDateTime(column)); } } catch (InvalidCastException ex) { string columnValue = reader.GetString(column); logger.Info(ex, "Could not cast column {column} value {value} as DateTime. returning default value.", column, columnValue); return(new DateTime()); } catch (Exception ex) { logger.Error("An unexpected error occurred while processing reader column {column}. Error: {errorMessage}", column, ex.Message); throw; } }
//funcion para obtener todos los encabezados public Tuple <int, DateTime, string, double> funcObtenerDatoPolEnc(int Codigo) { int CodigoEnc = 0; DateTime Fecha = DateTime.Now; string Descripcion = ""; double Monto = 0; try { string Buscar = "SELECT PK_POLIZA_ENCABEZADO, FECHA_POLIZA_ENCABEZADO, DESCRIPCION_POLIZA_ENCABEZADO, TOTAL_POLIZA_ENCABEZADO" + " FROM POLIZA_ENCABEZADO WHERE PK_POLIZA_ENCABEZADO=" + Codigo; OdbcCommand Comm = new OdbcCommand(Buscar, Con.conexion()); OdbcDataReader Reader = Comm.ExecuteReader(); if (Reader.Read()) { CodigoEnc = Reader.GetInt32(0); Fecha = Reader.GetDateTime(1); Descripcion = Reader.GetString(2); Monto = Reader.GetDouble(3); } return(Tuple.Create(CodigoEnc, Fecha, Descripcion, Monto)); } catch (Exception Ex) { Console.WriteLine(Ex.Message.ToString() + " \nError en asignarCombo, revise los parametros \n -\n -"); return(Tuple.Create(CodigoEnc, Fecha, Descripcion, Monto)); } }
private Order[] SelectOrders(OrderType type, string methodName, int stockId) { IList <Order> orders = new List <Order>(); using (OdbcCommand command = new OdbcCommand()) { command.Connection = connection; command.CommandText = string.Format("SELECT id, broker_id, stock_id, amount, price, received FROM {0}({1});", methodName, stockId); using (OdbcDataReader reader = command.ExecuteReader()) { while (reader.Read()) { //id, bid, sid, amount, price, received Order order = new Order(); order.Type = type; order.Id = reader.GetInt32(0); order.BrokerId = reader.GetInt32(1); order.StockId = reader.GetInt32(2); order.Amount = reader.GetInt32(3); order.ProposedPrice = reader.GetDecimal(4); order.Received = reader.GetDateTime(5); orders.Add(order); } reader.Close(); } } return(orders.ToArray()); }
static void Main(string[] args) { // Connection string connectionString = "DSN=mySqlServer;Uid=SYSTEM;Pwd=password"; OdbcConnection conn = new OdbcConnection(); conn = new OdbcConnection(connectionString); conn.Open(); //reading from an RDBMS via ODBC. Note the use of isDBNull, use it for string query = "SELECT ID, Name, Birthdate, Picture FROM Customer ORDER BY ID"; OdbcCommand exe = new OdbcCommand(query, conn); OdbcDataReader read = exe.ExecuteReader(); byte[] contentDataBuffer = new byte[2097125]; // 2 MB - while (read.Read()) { string tmpUid = (read.GetInt64(0)).ToString(); string tmpName = read.IsDBNull(1) == false?read.GetString(1) : null; DateTime tmpBirthDate = read.GetDateTime(2); long lCntRead = read.GetBytes(3, 0, contentDataBuffer, 0, 2097125); } Form1 form = new Form1(); form.ShowMyImage(ByteToImage(contentDataBuffer)); // byteArr holds byte array value, display image in Form }
/// <summary> /// Permite obtener la fecha de antigüedad del empleado ingresado como parámetro /// </summary> /// <param name="EmpladoId"></param> /// <returns>DateTime</returns> public static DateTime GetAntiquity(int EmpleadoId) { DateTime AntiquityDate = new DateTime(); try { string QueryString = "SELECT fecha_antiguedad " + " FROM Empleados EMP "+ "INNER JOIN vwEmpleados VISTA " + " ON VISTA.idEmpleado = EMP.id "+ " AND VISTA.idCompania = EMP.compania "+ " WHERE VISTA.idEmpleado = "+ EmpleadoId; System.Data.Odbc.OdbcCommand command = new System.Data.Odbc.OdbcCommand(QueryString); using (System.Data.Odbc.OdbcConnection connection = new System.Data.Odbc.OdbcConnection(CadenaConexion)) { command.Connection = connection; connection.Open(); using (OdbcDataReader reader = command.ExecuteReader()) { if (reader.Read()) { AntiquityDate = reader.GetDateTime(0); } } } } catch (Exception exc) { //Agregar bitácora para marcar las excepciones surgidas en la clase de acceso a datos. } return(AntiquityDate); }
public override Trade[] SelectTrades(int stockId) { IList <Trade> trades = new List <Trade>(); using (OdbcCommand command = new OdbcCommand()) { command.Connection = connection; command.CommandText = string.Format( "SELECT id, buy_order_id, sell_order_id, stock_id, buyer_id, seller_id, amount, price, executed " + "FROM get_trades({0});", stockId); using (OdbcDataReader reader = command.ExecuteReader()) { while (reader.Read()) { Trade trade = new Trade(); trade.Id = reader.GetInt32(0); trade.BuyOrderId = reader.GetInt32(1); trade.SellOrderId = reader.GetInt32(2); trade.StockId = reader.GetInt32(3); trade.BuyerId = reader.GetInt32(4); trade.SellerId = reader.GetInt32(5); trade.Amount = reader.GetInt32(6); trade.Price = reader.GetDecimal(7); trade.Executed = reader.GetDateTime(8); trades.Add(trade); } reader.Close(); } } return(trades.ToArray()); }
public static void TaskCount() { rid = 0; try { Connection.tempConnection.Open(); if (Connection.tempConnection.State == ConnectionState.Open) { using (OdbcCommand MyCommand = new OdbcCommand("SELECT rid,duedate FROM tms_reminders WHERE assignedto='" + Login.userid + "' AND duedate> '" + Util.getDateTime().AddMinutes(1).ToString("yyyy-MM-dd HH:mm") + "' AND DATE(duedate)='" + Util.getDateTime().ToString("yyyy-MM-dd") + "' ORDER BY duedate LIMIT 1", Connection.tempConnection)) { OdbcDataReader MyDataReader = MyCommand.ExecuteReader(); MyDataReader.Read(); rid = MyDataReader.GetInt32(0); duedate = MyDataReader.GetDateTime(1); MyDataReader.Close(); if (timerflag && rid == 0) { dispatcherTimer.Stop(); } } Connection.tempConnection.Close(); } } catch (Exception) { if (Connection.tempConnection.State == ConnectionState.Open) { Connection.tempConnection.Close(); } } }
private Order[] SelectOrders(int stockId, OrderType type) { IList <Order> orderList = new List <Order>(); int orderTypeId = (type == OrderType.BuyOrder) ? 1 : 2; string query = "SELECT id, bid, amount, price, received FROM live_orders WHERE oid = " + orderTypeId + " AND sid = " + stockId; OdbcCommand command = new OdbcCommand(query, connection); OdbcDataReader reader = command.ExecuteReader(); while (reader.Read()) { Order order = new Order(); order.Id = reader.GetInt32(0); order.Type = type; order.StockId = stockId; order.BrokerId = reader.GetInt32(1); order.Amount = reader.GetInt32(2); order.ProposedPrice = reader.GetDecimal(3); order.Received = reader.GetDateTime(4); orderList.Add(order); } reader.Close(); return(orderList.ToArray()); }
public List <Object> getDatosComponenteAutorizacion() { string sql = "select p.Nombre as [Proyecto],c.Nombre as [Componente], a.Descripcion as [Autorizacion],ca.FechaMax_Fin" + " from Proyecto p,Componente_Autorizacion ca,Autorizacion a, Componente c" + " where ca.CodComponente=c.Codigo and ca.CodAutoriz=a.Codigo and c.CodProyecto=p.Codigo and ca.ID=" + this.ID + ";"; List <Object> datosGet = new List <Object>(); try { Conexion.abrirConexion(); OdbcDataReader dr = Conexion.ObtenerTuplas(sql); if (dr.Read()) { datosGet.Add(dr.GetString(0)); datosGet.Add(dr.GetString(1)); datosGet.Add(dr.GetString(2)); datosGet.Add(dr.GetDateTime(3)); } dr.Close(); return(datosGet); } catch (Exception ex) { string errorr = ex.Message; return(null); } finally { Conexion.cerrarConexion(); } }
public static string GetNameFromPlayerNumbersTableIndividual(OdbcConnection conn, int sectionID, int round, int playerNo) { string number = "###"; string name = ""; string SQLString = $"SELECT Number, Name, Round, TimeLog FROM PlayerNumbers WHERE Section={sectionID} AND TabPlayPairNo={playerNo}"; OdbcCommand cmd = new OdbcCommand(SQLString, conn); OdbcDataReader reader = null; try { ODBCRetryHelper.ODBCRetry(() => { reader = cmd.ExecuteReader(); DateTime latestTimeLog = new DateTime(2010, 1, 1); while (reader.Read()) { try { int readerRound = reader.GetInt32(2); DateTime timeLog; if (reader.IsDBNull(3)) { timeLog = new DateTime(2010, 1, 1); } else { timeLog = reader.GetDateTime(3); } if (readerRound <= round && timeLog >= latestTimeLog) { number = reader.GetString(0); name = reader.GetString(1); latestTimeLog = timeLog; } } catch // Record found, but format cannot be parsed { if (number == "###") { number = ""; } } } }); } finally { cmd.Dispose(); reader.Close(); } if (number == "###") // Nothing found { number = ""; } return(FormatName(name, number)); }
/// <summary> /// Constructs a user from the output of a datareader. Assumes that there is data /// ready to be read from the current record 14/12/15 /// </summary> private static User readUser(OdbcDataReader dataReader) { return(new User(dataReader.GetInt16(0), dataReader.GetString(1), dataReader.GetString(3), dataReader.GetString(4), dataReader.GetString(5), dataReader.GetBoolean(6), dataReader.GetDateTime(7), dataReader.GetInt16(8), dataReader.GetInt16(9), dataReader.GetBoolean(10), dataReader.GetBoolean(11), dataReader.GetInt16(13))); }
public Article Read_once(string code) { Article article = new Article(); try { Database.Connect(); command = new OdbcCommand { Connection = Database.GetConn(), CommandType = CommandType.StoredProcedure, CommandText = "{call csg.Article_ReadOnce(?)}" }; command.Parameters.Add("Code", OdbcType.VarChar, 50).Value = code; dataReader = command.ExecuteReader(); if (dataReader.Read()) { article = new Article { Article_code = dataReader.GetString(0), Article_description = dataReader.GetString(1), Article_warranty = dataReader.GetInt32(2), Category = dataReader.GetByte(3) }; //agregamos los datos de creación article.Create_by = dataReader.GetString(4); article.Create_date = dataReader.GetDateTime(5); //Agregamos los campos de actualización article.Update_by = dataReader.GetString(6); article.Update_date = dataReader.GetDateTime(7); } } catch (Exception ex) { MessageBox.Show("Excepción controlada en ArticleDAO->Read_once: " + ex.Message, "Excepción", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { Database.Disconnect(); } return(article); }
public bool newTokenDb(string Cuenta, string mail) { string selectQuery = "SELECT cuenta_telegram,fecha_ultimo_token from [Datos Alumno Bot] where cuenta_telegram= ? ;"; try { cmd = new OdbcCommand(selectQuery, odbcConnection); Open(); cmd.Parameters.Add("@Cuenta", OdbcType.VarChar).Value = Cuenta; OdbcDataReader MyDataReader = cmd.ExecuteReader(); while (MyDataReader.Read()) { // Console.WriteLine(selectResult.GetString(0)); if (Cuenta == MyDataReader.GetString(0)) { DateTime actual = MyDataReader.GetDateTime(1); actual = actual.AddMinutes(5); DateTime nos = DateTime.Now; int compare = DateTime.Compare(actual, nos); // Console.WriteLine(nos); if (DateTime.Compare(actual, nos) <= 0) { Console.WriteLine(mail); Close(); string tokenNuevo = createToken(); EnviarCorreo(mail, tokenNuevo); AccesDB db = new AccesDB(); db.connection(); //string updateQuery = "UPDATE alumnos_bot set token_generado=@token,fecha_ultimo_token=@nos WHERE cuenta_telegram=@Cuenta"; string updateQuery = "UPDATE [Datos Alumno Bot] set token_generado='" + tokenNuevo + "',fecha_ultimo_token='" + nos + "' WHERE cuenta_telegram= ?"; OdbcCommand updateCommand = new OdbcCommand(updateQuery, db.odbcConnection); db.Open(); updateCommand.Parameters.Add("@Cuenta", OdbcType.Text).Value = Cuenta; updateCommand.ExecuteNonQuery(); db.Close(); return(true); } } } } catch (Exception e) { Logger.Log("Error generando token" + e.Message, LogType.Warn); Console.WriteLine("new token" + e.Message); } return(false); }
public Order Read_once(string number) { Order order = new Order(); try { Database.Connect(); command = new OdbcCommand { Connection = Database.GetConn(), CommandType = CommandType.StoredProcedure, CommandText = "{call csg.Order_ReadOnce(?)}" }; command.Parameters.Add("Number", OdbcType.VarChar, 50).Value = number; dataReader = command.ExecuteReader(); if (dataReader.Read()) { order = new Order { Order_number = dataReader.GetString(0), Order_reception_date = dataReader.GetDateTime(1), //Order_end_date = dataReader.GetDateTime(2), Order_type = dataReader.GetString(3), Order_invoice = dataReader.GetString(4), //Order_sale_date = dataReader.GetDate(5), Order_state = dataReader.GetString(6), //Order_comentarys = dataReader.GetString(7), Order_report_client = dataReader.GetString(8) }; string t = dataReader.GetString(9); string c = dataReader.GetString(10); string ct = dataReader.GetString(11); Database.Disconnect(); ITechnicianDAO technicianDAO = new TechnicianDAO(); Technician technician = technicianDAO.Read_once(t); order.Technician = technician; IClientDAO clientDAO = new ClientDAO(); Client client = clientDAO.Read_once(c); order.Client = client; ICotizationDAO cotizationDAO = new CotizationDAO(); Cotization cotization = cotizationDAO.Read_once(ct); order.Cotization = cotization; } } catch (Exception ex) { MessageBox.Show("Excepción controlada en OrderDAO->Read_once: " + ex.Message, "Excepción", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { Database.Disconnect(); } return(order); }
public List <Cotization> Read_all() { List <Cotization> cotizations = new List <Cotization>(); try { Database.Connect(); command = new OdbcCommand { Connection = Database.GetConn(), CommandType = CommandType.StoredProcedure, CommandText = "{call csg.Cotization_ReadAll}" }; dataReader = command.ExecuteReader(); while (dataReader.Read()) { Cotization cotization = new Cotization { Cotization_id = dataReader.GetString(0), Cotization_generation_date = dataReader.GetDateTime(1), Cotization_expiration_date = dataReader.GetDateTime(2), Cotization_quantity = dataReader.GetByte(3), Cotization_comentarys = dataReader.GetString(4), Cotization_subtotal = dataReader.GetString(5), Cotization_discount = dataReader.GetString(6), Cotization_iva = dataReader.GetString(7), Cotization_total = dataReader.GetString(8) }; cotizations.Add(cotization); } } catch (Exception ex) { MessageBox.Show("Excepción controlada en CotizationDAO->Read_all: " + ex.Message, "Excepción", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { Database.Disconnect(); } return(cotizations); }
private void Select_Min_Max_Date() { string temp_SQL = Remove_TSDBA(sql_MIN_MAX_DATE); string[] REGION = comboBox_REGIONS.SelectedItem.ToString().Split('['); temp_SQL += " WHERE REGION_ID = '" + REGION[0].Trim() + "'"; OdbcCommand odbc_CMD = new OdbcCommand(temp_SQL, odbc_CONN); try { OdbcDataReader odbc_RESULT = odbc_CMD.ExecuteReader(); if (odbc_RESULT.HasRows) { odbc_RESULT.Read(); //dateTimePicker_CREATION_DT_START.MinDate = odbc_RESULT.GetDateTime(0); //dateTimePicker_CREATION_DT_START.MaxDate = odbc_RESULT.GetDateTime(1); //dateTimePicker_CREATION_DT_END.MinDate = odbc_RESULT.GetDateTime(0); //dateTimePicker_CREATION_DT_END.MaxDate = odbc_RESULT.GetDateTime(1); dateTimePicker_CREATION_DT_START.Value = odbc_RESULT.GetDateTime(0); dateTimePicker_CREATION_DT_END.Value = odbc_RESULT.GetDateTime(1); } odbc_RESULT.Close(); } catch (Exception ERROR) { MessageBox.Show(First_Error(ERROR.Message) , "WARNING" , MessageBoxButtons.OK); } finally { odbc_CMD.Dispose(); } }
public static bool CreateForm(OdbcDataReader reader, PaymentHistory paymentHistory) { int fCount = reader.FieldCount; for (int i = 0; i < fCount; i++) { string name = reader.GetName(i); // Map to DB field. Need to change if db changed switch (name) { case "payment_id": paymentHistory._paymentID = reader.GetInt32(i); break; case "course_id": paymentHistory._courseID = reader.GetInt32(i); break; case "paid_cost": paymentHistory._paidCost = reader.GetInt32(i); break; case "paid_date": paymentHistory._paidDate = new DateTime(reader.GetDateTime(i).Ticks); break; case "sum_all_cost": paymentHistory._sumAllCost = reader.GetInt32(i); break; case "sum_max_payable": paymentHistory._sumMaxPayable = reader.GetInt32(i); break; case "sum_paid_cost": paymentHistory._sumPaidCost = reader.GetInt32(i); break; case "cost_info": paymentHistory._costInfo = reader.GetString(i); break; case "paid_round": paymentHistory._paidRound = reader.GetInt32(i); break; case "receiver_teacher_id": paymentHistory._receiverTeacherID = reader.GetInt32(i); break; case "username": paymentHistory._username = reader.GetString(i); break; case "branch_id": paymentHistory._branchID = reader.GetInt32(i); break; // helper info } } return(reader.HasRows); }
/// <summary> /// Returns a list of achievements that are of the specified categories. 27/11/15 /// </summary> public static List <Achievement> GetAchievements(List <string> categories) { // Create a list to store the returned achievements List <Achievement> achievements = new List <Achievement>(); // Get all achievements where the category is... string query = "SELECT * FROM `" + achievementTable + "` WHERE `Category` IN ("; // ..any of the categories specified. foreach (string x in categories) { query = (query + '"' + x + '"' + ","); } // Remove the succeeding comma that is added due to the previous foreach loop, // and finish the query with a bracket. query = query.Remove(query.Length - 1); query = query + ")"; if (connectionOpen()) { // Create a database command from the query and existing connection. OdbcCommand cmd = new OdbcCommand(query, connection); try { // Execute the command and open a reader. OdbcDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) // Read the next record. { // Get the id first, and check to make sure it is something. int id = dataReader.GetInt16(0); if (id != 0) { // Adds the achievement that is read from the database to the // list of achievements that is to be returned. achievements.Add(new Achievement(id, dataReader.GetString(1), dataReader.GetString(2), dataReader.GetString(3), dataReader.GetString(4), dataReader.GetInt16(5), dataReader.GetDateTime(6), dataReader.GetBoolean(7))); } } dataReader.Close(); } catch (OdbcException ex) { // Displays an error if something bad occurs while executing the command error = ex.Message; } } return(achievements); }
private static string GetNameFromPlayerNumbersTableIndividual(OdbcConnection conn, TableStatus tableStatus, int playerNo) { if (playerNo == 0) { return(""); } string number = ""; string name = ""; DateTime latestTimeLog = new DateTime(2010, 1, 1); string SQLString = $"SELECT Number, Name, Round, TimeLog FROM PlayerNumbers WHERE Section={tableStatus.SectionID} AND TabScorePairNo={playerNo}"; OdbcCommand cmd = new OdbcCommand(SQLString, conn); OdbcDataReader reader = null; try { ODBCRetryHelper.ODBCRetry(() => { reader = cmd.ExecuteReader(); while (reader.Read()) { try { int readerRoundNumber = reader.GetInt32(2); DateTime timeLog; if (reader.IsDBNull(3)) { timeLog = new DateTime(2010, 1, 1); } else { timeLog = reader.GetDateTime(3); } if (readerRoundNumber <= tableStatus.RoundNumber && timeLog >= latestTimeLog) { number = reader.GetString(0); name = reader.GetString(1); latestTimeLog = timeLog; } } catch { } // Record found, but format cannot be parsed } }); } finally { cmd.Dispose(); reader.Close(); } return(FormatName(name, number)); }