Exemplo n.º 1
0
        private void SearchBtn_Click(object sender, RoutedEventArgs e)
        {
            //이전 데이터 제거
            searchTable.Children.RemoveRange(8, searchTable.Children.Count - 8);
            String sql;

            if (yearOption)
            {
                sql  = String.Format("SELECT * from (SELECT date, '일정' classify, calendar content FROM calendar WHERE calendar LIKE '%{0}%' UNION ", searchBox.Text);
                sql += String.Format("SELECT date, '보고공문' classify, report content FROM calendar WHERE report LIKE '%{0}%' UNION ", searchBox.Text);
                sql += String.Format("SELECT date, '복무' classify, service content FROM calendar WHERE service LIKE '%{0}%') WHERE date BETWEEN date('now', '-1 year') AND date('now', '+1 year')", searchBox.Text);
            }
            else
            {
                sql  = String.Format("SELECT date, '일정' classify, calendar content FROM calendar WHERE calendar LIKE '%{0}%' UNION ", searchBox.Text);
                sql += String.Format("SELECT date, '보고공문' classify, report content FROM calendar WHERE report LIKE '%{0}%' UNION ", searchBox.Text);
                sql += String.Format("SELECT date, '복무' classify, service content FROM calendar WHERE service LIKE '%{0}%'", searchBox.Text);
            }


            var conn = new SQLiteConnection(App.filePath);

            conn.Open();
            SQLiteCommand    cmd = new SQLiteCommand(sql, conn);
            SQLiteDataReader rdr = cmd.ExecuteReader();

            //검색 결과 수 만큼 행 생성

            int rowCount = 1;

            while (rdr.Read())
            {
                RowDefinition gridRow = new RowDefinition();
                //gridRow.Height = new GridLength(50);
                searchTable.RowDefinitions.Add(gridRow);

                //경계 선 만들기
                Border border1 = new Border();
                Grid.SetRow(border1, rowCount);
                Grid.SetColumn(border1, 0);
                border1.BorderThickness = new Thickness(1, 0, 0, 1);
                border1.Background      = Brushes.Transparent;
                border1.BorderBrush     = Brushes.Black;
                searchTable.Children.Add(border1);

                Border border2 = new Border();
                Grid.SetRow(border2, rowCount);
                Grid.SetColumn(border2, 1);
                border2.BorderThickness = new Thickness(1, 0, 0, 1);
                border2.Background      = Brushes.Transparent;
                border2.BorderBrush     = Brushes.Black;
                searchTable.Children.Add(border2);

                Border border3 = new Border();
                Grid.SetRow(border3, rowCount);
                Grid.SetColumn(border3, 2);
                border3.BorderThickness = new Thickness(1, 0, 0, 1);
                border3.Background      = Brushes.Transparent;
                border3.BorderBrush     = Brushes.Black;
                searchTable.Children.Add(border3);

                Border border4 = new Border();
                Grid.SetRow(border4, rowCount);
                Grid.SetColumn(border4, 3);
                border4.BorderThickness = new Thickness(1, 0, 1, 1);
                border4.Background      = Brushes.Transparent;
                border4.BorderBrush     = Brushes.Black;
                searchTable.Children.Add(border4);

                //텍스트 만들기

                TextBlock dateText     = new TextBlock();
                DateTime  tempDateTime = Convert.ToDateTime(rdr["date"].ToString());
                dateText.Text              = tempDateTime.ToString("yyyy-MM-dd (ddd)");
                dateText.Padding           = new Thickness(5);
                dateText.TextAlignment     = TextAlignment.Center;
                dateText.VerticalAlignment = VerticalAlignment.Center;
                Grid.SetRow(dateText, rowCount);
                Grid.SetColumn(dateText, 0);

                TextBlock classText = new TextBlock();
                classText.Text              = rdr["classify"].ToString();
                classText.Padding           = new Thickness(5);
                classText.TextAlignment     = TextAlignment.Center;
                classText.VerticalAlignment = VerticalAlignment.Center;
                Grid.SetRow(classText, rowCount);
                Grid.SetColumn(classText, 1);

                TextBlock CoincideText = new TextBlock();
                CoincideText.Text         = rdr["content"].ToString();
                CoincideText.Padding      = new Thickness(5);
                CoincideText.TextWrapping = TextWrapping.Wrap;
                CoincideText.TextTrimming = TextTrimming.CharacterEllipsis;
                Grid.SetRow(CoincideText, rowCount);
                Grid.SetColumn(CoincideText, 2);

                Button linkBtn = new Button();

                ////리소스에서 이미지 가져오기
                //System.Drawing.Bitmap image = Properties.Resources._2268137;
                //MemoryStream imgStream = new MemoryStream();
                //image.Save(imgStream, System.Drawing.Imaging.ImageFormat.Bmp);
                //imgStream.Seek(0, SeekOrigin.Begin);
                //BitmapFrame newimg = BitmapFrame.Create(imgStream);
                var converter = new System.Windows.Media.BrushConverter();
                var brush     = (Brush)converter.ConvertFromString("#673AB7");

                linkBtn.Content = new PackIcon {
                    Kind = PackIconKind.Launch, Foreground = brush, Background = System.Windows.Media.Brushes.Transparent
                };
                linkBtn.HorizontalAlignment = HorizontalAlignment.Center;
                linkBtn.VerticalAlignment   = VerticalAlignment.Center;
                linkBtn.Background          = System.Windows.Media.Brushes.Transparent;
                linkBtn.BorderThickness     = new Thickness(0);

                linkBtn.Click += (object eventSender, RoutedEventArgs eventArgs) =>
                {
                    int         index    = 0;
                    CultureInfo provider = CultureInfo.InvariantCulture;
                    DateTime    dtDate   = tempDateTime;
                    _window.calendar.SelectedDate = dtDate;
                    _window.calendar.DisplayDate  = dtDate;
                    switch (classText.Text)
                    {
                    case "일정":
                        index = 0;
                        break;

                    case "보고공문":
                        index = 1;
                        break;

                    case "복무":
                        index = 2;
                        break;
                    }
                    _window.ComboBox.SelectedIndex = index;
                };
                Grid.SetRow(linkBtn, rowCount);
                Grid.SetColumn(linkBtn, 3);


                searchTable.Children.Add(dateText);
                searchTable.Children.Add(CoincideText);
                searchTable.Children.Add(classText);
                searchTable.Children.Add(linkBtn);

                rowCount++;
            }

            rdr.Close();
            conn.Close();
        }
