Exemplo n.º 1
0
    public string ReadeDialogMessage(int dialogID, int messageID)
    {
        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();


        //      string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";


        string queryString = "SELECT MessageText FROM Messages Where (DialogID=@DialogID) and (MessageID = @MessageID)";

        oCommand.PrepareSelectQuery(queryString, oConnection.connection);
        oCommand.AddSelectParam("@DialogID", dialogID);   //Select Parameter
        oCommand.AddSelectParam("@MessageID", messageID); //Select Parameter

        SqlDataReader reader = oCommand.ExectuteReader();

        string messageText = null;

        if (reader.Read())
        {
            messageText = Convert.ToString(reader[0]);
        }

        oConnection.closeConnection();

        return(messageText);


//      listBox.Items.add
    }
Exemplo n.º 2
0
    public string ReadePersonSurname(int dialogID, int messageID)
    {
        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();


        //      string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";


        string queryString = "SELECT FromUserID FROM Messages Where (DialogID=@DialogID) and (MessageID = @MessageID)";

        oCommand.PrepareSelectQuery(queryString, oConnection.connection);
        oCommand.AddSelectParam("@DialogID", dialogID);   //Select Parameter
        oCommand.AddSelectParam("@MessageID", messageID); //Select Parameter

        SqlDataReader reader = oCommand.ExectuteReader();

        int    PersonID      = 0;
        string PersonSurname = null;

        if (reader.Read())
        {
            PersonID = Convert.ToInt32(reader[0]);
        }
        oConnection.closeConnection();

        PeoplesClass oPeoples = new PeoplesClass();

        PersonSurname = Convert.ToString(oPeoples.GetPeopleValue(PersonID, "Surname"));

        return(PersonSurname);
    }
Exemplo n.º 3
0
    public int getMaxMessageID(int dialogID)
    {
        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();


        //      string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";


        string queryString = "SELECT MessageID FROM Messages Where (DialogID=@DialogID)";

        oCommand.PrepareSelectQuery(queryString, oConnection.connection);
        oCommand.AddSelectParam("@DialogID", dialogID);//Select Parameter

        SqlDataReader reader = oCommand.ExectuteReader();

        int maxID     = 0;
        int messageID = 0;

        while (reader.Read())
        {
            messageID = Convert.ToInt32(reader[0]);

            if (messageID > maxID)
            {
                maxID = messageID;
            }
        }

        oConnection.closeConnection();

        return(maxID);
    }
Exemplo n.º 4
0
    public int GetDialogID(int FirstPersonID, int SecondPersonID) //проверить
    {
        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();


        //      string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";


        string queryString = "SELECT DialogID FROM Messages Where((FromUserID=@FirstID) and (ToUserID = @SecondID) ) or ( (FromUserID = @SecondID) and (ToUserID = @FirstID))";

        oCommand.PrepareSelectQuery(queryString, oConnection.connection);
        oCommand.AddSelectParam("@FirstID", FirstPersonID);   //Select Parameter
        oCommand.AddSelectParam("@SecondID", SecondPersonID); //Select Parameter

        SqlDataReader reader = oCommand.ExectuteReader();

        int DialogID = -1;

        if (reader.Read())
        {
            DialogID = Convert.ToInt32(reader[0]);
        }

        oConnection.closeConnection();

        return(DialogID);
    }
Exemplo n.º 5
0
    //получаем максимальный номер
    public int GetMaxDialogID()
    {
        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();


        //      string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";


        string queryString = "SELECT DialogID FROM Messages";

        oCommand.PrepareSelectQuery(queryString, oConnection.connection);

        SqlDataReader reader = oCommand.ExectuteReader();


        int max      = 0;
        int DialogID = -1;

        while (reader.Read())
        {
            DialogID = Convert.ToInt32(reader[0]);
            if (DialogID > max)
            {
                max = DialogID;
            }
        }

        //если диалогов нет то будет нулевым диалогом

        oConnection.closeConnection();

        return(max);
    }
