/// <summary> /// /// </summary> /// <param name="contrl">лист объектов которые надо сохрнить. обычно равно this</param> /// <param name="json">json к которому надо добавить ещё больше json-а</param> /// <returns></returns> public JArray formSerialize(Control contrl, JArray json = null) { if (json == null) { json = new JArray(); } foreach (Control ctr in contrl.Controls) { if (ctr.GetType().ToString() == "System.Windows.Forms.Button") { Dictionary <string, string> button = new Dictionary <string, string>(); //button.Add("BackgroundImage", imageText(ctr.BackgroundImage)); button.Add("Name", ctr.Name); button.Add("Enabled", ctr.Enabled.ToString()); button.Add("Visible", ctr.Visible.ToString()); button.Add("BackgroundImageLayout", ctr.BackgroundImageLayout.ToString()); button.Add("FontSize", ctr.Font.Size.ToString()); button.Add("BackColor", ButtonUniqueForm.ColorToJSON(ctr.BackColor)); //ctr.BackColor.Name); button.Add("Type", "Button"); button.Add("ForeColor", ButtonUniqueForm.ColorToJSON(ctr.ForeColor)); //ctr.ForeColor.Name); button.Add("Font", ctr.Font.Name); button.Add("FlatStyle", Convert.ToString(DesignClass.FLAT_OF_BUTTON)); json.Add(JObject.FromObject(button)); } else if (ctr.GetType().ToString() == "System.Windows.Forms.Label") { Dictionary <string, string> label = new Dictionary <string, string>(); label.Add("Name", ctr.Name); label.Add("BackColor", ButtonUniqueForm.ColorToJSON(ctr.BackColor));//((Label)ctr).BackColor.Name); label.Add("Enabled", ctr.Enabled.ToString()); label.Add("Visible", ctr.Visible.ToString()); label.Add("Type", "Label"); label.Add("FontSize", ctr.Font.Size.ToString()); label.Add("Font", ctr.Font.Name); label.Add("ForeColor", ((Label)ctr).ForeColor.Name); json.Add(JObject.FromObject(label)); } else if (ctr.GetType().ToString() == "System.Windows.Forms.Panel") { json.Add(formSerialize(ctr, json)); Dictionary <string, string> panel = new Dictionary <string, string>(); panel.Add("Name", ctr.Name); panel.Add("Enabled", ctr.Enabled.ToString()); panel.Add("Visible", ctr.Visible.ToString()); panel.Add("Type", "panel"); panel.Add("Form", ctr.FindForm().Name); json.Add(JObject.FromObject(panel)); } } return(json); }
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 + "')"); }
/// <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); }