/// <summary> /// Применить настройку внешнего вида для объекта из объекта /// <see cref="T:System.Data.DataRow" /> /// </summary> /// <param name="control">Объект для сохранения внешнего вида</param> /// <param name="layout"> /// Объект типа /// <see cref="T:System.Data.DataRow" /> /// </param> public static void AcceptLayoutForControl(this Control control, UserLayout layout) { ISupportXtraSerializer sxs = null; var gc = control as GridControl; if (gc != null) { sxs = gc.MainView; } else { var pv = control as PivotGridControl; if (pv != null) { sxs = pv; } else { var tl = control as TreeList; if (tl != null) { sxs = tl; } } } if (layout == null || sxs == null) { return; } sxs.RestoreLayoutSerializingFromStream(layout.Layout); }
/// <summary> /// Получить настройки для внешнего вида объекта в виде массива байтов /// </summary> /// <param name="control">Контрол, для которого необходимо получить Layout в виде массива байтов</param> /// <returns>Возвращает массив байтов</returns> public static byte[] GetLayoutData(this Control control) { ISupportXtraSerializer sxs = null; var gc = control as GridControl; if (gc != null) { sxs = gc.MainView; } else { var pv = control as PivotGridControl; if (pv != null) { sxs = pv; } else { var tl = control as TreeList; if (tl != null) { sxs = tl; } } } if (sxs == null) { return(null); } var stream = new MemoryStream(); sxs.SaveLayoutToStream(stream); return(stream.GetBuffer()); }
private void SaveLayout(State state, string name, ISupportXtraSerializer serializer) { using (var stream = new MemoryStream()) { serializer.SaveLayoutToStream(stream); stream.Position = 0; using (var reader = new StreamReader(stream)) { state[name] = reader.ReadToEnd(); } } }
private void RestoreLayout(State state, string name, ISupportXtraSerializer serializer) { using (var stream = new MemoryStream()) { var layout = (string)state[name]; if (string.IsNullOrEmpty(layout)) { return; } var writter = new StreamWriter(stream); writter.AutoFlush = true; writter.Write(layout); stream.Position = 0; serializer.RestoreLayoutFromStream(stream); } }
/// <summary> /// Применить настройку внешнего вида для объекта из таблицы настроек по умолчанию /// </summary> /// <param name="form">Форма на которой находится объект</param> /// <param name="name">Название объекта</param> /// <param name="control">Объект</param> public static void AcceptDefaultLayoutForControl(this Form form, string name, Control control) { ISupportXtraSerializer sxs = null; var gc = control as GridControl; if (gc != null) { sxs = gc.MainView; } else { var pv = control as PivotGridControl; if (pv != null) { sxs = pv; } else { var tl = control as TreeList; if (tl != null) { sxs = tl; } } } if (sxs == null) { return; } using (var db = new ApplicationEntitie(0)) { var tableName = form.Name + "." + name; var defLayout = db.DefaultLayouts.FirstOrDefault(dl => dl.TableName == tableName); if (defLayout == null) { MessageWindow.GetInstance("Для данной формы не найдено начальное состояние."); return; } sxs.RestoreLayoutSerializingFromStream(defLayout.Layout); } var tuner = control.GetControlTuner() as ILayoutTuner; if (tuner != null) { tuner.LoadPropertiesFromXml(control, FormControls.XmlDocumentFromStrinList(form.GetXmlSettings())); } }
/// <summary> /// Загрузить внешний вид объекта из массива байтов /// </summary> /// <param name="sxs">Объект для применения настроек</param> /// <param name="layout">Массив байтов</param> internal static void RestoreLayoutSerializingFromStream(this ISupportXtraSerializer sxs, byte[] layout) { if (sxs == null || layout == null || layout.Count() == 0) { return; } var stream = new MemoryStream(layout); try { sxs.RestoreLayoutFromStream(stream); } catch (Exception ex) { throw new Exception("Wrong data format", ex); } }
/// <summary> /// Загрузить внешний вид объекта из массива байтов /// </summary> /// <param name="control">Объект для применения настроек</param> /// <param name="layout">Массив байтов</param> public static void RestoreLayoutFromStream(this Control control, byte[] layout) { ISupportXtraSerializer sxs = null; var gc = control as GridControl; if (gc != null) { sxs = gc.MainView; } else { var pv = control as PivotGridControl; if (pv != null) { sxs = pv; } else { var tl = control as TreeList; if (tl != null) { sxs = tl; } } } if (sxs == null) { return; } if (layout == null || layout.Count() == 0) { return; } var stream = new MemoryStream(layout); try { sxs.RestoreLayoutFromStream(stream); } catch (Exception ex) { throw new Exception("Wrong data format", ex); } }
public void SaveLayout(ISupportXtraSerializer control, string regPath) { control.SaveLayoutToRegistry(regPath); }
public XtraSerializerAdapter(ISupportXtraSerializer serializer) { _serializer = serializer; }