Esempio n. 1
0
 public Empresa(int id, int idDiretor, int idComercial, int idTecnico, string cnpj, string razaoSocial,
                string tel1, string tel2, string endereco, int numero, string complemento, string cep, double lat, double lon, Cidade cidade,
                MySqlDateTime inicioEmpresa, string descEmpresa, int qtdFuncionarios, int repTempo, int repQualidade, int repAtendimento,
                int repQuantidade, int repFiscal, int qtdServ, string zonaAtendimento, MySqlDateTime dataCadastro, int block)
 {
     this.id              = id;
     this.idDiretor       = idDiretor;
     this.idComercial     = idComercial;
     this.idTecnico       = idTecnico;
     this.cnpj            = cnpj;
     this.razaoSocial     = razaoSocial;
     this.tel1            = tel1;
     this.tel2            = tel2;
     this.endereco        = endereco;
     this.numero          = numero;
     this.complemento     = complemento;
     this.cep             = cep;
     this.lat             = lat;
     this.lon             = lon;
     this.cidade          = cidade;
     this.inicioEmpresa   = inicioEmpresa;
     this.descEmpresa     = descEmpresa;
     this.qtdFuncionarios = qtdFuncionarios;
     this.repTempo        = repTempo;
     this.repQualidade    = repQualidade;
     this.repAtendimento  = repAtendimento;
     this.repQuantidade   = repQuantidade;
     this.repFiscal       = repFiscal;
     this.qtdServ         = qtdServ;
     this.zonaAtendimento = zonaAtendimento;
     this.dataCadastro    = dataCadastro;
     this.block           = block;
 }
Esempio n. 2
0
 public Usuario(int id, string login, string senha, string nome, string email,
                string cpf, string tel1, string tel2, string endereco, int numero, string complemento,
                string cep, Cidade cidade, int reputacao, MySqlDateTime dataCadastro, MySqlDateTime ultimoLogin,
                int errosSenha, int block, int qtdServicos, UsuarioEmpresa userEmp)
 {
     this.id           = id;
     this.login        = login;
     this.senha        = senha;
     this.nome         = nome;
     this.email        = email;
     this.cpf          = cpf;
     this.tel1         = tel1;
     this.tel2         = tel2;
     this.endereco     = endereco;
     this.numero       = numero;
     this.complemento  = complemento;
     this.cep          = cep;
     this.cidade       = cidade;
     this.reputacao    = reputacao;
     this.dataCadastro = dataCadastro;
     this.ultimoLogin  = ultimoLogin;
     this.errosSenha   = errosSenha;
     this.block        = block;
     this.qtdServicos  = qtdServicos;
     this.userEmp      = userEmp;
 }
Esempio n. 3
0
        public void ZeroMySqlDateTimeIsNotValidDateTime()
        {
            var msdt = new MySqlDateTime(0, 0, 0, 0, 0, 0, 0);

            Assert.False(msdt.IsValidDateTime);
        }
Esempio n. 4
0
        public void NonZeroMySqlDateTimeIsValidDateTime()
        {
            var msdt = new MySqlDateTime(2018, 6, 9, 0, 0, 0, 0);

            Assert.True(msdt.IsValidDateTime);
        }
