public static void SaveDesignForm(System.Windows.Forms.Control.ControlCollection ctrs) { foreach (System.Windows.Forms.Control ctr in ctrs) { if (ctr is System.Windows.Forms.PictureBox) { System.Windows.Forms.PictureBox pic = (System.Windows.Forms.PictureBox)ctr; //resize image and convert to byte //byte[] imgb = CImageUtility.ImageToByte(pic.Image.GetThumbnailImage(pic.Size.Width, pic.Size.Height, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero)); byte[] imgb = CImageUtility.ImageToByte(CImageUtility.ResizeImage(pic.Image, pic.Size.Width, pic.Size.Height)); UIMessage.DBEngine.exec("FormLayout_Save", "@FormName", ctr.FindForm().Name, "@ControlName", ctr.Name, "@Image", imgb, "@SizeMode", pic.SizeMode.ToString(), "@ParentControl", ctr.Parent.Name, "@SystemType", string.Format("{0},{1}", ctr.GetType().FullName, ctr.GetType().Namespace), "@LocationX", ctr.Location.X, "@LocationY", ctr.Location.Y, "@Height", ctr.Size.Height, "@Visible", ctr.Visible, "@Enabled", ctr.Enabled, "@Width", ctr.Size.Width); } else { UIMessage.DBEngine.exec("FormLayout_Save", "@FormName", ctr.FindForm().Name, "@ControlName", ctr.Name, "@ParentControl", ctr.Parent.Name, "@SystemType", string.Format("{0},{1}", ctr.GetType().FullName, ctr.GetType().Namespace), "@TabIndex", ctr.TabIndex, "@LocationX", ctr.Location.X, "@LocationY", ctr.Location.Y, "@Height", ctr.Size.Height, "@Visible", ctr.Visible, "@Enabled", ctr.Enabled, "@Width", ctr.Size.Width, "@FontName", ctr.Font.FontFamily.GetName(0), "@FontSize", ctr.Font.Size, "@FontBold", ctr.Font.Bold, "@FontItalic", ctr.Font.Italic, "@FontStrikeout", ctr.Font.Strikeout, "@FontUnderline", ctr.Font.Underline, "@ForeColor", string.Format("{0},{1},{2},{3}", ctr.ForeColor.A.ToString(), ctr.ForeColor.R.ToString(), ctr.ForeColor.G.ToString(), ctr.ForeColor.B.ToString()) ); } if (ctr.Controls.Count > 0 && !ctr.GetType().FullName.Equals("DevExpress.XtraGrid.GridControl") && !ctr.GetType().FullName.Contains("DevExpress.XtraEditors.")) { SaveDesignForm(ctr.Controls); } } UIMessage.DBEngine.exec(string.Format("delete tblFormLayout where (IsLayout is null or IsLayout = 0) and FormName = '{0}'", ctrs[0].FindForm().Name)); }
private static void LoadDesignedControls(SplitContainer ctrs, string formName) { try { Control ctlParent = ctrs.Panel1; string ControlName = string.Empty; DataTable dtControlsList = UIMessage.DBEngine.execReturnDataTable(string.Format("select * from tblFormLayout where FormName = '{0}' and (IsLayout = 1)", formName)); if (dtControlsList != null && dtControlsList.Rows.Count > 0) { foreach (DataRow dr in dtControlsList.Rows) { if (dr[CommonConst.ControlName] != DBNull.Value && !dr[CommonConst.ControlName].ToString().Trim().Equals(string.Empty) && !dr[CommonConst.ControlName].ToString().Equals(formName)) { Control ctr = (Control)CreateComponent(dr[CommonConst.SystemType].ToString(), dr[CommonConst.ControlName].ToString()); ctr.Name = dr[CommonConst.ControlName].ToString(); ctr.Location = new Point((int)dr[CommonConst.LocationX], (int)dr[CommonConst.LocationY]); if (ctr is DevExpress.XtraEditors.LabelControl) { ctr.Text = HPA.Common.UIMessage.Get_Message(ctr.Name); } ctr.Size = new Size((int)dr[CommonConst.Width], (int)dr[CommonConst.Height]); ctr.Visible = Convert.ToBoolean(dr[CommonConst.Visible]); ctr.Enabled = Convert.ToBoolean(dr[CommonConst.Enabled]); if (dr[CommonConst.TabIndex] != DBNull.Value) { ctr.TabIndex = Convert.ToInt32(dr[CommonConst.TabIndex]); } if (dr[CommonConst.FontName] != DBNull.Value) { SetFontStyle(ref ctr, dr); } if (dr[CommonConst.ForeColor] != DBNull.Value) { SetForeColor(ref ctr, dr); } if (ctr is PictureBox) { if (dr[CommonConst.Image] != DBNull.Value) { ((PictureBox)ctr).Image = CImageUtility.byteArrayToImage((byte[])dr[CommonConst.Image]); } } if (dr[CommonConst.Validation] != DBNull.Value) { SetValidationToControl(ref ctr, dr); } if (dr[CommonConst.MaskType] != DBNull.Value) { SetMastToControl(ref ctr, dr); } ctlParent.Controls.Add(ctr); } else if (dr[CommonConst.ControlName].ToString().Equals(formName)) { ctlParent.Size = new Size((int)dr[CommonConst.Width], (int)dr[CommonConst.Height]); ctlParent.Name = dr[CommonConst.FormName].ToString(); } } foreach (DataRow dr in dtControlsList.Rows) { if (dr[CommonConst.ParentControl] == DBNull.Value) { continue; } string PrentCtrName = dr[CommonConst.ParentControl].ToString(); if (!PrentCtrName.Equals(ctlParent.Name) && !dr[CommonConst.ControlName].ToString().Trim().Equals(string.Empty)) { if (ctlParent.Controls.Find(PrentCtrName, true).Length > 0 && ctlParent.Controls.Find(dr[CommonConst.ControlName].ToString(), true).Length > 0) { ctlParent.Controls.Find(PrentCtrName, true)[0].Controls.Add(ctlParent.Controls.Find(dr[CommonConst.ControlName].ToString(), true)[0]); } } } } } catch (Exception ex) { Helper.LogError(ex, ex.Message, "LoadDesignedControls()"); } }