예제 #1
0
 public void updateData(clsDesign designClass)
 {
     clearData();
     saveData(designClass);
 }
예제 #2
0
        public void saveData(clsDesign designClass)
        {
            clearData();
            XDocument xmlDocument = XDocument.Load(designXmlFilePath);

            XElement designRoot = xmlDocument.Descendants("Design")
                                  .Where(mi => mi.Attribute("id").Value == templateId)
                                  .FirstOrDefault();

            designRoot.Attribute("Description").Value = designClass.description;
            if (listViewBgClass.propBackground.ToString() == "#00FFFFFF")
            {
                designRoot.Add(new XElement("Background", "#FFFFFF"));
            }
            else
            {
                designRoot.Add(new XElement("Background", listViewBgClass.propBackground.ToString()));
            }
            foreach (clsControl cc in controlCollection)
            {
                designRoot.Add(new XElement("Control", new XAttribute("id", cc.id), new XAttribute("type", cc.type)));
            }

            XElement textblockRoot = xmlDocument.Descendants("TextBlocks").FirstOrDefault();

            foreach (clsTextblock ctb in textBlockCollection)
            {
                textblockRoot.Add(new XElement("TextBlock", new XAttribute("id", ctb.propId.ToString()),
                                               new XElement("Foreground", ctb.propForeground),
                                               new XElement("Text", ctb.propContent),
                                               new XElement("Margin", ctb.propMargin),
                                               new XElement("HorizontalAlignment", ctb.propAlignment),
                                               new XElement("FontFamily", ctb.propFontFamily),
                                               new XElement("FontSize", ctb.propFontSize.ToString())
                                               )
                                  );
            }

            XElement imageRoot = xmlDocument.Descendants("Images").FirstOrDefault();

            foreach (clsImage cI in imageCollection)
            {
                if (!File.Exists(cI.propImageLocation))
                {
                    imageRoot.Add(new XElement("Image", new XAttribute("id", cI.propId.ToString()),
                                               new XElement("ImageLocation", cI.propImageLocation),
                                               new XElement("ImageData", cI.propImageData),
                                               new XElement("Height", cI.propImageHeight),
                                               new XElement("Margin", cI.propMargin),
                                               new XElement("Width", cI.propImageWidth.ToString()),
                                               new XElement("HorizontalAlignment", cI.propAlignment)
                                               )
                                  );
                }
                else
                {
                    BitmapImage x         = new BitmapImage(new Uri(cI.propImageLocation));
                    byte[]      bits      = getJPGFromImageControl(x);
                    string      imgSource = Convert.ToBase64String(bits);
                    cI["propImageData"] = imgSource;
                    imageRoot.Add(new XElement("Image", new XAttribute("id", cI.propId.ToString()),
                                               new XElement("ImageLocation", cI.propImageLocation),
                                               new XElement("ImageData", cI.propImageData),
                                               new XElement("Height", cI.propImageHeight),
                                               new XElement("Margin", cI.propMargin),
                                               new XElement("Width", cI.propImageWidth.ToString()),
                                               new XElement("HorizontalAlignment", cI.propAlignment)
                                               )
                                  );
                }
            }

            XElement buttonRoot = xmlDocument.Descendants("Buttons").FirstOrDefault();

            foreach (clsButton cbtn in buttonCollection)
            {
                buttonRoot.Add(new XElement("Button", new XAttribute("id", cbtn.propId.ToString()),
                                            new XElement("Foreground", cbtn.propForeground),
                                            new XElement("Background", cbtn.propBtnBackground),
                                            new XElement("Content", cbtn.propContent),
                                            new XElement("Height", cbtn.propHeight.ToString()),
                                            new XElement("Margin", cbtn.propMargin.ToString()),
                                            new XElement("Width", cbtn.propWidth.ToString()),
                                            new XElement("HorizontalAlignment", cbtn.propAlignment.ToString()),
                                            new XElement("FontFamily", cbtn.propFontFamily),
                                            new XElement("FontSize", cbtn.propFontSize.ToString()),
                                            new XElement("Action",
                                                         new XElement("TableName", cbtn.propButtonAction == null ? "" : cbtn.propButtonAction.propTableName),
                                                         new XElement("ConnectionString", cbtn.propButtonAction == null ? "" : cbtn.propButtonAction.propConnectionString),
                                                         new XElement("Query", cbtn.propButtonAction == null ? "" : cbtn.propButtonAction.propQuery)
                                                         )
                                            )
                               );
            }

            XElement textBoxRoot = xmlDocument.Descendants("TextBoxes").FirstOrDefault();

            foreach (clsTextBox ctb in textBoxCollection)
            {
                textBoxRoot.Add(new XElement("TextBox", new XAttribute("id", ctb.propId.ToString()),
                                             new XElement("Name", ctb.propName),
                                             new XElement("DataType", ctb.propInputDataType),
                                             new XElement("Content", ctb.propContent),
                                             new XElement("Height", ctb.propHeight.ToString()),
                                             new XElement("Margin", ctb.propMargin.ToString()),
                                             new XElement("Width", ctb.propWidth.ToString()),
                                             new XElement("HorizontalAlignment", ctb.propAlignment.ToString())
                                             )
                                );
            }

            XElement comboboxRoot = xmlDocument.Descendants("ComboBoxes").FirstOrDefault();

            foreach (clsComboBox ccb in comboboxCollection)
            {
                string cbItemCollection = "";
                foreach (string item in ccb.propComboboxItem)
                {
                    cbItemCollection += item + ";";
                }
                comboboxRoot.Add(new XElement("ComboBox", new XAttribute("id", ccb.propId.ToString()),
                                              new XElement("Name", ccb.propName),
                                              new XElement("DataType", ccb.propInputType),
                                              new XElement("Height", ccb.propHeight.ToString()),
                                              new XElement("Margin", ccb.propMargin.ToString()),
                                              new XElement("ComboboxItem", cbItemCollection)
                                              )
                                 );
            }

            XElement datePickerRoot = xmlDocument.Descendants("DatePickers").FirstOrDefault();

            foreach (clsDatePicker cdp in datePickerCollection)
            {
                datePickerRoot.Add(new XElement("DatePicker", new XAttribute("id", cdp.propId.ToString()),
                                                new XElement("Name", cdp.propName),
                                                new XElement("DataType", cdp.propInputType),
                                                new XElement("Height", cdp.propHeight.ToString()),
                                                new XElement("Width", cdp.propWidth.ToString())
                                                )
                                   );
            }

            xmlDocument.Save(designXmlFilePath);
        }