Esempio n. 5
0
        /// <summary>
        /// Converts a value of a specified MySQL DB type to PHP value.
        /// </summary>
        /// <param name="dataType">MySQL DB data type.</param>
        /// <param name="sqlValue">The value.</param>
        /// <returns>PHP value.</returns>
        private static object ConvertDbValue(string dataType, object sqlValue)
        {
            if (sqlValue == null || sqlValue.GetType() == typeof(string))
            {
                return(sqlValue);
            }

            if (sqlValue.GetType() == typeof(double))
            {
                return(Core.Convert.DoubleToString((double)sqlValue));
            }

            if (sqlValue == System.DBNull.Value)
            {
                return(null);
            }

            if (sqlValue.GetType() == typeof(int))
            {
                return(((int)sqlValue).ToString());
            }

            if (sqlValue.GetType() == typeof(uint))
            {
                return(((uint)sqlValue).ToString());
            }

            if (sqlValue.GetType() == typeof(bool))
            {
                return((bool)sqlValue ? "1" : "0");
            }

            if (sqlValue.GetType() == typeof(byte))
            {
                return(((byte)sqlValue).ToString());
            }

            if (sqlValue.GetType() == typeof(sbyte))
            {
                return(((sbyte)sqlValue).ToString());
            }

            if (sqlValue.GetType() == typeof(short))
            {
                return(((short)sqlValue).ToString());
            }

            if (sqlValue.GetType() == typeof(ushort))
            {
                return(((ushort)sqlValue).ToString());
            }

            if (sqlValue.GetType() == typeof(float))
            {
                return(Core.Convert.DoubleToString((float)sqlValue));
            }

            if (sqlValue.GetType() == typeof(DateTime))
            {
                return(ConvertDateTime(dataType, (DateTime)sqlValue));
            }

            if (sqlValue.GetType() == typeof(long))
            {
                return(((long)sqlValue).ToString());
            }

            if (sqlValue.GetType() == typeof(ulong))
            {
                return(((ulong)sqlValue).ToString());
            }

            if (sqlValue.GetType() == typeof(TimeSpan))
            {
                return(((TimeSpan)sqlValue).ToString());
            }

            if (sqlValue.GetType() == typeof(decimal))
            {
                return(((decimal)sqlValue).ToString());
            }

            if (sqlValue.GetType() == typeof(byte[]))
            {
                return(new PhpBytes((byte[])sqlValue));
            }

            //MySqlDateTime sql_date_time = sqlValue as MySqlDateTime;
            if (sqlValue.GetType() == typeof(MySqlDateTime))
            {
                MySqlDateTime sql_date_time = (MySqlDateTime)sqlValue;
                if (sql_date_time.IsValidDateTime)
                {
                    return(ConvertDateTime(dataType, sql_date_time.GetDateTime()));
                }

                if (dataType == "DATE" || dataType == "NEWDATE")
                {
                    return("0000-00-00");
                }
                else
                {
                    return("0000-00-00 00:00:00");
                }
            }

            Debug.Fail("Unexpected DB field type " + sqlValue.GetType() + ".");
            return(sqlValue.ToString());
        }
Esempio n. 6
0
        public void InvalidDateTimeConvertibleToString()
        {
            IConvertible convertible = new MySqlDateTime();

            Assert.Equal("0000-00-00", convertible.ToString(CultureInfo.InvariantCulture));
        }
