Example #1
0
    public void sendMessageFromUserID(int DialogId, int FromID, int ToID, String textMessage)
    {
        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();

        string sqlIns = "INSERT INTO Messages(DialogID, FromUserID, ToUserID, MessageID, MessageText) VALUES(@DialogID,@FromID, @ToID, @MessageID, @textMessage ) ";

        //использовать только в такой последовательности
        oCommand.PrepareInsertQuery(sqlIns, oConnection.connection);

        oCommand.AddInsertParameter("@DialogID", DialogId);
        oCommand.AddInsertParameter("@FromID", FromID);
        oCommand.AddInsertParameter("@ToID", ToID);


        //======это чтобы вычислить айди нового сообщения
        this.getMessagesIDs(FromID, ToID);//получаем номера сообщений в прямую сторону и в обратную сторону
        //айди сообщений получены

        int maxMesID = this.GetMaxMessageID();//вычисляем айди нового сообщения. максим + 1.

        //===============================================

        oCommand.AddInsertParameter("@MessageID", maxMesID + 1);//new message id;
        oCommand.AddInsertParameter("@textMessage", textMessage);



        oCommand.ExecuteQuery();

        oConnection.closeConnection();
    }
Example #2
0
    /// <summary>
    /// Это метод используется чаще всего
    /// </summary>
    /// <param name="ImageID"></param>
    /// <param name="CommentPeopleID"></param>
    /// <param name="text"></param>

    public void AddCommentToImage(int ImageID, int CommentPeopleID, string text)
    {
        if (text == null || text == "")
        {
            return;//если пустая строка то не добавляем
        }
        SQLConnectionClass oConnection  = new SQLConnectionClass();
        SQLCommandClass    oCommand     = new SQLCommandClass();
        TableOpreatorClass TablePerator = new TableOpreatorClass();

        int ID = this.GenerateNewID(ImageID);//Последовательность номеров для каждой картинки

        TableOpreatorClass oTable = new TableOpreatorClass();
        int ImgCommentID          = oTable.GenerateNewID("ImgCommentID", "ImageComment");//Уникальный номер для каждой картинки

        string sqlIns = "INSERT INTO ImageComment( ID, ImgCommentID, ImageID, CommentPeopleID, Text ) VALUES (@ID ,@ImgComID, @ImageID, @CommentPeopleID, @Text )";

        //использовать только в такой последовательности
        oCommand.PrepareInsertQuery(sqlIns, oConnection.connection);


        oCommand.AddInsertParameter("@ID", ID);                 //заносим новый айди
        oCommand.AddInsertParameter("@ImgComID", ImgCommentID); //заносим новый айди
        oCommand.AddInsertParameter("@ImageID", ImageID);
        oCommand.AddInsertParameter("@CommentPeopleID", CommentPeopleID);
        oCommand.AddInsertParameter("@Text", text);

        oCommand.ExecuteQuery();
        oConnection.closeConnection();
    }
Example #3
0
    public void AddFriend(int ID_1, int ID_2)
    {
        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();

        TableOpreatorClass TablePerator = new TableOpreatorClass();

        if (isFriendsExist(ID_1, ID_2))
        {
            return;// они уже друзья. Не надо заново добавлять  друзей
        }
        int ID = TablePerator.GenerateNewID("ID", "FriendTable");

        string sqlIns = "INSERT INTO FriendTable( ID, Friend_1_ID, Friend_2_ID ) VALUES (@ID, @Friend_1, @Friend_2 )";

        //использовать только в такой последовательности
        oCommand.PrepareInsertQuery(sqlIns, oConnection.connection);


        int newIDPeoples = ID_OPerator.createNewTableID("ID", "Peoples");

        if (newIDPeoples == -2)
        {
            //некорректные параметры
        }

        oCommand.AddInsertParameter("@ID", ID);//заносим новый айди
        oCommand.AddInsertParameter("@Friend_1", ID_1);
        oCommand.AddInsertParameter("@Friend_2", ID_2);

        oCommand.ExecuteQuery();
        oConnection.closeConnection();
    }
Example #4
0
    public void createNewUserIDCounter(int userID, string counterName, int value)//работает строго с таблицей UserCounters
    {
        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();

        string sqlIns = "INSERT INTO UserCounters( UserID, " + counterName + " ) " + " VALUES(@UserID, @Value )";

        //использовать только в такой последовательности
        oCommand.PrepareInsertQuery(sqlIns, oConnection.connection);


        int newIDPeoples = ID_OPerator.createNewTableID("ID", "Peoples");

        if (newIDPeoples == -2)
        {
            //некорректные параметры
        }
        oCommand.AddInsertParameter("@UserID", userID);//заносим новый айди
        oCommand.AddInsertParameter("@Name", value);

        oCommand.ExecuteQuery();

        oConnection.closeConnection();
    }