Exemplo n.º 6
0
    public int GetMaxID(int ImageID)
    {
        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();

        //      string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";

        string queryString = "SELECT ID FROM ImageComment Where ImageID=@ImageID";

        oCommand.PrepareSelectQuery(queryString, oConnection.connection);
        oCommand.AddSelectParam("@ImageID", ImageID);//Select Parameter

        SqlDataReader reader = oCommand.ExectuteReader();

        int maxID = -1;//если в таблице совсем нет записей
        int ID    = 0;

        while (reader.Read())
        {
            if ((reader[0] != null) && (!Convert.IsDBNull(reader[0])))
            {
                ID = Convert.ToInt32(reader[0]);//
                if (maxID < ID)
                {
                    maxID = ID;
                }
            }
        }

        oConnection.closeConnection();

        return(maxID);
    }
Exemplo n.º 7
0
    public String GetMessageText(int MessageID)// этот метод удалить
    {
        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();


        //      string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";


        string queryString = "SELECT MessageText FROM Messages Where(MessageID=@MessageID)";

        oCommand.PrepareSelectQuery(queryString, oConnection.connection);
        oCommand.AddSelectParam("@MessageID", MessageID);//Select Parameter

        SqlDataReader reader = oCommand.ExectuteReader();

        string messageText = null;

        if (reader.Read())
        {
            messageText = Convert.ToString(reader[0]);
        }

        oConnection.closeConnection();

        return(messageText);
    }
Exemplo n.º 8
0
    public bool isFriendsExist(int ID_1, int ID_2)
    {
        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();


        //      string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";


        //        string queryString = "SELECT ID FROM FriendTable" + " Where( (Friend_1_ID=@Fr_1) AND (Friend_2_ID=@Fr_2) ) or ( (Friend_1_ID=@Fr_2) AND (Friend_2_ID=@Fr_1) )";

        string queryString = "SELECT ID FROM FriendTable Where( (Friend_1_ID=@Fr_1) AND (Friend_2_ID=@Fr_2) )";

        oCommand.PrepareSelectQuery(queryString, oConnection.connection);
        oCommand.AddSelectParam("@Fr_1", ID_1); //Select Parameter
        oCommand.AddSelectParam("@Fr_2", ID_2); //Select Parameter



        //     oCommand.PrepareSelectQuery(queryString, oConnection.connection);

        SqlDataReader reader = oCommand.ExectuteReader();

        bool returnValue = false;

        if (reader.Read())
        {
            returnValue = true; //найдены друзья
        }

        oConnection.closeConnection();
        return(returnValue);
    }
Exemplo n.º 9
0
    public void getPeopleIDs(string name, string surname, string tableName)
    {
        if (PeopleIDs != null)
        {
            PeopleIDs = new List <int>();;//очищаем чтобы заполнить заново
        }
        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();


        //      string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";

        string queryString = "SELECT ID FROM " + tableName + " Where(Name=@Name) AND (Surname=@Surname)";

        oCommand.PrepareSelectQuery(queryString, oConnection.connection);
        oCommand.AddSelectParam("@Name", name);       //Select Parameter
        oCommand.AddSelectParam("@Surname", surname); //Select Parameter


        SqlDataReader reader = oCommand.ExectuteReader();

        while (reader.Read())
        {
            int id = Convert.ToInt32(reader[0]);

            PeopleIDs.Add(id);//считывание в массив юрэлов
        }



        counter = 0;
        oConnection.closeConnection();
    }