Esempio n. 7
0
        /// <summary>
        /// tworzenie pliku kopi bazy danych
        /// </summary>
        public void createBackup()
        {
            if (File.Exists(_sBackupFileName))
            {
                FileInfo oFileInfo = new FileInfo(_sBackupFileName);
                oFileInfo.Delete();
            }

            string sNazwaBazy = _oConn.Database;

            /// pobranie listy tabel
            _sSqlQuery = "SHOW TABLE STATUS FROM " + sNazwaBazy + " WHERE ENGINE IS NOT NULL";
            if (checkConnectionState())
            {
                MySqlCommand    oCmd    = new MySqlCommand(_sSqlQuery, _oConn);
                MySqlDataReader oReader = oCmd.ExecuteReader();

                //StringBuilder sSchema = new StringBuilder();
                List <SortedList <string, object[]> > aListaTabel = new List <SortedList <string, object[]> >();
                if (oReader.HasRows)
                {
                    while (oReader.Read())
                    {
                        SortedList <string, object[]> aTabela = new SortedList <string, object[]>();

                        object[] aTableInfo = new object[] {
                            oReader["Engine"], oReader["Collation"], oReader["Auto_increment"]
                        };

                        aTabela.Add(oReader["Name"].ToString(), aTableInfo);
                        aListaTabel.Add(aTabela);
                    }
                    oReader.Close();
                }

                foreach (SortedList <string, object[]> aInformacje in aListaTabel)
                {
                    foreach (KeyValuePair <string, object[]> aTabela in aInformacje)
                    {
                        string[] aSklejaniePol = new string[2];

                        zapisanieDoPliku("#", false);
                        zapisanieDoPliku(string.Format("# Struktura tabeli {0}", aTabela.Key), false);
                        zapisanieDoPliku("#", false);
                        zapisanieDoPliku(string.Format("DROP TABLE IF EXISTS `{0}`;", aTabela.Key), false);
                        zapisanieDoPliku(string.Format("CREATE TABLE IF NOT EXISTS {0} (", aTabela.Key), false);

                        _sSqlQuery = string.Format("SHOW KEYS FROM `{0}`", aTabela.Key);
                        oCmd       = new MySqlCommand(_sSqlQuery, _oConn);
                        oReader    = oCmd.ExecuteReader();

                        SortedList <string, List <string> > aInfoOkluczach = new SortedList <string, List <string> >();
                        if (oReader.HasRows)
                        {
                            while (oReader.Read())
                            {
                                List <string> aInfoKolumny = new List <string>();
                                string        sKeyName     = oReader["Key_name"].ToString();
                                /// jesli klucz nie jest kluczem glowny i jest unikalny
                                if (sKeyName != "PRIMARY" && oReader["Non_unique"].ToString() == "1")
                                {
                                    sKeyName = "UNIQUE " + sKeyName;
                                }
                                else if (sKeyName != "PRIMARY" && oReader["Non_unique"].ToString() == "0")
                                {
                                }

                                aInfoKolumny.Add(oReader["Column_name"].ToString());
                                int iIndex = aInfoOkluczach.IndexOfKey(sKeyName);
                                if (iIndex == -1)
                                {
                                    aInfoOkluczach.Add(sKeyName, aInfoKolumny);
                                }
                                else
                                {
                                    aInfoOkluczach[sKeyName].Clear();
                                    aInfoOkluczach[sKeyName] = aInfoKolumny;
                                }
                            }
                        }

                        oReader.Close();

                        int           iFields   = aInfoOkluczach.Count;
                        int           iIndexCol = 0;
                        StringBuilder sKlucze   = new StringBuilder();

                        string[] aKluczeDoTabeli = new string[aInfoOkluczach.Count];
                        foreach (KeyValuePair <string, List <string> > aInfo in aInfoOkluczach)
                        {
                            string[] aColumns = new string[aInfo.Value.Count];
                            for (int j = 0; j < aInfo.Value.Count; j++)
                            {
                                aColumns[j] = aInfo.Value[j];
                            }

                            int iMaxLen = aInfo.Key.Length;

                            string sKolumny = string.Join("`,`", aColumns);
                            if (aInfo.Key == "PRIMARY")
                            {
                                aKluczeDoTabeli[iIndexCol] = string.Format("   PRIMARY KEY (`{0}`)", sKolumny);
                            }
                            else if (aInfo.Key.Substring(0, iMaxLen) == "UNIQUE")
                            {
                                aKluczeDoTabeli[iIndexCol] = string.Format("   UNIQUE KEY {0} (`{1}`)", aInfo.Key.Substring(7), sKolumny);
                            }
                            else
                            {
                                aKluczeDoTabeli[iIndexCol] = string.Format("   KEY {0} (`{1}`)", aInfo.Key, sKolumny);
                            }
                            iIndexCol++;
                        }

                        aSklejaniePol[1] = string.Join(",\n", aKluczeDoTabeli);

                        _sSqlQuery = string.Format("SHOW FIELDS FROM `{0}`", aTabela.Key);
                        oCmd       = new MySqlCommand(_sSqlQuery, _oConn);
                        oReader    = oCmd.ExecuteReader();
                        if (oReader.HasRows)
                        {
                            List <string> aLista = new List <string>();
                            while (oReader.Read())
                            {
                                string sNotNull = null;
                                if (oReader["Null"].ToString() == "Yes")
                                {
                                    sNotNull = " NOT NULL";
                                }

                                string sDefault = null;
                                if (oReader["Default"].ToString() != "")
                                {
                                    sDefault = string.Format(" default '{0}'", oReader["Default"]);
                                }

                                string sExtra = null;
                                if (oReader["Extra"].ToString() != "")
                                {
                                    sExtra = string.Format(" {0}", oReader["Extra"]);
                                }

                                aLista.Add(string.Format("   `{0}` {1}{2}{3}{4}",
                                                         oReader["Field"], oReader["Type"], sNotNull, sDefault, sExtra));
                            }
                            string[] aPola = new string[aLista.Count];
                            for (int k = 0; k < aLista.Count; k++)
                            {
                                aPola[k] = aLista[k];
                            }

                            aSklejaniePol[0] = string.Join(",\n", aPola);
                        }

                        oReader.Close();
                        string sDoZapisania = string.Join(",\n", aSklejaniePol);

                        zapisanieDoPliku(sDoZapisania, false);

                        string sAutoIncrement = null;
                        if ((aTabela.Value[2]).ToString() != "")
                        {
                            sAutoIncrement = string.Format(" AUTO_INCREMENT={0}", aTabela.Value[2]);
                        }

                        string[] sCharset = aTabela.Value[1].ToString().Split(new char[] { '_' });
                        zapisanieDoPliku(string.Format(") ENGINE={0} DEFAULT CHARSET={1} COLLATE={2}{3};\n\n",
                                                       aTabela.Value[0], sCharset[0], aTabela.Value[1], sAutoIncrement), false);

                        _sSqlQuery = string.Format("SELECT * FROM {0}", aTabela.Key);
                        oCmd       = new MySqlCommand(_sSqlQuery, _oConn);
                        oReader    = oCmd.ExecuteReader();
                        if (oReader.HasRows)
                        {
                            zapisanieDoPliku("#", false);
                            zapisanieDoPliku(string.Format("# Dane  z tabeli {0}", aTabela.Key), false);
                            zapisanieDoPliku("#", false);

                            List <string> aRows = new List <string>();
                            while (oReader.Read())
                            {
                                string[] aWartosci = new string[oReader.FieldCount];
                                for (int i = 0; i < oReader.FieldCount; i++)
                                {
                                    string sWartosc = null;

                                    switch (oReader[i].GetType().ToString())
                                    {
                                    case "System.DBNull":
                                        sWartosc = "";
                                        break;

                                    case "System.Boolean":
                                        sWartosc = (oReader.GetBoolean(i)) ? "1" : "0";
                                        break;

                                    case "System.Byte[]":
                                        Byte[] bBlob = new Byte[(oReader.GetBytes(i, 0, null, 0, int.MaxValue))];
                                        if (bBlob != null)
                                        {
                                            oReader.GetBytes(i, 0, bBlob, 0, bBlob.Length);
                                            if (bBlob != null)
                                            {
                                                sWartosc = System.Text.Encoding.GetEncoding("utf-8").GetString(bBlob);
                                                if (true)
                                                {
                                                    sWartosc = parseString(sWartosc);
                                                }
                                            }
                                        }
                                        break;

                                    case "MySql.Data.Types.MySqlDateTime":
                                        MySqlDateTime oDateTime = oReader.GetMySqlDateTime(i);
                                        sWartosc = oDateTime.ToString();
                                        break;

                                    default:
                                        sWartosc = string.Format("{0}", parseString(oReader.GetString(i)));
                                        break;
                                    }

                                    aWartosci[i] = string.Format("'{0}'", sWartosc);
                                }
                                zapisanieDoPliku(string.Format("INSERT INTO {0} VALUES ({1});", aTabela.Key, string.Join(",", aWartosci)), false);
                            }
                        }
                        else
                        {
                            zapisanieDoPliku("#", false);
                            zapisanieDoPliku(string.Format("# Brak danych w tabeli {0}", aTabela.Key), false);
                            zapisanieDoPliku("#", false);
                        }
                        oReader.Close();
                        zapisanieDoPliku("", false);
                    }
                }
            }
        }
