Exemplo n.º 1
0
 private void SaveTemplate()
 {
     if (base.InvokeRequired)
     {
         base.Invoke(new MethodInvoker(this.SaveTemplate));
     }
     else
     {
         try
         {
             string text = string.Empty;
             string text2 = string.Empty;
             string name = TemplateManager.Instance.CurrentActiveTemplateView.Name;
             TemplateView.ContentState templateState = TemplateManager.Instance.GetTemplateState(TemplateManager.Instance.CurrentActiveTemplateView.Name);
             text = TemplateManager.Instance.CurrentActiveTemplateView.Name;
             text2 = ApplicationInfo.GetTemplatePathByUser();
             if (!string.IsNullOrEmpty(text))
             {
                 Form activeMdiChild = base.ActiveMdiChild;
                 string str = text + ".xml";
                 TemplateDS templateDS = new TemplateDS();
                 Dictionary<string, object> templateProperties = TemplateManager.Instance.GetTemplateProperties(text);
                 if (templateProperties != null)
                 {
                     TemplateDS.TemplatePropertyRow templatePropertyRow = templateDS.TemplateProperty.NewTemplatePropertyRow();
                     templatePropertyRow.PropertyName = "Name";
                     templatePropertyRow.PropertyValue = text;
                     templateDS.TemplateProperty.AddTemplatePropertyRow(templatePropertyRow);
                     foreach (KeyValuePair<string, object> current in templateProperties)
                     {
                         if (current.Key != "Name")
                         {
                             templatePropertyRow = templateDS.TemplateProperty.NewTemplatePropertyRow();
                             templatePropertyRow.PropertyName = current.Key;
                             templatePropertyRow.PropertyValue = current.Value.ToString();
                             templateDS.TemplateProperty.AddTemplatePropertyRow(templatePropertyRow);
                         }
                     }
                     List<Dictionary<string, object>> allFormProperties = TemplateManager.Instance.GetAllFormProperties(text);
                     if (allFormProperties != null && allFormProperties.Count > 0)
                     {
                         int num = 0;
                         foreach (Dictionary<string, object> current2 in allFormProperties)
                         {
                             num++;
                             if (current2 != null)
                             {
                                 TemplateDS.FormInfoRow formInfoRow = templateDS.FormInfo.NewFormInfoRow();
                                 formInfoRow.FormID = num;
                                 foreach (KeyValuePair<string, object> current3 in current2)
                                 {
                                     if (current3.Key == "Type")
                                     {
                                         formInfoRow.Type = current3.Value.ToString();
                                     }
                                     else if (current3.Key == "Name")
                                     {
                                         formInfoRow.Name = current3.Value.ToString();
                                     }
                                     else
                                     {
                                         TemplateDS.FormPropertyRow formPropertyRow = templateDS.FormProperty.NewFormPropertyRow();
                                         formPropertyRow.FormID = num;
                                         formPropertyRow.PropertyName = current3.Key;
                                         if (current3.Key == "Font")
                                         {
                                             Font font = (Font)current3.Value;
                                             formPropertyRow.PropertyValue = string.Format("{0}|{1}|{2}", font.Name, font.Size, (int)font.Style);
                                         }
                                         else
                                         {
                                             formPropertyRow.PropertyValue = current3.Value.ToString();
                                         }
                                         templateDS.FormProperty.AddFormPropertyRow(formPropertyRow);
                                     }
                                 }
                                 templateDS.FormInfo.AddFormInfoRow(formInfoRow);
                                 if (current2.ContainsKey("Name"))
                                 {
                                     Dictionary<string, object> formPropertyFields = TemplateManager.Instance.GetFormPropertyFields(text, current2["Name"].ToString());
                                     if (formPropertyFields != null)
                                     {
                                         foreach (KeyValuePair<string, object> current4 in formPropertyFields)
                                         {
                                             TemplateDS.FormRememberFieldRow formRememberFieldRow = templateDS.FormRememberField.NewFormRememberFieldRow();
                                             formRememberFieldRow.FormID = num;
                                             formRememberFieldRow.FieldName = current4.Key;
                                             formRememberFieldRow.FieldValue = current4.Value.ToString();
                                             templateDS.FormRememberField.AddFormRememberFieldRow(formRememberFieldRow);
                                         }
                                     }
                                 }
                             }
                         }
                         try
                         {
                             if (!Directory.Exists(text2))
                             {
                                 Directory.CreateDirectory(text2);
                             }
                             templateDS.WriteXml(text2 + "\\" + str);
                         }
                         catch (Exception ex)
                         {
                             this.ShowError("SaveTemplate", ex);
                             return;
                         }
                     }
                 }
             }
             text = null;
             text2 = null;
         }
         catch (Exception ex)
         {
             this.ShowError("SaveTemplate", ex);
         }
     }
 }