Esempio n. 1
0
        //#endregion

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            bool unique = false;

            if (Oznakaenabled)
            {
                for (int i = 0; i < MainWindow.Typesc.Len( ); i++)
                {
                    if (Oznaka.Equals(MainWindow.Typesc.GetTypeAtI(i).oznaka) || Oznaka.Equals(""))
                    {
                        unique = true;//greska
                    }
                }
                for (int i = 0; i < MainWindow.Resources.Len( ); i++)
                {
                    if (Oznaka.Equals(MainWindow.Resources.GetResourceAtI(i).oznaka) || Oznaka.Equals(""))
                    {
                        unique = true;//greska
                    }
                }
                for (int i = 0; i < MainWindow.Tags.Len( ); i++)
                {
                    if (Oznaka.Equals(MainWindow.Tags.GetTagAtI(i).oznaka) || Oznaka.Equals(""))
                    {
                        unique = true;//greska
                    }
                }
                if (Oznaka.Equals(" ") || Opis.Equals("") || unique)
                {
                    var s = new messageBox.Window1("Popunite sva polja prema zahtevima");
                    s.ShowDialog( );
                    return;
                }
            }

            Tag t = new Tag(Oznaka, Opis, Boja.ToString());

            if (s.Equals("c"))
            {
                Tag tt = MainWindow.Tags.GetTagById(Oznaka);
                tt.boja = t.boja;
                tt.opis = t.opis;

                /*for (int i = 0; i < MainWindow.Tags.Len( ); i++) {
                 *  if (MainWindow.Tags.GetTagAtI(i).oznaka == t.oznaka) {
                 *      MainWindow.Tags.GetTagAtI(i).opis = t.opis;
                 *      MainWindow.Tags.GetTagAtI(i).boja = t.boja;
                 *      break;
                 *  }
                 * }*/
            }
            else
            {
                MainWindow.Tags.addTag(t);
            }
            MainWindow win = (MainWindow)Application.Current.MainWindow;

            //update mape

            /*if (win.canvas != null) {
             *  foreach (var v in win.canvas.Children) {
             *      if (v is Image) {
             *          Regex reg = new Regex(@"([a-zA-Z]+)(\d+)");
             *          Match result = reg.Match((v as Image).Name);
             *          string n = result.Groups[1].Value;
             *          Res r = MainWindow.Resources.GetResourceById(n);
             *          if (r != null) {
             *              ToolTip tool = MainWindow.makeTooltip(r);
             *              (v as Image).ToolTip = tool;
             *          }
             *      }
             *  }
             * }*/

            for (int i = 0; i < MainWindow.Tags.Len( ); i++)
            {
                win.Test1 += MainWindow.Tags.GetTagAtI(i).oznaka + " " + MainWindow.Tags.GetTagAtI(i).boja;
            }
            this.Close( );
        }
Esempio n. 2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            bool unique = false;

            if (Oznakaenabled)
            {
                for (int i = 0; i < MainWindow.Typesc.Len( ); i++)
                {
                    if (Oznaka.Equals(MainWindow.Typesc.GetTypeAtI(i).oznaka) || Oznaka.Equals(""))
                    {
                        unique = true;//greska
                    }
                }
                for (int i = 0; i < MainWindow.Resources.Len( ); i++)
                {
                    if (Oznaka.Equals(MainWindow.Resources.GetResourceAtI(i).oznaka) || Oznaka.Equals(""))
                    {
                        unique = true;//greska
                    }
                }
                for (int i = 0; i < MainWindow.Tags.Len( ); i++)
                {
                    if (Oznaka.Equals(MainWindow.Tags.GetTagAtI(i).oznaka) || Oznaka.Equals(""))
                    {
                        unique = true;//greska
                    }
                }
                if (Oznaka.Equals(" ") || Ime.Equals(" ") || Opis.Equals("") || unique)
                {
                    var s = new messageBox.Window1("Popunite sva polja prema zahtevima");
                    s.ShowDialog( );
                    return;
                }
            }
            Type       t   = new Type(Oznaka, Ime, Opis, Ikonica);
            MainWindow win = (MainWindow)Application.Current.MainWindow;

            /*for (int i = 0; i < MainWindow.Typesc.Len( ); i++) {
             *  win.Test1 += MainWindow.Typesc.GetTypeAtI(i).ime + " "+  MainWindow.Typesc.GetTypeAtI(i).ikonica;
             * }*/
            if (s.Equals("c"))
            {
                Type tt = MainWindow.Typesc.GetTypeById(Oznaka);
                tt.opis    = t.opis;
                tt.ime     = t.ime;
                tt.ikonica = t.ikonica;

                //menja sliku na dugnemu
                for (int i = 0; i < MainWindow.Resources.Len(); i++)
                {
                    if (MainWindow.Resources.GetResourceAtI(i).tip == tt.oznaka)
                    {
                        Res re = MainWindow.Resources.GetResourceAtI(i);
                        System.Windows.Controls.Image newImg = new Image( );
                        re.tipImg = tt.ikonica;
                        try {
                            newImg.Source = new BitmapImage(new Uri(uriString: @re.ikonica));
                        } catch {
                            try {
                                newImg.Source = new BitmapImage(new Uri(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, re.tipImg)));
                            } catch {
                                newImg.Source = new BitmapImage(new Uri(@"../../resources/image.png", UriKind.Relative));
                            }
                        }

                        foreach (Button b in win.ResourcePanel.Children)  //zasto ovo ne radi :O
                        {
                            String pom = (b.Name).Substring(1);
                            if (pom == re.oznaka)
                            {
                                b.Content = newImg;
                            }
                        }

                        if (win.canvas != null)
                        {
                            foreach (var v in win.canvas.Children)
                            {
                                if (v is Image)
                                {
                                    Regex  reg    = new Regex(@"([a-zA-Z]+)(\d+)");
                                    Match  result = reg.Match((v as Image).Name);
                                    string n      = result.Groups[1].Value;

                                    if (n.Equals(re.oznaka))
                                    {
                                        (v as Image).Source = newImg.Source;
                                        ToolTip tool = MainWindow.makeTooltip(re);
                                        (v as Image).ToolTip = tool;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                MainWindow.Typesc.addType(t);
            }
            this.Close( );
        }