Exemplo n.º 10
0
    /// <summary>
    /// возвращает номера таблиц в которых содержатся номера друзей
    /// </summary>
    /// <param name="PeopleID"></param>
    /// <returns></returns>

    public List <int> GetFriendIDList(int PeopleID)
    {
        List <int> FriendListIDs = new List <int>();;//очищаем чтобы заполнить заново

        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();


        //      string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";

        string queryString = "SELECT ID FROM FriendTable Where(Friend_1_ID=@PeopleID) OR (Friend_2_ID=@PeopleID)";

        oCommand.PrepareSelectQuery(queryString, oConnection.connection);
        oCommand.AddSelectParam("@PeopleID", PeopleID);//Select Parameter

        SqlDataReader reader = oCommand.ExectuteReader();

        while (reader.Read())
        {
            int id = Convert.ToInt32(reader[0]);
            FriendListIDs.Add(id);//считывание в массив юрэлов
        }

        oConnection.closeConnection();

        return(FriendListIDs);
    }
Exemplo n.º 11
0
    public bool isLoginExist(string Login)
    {
        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();


        //      string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";

        string queryString = "SELECT Phone FROM Peoples";

        oCommand.PrepareSelectQuery(queryString, oConnection.connection);

        SqlDataReader reader = oCommand.ExectuteReader();

        bool returnValue = false;

        while (reader.Read())
        {
            string phone = Convert.ToString(reader[0]);

            if (phone == Login)
            {
                //совпадение найдено
                returnValue = true;// такой логин существует
                continue;
            }
        }
        oConnection.closeConnection();
        return(returnValue);
    }
Exemplo n.º 12
0
    public void readeImageURls(int UserID, string tableName)  //reade from database to List
    {
        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();

        userID = UserID;

        //      string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";

        string queryString = "SELECT PeopleID, imgURL_Path FROM " + tableName + " Where PeopleID=@PeopleID";

        oCommand.PrepareSelectQuery(queryString, oConnection.connection);
        oCommand.AddSelectParam("@PeopleID", UserID);//Select Parameter
        SqlDataReader reader = oCommand.ExectuteReader();

        while (reader.Read())
        {
            imageUrls.Add(reader[1] as string);//считывание в массив юрэлов
        }


        counter = 0;
        oConnection.closeConnection();
    }
Exemplo n.º 13
0
    private void getNextMessagesIDs(int FromID, int ToID)
    {
        if (MessagesIDs == null)
        {
            MessagesIDs = new List <int>();
        }

        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();


        //      string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";


        string queryString = "SELECT MessageID FROM Messages Where(FromUserID=@FromID) AND (ToUserID=@ToID)";

        oCommand.PrepareSelectQuery(queryString, oConnection.connection);
        oCommand.AddSelectParam("@FromID", FromID); //Select Parameter
        oCommand.AddSelectParam("@ToID", ToID);     //Select Parameter


        SqlDataReader reader = oCommand.ExectuteReader();

        while (reader.Read())
        {
            int id = Convert.ToInt32(reader[0]);

            MessagesIDs.Add(id);//считывание в массив юрэлов
        }

        counter = 0;
        oConnection.closeConnection();
    }
Exemplo n.º 14
0
    public int getMaxMessageID(int FromID, int ToID)
    {
        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();


        //      string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";


        string queryString = "SELECT MessageID FROM Messages Where(FromUserID=@FromID) AND (ToUserID=@ToID)";

        oCommand.PrepareSelectQuery(queryString, oConnection.connection);
        oCommand.AddSelectParam("@FromID", FromID); //Select Parameter
        oCommand.AddSelectParam("@ToID", ToID);     //Select Parameter


        SqlDataReader reader = oCommand.ExectuteReader();

        int max = 0;

        while (reader.Read())
        {
            int id = Convert.ToInt32(reader[0]);
            if (max < id)
            {
                max = id;
            }
        }

        oConnection.closeConnection();
        return(max);
    }
