Ejemplo n.º 1
0
 public static void UpdateLabelDesignInDb(Control pb)
 {
     SQLClass.Delete("DELETE FROM " + Tables.Unique +
                     " WHERE type = 'Label'" +
                     " AND name = '" + pb.Name +
                     "' AND FormFrom = '" + pb.FindForm().Name + "'");
     SQLClass.Insert("INSERT INTO " + Tables.Unique +
                     " (type, design, author, name, FormFrom) VALUES " +
                     "('Label', " +
                     "'ForeColor = " + ButtonUniqueForm.ColorToJSON(pb.ForeColor) +
                     ", FontName = " + pb.Font.Name +
                     ", FontSize = " + pb.Font.Size +
                     ", Text = " + pb.Text +
                     "', 'admin', '" + pb.Name + "', '" + pb.FindForm().Name + "')");
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Обновление дизайна конкретной панели в БД
        /// </summary>
        public static void UpdatePanelDesignInDb(Panel p)
        {
            SQLClass.Delete("DELETE FROM " + Tables.Unique +
                            " WHERE type = 'Panel'" +
                            " AND name = '" + p.Name +
                            "' AND FormFrom = '" + p.FindForm().Name + "'");

            SQLClass.Insert("INSERT INTO " + Tables.Unique +
                            " (type, design, author, name, FormFrom) VALUES " +
                            "('Panel', " +
                            "'Color = " + p.BackColor +
                            ", Visible = " + p.Visible +
                            ", BackgroundImage = " + p.BackgroundImage + "', " +
                            "'admin', '" +
                            p.Name + "', '" +
                            p.FindForm().Name + "')");
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Обновление дизайна конкретной кнопки в БД
 /// </summary>
 public static void UpdateButtonDesignInDb(Button pb)
 {
     SQLClass.Delete("DELETE FROM " + Tables.Unique +
                     " WHERE type = 'Button'" +
                     " AND name = '" + pb.Name +
                     "' AND FormFrom = '" + pb.FindForm().Name + "'");
     SQLClass.Insert("INSERT INTO " + Tables.Unique +
                     " (type, design, author, name, FormFrom) VALUES " +
                     "('Button', " +
                     "'Color = " + ColorToJSON(pb.BackColor) +
                     ", Visible = " + pb.Visible +
                     ", BackgroundImage = " + pb.BackgroundImage +
                     ", Text = " + pb.Text +
                     ", Dock = " + pb.Dock.ToString() +
                     ", FlatStyle = " + pb.FlatStyle +
                     "', 'admin', '" + pb.Name + "', '" + pb.FindForm().Name + "')");
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Загрузка дизайна конкретной формы из БД
        /// </summary>
        public static void GetFormDesignFromDb(ref Control c)
        {
            List <String> uniqueDesign = SQLClass.Select("SELECT design FROM " + Tables.Unique +
                                                         " WHERE FormFrom = '" + c.Name + "' and Type = 'Form'");

            if (uniqueDesign.Count == 0)
            {
                return;
            }
            String[] words = uniqueDesign[0].Split(new string[] { ":", ",", " = ", "=" }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < words.Length; i++)
            {
                if (words[i] == "MinimizeBox")
                {
                    ((Form)c).MinimizeBox = (words[i + 1].Trim() == "True");
                }

                if (words[i] == "Color")
                {
                    foreach (String colorName in Enum.GetNames(typeof(KnownColor)))
                    {
                        String colorFromDB = words[i + 1];
                        if (colorFromDB.Trim().StartsWith("Color"))
                        {
                            colorFromDB = colorFromDB.Trim().Replace("Color [", "").Replace("]", "");
                        }

                        if (colorName == colorFromDB.Trim())
                        {
                            Color knownColor = Color.FromKnownColor((KnownColor)Enum.Parse(typeof(KnownColor), colorName));
                            c.BackColor = knownColor;
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Чтение дизайна для Panel
        /// </summary>
        public void ReadPanelDefault()
        {
            List <String> Auths        = SQLClass.Select("SELECT design FROM " + Tables.Default + " WHERE type = 'panel'");
            String        designKnopki = Auths[0];

            String[] words = designKnopki.Split(new char[] { ':', ',', ' ', '\"' }, StringSplitOptions.RemoveEmptyEntries);

            for (int index = 0; index < words.Length; index++)
            {
                if (words[index] == "BackColor")
                {
                    foreach (String colorName in Enum.GetNames(typeof(KnownColor)))
                    {
                        if (colorName == words[index + 1])
                        {
                            Color knownColor = Color.FromKnownColor((KnownColor)Enum.Parse(typeof(KnownColor), colorName));
                            DesignClass.PANEL_COLOR = knownColor;
                        }
                    }
                }

                if (words[index] == "Transparency")
                {
                    DesignClass.PANEL_TRANSPARENCY = Convert.ToBoolean(words[index + 1]);
                }
                if (words[index] == "BackGroundImageAddress")
                {
                    DesignClass.PANEL_BACKGROUND_ADDRESS = words[index + 1] + ":" + words[index + 2];

                    PictureBox pb1 = new PictureBox();
                    pb1.Load(DesignClass.PANEL_BACKGROUND_ADDRESS);
                    DesignClass.PANEL_BACKGROUND_IMG = pb1.Image;
                    pb1.Dispose();
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Чтение дефолтного дизайна Button
        /// </summary>
        public static void ReadButtonDefault()
        {
            List <String> Auths = SQLClass.Select("SELECT design FROM " + Tables.Default + " WHERE type = 'Button'");

            if (Auths.Count == 0)
            {
                return;
            }

            String[] words = Auths[0].Split(new char[] { ':', ',', ' ', '\"' }, StringSplitOptions.RemoveEmptyEntries);

            for (int index = 0; index < words.Length; index++)
            {
                if (words[index] == "BackColor")
                {
                    foreach (String colorName in Enum.GetNames(typeof(KnownColor)))
                    {
                        if (colorName == words[index + 1])
                        {
                            Color knownColor = Color.FromKnownColor((KnownColor)Enum.Parse(typeof(KnownColor), colorName));
                            DesignClass.BUTTON_COLOR = knownColor;
                        }
                    }
                }

                if (words[index] == "ForeColor")
                {
                    foreach (String colorName in Enum.GetNames(typeof(KnownColor)))
                    {
                        if (colorName == words[index + 1])
                        {
                            Color knownColor = Color.FromKnownColor((KnownColor)Enum.Parse(typeof(KnownColor), colorName));
                            DesignClass.BUTTON_TEXT_COLOR = knownColor;
                        }
                    }
                }

                if (words[index] == "Font")
                {
                    foreach (FontFamily item in FontFamily.Families)
                    {
                        if (item.ToString() == words[index + 1])
                        {
                            DesignClass.BUTTON_FONT = new Font(item, 14);
                        }
                    }
                }

                if (words[index].Trim() == "BackgroundImage")
                {
                    DesignClass.BUTTON_BACKGROUND_IMG_ADRESS = words[index + 1] + ":" + words[index + 2];
                    PictureBox pb = new PictureBox();
                    pb.Load(DesignClass.BUTTON_BACKGROUND_IMG_ADRESS);
                    DesignClass.BUTTON_BACKGROUND_IMG = pb.Image;
                }

                if (words[index] == "FlatStyle")
                {
                    if (words[index + 1] == "Popup")
                    {
                        DesignClass.FLAT_OF_BUTTON = FlatStyle.Popup;
                    }
                    else if (words[index + 1] == "System")
                    {
                        DesignClass.FLAT_OF_BUTTON = FlatStyle.System;
                    }
                    else if (words[index + 1] == "Standard")
                    {
                        DesignClass.FLAT_OF_BUTTON = FlatStyle.Popup;
                    }
                    else if (words[index + 1] == "Flat")
                    {
                        DesignClass.FLAT_OF_BUTTON = FlatStyle.System;
                    }
                }

                #region ImageAlign
                if (words[index].Trim() == "ImageAlign")
                {
                    //DesignClass.BUTTONIMAGE_ALLINE = (ContentAlignment)(words[index + 1]);
                    if (words[index + 1] == "TopLeft")
                    {
                        DesignClass.BUTTONIMAGE_ALLINE = ContentAlignment.TopLeft;
                    }
                    else if (words[index + 1] == "TopCenter")
                    {
                        DesignClass.BUTTONIMAGE_ALLINE = ContentAlignment.TopCenter;
                    }
                    else if (words[index + 1] == "TopRight")
                    {
                        DesignClass.BUTTONIMAGE_ALLINE = ContentAlignment.TopRight;
                    }
                    else if (words[index + 1] == "MiddleLeft")
                    {
                        DesignClass.BUTTONIMAGE_ALLINE = ContentAlignment.MiddleLeft;
                    }
                    else if (words[index + 1] == "MiddleCenter")
                    {
                        DesignClass.BUTTONIMAGE_ALLINE = ContentAlignment.MiddleCenter;
                    }
                    else if (words[index + 1] == "MiddleRight")
                    {
                        DesignClass.BUTTONIMAGE_ALLINE = ContentAlignment.MiddleRight;
                    }
                    else if (words[index + 1] == "BottomLeft")
                    {
                        DesignClass.BUTTONIMAGE_ALLINE = ContentAlignment.BottomLeft;
                    }
                    else if (words[index + 1] == "BottomCenter")
                    {
                        DesignClass.BUTTONIMAGE_ALLINE = ContentAlignment.BottomCenter;
                    }
                    else if (words[index + 1] == "BottomRight")
                    {
                        DesignClass.BUTTONIMAGE_ALLINE = ContentAlignment.BottomRight;
                    }
                }
                #endregion
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// ЧТение дефолтного дизайна для Label
        /// </summary>
        public void ReadLabelDefault()
        {
            List <String> Auths        = SQLClass.Select("SELECT design FROM " + Tables.Default + " WHERE type = 'label'");
            String        designKnopki = Auths[0];

            String[] words = designKnopki.Split(new char[] { ':', ',', ' ', '\"' }, StringSplitOptions.RemoveEmptyEntries);

            for (int index = 0; index < words.Length; index++)
            {
                if (words[index] == "BackColor")
                {
                    String colorFromDB = words[index + 1].Trim();
                    if (colorFromDB.StartsWith("Color"))
                    {
                        colorFromDB = colorFromDB.Replace("Color [", "").Replace("]", "");
                    }

                    foreach (String colorName in Enum.GetNames(typeof(KnownColor)))
                    {
                        if (colorName == colorFromDB)
                        {
                            Color knownColor = Color.FromKnownColor((KnownColor)Enum.Parse(typeof(KnownColor), colorName));
                            DesignClass.LABEL_COLOR = knownColor;
                        }
                    }
                }

                if (words[index] == "ForeColor")
                {
                    String colorFromDB = words[index + 1].Trim();
                    if (colorFromDB.StartsWith("Color"))
                    {
                        colorFromDB = colorFromDB.Replace("Color [", "").Replace("]", "");
                    }

                    foreach (String colorName in Enum.GetNames(typeof(KnownColor)))
                    {
                        if (colorName == colorFromDB)
                        {
                            Color knownColor = Color.FromKnownColor((KnownColor)Enum.Parse(typeof(KnownColor), colorName));
                            DesignClass.LABEL_TEXT_COLOR = knownColor;
                        }
                    }
                }

                if (words[index].Trim() == "FontName")
                {
                    DesignClass.NAME_FONT_OF_LABEL = words[index + 1];
                }

                if (words[index].Trim() == "FontSize")
                {
                    DesignClass.SIZE_FONT_OF_LABEL = (int)(Convert.ToDecimal(words[index + 1]));
                }
                if (words[index].Trim() == "TextAlign")
                {
                    DesignClass.LABEL_AUTO_SIZE = false;
                    switch (words[index + 1])
                    {
                    case "BottomCenter":
                        DesignClass.LABEL_TEXT_ALIGN = System.Drawing.ContentAlignment.BottomCenter;
                        break;

                    case "BottomLeft":
                        DesignClass.LABEL_TEXT_ALIGN = System.Drawing.ContentAlignment.BottomLeft;
                        break;

                    case "BottomRight":
                        DesignClass.LABEL_TEXT_ALIGN = System.Drawing.ContentAlignment.BottomRight;
                        break;

                    case "MiddleCenter":
                        DesignClass.LABEL_TEXT_ALIGN = System.Drawing.ContentAlignment.MiddleCenter;
                        break;

                    case "MiddleLeft":
                        DesignClass.LABEL_TEXT_ALIGN = System.Drawing.ContentAlignment.MiddleLeft;
                        break;

                    case "MiddleRight":
                        DesignClass.LABEL_TEXT_ALIGN = System.Drawing.ContentAlignment.MiddleRight;
                        break;

                    case "TopCenter":
                        DesignClass.LABEL_TEXT_ALIGN = System.Drawing.ContentAlignment.TopCenter;
                        break;

                    case "TopLeft":
                        DesignClass.LABEL_TEXT_ALIGN = System.Drawing.ContentAlignment.TopLeft;
                        break;

                    case "TopRight":
                        DesignClass.LABEL_TEXT_ALIGN = System.Drawing.ContentAlignment.TopRight;
                        break;

                    default:
                        DesignClass.LABEL_AUTO_SIZE = true;
                        break;
                    }
                }
            }

            if (DesignClass.NAME_FONT_OF_LABEL != null && DesignClass.SIZE_FONT_OF_LABEL != 0)
            {
                DesignClass.FONT_OF_LABEL = new Font(DesignClass.NAME_FONT_OF_LABEL, DesignClass.SIZE_FONT_OF_LABEL);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Сохранение дефолтного дизайна в базу
        /// </summary>
        /// <returns></returns>
        public static Dictionary <string, JObject> typeSerialize()
        {
            Dictionary <string, JObject> AllTypesData = new Dictionary <string, JObject>();

            #region Button
            Dictionary <string, string> ButtonData = new Dictionary <string, string>();
            if (DesignClass.BUTTON_BACKGROUND_IMG_ADRESS != null)
            {
                ButtonData.Add("BackgroundImage", DesignClass.BUTTON_BACKGROUND_IMG_ADRESS.ToString());
            }

            //ButtonData.Add("BackgroundImageLayout", button1.BackgroundImageLayout.ToString());

            if (DesignClass.BUTTON_TEXT_COLOR != null)
            {
                ButtonData.Add("ForeColor", ButtonUniqueForm.ColorToJSON(DesignClass.BUTTON_TEXT_COLOR));//DesignClass.BUTTON_TEXT_COLOR.ToString());
            }
            if (DesignClass.BUTTON_FONT != null)
            {
                ButtonData.Add("Font", DesignClass.BUTTON_FONT.ToString());
            }
            if (DesignClass.BUTTON_COLOR != null)
            {
                ButtonData.Add("Color", ButtonUniqueForm.ColorToJSON(DesignClass.BUTTON_COLOR));//.ToString());
            }

            ButtonData.Add("ImageAlign", DesignClass.BUTTONIMAGE_ALLINE.ToString());   //.ToString());
            ButtonData.Add("FlatStyle", Convert.ToString(DesignClass.FLAT_OF_BUTTON)); //.ToString());

            #endregion

            #region Panel
            Dictionary <string, string> PanelData = new Dictionary <string, string>();
            if (DesignClass.PANEL_COLOR != null)
            {
                PanelData.Add("BackColor", ButtonUniqueForm.ColorToJSON(DesignClass.PANEL_COLOR));// DesignClass.PANEL_COLOR.ToString());
            }
            if (DesignClass.PANEL_BACKGROUND_ADDRESS != null)
            {
                PanelData.Add("BackGroundImageAddress", DesignClass.PANEL_BACKGROUND_ADDRESS);
            }
            if (DesignClass.PANEL_TRANSPARENCY != false)
            {
                PanelData.Add("Transparency", "true");
            }
            #endregion

            #region Label
            Dictionary <string, string> labelData = new Dictionary <string, string>();
            if (DesignClass.LABEL_COLOR != null)
            {
                labelData.Add("BackColor", ButtonUniqueForm.ColorToJSON(DesignClass.LABEL_COLOR));//DesignClass.LABEL_COLOR.ToString());
            }
            if (DesignClass.LABEL_TEXT_COLOR != null)
            {
                labelData.Add("ForeColor", ButtonUniqueForm.ColorToJSON(DesignClass.LABEL_TEXT_COLOR));//DesignClass.LABEL_TEXT_COLOR.ToString());
            }
            if (DesignClass.FONT_OF_LABEL != null)
            {
                labelData.Add("FontSize", DesignClass.FONT_OF_LABEL.Size.ToString());
                labelData.Add("FontName", DesignClass.FONT_OF_LABEL.Name);
            }

            if (!DesignClass.LABEL_AUTO_SIZE)
            {
                labelData.Add("TextAlign", DesignClass.LABEL_TEXT_ALIGN.ToString());
            }
            else
            {
                labelData.Add("TextAlign", "null");
            }
            #endregion

            AllTypesData.Add("button", JObject.FromObject(ButtonData));
            AllTypesData.Add("label", JObject.FromObject(labelData));
            AllTypesData.Add("panel", JObject.FromObject(PanelData));

            foreach (string type in AllTypesData.Keys)
            {
                SQLClass.Delete("DELETE FROM " + Tables.Default + " WHERE type = '" + type + "'");
                SQLClass.Insert(String.Format("INSERT INTO " + Tables.Default + "(type, design, author) VALUES ('{0}','{1}','{2}')",
                                              type, AllTypesData[type].ToString(), "test"));
            }

            return(AllTypesData);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Получение уникального дизайна кнопки из базы данных
        /// </summary>
        /// <param name="name">Имя кнопки</param>
        /// <param name="words">Массив слов (что-то связанное с JSON)</param>
        /// <returns>
        /// Новая кнопка со свойствами уникальной кнопки с названием <paramref name="name"/> из базы
        /// Её НЕЛЬЗЯ использовать как <code>ctr = GetUniqueDesignFromDB(...)</code>
        /// Нужно по отдельности задавать её свойства вашей кнопке.
        /// </returns>
        public static Button GetUniqueDesignFromDB(string name)
        {
            Button temp        = new Button();
            string temp_design = "";

            try
            {
                temp_design = SQLClass.Select(string.Format("SELECT design FROM `{1}` WHERE `name`='{0}'", name, Tables.Unique))[0];
            } catch (ArgumentOutOfRangeException)
            {
                return(new Button());
            }
            string[] words = temp_design.Split(new string[] { ":", ",", " = ", "=", "[", "]" }, StringSplitOptions.RemoveEmptyEntries);

            var FontName = "";
            var FontSize = 0;

            #region Код декодировки temp_design
            for (int i = 0; i < words.Length; i++)
            {
                #region Задаём цвет
                if (words[i].Trim() == "Color")
                {
                    try
                    {
                        temp.BackColor = Color.FromArgb(
                            Convert.ToInt32(words[i + 1]),
                            Convert.ToInt32(words[i + 2]),
                            Convert.ToInt32(words[i + 3]), Convert.ToInt32(words[i + 4]));
                    }
                    catch (Exception)
                    {
                        foreach (String colorName in Enum.GetNames(typeof(KnownColor)))
                        {
                            String colorFromDB = words[i + 1].Trim();
                            if (colorFromDB.StartsWith("Color"))
                            {
                                colorFromDB = colorFromDB.Replace("Color [", "").Replace("]", "");
                            }

                            if (colorName == colorFromDB)
                            {
                                Color knownColor = Color.FromKnownColor((KnownColor)Enum.Parse(typeof(KnownColor), colorName));
                                temp.BackColor = knownColor;
                            }
                        }
                    }
                }

                if (words[i].Trim() == "ForeColor")
                {
                    try
                    {
                        temp.ForeColor = Color.FromArgb(
                            Convert.ToInt32(words[i + 1]),
                            Convert.ToInt32(words[i + 2]),
                            Convert.ToInt32(words[i + 3]), Convert.ToInt32(words[i + 4]));
                    }
                    catch (Exception)
                    {
                        foreach (String colorName in Enum.GetNames(typeof(KnownColor)))
                        {
                            String colorFromDB = words[i + 1].Trim();
                            if (colorFromDB.StartsWith("Color"))
                            {
                                colorFromDB = colorFromDB.Replace("Color [", "").Replace("]", "");
                            }

                            if (colorName == colorFromDB)
                            {
                                Color knownColor = Color.FromKnownColor((KnownColor)Enum.Parse(typeof(KnownColor), colorName));
                                temp.ForeColor = knownColor;
                            }
                        }
                    }
                }
                #endregion

                #region Задаём видимость
                if (words[i].Trim() == "Visible")
                {
                    temp.Visible = (words[i + 1] == "True");
                }
                #endregion

                #region Задаём шрифт
                if (words[i].Trim() == "FontName")
                {
                    FontName = words[i + 1];
                }
                #endregion

                #region Задаём размер шрифта
                if (words[i].Trim() == "FontSize")
                {
                    FontSize = (int)(Convert.ToDecimal(words[i + 1]));
                }
                #endregion

                #region Задаем стиль кнопки
                if (words[i].Trim() == "FlatStyle")
                {
                    if (words[i + 1] == "Popup")
                    {
                        ((Button)temp).FlatStyle = FlatStyle.Popup;
                    }
                    else if (words[i + 1] == "System")
                    {
                        ((Button)temp).FlatStyle = FlatStyle.System;
                    }
                    else if (words[i + 1] == "Standard")
                    {
                        ((Button)temp).FlatStyle = FlatStyle.Standard;
                    }
                    else if (words[i + 1] == "Flat")
                    {
                        ((Button)temp).FlatStyle = FlatStyle.Flat;
                    }
                }
                #endregion
            }

            if (FontName != "" && FontSize > 0)
            {
                temp.Font = new Font(FontName, FontSize);
            }
            #endregion

            return(temp);
        }