public int InsertNewWall()//returns new wall ID { TableOpreatorClass oTable = new TableOpreatorClass(); TableValue value1 = new TableValue(); value1.ValueName = "ID"; int ID = oTable.GenerateNewID("ID", "Wall"); value1.Value = ID; int returnValue = ID; TableValue value2 = new TableValue(); value2.ValueName = "PublicationListID"; ID = oTable.GenerateNewID("ID", "PublicationList"); value2.Value = ID; TableValue value3 = new TableValue(); value3.ValueName = "DateTime"; value3.Value = DateTime.Now; List <TableValue> tableValueList = new List <TableValue>(); tableValueList.Add(value1); tableValueList.Add(value2); tableValueList.Add(value3); oTable.InsertToTable(tableValueList, "Wall");//CreateNewWall return(returnValue); }
/// <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(); }
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(); }
public void InsertNewPublication(int AuthorID /*PeopleID*/, int WallID, string Text, List <int> ImageIDList) { TableOpreatorClass oTable = new TableOpreatorClass(); TableValue value1 = new TableValue(); value1.ValueName = "WallID"; value1.Value = WallID; TableValue value2 = new TableValue(); value2.ValueName = "UniqueID"; int PublicationID = oTable.GenerateNewID("UniqueID", "Publication"); value2.Value = PublicationID; TableValue value3 = new TableValue(); value3.ValueName = "IDinSequence"; value3.Value = oTable.GetMaxIDInGroup("IDinSequence", "Publication", "WallID", WallID);/*У стенки много публикаций * Каждая публикация имеет уникальный айди и айди (IDinSequence) в последовательности публикаций со сходным WallID */ TableValue value4 = new TableValue(); value4.ValueName = "DateTime"; value4.Value = DateTime.Now; TableValue value5 = new TableValue(); value5.ValueName = "ImageListID"; value5.Value = oTable.GenerateNewID("ID", "ImageList"); TableValue value6 = new TableValue(); value6.ValueName = "AuthorID"; value6.Value = AuthorID; TableValue value7 = new TableValue(); value7.ValueName = "Text"; value7.Value = Text; List <TableValue> tableValueList = new List <TableValue>(); tableValueList.Add(value1); tableValueList.Add(value2); tableValueList.Add(value3); tableValueList.Add(value4); tableValueList.Add(value5); tableValueList.Add(value6); tableValueList.Add(value7); oTable.InsertToTable(tableValueList, "Wall");//CreateNewWall tableValueList.Clear(); TableValue value8 = new TableValue(); value8.ValueName = "ID"; Wall oWall = new Wall(); int PublicationListID = oWall.GetPublicationListID(WallID);//узнаем айди списка публикаций value8.Value = PublicationListID; TableValue value9 = new TableValue(); value9.ValueName = "PublicationID"; value9.Value = PublicationID; oTable.InsertToTable(tableValueList, "PublicationList");//CreateNewWall }