Exemplo n.º 15
0
    public int GetMaxID(string IDName, string TableName)// -1 если не найден ни один айди
    {
        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();

        //      string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";

        string queryString = "SELECT " + IDName + " FROM " + TableName;

        oCommand.PrepareSelectQuery(queryString, oConnection.connection);


        SqlDataReader reader = oCommand.ExectuteReader();

        int maxID = -1;
        int ID    = 0;

        while (reader.Read())
        {
            if ((reader[0] != null) && (!Convert.IsDBNull(reader[0])))
            {
                ID = Convert.ToInt32(reader[0]); //
                if (maxID < ID)
                {
                    maxID = ID;
                }
            }
        }

        oConnection.closeConnection();

        return(maxID);
    }
Exemplo n.º 16
0
    public object GetValueFromTableByIDName(int ID, string IDName, String ColumnName, string tableName)
    {
        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();


        //      string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";

        string queryString = "SELECT " + ColumnName + " FROM " + tableName + " Where " + IDName + "=@ID ";

        oCommand.PrepareSelectQuery(queryString, oConnection.connection);
        oCommand.AddSelectParam("@ID", ID);//Select Parameter

        SqlDataReader reader = oCommand.ExectuteReader();

        object returnValue = null;

        if (reader.Read())
        {
            returnValue = reader[0] as object;
        }

        oConnection.closeConnection();
        return(returnValue);
    }
Exemplo n.º 17
0
    public void readeImageIDs(int PeopleID, List <int> ImageIDsOut)
    {
//        ImageIDsOut = new List<int>();
        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();

        //      string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";

        string queryString = "SELECT ImageID FROM Images Where PeopleID=@PeopleID";

        oCommand.PrepareSelectQuery(queryString, oConnection.connection);
        oCommand.AddSelectParam("@PeopleID", PeopleID);//Select Parameter
        SqlDataReader reader = oCommand.ExectuteReader();



        while (reader.Read())
        {
            if (reader[0] != DBNull.Value)
            {
                ImageIDsOut.Add(Convert.ToInt32(reader[0]));//считывание в массив юрэлов
            }
        }

        oConnection.closeConnection();
    }
Exemplo n.º 18
0
    public int GetMaxIDInGroup(string IDName, string tableName, string GroupIDName, int GroupID)
    {
        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();


        //      string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";

        string queryString = "SELECT " + IDName + " FROM " + tableName + " Where " + GroupIDName + "=@GroupID";

        oCommand.PrepareSelectQuery(queryString, oConnection.connection);
        oCommand.AddSelectParam("@GroupID", GroupID);//Select Parameter

        SqlDataReader reader = oCommand.ExectuteReader();

        int maxID = -1;

        while (reader.Read())
        {
            int readVal = Convert.ToInt32(reader[0]);
            if (readVal > maxID)
            {
                maxID = readVal;
            }
        }

        oConnection.closeConnection();

        return(maxID);
    }
Exemplo n.º 19
0
    /// <summary>
    /// Возвращает номер друга
    /// </summary>
    /// <param name="userID"></param>
    /// <param name="FriendListID"></param>
    /// <returns></returns>
    public int GetFriendID(int userID, int FriendListID)
    {
        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand    = new SQLCommandClass();
        int             returnValue = 0;

        //      string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";

        string queryString = "SELECT Friend_1_ID, Friend_2_ID FROM FriendTable Where(ID=@FriendListID)";

        oCommand.PrepareSelectQuery(queryString, oConnection.connection);
        oCommand.AddSelectParam("@FriendListID", FriendListID);//Select Parameter

        SqlDataReader reader = oCommand.ExectuteReader();

        if (reader.Read())
        {
            int FirstId  = Convert.ToInt32(reader[0]);
            int SecondId = Convert.ToInt32(reader[1]);

            if (userID == FirstId)
            {
                returnValue = SecondId;
            }
            else
            {
                returnValue = FirstId;
            }
        }

        oConnection.closeConnection();
        return(returnValue);
    }
