private void Open() { try { int id = SelectedId; if (id != 0) { ConfigRecord configRecord = null; using (GmConnection conn = App.CreateConnection()) { configRecord = ConfigRecord.GetConfigRecord(conn, id); } if (configRecord != null) { ConfigForm form = new ConfigForm(configRecord, true); if (form.ShowDialog() == DialogResult.OK) { // UpdateRow(SelectedRow,form); } } } } catch (Exception ex) { Log.Exception(ex); } }
private void btnExportToXML_Click(object sender, EventArgs e) { try { int id = SelectedId; if (id != 0) { dlgSaveFile.FileName = string.Format("HosDepConfig{0}.xml", id); if (dlgSaveFile.ShowDialog() == DialogResult.OK) { using (WaitCursor wc = new WaitCursor()) { ConfigRecord configRecord = null; using (GmConnection conn = App.CreateConnection()) { configRecord = ConfigRecord.GetConfigRecord(conn, id); } if (configRecord != null) { configRecord.config.Serialize(dlgSaveFile.FileName); } } } } } catch (Exception ex) { Log.Exception(ex); } }
// Close // // Close the object. This does not mean it can not be used anymore, // it just means that the cleanup as been done, so we don't have // to worry about closing it anymore // void Close() { // Only close if we are propertly initialized if (_flags[FInited]) { // Only close if we haven't already closed if (_flags.ChangeValue(FClosed, true)) { // Remove the config record if we own it // N.B. ConfigRecord.Remove is safe to call more than once. if (_flags[FOwnsConfigRecord]) { ConfigRecord.Remove(); } } } }
public ConfigForm(ConfigRecord configRecord, bool readOnly) { InitializeComponent(); this.readOnly = readOnly; this.configRecord = configRecord; config = (Config)configRecord.config.Clone(); ucReports.Init(config); ucGuiConfig.Init(config); ucHandbookGroups.Init(config); ucDepartmentConfig.Init(config); ucConfigRecord.Init(configRecord, readOnly); FormUtils.Init(this); if (readOnly) { btnSave.Text = "Закрыть"; btnCancel.Visible = !readOnly; } }
/* private void UpdateRow(DataRow dr, ConfigRecordForm form) * { * ConfigRecord configRecord = form.ConfigRecord; * dr["Id"] = configRecord.Id; * dr["Number"] = configRecord.number; * dr["NumberOfBeds"] = configRecord.numberOfBeds; * dr["ConfigRecordTypeName"] = form.ConfigRecordTypeName; * }*/ private void btnRestore_Click(object sender, EventArgs e) { try { if (maxId == App.ConfigRecord.Id) { int selId = SelectedId; // btnRestore.Enabled = selId > 0 && selId < maxId; string s = string.Format("Вы уверены, что хотите восстановить конфигурацию {0} и отменить конфигурацию {1}?", selId, maxId); if (MessageBoxUtils.Ask(s)) { using (WaitCursor wc = new WaitCursor()) { ConfigRecord configRecord = null; using (GmConnection conn = App.CreateConnection()) { configRecord = ConfigRecord.GetConfigRecord(conn, selId); } ConfigUpdate.CheckUpdate(configRecord.config); App.Instance.SetConfig(configRecord.config, "Конфигурация восстановлена.", configRecord.Id); LoadData(); UpdateControls(); } MessageBox.Show("Конфигурация успешно восстановлена."); } } else { MessageBox.Show("В базе данных обнаружена новая конфигурация. Для восстановления старой конфигурации перезапустите программу."); } } catch (Exception ex) { Log.Exception(ex); } }
public Constituency ReadConstituencyDataFromFile(ConfigRecord configRecord) { // Use helper class to get a known Newcastle North.xml instance return(Helper_KnownConstituencyDataRepository.GetKnownNewcastleN()); }
/// <summary> /// 更新配置 /// </summary> /// <param name="record"></param> public void Update(ConfigRecord record) { DataBase.Update(record); }
private void Synchronize(Type type) { var properties = type .GetProperties(BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty) .Where(p => p.CanRead && p.CanWrite); var now = DateTime.Now; var notExistNames = properties.Select(e => e.Name).ToList(); var notExists = DataBase.GetList <ConfigRecord>(e => !notExistNames.Contains(e.Name)); notExists.ForEach(item => DataBase.Delete(item)); foreach (var property in properties) { var exist = Query(new ConfigRecordQuery() { Catalog = type.FullName, Name = property.Name, PageIndex = int.MaxValue }); if (exist.Count > 0) { } else { var record = new ConfigRecord() { Catalog = type.FullName, Name = property.Name, CreatedAt = now, Description = property.Name, FriendlyName = property.Name, LastModifiedAt = now, Value = "", }; var defaultAttr = property.GetCustomAttribute <DefaultValueAttribute>(); if (defaultAttr != null) { record.Value = defaultAttr.Value.ToString(); } else { switch (Type.GetTypeCode(type)) { case TypeCode.DateTime: record.Value = DateTime.Now.ToString(CultureInfo.InvariantCulture); break; case TypeCode.Boolean: record.Value = "true"; break; case TypeCode.Decimal: case TypeCode.Int32: case TypeCode.Int64: record.Value = "0"; break; case TypeCode.String: record.Value = string.Empty; break; default: record.Value = string.Empty; break; } } var description = property.GetCustomAttribute <DescriptionAttribute>(); if (description != null) { record.FriendlyName = description.Description; record.Description = description.Description; } var configTypeCode = property.GetCustomAttribute <ConfigTypeCodeAttribute>(); if (configTypeCode != null) { record.ValueTypeCode = configTypeCode.TypeCode; } else { switch (Type.GetTypeCode(type)) { case TypeCode.DateTime: record.ValueTypeCode = ConfigTypes.DateTime; break; case TypeCode.Boolean: record.ValueTypeCode = ConfigTypes.Text; break; case TypeCode.Decimal: record.ValueTypeCode = ConfigTypes.Number; break; case TypeCode.Int32: record.ValueTypeCode = ConfigTypes.Integer; break; case TypeCode.String: record.ValueTypeCode = ConfigTypes.Text; break; default: record.ValueTypeCode = ConfigTypes.Text; break; } } DataBase.Save(record); } } }
public void Init(ConfigRecord configRecord, bool readOnly) { this.configRecord = configRecord; this.readOnly = readOnly; }