Beispiel #1
0
        /// <summary>
        /// Добавление UserControl с категориями
        /// </summary>
        public static void AddNewBlock(object sender, EventArgs e)
        {
            Control      c = ((ContextMenuStrip)((ToolStripMenuItem)sender).Owner).SourceControl;
            UCParameters p = new UCParameters("CategoriesUserControl", new List <string>()
            {
                "2", "2"
            });

            p.ShowDialog();
            if (p.ParamsList != new List <string>())
            {
                CategoriesUserControl a1 = new CategoriesUserControl(p.ParamsList);
                string shsvfhksv         = "";
                foreach (string asd in p.ParamsList)
                {
                    shsvfhksv += asd + ',';
                }
                a1.Controls.Add(CategoriesUserControl.l1);
                Menus.InsertBlockToDB(sender, a1, shsvfhksv);
            }
        }
        /// <summary>
        /// Когда отпускаем мышку, сохраняем координаты ЮзерКонтрола в БД
        /// </summary>
        public void FormTest_MouseUp(object sender, MouseEventArgs e)
        {
            IsDragging = false;

            UserControl ActualUC = (UserControl)sender;


            //if (sender.Equals(ActualUC))
            //{
            string paramsAsString = "";

            switch (ActualUC.GetType().Name)
            {
            case "AdsUserControl":
                AdsUserControl NewPreview = (AdsUserControl)sender;
                foreach (string pr in NewPreview.ParamsAds)
                {
                    paramsAsString += pr + ",";
                }
                break;

            case "ArticleDetailsUserControl":
                ArticleDetailsUserControl NewPreview2 = (ArticleDetailsUserControl)sender;
                foreach (string pr in NewPreview2.ListOfArticles)
                {
                    paramsAsString += pr + ",";
                }
                break;

            case "ArticlePreviewUserControl":
                ArticlePreviewUserControl NewPreview3 = (ArticlePreviewUserControl)sender;
                foreach (string pr in NewPreview3.asd)
                {
                    paramsAsString += pr + ",";
                }
                break;

            case "CategoriesUserControl":
                CategoriesUserControl NewPreview4 = (CategoriesUserControl)sender;
                foreach (string pr in NewPreview4.asd)
                {
                    paramsAsString += pr + ",";
                }
                break;

            case "UserControlAutorsList":
                UserControlAutorsList NewPreview5 = (UserControlAutorsList)sender;
                foreach (string pr in NewPreview5.asd)
                {
                    paramsAsString += pr + ",";
                }
                break;

            case "UserControlMainAuthor":
                UserControlMainAuthor NewPreview6 = (UserControlMainAuthor)sender;
                foreach (string pr in NewPreview6.par)
                {
                    paramsAsString += pr + ",";
                }
                break;

            case "UserControlSearch":
                UserControlSearch NewPreview7 = (UserControlSearch)sender;

                /*foreach (string pr in NewPreview7.as)
                 * {
                 *  param7 += pr + ",";
                 * }*/
                break;
            }

            SQLClass.Update("UPDATE block SET" +
                            " x = " + ((UserControl)sender).Location.X.ToString() + "," +
                            " y = " + ((UserControl)sender).Location.Y.ToString() +
                            " WHERE id = '" + ActualUC.Tag + "'");

            if (paramsAsString.Length > 0)
            {
                SQLClass.Update("UPDATE block SET" +
                                " Params = '" + paramsAsString +
                                "' WHERE id = '" + ActualUC.Tag + "'");
            }
            //}
        }
