コード例 #1
0
ファイル: ClassGridGroup.cs プロジェクト: SokolSib/FRANCE
        /*    public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
         *  {
         *      if (depObj != null)
         *      {
         *          for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
         *          {
         *              DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
         *              if (child != null && child is T)
         *              {
         *                  yield return (T)child;
         *              }
         *
         *              foreach (T childOfChild in FindVisualChildren<T>(child))
         *              {
         *                  yield return childOfChild;
         *              }
         *          }
         *      }
         *  }*/
        public void save(Button b)
        {
            W_GridPay ws = Window.GetWindow((Button)b) as W_GridPay;

            string x, y, Caption;//, Img;

            string Cr = "Default";

            string Cr_ = "Default";

            string[] dd = b.Name.ToString().Split('x');

            x = dd[0].Substring(2, dd[0].Length - 2);

            y = dd[1];

            Caption = b.Content.ToString();

            SolidColorBrush s  = b.Background as SolidColorBrush;
            SolidColorBrush s_ = b.Foreground as SolidColorBrush;

            if (s != null)
            {
                Cr = s.Color.A + "," + s.Color.R + "," + s.Color.G + "," + s.Color.B;
            }
            if (s_ != null)
            {
                Cr_ = s_.Color.A + "," + s_.Color.R + "," + s_.Color.G + "," + s_.Color.B;
            }

            string funcType = b.ToolTip == null ? "" : b.ToolTip.ToString();

            XDocument doc = null;

            if (b.Name.Substring(0, 1) == "e")
            {
                doc = XDocument.Load(path4);
            }
            if (b.Name.Substring(0, 1) == "c")
            {
                doc = XDocument.Load(path3);
            }
            if (b.Name.Substring(0, 1) == "a")
            {
                doc = XDocument.Load(path2);
            }
            if (b.Name.Substring(0, 1) == "b")
            {
                doc = XDocument.Load(path);
            }
            if (b.Name.Substring(0, 1) == "m")
            {
                doc     = XDocument.Load(System.AppDomain.CurrentDomain.BaseDirectory + @"\Data\" + ws.typesPay.Id + ".xml");
                Caption = ((Label)((StackPanel)b.Content).FindName("mlb_" + x + "x" + y)).Content.ToString();
            }
            XElement target;

            try
            {
                target = doc.Elements("Grid").Elements("rec")
                         .Where(e => (e.Element("X").Value == x) & (e.Element("Y").Value == y))
                         .Single();
            }

            catch
            {
                target = null;
            }

            if (target != null)
            {
                XNode[] d = target.Nodes().ToArray();

                XElement id_ = (d[0] as XElement);

                XElement Date_upd_ = (d[1] as XElement);

                XElement X_ = (d[2] as XElement);

                XElement Y_ = (d[3] as XElement);

                XElement Caption_ = (d[4] as XElement);

                XElement Color_ = (d[5] as XElement);

                XElement Color__ = (d[6] as XElement);

                XElement Img_ = (d[7] as XElement);

                XElement Fun_ = (d[8] as XElement);

                Date_upd_.Value = DateTime.Now.ToString();

                Caption_.Value = Caption;

                Color_.Value = Cr;

                Color__.Value = Cr_;

                Fun_.Value = funcType;
                if (Cr == "Default")
                {
                    target.Remove();
                }
                if (Cr_ == "Default")
                {
                    target.Remove();
                }
            }

            else
            {
                if (Cr != "Default")
                {
                    doc.Element("Grid").Add(
                        new XElement("rec",
                                     new XElement("id", (int.Parse(x) * int.Parse(y)).ToString()),
                                     new XElement("Date_upd", DateTime.Now.ToString()),
                                     new XElement("X", x),
                                     new XElement("Y", y),
                                     new XElement("Caption", Caption),
                                     new XElement("Color", Cr),
                                     new XElement("foreground", Cr_),
                                     new XElement("Img", ""),
                                     new XElement("Fun", funcType)
                                     )
                        );
                }
            }



            switch (b.Name.Substring(0, 1))
            {
            case "m":
                doc.Save(System.AppDomain.CurrentDomain.BaseDirectory + @"Data\" + ws.typesPay.Id + ".xml");
                ClassXMLDB.saveDB(System.AppDomain.CurrentDomain.BaseDirectory + @"Data\" + ws.typesPay.Id + ".xml", doc);
                break;

            case "c":
                doc.Save(path3);
                ClassXMLDB.saveDB(path3, doc);
                break;

            case "a":
                doc.Save(path2);
                ClassXMLDB.saveDB(path2, doc);
                break;

            case "b":
                doc.Save(path);
                ClassXMLDB.saveDB(path, doc);
                break;

            case "e":
                doc.Save(path4);
                ClassXMLDB.saveDB(path4, doc);
                break;
            }
        }
コード例 #2
0
ファイル: ClassGridProduct.cs プロジェクト: SokolSib/FRANCE
        public void save(elm el, int X, int Y)
        {
            grid[X, Y, Convert.ToInt16(el.x), Convert.ToInt16(el.y)] = el;

            SolidColorBrush solid  = (el.background as SolidColorBrush);
            SolidColorBrush solid2 = (el.font as SolidColorBrush);

            string colorText = solid != null ? solid.Color.R + "," + solid.Color.G + "," + solid.Color.B : "255,0,0";

            string colorFontText = solid2 != null ? solid2.Color.R + "," + solid2.Color.G + "," + solid2.Color.B : "255,0,0";

            var doc = XDocument.Load(path);

            XElement target;

            try
            {
                target = doc.Elements("GridProduct").Elements("_" + X + "x" + Y).Elements("rec")
                         .Where(e => (e.Element("X").Value == el.x.ToString()) & (e.Element("Y").Value == el.y.ToString()))
                         .SingleOrDefault();
            }

            catch
            {
                target = null;
            }

            if (target != null)
            {
                XNode[]  d            = target.Nodes().ToArray();
                XElement id_          = (d[0] as XElement);
                XElement Date_upd_    = (d[1] as XElement);
                XElement X_           = (d[2] as XElement);
                XElement Y_           = (d[3] as XElement);
                XElement Description_ = (d[4] as XElement);
                XElement background_  = (d[5] as XElement);
                XElement img_         = (d[6] as XElement);
                XElement font_        = (d[7] as XElement);

                XElement customerId_;
                if (d.Length > 8)
                {
                    customerId_       = (d[8] as XElement);
                    customerId_.Value = el.customerId.ToString();
                }
                else
                {
                    target.Add(new XElement("customerId", el.customerId));
                }
                Date_upd_.Value = DateTime.Now.ToString();

                Description_.Value = el.Description;
                background_.Value  = colorText;
                // img_.Value = el.img;
                font_.Value = colorFontText;
            }

            else
            {
                XElement e = doc.Element("GridProduct").Element("_" + X + "x" + Y);

                if (e != null)
                {
                    e.Add(
                        new XElement("rec",
                                     new XElement("id", (el.x * el.y).ToString()),
                                     new XElement("Date_upd", DateTime.Now.ToString()),
                                     new XElement("X", el.x),
                                     new XElement("Y", el.y),
                                     new XElement("Description", el.Description),

                                     new XElement("background", colorText),
                                     new XElement("img", el.img),
                                     new XElement("font", el.font),
                                     new XElement("customerId", el.customerId)
                                     ))
                    ;
                }
                else
                {
                    doc.Element("GridProduct").Add(
                        new XElement("_" + X + "x" + Y,
                                     new XElement("rec",
                                                  new XElement("id", (el.x * el.y).ToString()),
                                                  new XElement("Date_upd", DateTime.Now.ToString()),
                                                  new XElement("X", el.x),
                                                  new XElement("Y", el.y),
                                                  new XElement("Description", el.Description),
                                                  new XElement("background", colorText),
                                                  new XElement("img", el.img),
                                                  new XElement("font", el.font),
                                                  new XElement("customerId", el.customerId)
                                                  )
                                     )
                        );
                }
            }
            doc.Save(path);

            ClassXMLDB.saveDB(path, doc);
        }