Exemplo n.º 20
0
    public string readeImageURl(int ImageID, int PeopleID)  //reade from database to List
    {
        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();

        string returnValue = null;

        //      string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";

        string queryString = "SELECT imgURL_Path FROM Images Where (ImageID = @ImageID) AND ( PeopleID=@PeopleID )";

        oCommand.PrepareSelectQuery(queryString, oConnection.connection);
        oCommand.AddSelectParam("@PeopleID", PeopleID); //Select Parameter
        oCommand.AddSelectParam("@ImageID", ImageID);   //Select Parameter

        SqlDataReader reader = oCommand.ExectuteReader();

        while (reader.Read())
        {
            returnValue = (reader[0] as string);//считывание в массив юрэлов
        }

        oConnection.closeConnection();
        return(returnValue);
    }
Exemplo n.º 21
0
    /*
     * поиск людей которым пользователь когда либо писал
     */
    public String GetMessageText(int FromID, int ToID, int messageID /*1....N*/)
    {
        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();


        //      string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";


        string queryString = "SELECT MessageText FROM Messages Where(FromUserID=@FromID) and (ToUserID = @ToID) and (MessageID = @MesID) ";

        oCommand.PrepareSelectQuery(queryString, oConnection.connection);
        oCommand.AddSelectParam("@FromID", FromID);   //Select Parameter
        oCommand.AddSelectParam("@ToID", ToID);       //Select Parameter
        oCommand.AddSelectParam("@MesID", messageID); //Select Parameter

        SqlDataReader reader = oCommand.ExectuteReader();

        string messageText = null;

        if (reader.Read())
        {
            messageText = Convert.ToString(reader[0]);
        }

        oConnection.closeConnection();

        return(messageText);
    }
Exemplo n.º 22
0
    // считаем количество лайков для картинки или для поста
    public int GetLikeCount(int GroupID /*ImageID or PublicID*/, string GroupTableName /*Images or Publics*/)
    {
        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();

        //      string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";

        string queryString = "SELECT IDinGroup FROM Like WHERE( GroupTableName=@GroupTableName ) and ( GroupID=@GroupID )";

//        string queryString = "SELECT GroupID FROM Like";// WHERE( GroupTableName=@GroupTableName ) and ( GroupID=@GroupID )";

        oCommand.PrepareSelectQuery(queryString, oConnection.connection);
        oCommand.AddSelectParam("@GroupTableName", GroupTableName); //Select Parameter
        oCommand.AddSelectParam("@GroupID", GroupID);               //Select Parameter

        SqlDataReader reader = oCommand.ExectuteReader();

        int likeCount = 0;

        while (reader.Read())
        {
            likeCount++;// считаем количество лайков для картинки или для поста
        }

        oConnection.closeConnection();

        return(likeCount);
    }
Exemplo n.º 23
0
    public int GetImgCommentID(int ID, int imgID)
    {
        int returnVal = 0;

        SQLConnectionClass oConnection = new SQLConnectionClass();
        SQLCommandClass    oCommand    = new SQLCommandClass();

        //      string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";

        string queryString = "SELECT ImgCommentID FROM ImageComment Where (ID=@ID) AND (ImageID=@ImageID)";

        oCommand.PrepareSelectQuery(queryString, oConnection.connection);
        oCommand.AddSelectParam("@ID", ID);         //Select Parameter
        oCommand.AddSelectParam("@ImageID", imgID); //Select Parameter
        SqlDataReader reader = oCommand.ExectuteReader();

        while (reader.Read())
        {
            if ((reader[0] != null) && (!Convert.IsDBNull(reader[0])))
            {
                returnVal = Convert.ToInt32(reader[0]);//
            }
        }

        oConnection.closeConnection();
        return(returnVal);
    }