Example #5
0
    protected void ButtonRegistration_Click(object sender, EventArgs e)
    {
        PeoplesClass oPeople = new PeoplesClass();

        bool loginExist = false;

        if (oPeople.isLoginExist(this.TextBoxPhone.Text))
        {
            this.LabelMessage.Text = " логин уже привязан к другой странице. Укажите другой логин.";
            loginExist             = true;
        }

        if (this.TextBoxPassw.Text.Length < 5)
        {
            this.LabelMessage.Text = " пароль слишком короткий. введите пароль не менее 5 символов";
            loginExist             = true;
        }

        if (!loginExist)
        {
            SQLConnectionClass oConnection = new SQLConnectionClass();

            SQLCommandClass oCommand = new SQLCommandClass();

            string sqlIns = "INSERT INTO Peoples( ID, Name, Surname, Phone, Password) VALUES (@ID, @Name, @Surname, @Phone, @Password)";

            //использовать только в такой последовательности
            oCommand.PrepareInsertQuery(sqlIns, oConnection.connection);


            int newIDPeoples = ID_OPerator.createNewTableID("ID", "Peoples");
            if (newIDPeoples == -2)
            {
                //некорректные параметры
            }

            oCommand.AddInsertParameter("@ID", Convert.ToString(newIDPeoples));//заносим новый айди
            oCommand.AddInsertParameter("@Name", this.TextBoxName.Text);
            oCommand.AddInsertParameter("@Surname", this.TextBoxSurname.Text);
            oCommand.AddInsertParameter("@Phone", this.TextBoxPhone.Text);
            oCommand.AddInsertParameter("@Password", this.TextBoxPassw.Text);

            oCommand.ExecuteQuery();

            oConnection.closeConnection();


            Response.Cookies[ConstantNames.UserID].Value   = Convert.ToString(newIDPeoples);//UserID to cookie
            Response.Cookies[ConstantNames.UserID].Expires = DateTime.Now.AddDays(1);

            Response.Redirect("Login.aspx");
        }
    }
Example #6
0
    public void SetValueToTable(int ID, String ColumnName, object InsertValue, string tableName)
    {
        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();

        string sqlIns = "INSERT INTO " + tableName + "( " + ColumnName + " ) VALUES(@Value) where( ID=@ID )";

        //использовать только в такой последовательности
        oCommand.PrepareInsertQuery(sqlIns, oConnection.connection);


        oCommand.AddInsertParameter("@Value", InsertValue);
        oCommand.AddInsertParameter("@ID", ID);


        oCommand.ExecuteQuery();

        oConnection.closeConnection();
    }
Example #7
0
    public void InsertNewImage(string path_Url, int PeopleID)
    {
        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();

        string sqlIns = "INSERT INTO Images(ImageID, PeopleID, imgURL_Path ) VALUES(@ImageID, @PeopleID, @ImagePathUrl) ";

        //использовать только в такой последовательности
        oCommand.PrepareInsertQuery(sqlIns, oConnection.connection);

        int NewImageID = this.GenerateNewImageID();

        oCommand.AddInsertParameter("@ImageID", NewImageID);
        oCommand.AddInsertParameter("@PeopleID", PeopleID);
        oCommand.AddInsertParameter("@ImagePathUrl", path_Url);


        oCommand.ExecuteQuery();

        oConnection.closeConnection();
    }
Example #8
0
    public void InsertToTable(List <TableValue> InsertValues, string TableName)
    {
        SQLConnectionClass oConnection = new SQLConnectionClass();

        SQLCommandClass oCommand = new SQLCommandClass();


        string string1 = null;
        string string2 = null;

        for (int i = 0; i < InsertValues.Count; i++)
        {
            if (i == InsertValues.Count - 1)//если является последним элементом, то не надо ставить запятую
            {
                string1 += InsertValues.ElementAt(i).ValueName;
                string2 += "@" + InsertValues.ElementAt(i).ValueName;
            }
            else //не последний элемент, то ставим запятую
            {
                string1 += InsertValues.ElementAt(i).ValueName + ",";
                string2 += "@" + InsertValues.ElementAt(i).ValueName + ",";
            }
        }

        string sqlIns = "INSERT INTO " + TableName + "( " + string1 + " ) VALUES(" + string2 + ")";

        //использовать только в такой последовательности
        oCommand.PrepareInsertQuery(sqlIns, oConnection.connection);

        //AddInsertParameters
        foreach (TableValue element in InsertValues)
        {
            oCommand.AddInsertParameter("@" + element.ValueName, element.Value);
        }

        oCommand.ExecuteQuery();
        oConnection.closeConnection();
    }