Beispiel #3
0
        /// <summary>
        /// Переписанная функция чтения из базы.
        /// </summary>
        /// <param name="FormName">Имя нужной формы</param>
        /// <returns>Лист контролов</returns>
        public static List <UserControl> ReadFromDB(string FormName, string parentName = "")
        {
            if (parentName == "")
            {
                parentName = FormName;
            }
            List <string> ListDB = SQLClass.Select(
                "SELECT form, x, y, name, Params, id, Dock FROM block WHERE form = '" + FormName + "' AND Parent = '" + parentName + "'");

            List <UserControl> ListOfControls = new List <UserControl>();

            foreach (List <string> Row in Split(ListDB, 7))
            {
                #region Вспомогательные переменные для того чтобы не писать Row[...]
                int       x    = Convert.ToInt32(Row[1]);
                int       y    = Convert.ToInt32(Row[2]);
                DockStyle d    = DockStyle.None;
                string    id   = Row[5];
                string    form = "";
                try
                {
                    form = Row[0];
                }
                catch (Exception)
                {
                    throw new NullReferenceException("form = null");
                }

                string name = "";
                try
                {
                    name = Row[3];
                }
                catch (Exception)
                {
                    throw new NullReferenceException("name = null");
                }

                List <string> Params = new List <string>();
                try
                {
                    Params = Row[4].Split(new char[] { ',' }).ToList();
                }
                catch (Exception)
                {
                    throw new NullReferenceException("Params = null");
                }
                try
                {
                    switch (Row[6])
                    {
                    case "Top":
                        d = DockStyle.Top;
                        break;

                    case "Right":
                        d = DockStyle.Right;
                        break;

                    case "Left":
                        d = DockStyle.Left;
                        break;

                    case "Fill":
                        d = DockStyle.Fill;
                        break;

                    case "Bottom":
                        d = DockStyle.Bottom;
                        break;
                    }
                }
                catch (Exception)
                {
                    d = DockStyle.None;
                    //throw new NullReferenceException("name = null");
                }
                #endregion


                switch (name)
                {
                case "AdsUserControl":
                    AdsUserControl NewAds = new AdsUserControl(Params)
                    {
                        Location = new Point(x, y),
                        Tag      = id,
                        Dock     = d,
                        Name     = "UCref"
                    };
                    ListOfControls.Add(NewAds);
                    break;

                case "ArticleDetailsUserControl":
                    ArticleDetailsUserControl NewDetails = new ArticleDetailsUserControl(Params)
                    {
                        Location = new Point(x, y),
                        Tag      = id,
                        Dock     = d,
                        Name     = "UCref"
                    };
                    ListOfControls.Add(NewDetails);
                    break;

                case "ArticlePreviewUserControl":
                    ArticlePreviewUserControl NewPreview = new ArticlePreviewUserControl(Params)
                    {
                        Location = new Point(x, y),
                        Tag      = id,
                        Dock     = d,
                        Name     = "UCref"
                    };
                    ListOfControls.Add(NewPreview);
                    break;

                case "AuthenticationUserControl":
                    AuthenticationUserControl NewAuth = new AuthenticationUserControl(Params)
                    {
                        Location = new Point(x, y),
                        Tag      = id,
                        Dock     = d,
                        Name     = "UCref"
                    };
                    ListOfControls.Add(NewAuth);
                    break;

                case "CategoriesUserControl":
                    CategoriesUserControl NewCateg = new CategoriesUserControl(Params)
                    {
                        Location = new Point(x, y),
                        Tag      = id,
                        Dock     = d,
                        Name     = "UCref"
                    };
                    ListOfControls.Add(NewCateg);
                    break;

                case "UserControlAutorsList":
                    UserControlAutorsList NewAuthorList = new UserControlAutorsList(Params)
                    {
                        Location = new Point(x, y),
                        Tag      = id,
                        Dock     = d,
                        Name     = "UCref"
                    };

                    ListOfControls.Add(NewAuthorList);
                    break;

                case "UserControlMainAuthor":
                    UserControlMainAuthor NewMainAuthor = new UserControlMainAuthor(Params)
                    {
                        Location = new Point(x, y),
                        Tag      = id,
                        Dock     = d,
                        Name     = "UCref"
                    };
                    ListOfControls.Add(NewMainAuthor);
                    break;

                case "UserControlSearch":
                    UserControlSearch NewSearch = new UserControlSearch(Params)
                    {
                        Location = new Point(x, y),
                        Tag      = id,
                        Dock     = d,
                        Name     = "UCref"
                    };
                    ListOfControls.Add(NewSearch);
                    break;

                case "PodborkiUserControl":
                    PodborkiUserControl NewCateg12 = new PodborkiUserControl()
                    {
                        Location = new Point(x, y),
                        Tag      = id,
                        Dock     = d,
                        Name     = "UCref"
                    };
                    ListOfControls.Add(NewCateg12);
                    break;

                default:
                    throw new Exception(string.Format("'{0}' это неправильное название блока", name));
                }
            }

            return(ListOfControls);
        }
        /// <summary>
        /// Функция указания текущих параметров перед показом формы UCParameters.
        /// </summary>
        public static void SetUCParametersToCurrent(object sender, EventArgs e)
        {
            UserControl   pb     = (UserControl)((ContextMenuStrip)((ToolStripMenuItem)sender).Owner).SourceControl;
            List <string> dnonil = new List <string>();

            switch (pb.GetType().ToString().Replace("OnlineMag.", ""))
            {
            case "AdsUserControl":
                AdsUserControl pb1 = (AdsUserControl)pb;
                dnonil.Add(pb1.amount.ToString());
                dnonil.Add(pb1.progal.ToString());
                break;

            case "ArticleDetailsUserControl":
                ArticleDetailsUserControl pb2 = (ArticleDetailsUserControl)pb;
                dnonil.Add(pb2.ListOfArticles[0]);
                break;

            case "ArticlePreviewUserControl":
                ArticlePreviewUserControl pb3 = (ArticlePreviewUserControl)pb;
                dnonil.Add(pb3.Article);
                dnonil.Add("5");
                break;

            case "CategoriesUserControl":
                CategoriesUserControl pb4 = (CategoriesUserControl)pb;
                if (pb4.asd.Count >= 2)
                {
                    dnonil.Add(pb4.asd[0]);
                    dnonil.Add(pb4.asd[1]);
                }
                break;

            case "UserControlAutorsList":
                UserControlAutorsList pb5 = (UserControlAutorsList)pb;
                if (pb5.asd.Count >= 3)
                {
                    dnonil.Add(pb5.asd[0]);
                    dnonil.Add(pb5.asd[1]);
                    dnonil.Add(pb5.asd[2]);
                }
                break;

            case "UserControlMainAuthor":
                UserControlMainAuthor pb6 = (UserControlMainAuthor)pb;
                dnonil.AddRange(pb6.par);
                break;

            case "UserControlSearch":
                UserControlSearch pb7 = (UserControlSearch)pb;
                dnonil.Add(" ");
                break;

            case "AuthenticationUserControl":
                AuthenticationUserControl pb8 = (AuthenticationUserControl)pb;
                dnonil.Add("");
                break;
            }

            UCParameters p = new UCParameters(pb.GetType().ToString().Replace("OnlineMag.", ""), dnonil);

            p.UCSize     = pb.Size;
            p.UCLocation = pb.Location;

            p.ShowDialog();
            pb.Size     = p.UCSize;
            pb.Location = p.UCLocation;
            if (pb.GetType().ToString().Replace("OnlineMag.", "") == "UserControlMainAuthor")
            {
                UserControlMainAuthor pb33 = (UserControlMainAuthor)pb;
                pb33.par = new List <string>()
                {
                    p.UserName
                };
                dnonil = pb33.par;
                pb33.Init(pb33.par);
            }
            else if (pb.GetType().ToString().Replace("OnlineMag.", "") == "CategoriesUserControl")
            {
                CategoriesUserControl pb2 = (CategoriesUserControl)pb;
                pb2.asd = p.ParamsList;
                dnonil  = p.ParamsList;
                CategoriesUserControl.RefreshUC(pb2, Convert.ToInt32(pb2.asd[0]));
            }

            else if (pb.GetType().ToString().Replace("OnlineMag.", "") == "UserControlAutorsList")
            {
                UserControlAutorsList pb2 = (UserControlAutorsList)pb;
                pb2.asd.Clear();
                pb2.asd         = p.ParamsList;
                pb2.authorsList = SQLClass.Select("SELECT `UserName` FROM `Authors` LIMIT 0," + p.Amount);
                pb2.UserControlAutorsList_Load(null, null);
                if (pb2.asd[2] == "")
                {
                    pb2.asd[2] = "0";
                }
                dnonil = pb2.asd;
            }

            else if (pb.GetType().ToString().Replace("OnlineMag.", "") == "ArticlePreviewUserControl")
            {
                ArticlePreviewUserControl pb2 = (ArticlePreviewUserControl)pb;

                pb2.Article         = p.ParamsList[0];
                pb2.linkLabel1.Text = pb2.Article;
                pb2.asd             = p.ParamsList;
                dnonil = pb2.asd;

                try
                {
                    List <string> kart = SQLClass.Select("SELECT `Picture` FROM `Articles1` WHERE `Header` = '" + pb2.Article + "'");
                    pb2.pictureBox1.Load(kart[0]);

                    List <string> likes = SQLClass.Select("SELECT `LikesCount`, `DisCount` FROM `Likes` WHERE `Article` = '" + pb2.Article + "'");
                    pb2.LikeCount.Text    = likes[0];
                    pb2.DisLikeCount.Text = likes[1];
                    pb2.like    = Convert.ToInt32(likes[0]);
                    pb2.dislike = Convert.ToInt32(likes[1]);
                }
                catch
                {
                    pb2.pictureBox1.Image = null;
                }
            }
            else if (pb.GetType().ToString().Replace("OnlineMag.", "") == "ArticleDetailsUserControl")
            {
                ArticleDetailsUserControl pb2 = (ArticleDetailsUserControl)pb;
                pb2.ListOfArticles.Clear();

                pb2.ListOfArticles    = p.ParamsList;
                pb2.ArticleLabel.Text = p.ParamsList[0];
                List <string> kart = SQLClass.Select("SELECT Picture, IFNULL(Text,'Ничего'), IFNULL(Author,'Никто')  FROM Articles1 WHERE Header = '" + pb2.ArticleLabel.Text + "'");
                if (kart.Count > 2)
                {
                    try
                    {
                        pb2.ArticlePicture.Load(kart[0]);
                    }
                    catch
                    {
                        pb2.ArticlePicture.Image = null;
                    }

                    pb2.ArticleTextLabel.Text = kart[1];
                    pb2.AuthorsNameLabel.Text = kart[2];
                }

                dnonil = pb2.ListOfArticles;
            }
            else if (pb.GetType().ToString().Replace("OnlineMag.", "") == "AdsUserControl")
            {
                AdsUserControl pb2 = (AdsUserControl)pb;
                pb2.ParamsAds = p.ParamsList;
                pb2.amount    = p.Amount;
                pb2.progal    = p.DistanceBetween;
                pb2.refreshADS();
                dnonil = pb2.ParamsAds;
            }
            else if (pb.GetType().ToString().Replace("OnlineMag.", "") == "UserControlAutorsList")
            {
                UserControlAutorsList pb2 = (UserControlAutorsList)pb;
                pb2.asd = p.ParamsList;
                dnonil  = p.ParamsList;
            }

            #region Сохранение в БД
            string param3 = "";
            foreach (string pr in dnonil)
            {
                param3 += pr + ",";
            }
            SQLClass.Update("UPDATE block SET" +
                            " Params = '" + param3 +
                            "' WHERE id = '" + pb.Tag + "'");
            SQLClass.Update("UPDATE block SET" +
                            " x = " + pb.Location.X.ToString() + "," +
                            " y = " + pb.Location.Y.ToString() +
                            " WHERE id = '" + pb.Tag + "'");
            #endregion
        }