Esempio n. 8
0
 public static string SQLDateTimeToStr(MySqlDateTime value)
 {
     return("'" + value.ToString() + "'");
 }
Esempio n. 9
0
        public static DateTime?GetNullableDateTime(Object val)
        {
            DateTime?actualRet;
            DateTime ret;

            if (!Convert.IsDBNull(val))
            {
                if (val is MySqlDateTime)
                {
                    MySqlDateTime d = (MySqlDateTime)val;
                    if (d.IsValidDateTime)
                    {
                        ret = d.Value;
                    }
                    else
                    {
                        ret = DateTime.MinValue;
                    }
                }
                else if (val is DateTime)
                {
                    ret = (DateTime)val;
                }
                else
                {
                    string strTime = val.ToString();

                    if (strTime.Length == 0)                                    // SPSP Why would we want to do this? || strTime[0] == '0')
                    {
                        ret = new DateTime();
                    }
                    else
                    {
                        // Try Parsing From Common String Format
                        if (!DateTime.TryParse(val.ToString(), out ret))
                        {
                            // Bug Fix: 250
                            // Try Parsing From Double or Decimal
                            strTime = String.Format("{0:0.000}", val);

                            if (DateTime.TryParseExact(strTime, "yyyyMMddHHmmss.fff", new CultureInfo("en-US", true), DateTimeStyles.None, out ret) == false)
                            {
                                strTime = String.Format("{0:0}", val);

                                if (DateTime.TryParseExact(strTime, "yyyyMMddHHmmss", new CultureInfo("en-US", true), DateTimeStyles.None, out ret) == false)
                                {
                                    ret = new DateTime();
                                }
                            }
                        }
                    }
                }

                actualRet = ret;
            }
            else
            {
                actualRet = null;
            }

            return(actualRet);
        }
Esempio n. 10
0
 public MyDate(MySqlDateTime mdt)
 {
     datum = mdt;
 }
Esempio n. 11
0
 // MySqlDateTime will convert 0 date values to DateTime.MinValue
 public static DateTime MySqlToNet(MySqlDateTime mySqlDateTime)
 {
     return((DateTime)mySqlDateTime);  // cast it an let MySqlDateTime do the work
 }