Exemple #1
0
        public static XResponse CreateTable(CodexDBF.TableCode codex, string name = "")
        {
            //ARMANDO QUERY
            XResponse resp = CodexDBF.GetStringTable(codex, name);

            if (resp.error)
            {
                return(resp);
            }
            string lcquery = resp.response;
            //enviando query
            XtrDataConnect mysql = new XtrDataConnect();

            if (!connect(ref mysql))
            {
                return(CrsCore.ResponseError(CrsCore.SaveLog("CreateTable connect fail:" + mysql.msg)));
            }
            MySqlCommand mycomand = new MySqlCommand(lcquery, mysql.connection);

            try
            {
                mycomand.ExecuteNonQuery();
            }
            catch (MySqlException ex)
            {
                mysql.connection.Close();
                return(CrsCore.ResponseError(CrsCore.SaveLog("CreateTable catch:" + lcquery + " " + ex.Message)));
            }
            mysql.connection.Close();
            return(new XResponse());
        }
Exemple #2
0
        public static bool Duplicated(string alias, string campo, string value)
        {
            string where = campo + " ='" + value.Trim() + "'";
            XResponse resp = CrsData.TableSelect(new List <string> {
                campo
            }, alias, where, 0);

            return(!resp.empty);
        }
Exemple #3
0
        public static XResponse GetFieldByUID(string campo, string alias, int uid)
        {
            XResponse resp = CrsData.TableSelect(new List <string> {
                campo
            }, "productos", "uid = " + uid, BuildType.TablaArray);

            if (resp.error || resp.empty)
            {
                return(resp);
            }
            Tabla[] tabla = (Tabla[])resp.objecto;
            resp.response = (string)tabla[0].datos[campo];
            return(resp);
        }
Exemple #4
0
        public static XResponse TableSelect(List <string> campos, string from, string where, BuildType output)
        {
            XResponse salida = new XResponse();

            if (string.IsNullOrEmpty(from))
            {
                return(CrsCore.ResponseError(CrsCore.SaveLog("TableSelect Falta from")));
            }
            DataTable      dtstruct = new DataTable();
            XtrDataConnect mysql    = new XtrDataConnect();

            if (!connect(ref mysql))
            {
                return(CrsCore.ResponseError(CrsCore.SaveLog("TableSelect connect fail:" + mysql.msg)));
            }
            //armando query
            string lcquery = "select ";
            string lcampos = "";
            string lcfrom  = " from " + from;
            string lcwhere = " where deleted = 0";

            lcwhere += (string.IsNullOrEmpty(where)) ? "" : " and " + where;
            for (int a = 0; a < campos.Count; a++)
            {
                lcampos += campos[a] + ",";
            }
            lcampos  = lcampos.Substring(0, lcampos.Length - 1);
            lcquery += lcampos + lcfrom + lcwhere + " LIMIT 0,100";
            MySqlCommand    mycomand = new MySqlCommand(lcquery, mysql.connection);
            MySqlDataReader myreader = mycomand.ExecuteReader();

            salida.empty = !myreader.HasRows;
            if (output == 0)
            {
                object[] sql = new object[2];
                sql[0]         = myreader;
                sql[1]         = mysql.connection;
                salida.objecto = sql;
            }
            else
            {
                salida.objecto = BuildOut(output, myreader);
            }
            if (!output.Equals(0))
            {
                myreader.Close();
                mysql.connection.Close();
            }
            return(salida);
        }
Exemple #5
0
        /// <summary>
        /// devuelve el uid si ya existe sino devuelve -1 (la tabla debe tener un campo uid)
        /// </summary>
        /// <param name="alias"></param>
        /// <param name="campo"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static int GetUID(string alias, string campo, string value)
        {
            string where = campo + " ='" + value.Trim() + "'";
            XResponse resp = CrsData.TableSelect(new List <string> {
                "uid"
            }, alias, where, BuildType.TablaArray);

            if (resp.empty || resp.error)
            {
                return(-1);
            }
            Tabla[] tabla = (Tabla[])resp.objecto;
            return(tabla[0].datos["uid"]);
        }