Exemplo n.º 24
0
    protected void enter(object sender, EventArgs e)//почемуто не переходит на другую страницу
    {
        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();


//      string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";

        string queryString = "SELECT ID, Name, Surname, Phone, Password FROM Peoples Where Phone=@phone";



        oCommand.PrepareSelectQuery(queryString, oConnection.connection);

        oCommand.AddSelectParam("@phone", this.TextBox6.Text);//Для сравнения

        SqlDataReader reader = oCommand.ExectuteReader();

        string phoneNumb;
        string Password;


        while (reader.Read())
        {
            phoneNumb = reader[3] as string; //приведение типов
            Password  = reader[4] as string; //приведение типов

            if (TextBox6.Text == phoneNumb)
            {                                  //проверка логина
                if (TextBox5.Text == Password) //проверка пароля
                {
                    //Запоминаем в куки файл
                    Response.Cookies[ConstantNames.UserID].Value   = Convert.ToString(reader[0]);//UserID to cookie
                    Response.Cookies[ConstantNames.UserID].Expires = DateTime.Now.AddDays(1);
                    // Response.Redirect("C:\Users\)_(\Documents\Visual Studio 2010\WebSites\WebSite5\main.aspx.cs");
                    Response.Redirect("Login.aspx");
                }
                else
                {
                    //Invalid password
                }
            }
        }

/*
 *      id = reader.GetValue(0);
 *      name = reader.GetValue(1);
 *      surname = reader.GetValue(2);
 *      age = reader.GetValue(3);
 */


//      cmdIns.Parameters.Add("@name", info);

//      cmdIns.ExecuteNonQuery();//выполнить команду

        oConnection.closeConnection();
    }
Exemplo n.º 25
0
    public void SelectFromTable(List <TableValue> SelectedValues, List <TableValue> WhereValues, string TableName)
    {
        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();


        //      string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";

        string SelectString = null;
        string WhereString  = null;

        foreach (TableValue element in SelectedValues)                         //Select Values
        {
            if (element == SelectedValues.ElementAt(SelectedValues.Count - 1)) //Если элемент последний то запятые не ставим
            {
                SelectString += element.ValueName;
            }
            else//Если элемент не последний то ставим запятые
            {
                SelectString += element.ValueName + ",";
            }
        }

        foreach (TableValue element in WhereValues)
        {
            if (element == WhereValues.ElementAt(WhereValues.Count - 1))
            {
                WhereString += element.ValueName + "=@" + element.ValueName;
            }
            else
            {
                WhereString += element.ValueName + "=@" + element.ValueName + ",";//Where ID = @ID
            }
        }

        string queryString = "SELECT " + "(" + SelectString + ") FROM " + TableName + "(" + WhereString + " ) ";

        oCommand.PrepareSelectQuery(queryString, oConnection.connection);


        foreach (TableValue element in WhereValues)                          // WhereValues
        {
            oCommand.AddSelectParam("@" + element.ValueName, element.Value); //Add Select Parameter
        }

        SqlDataReader reader = oCommand.ExectuteReader();

        object returnValue = null;

        if (reader.Read())
        {
            returnValue = reader[0] as object;
        }

        oConnection.closeConnection();
    }
Exemplo n.º 26
0
    //протестирвать эту функцию
    //если вернулось отрицательное значение, то ошибка
    public static int getMaxID(string IDName, string tableName)// -2 некорректные пареметры
    {
        if (tableName == null || IDName == null)
        {
            return(-2);// не задана таблица. не корректные параметры
        }
        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();


        //      string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";

        string queryString = "SELECT " + IDName + " FROM " + tableName;



        oCommand.PrepareSelectQuery(queryString, oConnection.connection);

        SqlDataReader reader = oCommand.ExectuteReader();

        int tableID = 0;


        int max       = -1;//если значение отрицательное то в таблице нет записей
        int tempValue = -2;

        while (reader.Read())
        {
            tableID = Convert.ToInt32(reader[0]);//приведение типов

            if (tableID > max)
            {//ищем максимальный идентификатор
                max = tableID;
            }
        }
        oConnection.closeConnection();


        return(max);// -1 если нет записей, тогда создастся 0
    }