Exemplo n.º 2
0
        // creates the BOTTOM grid and adds buttons
        private void CreateGrid()
        {
            NewGame();
            bombsLeft.Text = MyVariables.mine.ToString();

            //clear everything to start anew
            tablero.RowDefinitions.Clear();
            tablero.ColumnDefinitions.Clear();


            //this creates the grid's rows and columns
            for (int i = 0; i < gridy.theGrid.GetLength(0); i++)
            {
                RowDefinition row = new RowDefinition();
                row.MinHeight = 25;
                tablero.RowDefinitions.Add(row);
            }

            for (int j = 0; j < gridy.theGrid.GetLength(1); j++)
            {
                ColumnDefinition col = new ColumnDefinition();
                col.MinWidth = 25;
                tablero.ColumnDefinitions.Add(col);
            }

            //colors
            SolidColorBrush color  = new SolidColorBrush(Colors.LightSeaGreen);
            SolidColorBrush color2 = new SolidColorBrush(Colors.MediumAquamarine);


            // create all the children
            for (int i = 0; i < gridy.theGrid.GetLength(0); i++)
            {
                for (int j = 0; j < gridy.theGrid.GetLength(1); j++)
                {
                    //textblock - background
                    TextBlock block = new TextBlock();
                    block.Text       = gridy.theGrid[i, j].Mine.ToString();
                    block.FontWeight = FontWeights.UltraBold;

                    //make the grid display a bomb when the array value is 9, else just the numbers of different colors
                    if (gridy.theGrid[i, j].Mine == 9)
                    {
                        string bomb = "💣";
                        block.Text = bomb;
                    }
                    else if (gridy.theGrid[i, j].Mine == 0)
                    {
                        block.Text = " ";
                    }
                    else if (gridy.theGrid[i, j].Mine == 1)
                    {
                        block.Foreground = Brushes.Green;
                    }
                    else if (gridy.theGrid[i, j].Mine == 2)
                    {
                        block.Foreground = Brushes.Orange;
                    }
                    else if (gridy.theGrid[i, j].Mine == 3)
                    {
                        block.Foreground = Brushes.DarkOrange;
                    }
                    else if (gridy.theGrid[i, j].Mine == 4)
                    {
                        block.Foreground = Brushes.Red;
                    }
                    else if (gridy.theGrid[i, j].Mine == 5)
                    {
                        block.Foreground = Brushes.Tomato;
                    }
                    else if (gridy.theGrid[i, j].Mine == 6)
                    {
                        block.Foreground = Brushes.DeepPink;
                    }
                    else if (gridy.theGrid[i, j].Mine == 7)
                    {
                        block.Foreground = Brushes.Navy;
                    }
                    else if (gridy.theGrid[i, j].Mine == 8)
                    {
                        block.Foreground = Brushes.DarkGray;
                    }

                    block.Background          = color2;
                    block.TextAlignment       = TextAlignment.Center;
                    block.VerticalAlignment   = VerticalAlignment.Bottom;
                    block.Width               = 23;
                    block.Height              = 23;
                    block.Padding             = new Thickness(0, 5, 0, 0);
                    block.VerticalAlignment   = VerticalAlignment.Center;
                    block.HorizontalAlignment = HorizontalAlignment.Center;
                    block.Name = "b" + i + "_" + j;



                    //boton - top--------------------------------------------

                    Button boton = new Button();

                    boton.Content               = " "; //remove later
                    boton.Background            = color;
                    boton.Width                 = 25;
                    boton.Height                = 25;
                    boton.VerticalAlignment     = VerticalAlignment.Center;
                    boton.HorizontalAlignment   = HorizontalAlignment.Center;
                    boton.Click                += new RoutedEventHandler(Button_Click);
                    boton.MouseRightButtonDown += new MouseButtonEventHandler(Button_rightclick); //right click event

                    //to find the button later on
                    //   boton.Name = "boton" + i + "_" + j;
                    boton.Tag = i + "_" + j; //since I can't RegisterName...

                    //locate and add the block
                    Grid.SetRow(block, i);
                    Grid.SetColumn(block, j);


                    //locate and add the button
                    Grid.SetRow(boton, i);
                    Grid.SetColumn(boton, j);


                    tablero.Children.Add(block);
                    tablero.Children.Add(boton);



                    //put the tablero at the bottom
                    Grid.SetZIndex(tablero, 0);
                }
            }
        }
 private static void AddComponent(Grid grid, int row, int col, FrameworkElement control)
 {
     grid.Children.Add(control);
     Grid.SetRow(control, row);
     Grid.SetColumn(control, col);
 }