public Prescription(int pID, int doc, string pxName, string notes, DateTime startDate, DateTime endDate, string status) { _patientID = pID; _startDate = new MySqlDateTime(startDate); _endDate = new MySqlDateTime(endDate); _prescriptionName = pxName; _notes = notes; _Doctor = doc; _status = status; }
/// <summary> /// Constructs a new <b>MySqlDateTime</b> object by copying the current value of the given object. /// </summary> /// <param name="mdt">The <b>MySqlDateTime</b> object to copy.</param> public MySqlDateTime(MySqlDateTime mdt) { year = mdt.Year; month = mdt.Month; day = mdt.Day; hour = mdt.Hour; minute = mdt.Minute; second = mdt.Second; millisecond = 0; type = MySqlDbType.DateTime; isNull = false; }
public void TestSerializationMySqlDataTime() { MySqlDateTime dt = new MySqlDateTime(2011, 10, 6, 11, 38, 01, 0); Assert.AreEqual(2011, dt.Year); Assert.AreEqual(10, dt.Month); Assert.AreEqual(6, dt.Day); Assert.AreEqual(11, dt.Hour); Assert.AreEqual(38, dt.Minute); Assert.AreEqual(1, dt.Second); BinaryFormatter bf = new BinaryFormatter(); MemoryStream ms = new MemoryStream( 1024 ); bf.Serialize(ms, dt); ms.Position = 0; object o = bf.Deserialize(ms); dt = (MySqlDateTime)o; Assert.AreEqual(2011, dt.Year); Assert.AreEqual(10, dt.Month); Assert.AreEqual(6, dt.Day); Assert.AreEqual(11, dt.Hour); Assert.AreEqual(38, dt.Minute); Assert.AreEqual(1, dt.Second); }
public bool Select() { List<object[]> SingleRow = Database.Select("SELECT * FROM Prescription WHERE prid = " + _prescriptionID); if (SingleRow != null && SingleRow.Count > 0) { { foreach (object[] row in SingleRow) { _prescriptionID = Convert.ToInt32(row[0]); _patientID = Convert.ToInt32(row[1]); _Doctor = Convert.ToInt32(row[2]); _prescriptionName = row[3].ToString(); _notes = row[4].ToString(); _startDate = new MySqlDateTime(Convert.ToDateTime(row[5])); _endDate = new MySqlDateTime( Convert.ToDateTime(row[6])); _status = row[7].ToString(); } } return true; } return false; }
int IComparable.CompareTo(object obj) { MySqlDateTime otherDate = (MySqlDateTime)obj; if (Year < otherDate.Year) { return(-1); } else if (Year > otherDate.Year) { return(1); } if (Month < otherDate.Month) { return(-1); } else if (Month > otherDate.Month) { return(1); } if (Day < otherDate.Day) { return(-1); } else if (Day > otherDate.Day) { return(1); } if (Hour < otherDate.Hour) { return(-1); } else if (Hour > otherDate.Hour) { return(1); } if (Minute < otherDate.Minute) { return(-1); } else if (Minute > otherDate.Minute) { return(1); } if (Second < otherDate.Second) { return(-1); } else if (Second > otherDate.Second) { return(1); } if (Millisecond < otherDate.Millisecond) { return(-1); } else if (Millisecond > otherDate.Millisecond) { return(1); } return(0); }
internal MySqlDateTime(MySqlDbType type, bool isNull) { this = new MySqlDateTime(type, 0, 0, 0, 0, 0, 0, 0); this.isNull = isNull; }
static internal MySqlDateTime Parse(string s, DBVersion version) { var dt = new MySqlDateTime(); return dt.ParseMySql(s); }
public MySqlDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond) { this = new MySqlDateTime(MySqlDbType.DateTime, year, month, day, hour, minute, second, millisecond); }
public void setJsonTable(JObject jtable) { DataTable = null; DataTable = new Table(); var pairs = jtable.GetEnumerator(); while (pairs.MoveNext()) { if (string.Equals(pairs.Current.Key, DicKeys.columns)) { JArray columns = (JArray)pairs.Current.Value; foreach (JObject c in columns) { if (c.HasValues) { var colum = new Column(); colum.ColumnName = (string)c.GetValue(DicKeys.name); JToken type;; var success = c.TryGetValue(DicKeys.dbType, out type); if (success) { colum.DbType = type.ToString(); } DataTable.DataColumns.Add(colum); } } } else if (string.Equals(pairs.Current.Key, DicKeys.rows)) { JArray rows = (JArray)pairs.Current.Value; if (rows.HasValues) { //JArray firstRow = (JArray)rows[0]; //for (var i = 0; i < firstRow.Count; i++) //{ //if (firstRow[i].Type == JTokenType.String) // DataTable.DataColumns[i].DataType = typeof(string); //else if (firstRow[i].Type == JTokenType.Integer) // DataTable.DataColumns[i].DataType = typeof(int); //else if (firstRow[i].Type == JTokenType.Boolean) // DataTable.DataColumns[i].DataType = typeof(bool); //else if (firstRow[i].Type == JTokenType.Float) // DataTable.DataColumns[i].DataType = typeof(float); //else if (firstRow[i].Type == JTokenType.Null) // DataTable.DataColumns[i].DataType = typeof(DBNull); //} foreach (JArray r in rows) { var row = DataTable.NewRow(); for (var i = 0; i < r.Count; i++) { string originDbType = DataTable.DataColumns[i].DbType; string colum = "费用"; try { if (DataTable.DataColumns[i].ColumnName == "费用") { var dddd = r[i]; } } catch { } //row[i] = r[i]; if (originDbType.IsTheseType("now")) { row[i] = new MySql.Data.Types.MySqlDateTime(DateTime.Now); } else if (originDbType.IsTheseType("datetime")) { MySqlDateTime datetime = default(MySqlDateTime); try { datetime = new MySql.Data.Types.MySqlDateTime(Convert.ToDateTime((string)r[i])); } catch { } finally { row[i] = datetime;// new DateTime("vc"); } } else if (originDbType.IsTheseType("decimal") && (r[i].Type == JTokenType.String || r[i].Type == JTokenType.Null || r[i].Type == JTokenType.None)) { decimal decimalData = default(decimal); try { decimalData = decimal.Parse((string)r[i]); } catch { } finally { row[i] = decimalData; } } else if (originDbType.IsTheseType("decimal") && r[i].Type == JTokenType.Integer) { decimal decimalData = default(decimal); try { decimalData = new decimal((long)r[i]); } catch { } finally { row[i] = decimalData; } } else if (originDbType.IsTheseType("int") && (r[i].Type == JTokenType.String || r[i].Type == JTokenType.Null || r[i].Type == JTokenType.None)) { long intdata = default(long); try { intdata = long.Parse((string)r[i]); } catch { } finally { row[i] = intdata; } } else if (originDbType.IsTheseType("int") && r[i].Type == JTokenType.Integer) { long intdata = default(long); try { intdata = (long)r[i]; } catch { } finally { row[i] = intdata; } } else if (originDbType.IsTheseType("varchar")) { string varchrData = null; try { varchrData = (string)r[i]; } catch { } finally { row[i] = varchrData; } } else if (r[i].Type == JTokenType.Boolean) { row[i] = (bool)r[i]; } else if (r[i].Type == JTokenType.Integer) { row[i] = (int)r[i]; } else if (r[i].Type == JTokenType.Float) { row[i] = (double)r[i]; } else if (r[i].Type == JTokenType.String) { row[i] = (string)r[i]; } else { row[i] = (object)r[i]; } } DataTable.Rows.Add(row); } } } else if (string.Equals(pairs.Current.Key, DicKeys.name)) { DataTable.TableName = (string)pairs.Current.Value; } else if (string.Equals(pairs.Current.Key, DicKeys.dataBase)) { DataTable.Database = (string)pairs.Current.Value; } } }
void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object value, int length) { MySqlDateTime dtValue; if (value is DateTime) dtValue = new MySqlDateTime(type, (DateTime)value); else if (value is string) dtValue = new MySqlDateTime(type, DateTime.Parse((string)value, System.Globalization.CultureInfo.CurrentCulture)); else if (value is MySqlDateTime) dtValue = (MySqlDateTime)value; else throw new MySqlException("Unable to serialize date/time value."); if (!binary) { SerializeText(stream, dtValue); return; } if (type == MySqlDbType.Timestamp) stream.WriteByte(11); else stream.WriteByte(7); stream.WriteInteger(dtValue.Year, 2); stream.WriteByte((byte)dtValue.Month); stream.WriteByte((byte)dtValue.Day); if (type == MySqlDbType.Date) { stream.WriteByte(0); stream.WriteByte(0); stream.WriteByte(0); } else { stream.WriteByte((byte)dtValue.Hour); stream.WriteByte((byte)dtValue.Minute); stream.WriteByte((byte)dtValue.Second); } if (type == MySqlDbType.Timestamp) stream.WriteInteger(dtValue.Millisecond, 4); }
public void MySqlDateTimeFormatting() { DateTime dt = DateTime.Now; MySqlDateTime mdt = new MySqlDateTime(dt); Assert.AreEqual(dt.ToString(), mdt.ToString()); }
internal static MySqlDateTime Parse(string s) { MySqlDateTime dt = new MySqlDateTime(); return dt.ParseMySql(s, true); }
private void SerializeText(MySqlStream stream, MySqlDateTime value) { string val = String.Empty; if (type == MySqlDbType.Timestamp && !stream.Version.isAtLeast(4, 1, 0)) val = String.Format("{0:0000}{1:00}{2:00}{3:00}{4:00}{5:00}", value.Year, value.Month, value.Day, value.Hour, value.Minute, value.Second); else { val = String.Format("{0:0000}-{1:00}-{2:00}", value.Year, value.Month, value.Day); if (type != MySqlDbType.Date) val = String.Format("{0} {1:00}:{2:00}:{3:00}", val, value.Hour, value.Minute, value.Second); } stream.WriteStringNoNull("'" + val + "'"); }
void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object value, int length) { MySqlDateTime dtValue; string valueAsString = value as string; if (value is DateTime) dtValue = new MySqlDateTime(type, (DateTime)value); else if (valueAsString != null) dtValue = new MySqlDateTime(type, DateTime.Parse(valueAsString, CultureInfo.CurrentCulture)); else if (value is MySqlDateTime) dtValue = (MySqlDateTime)value; else throw new MySqlException("Unable to serialize date/time value."); if (!binary) { SerializeText(packet, dtValue); return; } if (type == MySqlDbType.Timestamp) packet.WriteByte(11); else packet.WriteByte(7); packet.WriteInteger(dtValue.Year, 2); packet.WriteByte((byte)dtValue.Month); packet.WriteByte((byte)dtValue.Day); if (type == MySqlDbType.Date) { packet.WriteByte(0); packet.WriteByte(0); packet.WriteByte(0); } else { packet.WriteByte((byte)dtValue.Hour); packet.WriteByte((byte)dtValue.Minute); packet.WriteByte((byte)dtValue.Second); } if (type == MySqlDbType.Timestamp) packet.WriteInteger(dtValue.Millisecond, 4); }
int IComparable.CompareTo(object obj) { MySqlDateTime mySqlDateTime = (MySqlDateTime)obj; if (this.Year < mySqlDateTime.Year) { return(-1); } if (this.Year > mySqlDateTime.Year) { return(1); } if (this.Month < mySqlDateTime.Month) { return(-1); } if (this.Month > mySqlDateTime.Month) { return(1); } if (this.Day < mySqlDateTime.Day) { return(-1); } if (this.Day > mySqlDateTime.Day) { return(1); } if (this.Hour < mySqlDateTime.Hour) { return(-1); } if (this.Hour > mySqlDateTime.Hour) { return(1); } if (this.Minute < mySqlDateTime.Minute) { return(-1); } if (this.Minute > mySqlDateTime.Minute) { return(1); } if (this.Second < mySqlDateTime.Second) { return(-1); } if (this.Second > mySqlDateTime.Second) { return(1); } if (this.Millisecond < mySqlDateTime.Millisecond) { return(-1); } if (this.Millisecond > mySqlDateTime.Millisecond) { return(1); } return(0); }
void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object value, int length) { string text = value as string; MySqlDateTime value2; if (value is DateTime) { value2 = new MySqlDateTime(this.type, (DateTime)value); } else { if (text != null) { value2 = MySqlDateTime.Parse(text); } else { if (!(value is MySqlDateTime)) { throw new MySqlException("Unable to serialize date/time value."); } value2 = (MySqlDateTime)value; } } if (!binary) { this.SerializeText(packet, value2); return; } if (value2.Millisecond > 0) { packet.WriteByte(11); } else { packet.WriteByte(7); } packet.WriteInteger((long)value2.Year, 2); packet.WriteByte((byte)value2.Month); packet.WriteByte((byte)value2.Day); if (this.type == MySqlDbType.Date) { packet.WriteByte(0); packet.WriteByte(0); packet.WriteByte(0); } else { packet.WriteByte((byte)value2.Hour); packet.WriteByte((byte)value2.Minute); packet.WriteByte((byte)value2.Second); } if (value2.Millisecond > 0) { long num = (long)((value2.Millisecond < 1000) ? (value2.Millisecond * 1000) : value2.Millisecond); for (int i = 0; i < 4; i++) { packet.WriteByte((byte)(num & 255L)); num >>= 8; } } }
/// <summary> /// Enables the contruction of a <b>MySqlDateTime</b> object by parsing a string. /// </summary> public MySqlDateTime(string dateTime) : this(MySqlDateTime.Parse(dateTime)) { }
static internal MySqlDateTime Parse(string s, Common.DBVersion version) { MySqlDateTime dt = new MySqlDateTime(); return dt.ParseMySql(s, version.isAtLeast(4, 1, 0)); }
public void DateTimeInDataTable() { execSQL("INSERT INTO Test VALUES(1, Now(), '0000-00-00', NULL, NULL)"); using (MySqlConnection c = new MySqlConnection( conn.ConnectionString + ";pooling=false;AllowZeroDatetime=true")) { c.Open(); MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", c); MySqlCommandBuilder cb = new MySqlCommandBuilder(da); DataTable dt = new DataTable(); da.Fill(dt); DataRow row = dt.NewRow(); row["id"] = 2; row["dt"] = new MySqlDateTime(DateTime.Now); row["d"] = new MySqlDateTime(DateTime.Now); row["t"] = new TimeSpan(1, 1, 1); row["ts"] = DBNull.Value; dt.Rows.Add(row); da.Update(dt); dt.Rows.Clear(); da.Fill(dt); Assert.AreEqual(2, dt.Rows.Count); cb.Dispose(); } }
static internal MySqlDateTime Parse(string s, Common.DBVersion version) { MySqlDateTime dt = new MySqlDateTime(); return(dt.ParseMySql(s, version.isAtLeast(4, 1, 0))); }
public void TestAllowZeroDateTime() { execSQL("TRUNCATE TABLE Test"); execSQL("INSERT INTO Test (id, d, dt) VALUES (1, '0000-00-00', '0000-00-00 00:00:00')"); using (MySqlConnection c = new MySqlConnection( conn.ConnectionString + ";pooling=false;AllowZeroDatetime=true")) { c.Open(); MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", c); using (MySqlDataReader reader = cmd.ExecuteReader()) { reader.Read(); Assert.IsTrue(reader.GetValue(1) is MySqlDateTime); Assert.IsTrue(reader.GetValue(2) is MySqlDateTime); Assert.IsFalse(reader.GetMySqlDateTime(1).IsValidDateTime); Assert.IsFalse(reader.GetMySqlDateTime(2).IsValidDateTime); try { reader.GetDateTime(1); Assert.Fail("This should not succeed"); } catch (MySqlConversionException) { } } DataTable dt = new DataTable(); MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", c); MySqlCommandBuilder cb = new MySqlCommandBuilder(da); da.Fill(dt); dt.Rows[0]["id"] = 2; DataRow row = dt.NewRow(); row["id"] = 3; row["d"] = new MySqlDateTime("2003-9-24"); row["dt"] = new MySqlDateTime("0000/0/00 00:00:00"); dt.Rows.Add(row); da.Update(dt); dt.Clear(); da.Fill(dt); Assert.AreEqual(2, dt.Rows.Count); MySqlDateTime date = (MySqlDateTime)dt.Rows[1]["d"]; Assert.AreEqual(2003, date.Year); Assert.AreEqual(9, date.Month); Assert.AreEqual(24, date.Day); cb.Dispose(); } }
static internal MySqlDateTime Parse(string s) { MySqlDateTime dt = new MySqlDateTime(); return dt.ParseMySql(s); }
public MySqlDateTime(DateTime dt) { this = new MySqlDateTime(MySqlDbType.DateTime, dt); }
private void SerializeText(MySqlPacket packet, MySqlDateTime value) { var val = String.Empty; val = String.Format("{0:0000}-{1:00}-{2:00}", value.Year, value.Month, value.Day); if (type != MySqlDbType.Date) { val = value.Millisecond > 0 ? String.Format("{0} {1:00}:{2:00}:{3:00}.{4:000}", val, value.Hour, value.Minute, value.Second, value.Millisecond) : String.Format("{0} {1:00}:{2:00}:{3:00} ", val, value.Hour, value.Minute, value.Second); } packet.WriteStringNoNull("'" + val + "'"); }
/// <summary> /// Enables the contruction of a <b>MySqlDateTime</b> object by parsing a string. /// </summary> /// <param name="s"></param> public MySqlDateTime(string s) : this(MySqlDateTime.Parse(s)) { }
public MySqlDateTime(string dateTime) { this = new MySqlDateTime(MySqlDateTime.Parse(dateTime)); }
static internal MySqlDateTime Parse(string s, Common.DBVersion version) { MySqlDateTime dt = new MySqlDateTime(); return dt.ParseMySql(s); }
void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object value, int length) { MySqlDateTime dtValue; string valueAsString = value as string; if (value is DateTime) { dtValue = new MySqlDateTime(type, (DateTime)value); } else if (valueAsString != null) { dtValue = MySqlDateTime.Parse(valueAsString); } else if (value is MySqlDateTime) { dtValue = (MySqlDateTime)value; } else { throw new MySqlException("Unable to serialize date/time value."); } if (!binary) { SerializeText(packet, dtValue); return; } if (dtValue.Millisecond > 0) { packet.WriteByte(11); } else { packet.WriteByte(7); } packet.WriteInteger(dtValue.Year, 2); packet.WriteByte((byte)dtValue.Month); packet.WriteByte((byte)dtValue.Day); if (type == MySqlDbType.Date) { packet.WriteByte(0); packet.WriteByte(0); packet.WriteByte(0); } else { packet.WriteByte((byte)dtValue.Hour); packet.WriteByte((byte)dtValue.Minute); packet.WriteByte((byte)dtValue.Second); } if (dtValue.Millisecond > 0) { long val = dtValue.Millisecond; for (int x = 0; x < 4; x++) { packet.WriteByte((byte)(val & 0xff)); val >>= 8; } } }
void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object value, int length) { MySqlDateTime dtValue; var valueAsString = value as string; if (value is DateTime) dtValue = new MySqlDateTime(type, (DateTime)value); else if (valueAsString != null) dtValue = Parse(valueAsString); else if (value is MySqlDateTime) dtValue = (MySqlDateTime)value; else throw new MySqlException("Unable to serialize date/time value."); if (!binary) { SerializeText(packet, dtValue); return; } if (dtValue.Millisecond > 0) packet.WriteByte(11); else packet.WriteByte(7); packet.WriteInteger(dtValue.Year, 2); packet.WriteByte((byte)dtValue.Month); packet.WriteByte((byte)dtValue.Day); if (type == MySqlDbType.Date) { packet.WriteByte(0); packet.WriteByte(0); packet.WriteByte(0); } else { packet.WriteByte((byte)dtValue.Hour); packet.WriteByte((byte)dtValue.Minute); packet.WriteByte((byte)dtValue.Second); } if (dtValue.Millisecond > 0) { long val = dtValue.Millisecond < 1000 ? dtValue.Millisecond * 1000 : dtValue.Millisecond; for (var x = 0; x < 4; x++) { packet.WriteByte((byte)(val & 0xff)); val >>= 8; } } }
static internal MySqlDateTime Parse(string s) { MySqlDateTime dt = new MySqlDateTime(); return(dt.ParseMySql(s)); }
static internal MySqlDateTime Parse(string s, Common.DBVersion version) { MySqlDateTime dt = new MySqlDateTime(); return(dt.ParseMySql(s)); }
static SqlDateTime MySqlDateTimeToSqlDateTime(MySqlDateTime mySqlDateTime) { if (!mySqlDateTime.IsValidDateTime) return SqlDateTime.Null; return mySqlDateTime.GetDateTime(); }