Exemplo n.º 27
0
    public string selectImageCommentText(int ImageID, int ID)
    {
        string returnValue = null;

        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();


        //      string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";



        string queryString = "SELECT CommentPeopleID, Text FROM ImageComment Where (ID = @ID) AND (ImageID = @ImageID)";

        oCommand.PrepareSelectQuery(queryString, oConnection.connection);
        oCommand.AddSelectParam("@ImageID", ImageID); //Select Parameter
        oCommand.AddSelectParam("@ID", ID);           //Select Parameter

        SqlDataReader reader = oCommand.ExectuteReader();

        if (reader.Read())
        {
            int CommentPeopleID = Convert.ToInt32(reader[0]);

            PeoplesClass oPeople = new PeoplesClass();

            string comPeopleSurname = oPeople.GetPeopleSurname(CommentPeopleID);
            string comPeopleName    = oPeople.GetPeopleName(CommentPeopleID);
            string comText          = Convert.ToString(reader[1]);

            returnValue = comPeopleSurname + comPeopleName + ": " + comText;

            //исключено что строка пустая
        }

        oConnection.closeConnection();

        return(returnValue);//null если нет записей в таблице
    }
Exemplo n.º 28
0
    public void getToIDsByFromID(int FromID)//сначала надо вызвать это
    {
        //сюда записываем айдишника
        ToIDs = new List <int>(); //очищаем чтобы заполнить заново

        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();


        //      string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";


        string queryString = "SELECT ToUserID FROM Messages Where(FromUserID=@FromID)";

        oCommand.PrepareSelectQuery(queryString, oConnection.connection);
        oCommand.AddSelectParam("@FromID", FromID);//Select Parameter

        SqlDataReader reader = oCommand.ExectuteReader();

        while (reader.Read())
        {
            int id = Convert.ToInt32(reader[0]);
            if (ToIDs.Count > 0)        //не первый элемент
            {
                if (ToIDs.Last() != id) //если нет повторения
                {
                    ToIDs.Add(id);      //считывание в массив юрэлов
                }
            }
            else
            {
                ToIDs.Add(id);//записываем первый элемент
            }
        }
        this.ToIDCounter = 0; //установка в ноль счетчика. Поскольку ToIDs считываем заново
        oConnection.closeConnection();
    }
Exemplo n.º 29
0
    public int GetCounterValue(int userID, string counterName) //работает строго с таблицей UserCounters
    {
        if (counterName == null)
        {
            return(-2);// не задана таблица. не корректные параметры
        }
        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();


        //      string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";

        string queryString = "SELECT userID, " + counterName + " FROM UserCounters where userID = @userID";


        oCommand.PrepareSelectQuery(queryString, oConnection.connection);

        oCommand.AddSelectParam("@phone", userID);//Для сравнения



        SqlDataReader reader = oCommand.ExectuteReader();

        int UserID  = 0;
        int counter = 0;


        UserID = Convert.ToInt32(reader[0]);//приведение типов

        counter = Convert.ToInt32(reader[1]);

        oConnection.closeConnection();

        return(UserID);
    }
Exemplo n.º 30
0
    public int GetLikeCounterOfImage(int ImageID)
    {
        int likeCounter = 0;

        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();

        //      string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";

        string queryString = "SELECT LikeCounter FROM Images Where ( ImageID = @ImageID )";

        /*
         * command.CommandText = "UPDATE Student(LastName, FirstName, Address, City)
         * VALUES (@ln, @fn, @add, @cit) WHERE LastName='" + lastName +
         *                         "' AND FirstName='" +  firstName+"'";
         */


        oCommand.PrepareSelectQuery(queryString, oConnection.connection);
        oCommand.AddSelectParam("@ImageID", ImageID);//Select Parameter

        SqlDataReader reader = oCommand.ExectuteReader();

        if (reader.Read())
        {
            if (reader[0] != DBNull.Value)
            {
                likeCounter = Convert.ToInt32(reader[0]);//считывание в массив юрэлов
            }
        }

        return(likeCounter);

        oConnection.closeConnection();
    }