Esempio n. 1
0
        public async Task <string> UpdateEntryAsync(EditArticle form)
        {
            var article = await _entryRepository
                          .FindBy(e => e.Id == form.Id)
                          .Include(e => e.EntryToTopics)
                          .FirstOrDefaultAsync();

            var tracker = new EditTracker <Entry>();

            if (article == default)
            {
                throw new AppException(ExceptionType.ARTICLE_NOT_FOUND);
            }

            try
            {
                article.LastModified = DateTime.Now;
                tracker.Track(e => e.LastModified);

                if (article.HeadLine != form.HeadLine)
                {
                    article.HeadLine = form.HeadLine;
                    article.Slug     = GenerateSlug(form.HeadLine);
                    tracker.Track(e => e.HeadLine);
                    tracker.Track(e => e.Slug);
                }

                if (article.Paragraph != form.Paragraph)
                {
                    article.Paragraph = form.Paragraph;
                    tracker.Track(e => e.Paragraph);
                }

                if (article.Url != form.Url)
                {
                    article.Url = form.Url;
                    tracker.Track(e => e.Url);
                }

                if (article.Body != form.Body)
                {
                    article.Body = form.Body;
                    tracker.Track(e => e.Body);
                }

                if (form.Img != null)
                {
                    article.Img = _imageProcessingService.ProcessFormImage(form.Img);
                    tracker.Track(e => e.Img);
                }

                if (form.Caption != null)
                {
                    article.Caption = form.Caption;
                    tracker.Track(e => e.Caption);
                }

                _entryRepository.Update(article, tracker);
                await _unitOfWork.Commit();
            }
            catch (Exception ex)
            {
                throw new AppException(ExceptionType.ARTICLE_UPDATE_FAILED, ex);
            }

            var topicId = article.EntryToTopics.FirstOrDefault(et => et.IsPrimary)?.TopicId;

            if (topicId == default)
            {
                var existing = await _entryToTopicRepository
                               .FindByKey(article.Id, form.PrimaryTopic.Value);

                if (existing != null)
                {
                    existing.IsPrimary = true;
                    _entryToTopicRepository.Update(existing, e => e.IsPrimary);
                }
                else
                {
                    // what happens if article doesn't have a primary topic
                    // get the form primary topic and set it
                    var primaryTopic = new EntryToTopic()
                    {
                        EntryId   = article.Id,
                        TopicId   = form.PrimaryTopic.Value,
                        IsPrimary = true
                    };

                    await _entryToTopicRepository.Create(primaryTopic);
                }

                await _unitOfWork.Commit();
            }
            else if (topicId.Value != form.PrimaryTopic.Value)
            {
                using (IDbContextTransaction transaction = await _unitOfWork.BeginTransaction())
                {
                    try
                    {
                        // set new topic as primary
                        var primaryTopic = await _entryToTopicRepository
                                           .FindBy(et => et.EntryId == article.Id && et.TopicId == topicId)
                                           .FirstOrDefaultAsync();

                        primaryTopic.IsPrimary = false;

                        _entryToTopicRepository.Update(primaryTopic, e => e.IsPrimary);

                        // does this article already have this topic ?
                        var newPrimaryTopic = await _entryToTopicRepository
                                              .FindByKey(article.Id, form.PrimaryTopic.Value);

                        if (newPrimaryTopic == default)
                        {
                            await _entryToTopicRepository.Create(new EntryToTopic()
                            {
                                EntryId   = article.Id,
                                TopicId   = form.PrimaryTopic.Value,
                                IsPrimary = true
                            });
                        }
                        else
                        {
                            newPrimaryTopic.IsPrimary = true;
                            _entryToTopicRepository.Update(newPrimaryTopic, e => e.IsPrimary);
                        }

                        await _unitOfWork.Commit();

                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                    }
                }
            }

            return(article.Slug);
        }
Esempio n. 2
0
 // Use this for initialization
 void Start()
 {
     editTracker   = EditTracker.Instance;
     transformTool = TransformTool.Instance;
 }
        public Reports()
        {
            this.InitializeComponent();

            //start displaying the items records
            Query q = new Query();

            //show according to what is needed

            if (this.chosen_test == "")
            {
                q.Get("reports");
            }
            else
            {
                q.Get("reports", "Where test_id = '" + this.chosen_test + "'");
            }
            q.Records();
            int reports_row = q.CountRows();
            //get the exact location of the _added_by column, so we count from behind, cause we know the position from the back.
            int reports_cols = q.CountFields() - 1;
            int adder_col    = 0;

            //int v = 0;

            for (int w = reports_cols, pos = 0; w >= 0; w--, pos++)
            {
                if (pos == 2)
                {//it's the _added_by col
                    adder_col = w;
                }
                if (pos > 2)
                {
                    break;
                }
            }
            bool check_records = q.CheckRecords();

            int i = 0;

            if (check_records == true)
            {
                //create 2 parts, one that shows the test to select

                Grid          main_g        = new Grid();
                RowDefinition rd            = new RowDefinition();
                StackPanel    main_p        = new StackPanel();
                Border        side_p_border = new Border();

                StackPanel side_p = new StackPanel();
                Border     side_p_inner_border = new Border();
                side_p_inner_border.BorderBrush         = new SolidColorBrush(Color.FromArgb(50, 0, 0, 0));
                side_p_inner_border.BorderThickness     = new Thickness(1);
                side_p_inner_border.HorizontalAlignment = HorizontalAlignment.Stretch;
                side_p_inner_border.Margin = new Thickness(0, 0, 0, 4.0);
                StackPanel side_p_head = new StackPanel();
                side_p_head.Background = new SolidColorBrush(Color.FromArgb(255, 250, 251, 251));
                TextBlock side_p_head_txt = new TextBlock();
                side_p_head_txt.Text     = "Tests";
                side_p_head_txt.FontSize = 23;
                side_p_head_txt.Padding  = new Thickness(10, 9, 5, 5);

                side_p_head_txt.Foreground = new SolidColorBrush(Color.FromArgb(255, 40, 40, 40));

                //design
                main_p.Margin = new Thickness(10, 7, 25, 5);

                side_p_border.BorderBrush = new SolidColorBrush(Color.FromArgb(50, 0, 0, 0));
                //side_p_border.BorderThickness = new Thickness(1);
                // side_p_border.Background = theme_color;
                // side_p_border.CornerRadius = new CornerRadius(3);
                side_p_border.Margin = new Thickness(5, 10, 5, 1);
                side_p_border.HorizontalAlignment = HorizontalAlignment.Right;
                ///////////////////////////////

                for (int j = 0; j < 2; j++)
                {//create 2 columns
                    ColumnDefinition cd = new ColumnDefinition();
                    if (j == 1)
                    {
                        cd.Width = new GridLength(250);
                    }
                    else
                    {
                        cd.Width = new GridLength(600);
                    }
                    main_g.ColumnDefinitions.Add(cd);
                }

                Grid.SetColumn(main_p, 0);
                Grid.SetRow(main_p, 0);

                //for the side menu.
                Grid.SetColumn(side_p_border, 1);
                Grid.SetRow(side_p_border, 0);
                main_g.RowDefinitions.Add(rd);
                //
                side_p_head.Children.Add(side_p_head_txt);
                side_p_inner_border.Child = side_p_head;
                side_p.Children.Add(side_p_inner_border);
                side_p_border.Child = side_p;

                main_g.Children.Add(side_p_border);

                main_g.Children.Add(main_p);
                reports_r.Children.Add(main_g);

                //design the side bar that shows the list of tests that have reports
                Query s_t = new Query();

                s_t.GetExtra("Select test_id,test_name from tests");
                s_t.Records();
                int counter = s_t.CountRows();
                //get the number of tests that have reports
                Query single = new Query();
                single.GetExtra("Select report_name,test_id FROM reports");
                int single_count = single.CountRows();
                single.Records();
                string test_checker = single.Results[0, 1];
                for (int m = 0; m < single_count; m++)
                {
                    //check if the test isn't deleted already
                    Query g = new Query();
                    g.GetExtra("SELECT test_id FROM tests WHERE test_id = '" + single.Results[m, 1] + "'");
                    if (g.CheckRecords() == true)
                    {
                        //check if they belong to more than one report
                        if (test_checker != single.Results[m, 1])
                        {//there's another test, so it's more than one
                            //lets show all
                            Button a_btn = new Button();
                            a_btn.Content             = "All";
                            a_btn.BorderBrush         = new SolidColorBrush(Color.FromArgb(23, 255, 255, 255));
                            a_btn.BorderThickness     = new Thickness(1, 1, 1, 1);
                            a_btn.HorizontalAlignment = HorizontalAlignment.Stretch;
                            a_btn.Background          = theme_color;
                            a_btn.Padding             = new Thickness(15, 20, 15, 5);
                            a_btn.BorderBrush         = new SolidColorBrush(Color.FromArgb(70, 0, 0, 0));
                            a_btn.Margin = new Thickness(-3, -10, -3, 1);
                            if (this.chosen_test == "")
                            {
                                //its all that was chosen, change the color
                                a_btn.Background = selected_color;
                                a_btn.Foreground = new SolidColorBrush(Colors.White);
                            }
                            a_btn.Click += (s, e) =>
                            {
                                //show the selected test reports
                                //set the value of chosen_test to empty;
                                (App.Current as App).chosen_test_for_report = "";
                                this.Frame.Navigate(typeof(Reports), null);
                            };

                            side_p.Children.Add(a_btn);
                            break;
                        }
                    }
                }

                Button[] btn = new Button[counter];

                for (int k = 0; k < counter; k++)
                {//now lets check for tests that have reports ,so that we don't display all/
                    Query t = new Query();
                    t.GetExtra("Select report_name FROM reports where test_id = '" + s_t.Results[k, 0] + "' ");
                    if (t.CheckRecords() == true)
                    {//there are records
                        int o = 0;
                        //start designing
                        int calc = counter - k;
                        btn[k] = new Button();
                        StackPanel panel = new StackPanel();
                        panel.Orientation         = Orientation.Horizontal;
                        panel.Margin              = new Thickness(15, 20, 15, 5);
                        panel.HorizontalAlignment = HorizontalAlignment.Center;
                        StackPanel count_p = new StackPanel();
                        count_p.Background = new SolidColorBrush(Colors.White);

                        TextBlock count_txt = new TextBlock();
                        count_p.Margin = new Thickness(10, 0, 0, 0);

                        count_txt.Text       = t.CountRows().ToString();
                        count_txt.FontSize   = 14.5;
                        count_txt.Foreground = theme_color;
                        count_txt.Padding    = new Thickness(7, 3, 7, 3);

                        TextBlock txt = new TextBlock();
                        txt.Text     = s_t.Results[k, 1];
                        txt.FontSize = 15.5;

                        btn[k].Foreground          = new SolidColorBrush(Colors.White);
                        btn[k].HorizontalAlignment = HorizontalAlignment.Stretch;
                        btn[k].BorderBrush         = new SolidColorBrush(Color.FromArgb(70, 0, 0, 0));
                        btn[k].Background          = theme_color;

                        //check if it's the only result,make sure it's not a deleted test.
                        int amount = 0;
                        for (int h = 0; h < q.CountRows(); h++)
                        {
                            Query g = new Query();
                            g.GetExtra("SELECT test_id from tests WHERE test_id = '" + q.Results[h, 3] + "'");
                            g.Record();
                            if (g.CheckRecords() == true)
                            {     //now check if h has looped once
                                if (h > 0)
                                { //now check if the previous value is the same, if it's only one value, they have to be the same :-)
                                    if (q.Results[h, 3] != q.Results[h - 1, 3])
                                    {
                                        amount += 1;
                                    }
                                }
                            }
                        }
                        if (amount > 0 && amount <= 1)
                        {//only 1 value
                            //its the one that's chosen, change the color
                            btn[k].Foreground    = new SolidColorBrush(Colors.WhiteSmoke);
                            btn[k].Background    = selected_color;
                            count_txt.Foreground = selected_color;

                            sort_txt.Text              = "| Showing result for " + s_t.Results[k, 1];
                            sort_txt.FontSize          = 13;
                            sort_txt.Foreground        = new SolidColorBrush(Color.FromArgb(255, 120, 120, 120));
                            sort_txt.VerticalAlignment = VerticalAlignment.Center;
                        }
                        else
                        {//ts more than one
                            if (this.chosen_test == s_t.Results[k, 0])
                            {
                                //its the one that's chosen, change the color
                                btn[k].Foreground    = new SolidColorBrush(Colors.WhiteSmoke);
                                btn[k].Background    = selected_color;
                                count_txt.Foreground = selected_color;

                                sort_txt.Text              = "| Showing result for " + s_t.Results[k, 1];
                                sort_txt.FontSize          = 13;
                                sort_txt.Foreground        = new SolidColorBrush(Color.FromArgb(255, 120, 120, 120));
                                sort_txt.VerticalAlignment = VerticalAlignment.Center;
                            }
                        }

                        btn[k].Margin = new Thickness(-3, -6.6, -3, 0);
                        if (calc == 1)
                        {
                            btn[k].BorderThickness = new Thickness(0, 0, 0, 0);
                        }
                        else
                        {
                            btn[k].BorderThickness = new Thickness(1, 0, 1, 1);
                        }
                        count_p.Children.Add(count_txt);
                        panel.Children.Add(txt);
                        panel.Children.Add(count_p);
                        btn[k].Content = panel;

                        //click event
                        //btn[k].Click +=Cancel_Click;
                        //lets solve the annoying issue that's common, if bla is the last value, bla - 1
                        int reduce = k;
                        if (k == counter)
                        {
                            //the last value
                            reduce = k - 1;
                        }
                        btn[k].Click += (s, e) =>
                        {
                            //show the selected test reports
                            //set the value of chosen_test to the selected test id
                            (App.Current as App).chosen_test_for_report = s_t.Results[reduce, 0];
                            this.Frame.Navigate(typeof(Reports), null);
                        };

                        side_p.Children.Add(btn[k]);
                    }
                }

                int ot = 0;//for switching designs.
                for (i = 0; i < (reports_row); i++)
                {
                    //get test info
                    Query c = new Query();
                    c.GetExtra("Select test_id,test_name FROM tests Where test_id = '" + q.Results[i, 3] + "'");
                    c.Record();


                    if (c.CheckRecords())
                    {
                        //start generating designs
                        //get color that will be used
                        SolidColorBrush text_color    = new SolidColorBrush(Color.FromArgb(255, 12, 12, 12));
                        SolidColorBrush head_bg       = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255));
                        SolidColorBrush body_bg       = new SolidColorBrush(Color.FromArgb(255, 250, 250, 250));
                        SolidColorBrush footer_bg     = head_bg;
                        SolidColorBrush f_text_color  = new SolidColorBrush(Color.FromArgb(255, 40, 40, 40));
                        SolidColorBrush f_text_color2 = new SolidColorBrush(Color.FromArgb(255, 60, 60, 60));

                        double footer_txt_size = 15;
                        //pattern

                        /*
                         * <border>
                         *  <stackpanel>
                         *      <stackpanel head>
                         *          <Textblock/>
                         *          <border/>
                         *      </stackpanel head>
                         *      <stackpanel body>
                         *          <Textblock/>
                         *      </stackpanel body>
                         *      <stackpanel footer>
                         *          <textblock/>
                         *          <textblock/>
                         *      </stackpanel footer>
                         *  </stackpanel>
                         *  </border>
                         */

                        Border parent_border = new Border();
                        parent_border.Margin       = new Thickness(5, 15, 5, 5);
                        parent_border.CornerRadius = new CornerRadius(5);
                        StackPanel parent_panel = new StackPanel();
                        //#################### HEAD
                        StackPanel head_panel = new StackPanel();
                        head_panel.MinHeight = 60;

                        Border head_border_t = new Border();
                        head_border_t.BorderThickness = new Thickness(2);
                        head_border_t.BorderBrush     = new SolidColorBrush(Color.FromArgb(255, 41, 128, 185));

                        StackPanel inner_head = new StackPanel();
                        inner_head.Margin = new Thickness(10, 6, 5, 5);

                        StackPanel inner_head1 = new StackPanel();
                        StackPanel inner_head2 = new StackPanel();
                        inner_head2.HorizontalAlignment = HorizontalAlignment.Right;
                        inner_head2.Orientation         = Orientation.Horizontal;
                        inner_head2.Margin = new Thickness(1, -60, 0, 0);

                        TextBlock head_txt = new TextBlock();
                        head_txt.FontSize   = 20;
                        head_txt.Foreground = new SolidColorBrush(Color.FromArgb(255, 30, 30, 30));
                        TextBlock head_txt_sub = new TextBlock();
                        head_txt_sub.FontSize   = 16;
                        head_txt_sub.Margin     = new Thickness(0, 5, 0, 10);
                        head_txt_sub.Foreground = new SolidColorBrush(Color.FromArgb(255, 65, 65, 65));

                        ////////////////////////
                        parent_border.BorderThickness = new Thickness(1);
                        parent_border.BorderBrush     = new SolidColorBrush(Color.FromArgb(30, 0, 0, 0));

                        ////////////////////////

                        //design
                        //inner_head.Orientation = Orientation.Horizontal;
                        head_txt.Text = q.Results[i, 1] + " ";//name of report
                        string test_name = c.RecordExist(c.Result[1], "");
                        string test_id   = c.Result[0];
                        ///////////////////////////////////////////
                        Query inner_q = new Query();
                        inner_q.Get("staffs", "WHERE staff_id ='" + q.Results[i, adder_col] + "'");
                        //for showing the adder

                        string person = "| Added by ";
                        if (inner_q.CheckRecords() == true)
                        {
                            inner_q.Record();
                            if ((App.Current as App).User_token.ToString() == inner_q.Result[0])
                            {
                                person += "You";
                            }
                            else
                            {
                                person += inner_q.Result[1];
                            }
                        }
                        else
                        {
                            person = "";
                        }
                        head_txt_sub.Text       = c.RecordExist("Report for " + test_name + " #(" + test_id + ") " + person + "", "Test Record not available");
                        head_txt_sub.Foreground = new SolidColorBrush(Color.FromArgb(255, 90, 90, 90));
                        head_txt_sub.FontSize   = 14;
                        head_txt.FontSize       = 18;
                        head_panel.Background   = head_bg;
                        head_panel.Height       = 50;

                        //Menu flyout
                        //MenuFlyout menu = new MenuFlyout();
                        //Button tn = new Button();
                        //MenuFlyoutItemBase b ;

                        //ADDING THE EDIT AND DELETE STUFF

                        string[]          stuff_text  = { "Edit", "Delete" };
                        string[]          stuff_image = { "", "" };
                        HyperlinkButton[] link        = new HyperlinkButton[stuff_text.Length];
                        Border[]          brd         = new Border[stuff_text.Length];
                        int reduce = i;
                        if (i == counter)
                        {
                            reduce = i - 1;
                        }

                        for (int t = 0; t < stuff_text.Length; t++)
                        {
                            //  option_border.BorderThickness = new Thickness(0, 0, 0, 1);
                            //option_border.BorderBrush = new SolidColorBrush(Color.FromArgb(50, 0, 0, 0));
                            Image      img    = new Image();
                            ImageBrush source = new ImageBrush();//new Uri("Assets/icons/edit-black.png");
                            //source.ImageSource = source.
                            //img.source =
                            TextBlock option_txt = new TextBlock();
                            option_txt.Foreground        = new SolidColorBrush(Color.FromArgb(150, 0, 0, 0));
                            option_txt.FontSize          = 15;
                            option_txt.Foreground        = new SolidColorBrush(Colors.White);
                            option_txt.Text              = stuff_text[t];
                            option_txt.Margin            = new Thickness(5, 0, 0, 0);
                            option_txt.VerticalAlignment = VerticalAlignment.Center;
                            //  Bitm
                            // Button button = new Button();
                            link[t]           = new HyperlinkButton();
                            brd[t]            = new Border();
                            brd[t].Background = selected_color;
                            if (option_txt.Text == stuff_text[1])
                            {
                                brd[t].Background = new SolidColorBrush(Colors.IndianRed);
                            }
                            brd[t].BorderBrush     = new SolidColorBrush(Color.FromArgb(53, 0, 0, 0));
                            brd[t].BorderThickness = new Thickness(1);
                            link[t].Foreground     = new SolidColorBrush(Colors.White);
                            link[t].Content        = option_txt;
                            link[t].Margin         = new Thickness(0);
                            brd[t].CornerRadius    = new CornerRadius(3);
                            // brd[t].Padding = new Thickness(-5);
                            brd[t].MaxWidth  = 85;
                            brd[t].MaxHeight = 38;
                            link[t].Click   += (s, e) =>
                            {
                                if (option_txt.Text == stuff_text[0])
                                {//editing time
                                    //call the editing stuff
                                    tracker = new EditTracker("reports", "report_id", q.Results[(reduce), 0]);
                                    //track the row.
                                    tracker.Track();

                                    Auth auth = new Auth();
                                    if (auth.CheckOwner("Reports", "report_id", q.Results[reduce, 0]) != true)
                                    {
                                        PopUp p = new PopUp("Sorry, You can't edit Report \"" + tracker.TrackResult[1] + "\" cause you didn't add the report.");
                                    }
                                    else
                                    {
                                        if (!Editing.IsOpen)
                                        {
                                            //OPEN
                                            this.Frame.Opacity = .4;

                                            parent.IsEnabled = false;
                                            //SET THE EDIT TRACKER
                                            //I DID (i-1) BECAUSE IT WAS INCREASE BY ONE, THEREFORE OUT OF BOUND ISH.

                                            this.r_id        = tracker.TrackResult[0];//set the id to the global var, so that we know what to edit.
                                            r_name_e.Text    = tracker.TrackResult[1];
                                            r_content_e.Text = tracker.TrackResult[2];
                                            Query a = new Query();
                                            a.Get("tests", "Where test_id = '" + q.Results[reduce, 3] + "'");
                                            a.Record();
                                            r_tests_e.SelectedIndex = f.SelectedInverse(a.Result[0], "tests", null, 1);
                                            Editing.IsOpen          = true;
                                        }
                                    }
                                }
                                else if (option_txt.Text == stuff_text[1])
                                {//delete
                                    //track first
                                    tracker = new EditTracker("Reports", "report_id", q.Results[(reduce), 0]);
                                    //track
                                    tracker.Track();

                                    Auth auth = new Auth();
                                    if (auth.CheckOwner("Reports", "report_id", q.Results[reduce, 0]) != true)
                                    {
                                        PopUp p = new PopUp("Sorry, You can't delete Report \"" + tracker.TrackResult[1] + "\" cause you didn't add the report");
                                    }
                                    else
                                    {
                                        this.Frame.Opacity = .4;

                                        //this.Opacity = .4;
                                        parent.IsEnabled = false;

                                        Messages msg = new Messages();
                                        msg.Confirm("Are you sure you want to delete Report \"" + tracker.TrackResult[1] + "\" ?");
                                        msg.p_container.IsOpen = true;
                                        parent_grid.Children.Add(msg.p_container);

                                        msg.TrueBtn.Click += (z, x) =>
                                        {
                                            //CALL THE DELETE QUERY
                                            //CALL THE DELETE QUERY
                                            Query que = new Query();
                                            que.successMessage = "Report has been deleted successfully.";
                                            que.Remove("reports", "where report_id = '" + tracker.TrackResult[0] + "'");
                                            (App.Current as App).chosen_test_for_report = "";
                                            this.Frame.Opacity = 1;

                                            this.Frame.Navigate(typeof(Reports), null);
                                        };

                                        msg.FalseBtn.Click += (z, x) =>
                                        {
                                            this.Frame.Opacity = 1;

                                            parent.IsEnabled = true;
                                        };
                                    }
                                }
                            };
                            //add
                            brd[t].Child = link[t];
                            inner_head2.Children.Add(brd[t]);
                        }
                        //  inner_head2.Children.Add();

                        //######################## /head


                        //######################## body
                        Border body_border = new Border();
                        body_border.BorderThickness = new Thickness(0, 1, 0, 1);
                        body_border.BorderBrush     = new SolidColorBrush(Color.FromArgb(40, 0, 0, 0));
                        //  body_border.Margin = new Thickness(0, 5, 0, 0);


                        StackPanel body_panel = new StackPanel();
                        body_panel.Background = body_bg;
                        TextBlock body_txt = new TextBlock();
                        body_txt.Text             = q.Results[i, 2];
                        body_txt.Foreground       = text_color;
                        body_txt.FontSize         = 16;
                        body_txt.Padding          = new Thickness(10, 7, 8, 9);
                        body_txt.CharacterSpacing = 12;
                        // body_txt.TextTrimming = TextTrimming.CharacterEllipsis;
                        body_txt.TextWrapping           = TextWrapping.Wrap;
                        body_txt.IsTextSelectionEnabled = true;
                        //######################## /body

                        //######################## footer
                        StackPanel footer_panel = new StackPanel();
                        footer_panel.Background = footer_bg;

                        StackPanel inner_footer_panel1 = new StackPanel();
                        inner_footer_panel1.Margin      = new Thickness(10, 10, 5, 7);
                        inner_footer_panel1.Orientation = Orientation.Horizontal;
                        StackPanel inner_footer_panel2 = new StackPanel();
                        inner_footer_panel2.Margin              = new Thickness(5, -25, 10, 7);
                        inner_footer_panel2.Orientation         = Orientation.Horizontal;
                        inner_footer_panel2.HorizontalAlignment = HorizontalAlignment.Right;

                        TextBlock footer_txt1 = new TextBlock();

                        TextBlock footer_txt2 = new TextBlock();
                        TextBlock footer_txt3 = new TextBlock();
                        TextBlock footer_txt4 = new TextBlock();
                        footer_txt1.Text             = "Created: ";
                        footer_txt1.Foreground       = f_text_color;
                        footer_txt1.FontSize         = footer_txt_size;
                        footer_txt1.CharacterSpacing = 12;

                        footer_txt2.Text             = f.Date(q.Results[i, 4], "");
                        footer_txt2.Foreground       = f_text_color2;
                        footer_txt2.FontSize         = 13;
                        footer_txt2.CharacterSpacing = 12;
                        footer_txt2.Margin           = new Thickness(5, 0, 0, 0);

                        footer_txt3.Text             = "Last Updated: ";
                        footer_txt3.Foreground       = f_text_color;
                        footer_txt3.FontSize         = footer_txt_size;
                        footer_txt3.CharacterSpacing = 12;

                        footer_txt4.Text             = f.CheckEmpty(f.Date(q.Results[i, 5], ""), "Never");
                        footer_txt4.FontStyle        = Windows.UI.Text.FontStyle.Italic;
                        footer_txt4.Foreground       = f_text_color2;
                        footer_txt4.FontSize         = 13;
                        footer_txt4.CharacterSpacing = 12;
                        footer_txt4.Margin           = new Thickness(5, 0, 0, 0);
                        //######################## /footer
                        int calc = ot % 2;

                        if (calc == 1)
                        {
                            head_border_t.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 120, 28, 45));
                        }

                        ot++;
                        //adding
                        inner_head1.Children.Add(head_txt);
                        inner_head1.Children.Add(head_txt_sub);
                        inner_head.Children.Add(inner_head1);

                        inner_head.Children.Add(inner_head2);
                        head_panel.Children.Add(head_border_t);
                        head_panel.Children.Add(inner_head);
                        //head_panel.Children.Add(head_border_b);

                        body_panel.Children.Add(body_txt);
                        body_border.Child = body_panel;

                        //adding footer stuff
                        inner_footer_panel1.Children.Add(footer_txt1);
                        inner_footer_panel1.Children.Add(footer_txt2);
                        inner_footer_panel2.Children.Add(footer_txt3);
                        inner_footer_panel2.Children.Add(footer_txt4);

                        footer_panel.Children.Add(inner_footer_panel1);
                        footer_panel.Children.Add(inner_footer_panel2);


                        parent_panel.Children.Add(head_panel);
                        parent_panel.Children.Add(body_border);
                        parent_panel.Children.Add(footer_panel);
                        parent_border.Child = parent_panel;

                        main_p.Children.Add(parent_border);
                    }
                }
            }
            else
            {
                //NO RECORD
                Messages msg = new Messages();
                msg.Note("No Reports record available.");
                reports_r.Children.Add(msg._b_Container);
            }


            ////////////////////////////////////////////////
            //fill some stuff in the form
            Query query = new Query();

            query.Get("Tests");

            int row_count = query.CountRows();

            query.Records();


            for (int r = 0; r < row_count; r++)
            {
                object p = query.Results[r, 1] + " #(" + query.Results[r, 0] + ")";
                //  t_patients.Items.Add(p[r]);
                r_tests.Items.Add(p);
                r_tests_e.Items.Add(p);
            }
        }
Esempio n. 4
0
        public Tests()
        {
            this.InitializeComponent();
            //FOR EDITING
            EditTracker tracker;
            //start displaying the tests records
            Query q = new Query();

            q.GetExtra("SELECT test_name,amount,patient_id,doctor_id,date,_added_by FROM tests");
            q.Records();
            ////
            Query test_id = new Query();

            test_id.GetExtra("SELECT test_id,doctor_id from tests");
            //GET THE RECORDS
            test_id.Records();
            ///////////////////
            int tests_row = q.CountRows();
            //AMOUNT OF COLUMN DEFINITIONS
            int    col_num       = Convert.ToInt32(tests_r.ColumnDefinitions.Count);
            Filter f             = new Filter();
            bool   check_records = q.CheckRecords();
            //  RowDefinition[] rd = new RowDefinition[q.CountRows()];
            // RowDefinition rd;


            //STACKPANEL TO HOLD THE ROWS
            // StackPanel parent_row_panel;
            //WE'RE ADDING +1 CAUSE THERE'S ALREADY A ROW DEFINED WHICH IT'S VALUE WOULD BE ZERO
            //SO IF WE DONT INCREMENT IT, IT STARTS WITH 0, WHICH MIGHT BE A BAD IDEA :(.
            //int i = 0;
            //now check the number of rows
            //keep adding rows as long as it doesn't exceed the row limit from the stupid database.

            int i = 0;

            //CHECK IF THERE'S ANY RECORD


            if (check_records)
            {
                for (i = 0; i < (tests_row); i++)
                {
                    RowDefinition rd = new RowDefinition();
                    // rd.Height = new GridLength(50);
                    tests_r.RowDefinitions.Add(rd);

                    /*++
                     * COLUMN DEFINITION
                     * CREATE COLUMNS ACCORDING TO THE PARENT COLUMN OF THE FIRST ROW, WHICH IS col_num.
                     */

                    //////////////////////////////////
                    int k  = 0;
                    int ke = 1;
                    for (k = 0; k < col_num; k++)
                    {
                        ColumnDefinition cd = new ColumnDefinition();
                        //cd.Width = new GridLength();
                        //cd.MinWidth = 150;

                        tests_r.ColumnDefinitions.Add(cd);

                        //reset column def so that when it starts looping the for again, it creates a new set of column definition
                        //column_def = 0;


                        //calculate odd and even ish
                        int calc = i % 2;
                        //////////////////////////////////////////////////////////
                        Border border = new Border();

                        TextBlock n = new TextBlock();
                        n.FontSize = 17.3;

                        n.Foreground = new SolidColorBrush(Color.FromArgb(180, 0, 0, 0));

                        //TextBlock


                        ///////////////////////////////////////
                        //stackpanel
                        StackPanel pa = new StackPanel();
                        // pa.Style = new Style();
                        //StackPanel m_pa = new StackPanel();
                        // m_pa.Name = "p";// + i.ToString();
                        StackPanel row_holder = new StackPanel();

                        //add
                        //pa.
                        pa.Children.Add(n);
                        pa.Margin = new Thickness(10);
                        //pa.MaxWidth = 115;
                        pa.HorizontalAlignment = HorizontalAlignment.Center;
                        pa.VerticalAlignment   = VerticalAlignment.Center;

                        border.BorderThickness = new Thickness(0, 0, 0, 1);
                        border.BorderBrush     = new SolidColorBrush(Color.FromArgb(50, 0, 0, 0));

                        //border.MaxWidth = 115;
                        //border.MinHeight = 60.5;
                        border.Child = pa;
                        row_holder.Children.Add(border);

                        //CHECK WHAT TO INPUT
                        Query c = new Query();
                        //check if it's the last column
                        int calcu = (col_num - k);


                        if (k == 2)
                        {
                            //GET THE PATIENT'S NAME
                            c.Get("patients", "WHERE patient_id = '" + q.Results[i, k] + "'");
                            //check if the patient still exists, if not, no record available

                            c.Records();

                            n.Text = c.RecordExist(c.Results[0, 1]);
                        }
                        else if (k == 3)
                        {//get the amount of reports
                            c.Get("reports", "WHERE test_id = '" + test_id.Results[i, 0] + "'");
                            n.Text = c.CountRows().ToString();
                        }
                        else if (k == 4)
                        {//get the doctor who performed the test
                            c.Get("doctors", "Where doctor_id = '" + test_id.Results[i, 1] + "'");
                            c.CheckRecords();
                            c.Records();
                            n.Text = c.RecordExist(c.Results[0, 1]);
                        }
                        else if (k == 5)
                        {//DATE
                            n.Text = f.Date(q.Results[i, 4], "dd-MM-yy");
                        }
                        else if (calcu == 2)
                        {//second to the last value, add added by
                            Query inner_q = new Query();
                            inner_q.Get("staffs", "WHERE staff_id ='" + q.Results[i, 5] + "'");
                            if (inner_q.CheckRecords() == true)
                            {
                                inner_q.Record();
                                string person = "";
                                if ((App.Current as App).User_token.ToString() == inner_q.Result[0])
                                {
                                    person = "You";
                                }
                                else
                                {
                                    person = inner_q.Result[1];
                                }

                                n.Text = person;
                            }
                            else
                            {
                                n.Text = "Not Available";
                            }
                        }
                        else if (calcu == 1)
                        {
                        }
                        else
                        {
                            n.Text = q.Results[i, k];
                        }
                        //////////////OPTION
                        StackPanel option_panel  = new StackPanel();
                        Border     option_border = new Border();
                        //////////////////////////////////////////////////////

                        ////FOR CHANGING THE ROW BACKGROUND.
                        if (calc == 1)
                        {
                            border.Background        = new SolidColorBrush(Color.FromArgb(250, 225, 225, 225));
                            option_border.Background = new SolidColorBrush(Color.FromArgb(250, 215, 215, 215));
                        }
                        else
                        {
                            border.Background        = new SolidColorBrush(Color.FromArgb(250, 236, 254, 251));
                            option_border.Background = new SolidColorBrush(Color.FromArgb(250, 226, 246, 241));
                        }

                        //DETERMINE WHEN TO ADD THE OPTION STUFF

                        if (calcu == 1)
                        {//CREATE THE OPTIONS STUFF
                            StackPanel option_inner_panel = new StackPanel();
                            //TO MAKE THINGS EASY JARE,LOOP IT THROUGH THE ARRAY
                            string   ed          = "Edit";
                            string   del         = "Delete";
                            string[] stuff_text  = { ed, del };
                            string[] stuff_image = { "", "" };
                            HyperlinkButton[,] link = new HyperlinkButton[tests_row, stuff_text.Length];
                            int reduce = i;
                            if (i == tests_row)
                            {
                                reduce = i - 1;
                            }
                            for (int t = 0; t < stuff_text.Length; t++)
                            {
                                option_border.BorderThickness = new Thickness(0, 0, 0, 1);
                                option_border.BorderBrush     = new SolidColorBrush(Color.FromArgb(50, 0, 0, 0));
                                TextBlock option_txt = new TextBlock();
                                option_txt.Text       = stuff_text[t];
                                option_txt.Foreground = new SolidColorBrush(Color.FromArgb(150, 0, 0, 0));
                                option_txt.FontSize   = 15;
                                option_txt.Margin     = new Thickness(10, 0, 3, 0);
                                // Button button = new Button();
                                link[i, t] = new HyperlinkButton();

                                //HyperlinkButton[] link = new HyperlinkButton[tests_row];
                                link[i, t].Content = option_txt.Text;
                                // link.Click = RoutedEventHandler.Combine(sender, RoutedEventArgs e);
                                // button.ClickMode = ClickMode.Hover;
                                //CLICK EVENT
                                int reduce_t = t;
                                if (t == stuff_text.Length)
                                {
                                    reduce_t = t - 1;
                                }
                                //link[i].Click += new RoutedEventHandler(EditRecord_Click("E",));
                                link[i, t].Click += (s, e) => {
                                    if ((string)link[reduce, reduce_t].Content == ed)
                                    {//IT's edit
                                        tracker = new EditTracker("Tests", "test_id", test_id.Results[(reduce), 0]);
                                        //track the row.
                                        tracker.Track();

                                        Auth auth = new Auth();
                                        if (auth.CheckOwner("Tests", "test_id", test_id.Results[reduce, 0]) != true)
                                        {
                                            PopUp p = new PopUp("Sorry, You can't edit Test " + tracker.TrackResult[1] + "'s record cause you didn't add the record");
                                        }
                                        else
                                        {
                                            if (!Editing.IsOpen)
                                            {
                                                //OPEN
                                                this.Frame.Opacity = .4;

                                                //this.Opacity = .4;
                                                parent.IsEnabled = false;
                                                //SET THE EDIT TRACKER
                                                //I DID (i-1) BECAUSE IT WAS INCREASE BY ONE, THEREFORE OUT OF BOUND ISH.
                                                this.t_id = tracker.TrackResult[0];//set the id to the global var, so that we know what to edit.

                                                t_name_e.Text  = tracker.TrackResult[1];
                                                t_price_e.Text = tracker.TrackResult[2];
                                                //get values for the combo boxes.
                                                c.Get("patients", "Where patient_id = '" + q.Results[reduce, 2] + "'");
                                                c.Records();

                                                t_patients_e.SelectedIndex = f.SelectedInverse(c.Results[0, 0], "patients", null, 1);

                                                c.Get("doctors", "Where doctor_id = '" + q.Results[reduce, 3] + "'");
                                                c.Records();

                                                t_doctors_e.SelectedIndex = f.SelectedInverse(c.Results[0, 0], "doctors", null, 1);


                                                Editing.IsOpen = true;
                                            }
                                        }
                                    }
                                    else if ((string)link[reduce, reduce_t].Content == del)
                                    {//it's the delete.
                                        //track first
                                        tracker = new EditTracker("Tests", "test_id", test_id.Results[(reduce), 0]);
                                        //track
                                        tracker.Track();

                                        Auth auth = new Auth();
                                        if (auth.CheckOwner("Tests", "test_id", test_id.Results[reduce, 0]) != true)
                                        {
                                            PopUp p = new PopUp("Sorry, You can't delete Test " + tracker.TrackResult[1] + "'s record cause you didn't add the record");
                                        }
                                        else
                                        {
                                            this.Frame.Opacity = .4;

                                            //this.Opacity = .4;
                                            parent.IsEnabled = false;

                                            Messages msg = new Messages();
                                            msg.Confirm("Are you sure you want to delete Test " + tracker.TrackResult[1] + "'s record?");
                                            msg.p_container.IsOpen = true;
                                            parent_grid.Children.Add(msg.p_container);

                                            msg.TrueBtn.Click += (z, x) =>
                                            {
                                                //CALL THE DELETE QUERY
                                                Query que = new Query();
                                                que.successMessage = "Test " + tracker.TrackResult[1] + " has been deleted.";
                                                que.Remove("Tests", "where test_id = '" + tracker.TrackResult[0] + "'");
                                                this.Frame.Opacity = 1;
                                                this.Frame.Navigate(typeof(Tests), null);
                                            };

                                            msg.FalseBtn.Click += (z, x) =>
                                            {
                                                this.Frame.Opacity = 1;

                                                parent.IsEnabled = true;
                                            };
                                        }
                                    }
                                };

                                //private void R_C(object sender, EventArgs e){

                                //}
                                ////ADDING
                                option_inner_panel.Children.Add(link[i, t]);
                                //ADD THE EDIT, DELETE ICON
                                //Image img = new Image();
                                //img.Source = new ;
                            }
                            option_panel.Children.Add(option_inner_panel);
                            option_inner_panel.Orientation = Orientation.Horizontal;
                            option_panel.VerticalAlignment = VerticalAlignment.Center;

                            option_border.Child = option_panel;
                            Grid.SetColumn(option_border, k);
                            Grid.SetRow(option_border, i + 1);
                            tests_r.Children.Add(option_border);
                        }

                        else
                        {
                            Grid.SetRow(row_holder, i + 1);
                            Grid.SetColumn(row_holder, k);
                            tests_r.Children.Add(row_holder);
                        }

                        ///i've even forgotten what this does. :(
                        ke++;
                    }
                }
            }

            else
            {//NO RECORD, SHOW SOMETHING
                Messages msg = new Messages();
                msg.Note("No Tests record available.");
                tests_r.Children.Add(msg._b_Container);
                RowDefinition rd = new RowDefinition();
                // rd.Height = new GridLength(50);
                tests_r.RowDefinitions.Add(rd);
                Grid.SetColumnSpan(msg._b_Container, col_num);
                Grid.SetColumn(msg._b_Container, 0);
                Grid.SetRow(msg._b_Container, 1);
            }

            ////////////////////////////////////////////////
            //fill some stuff in the form
            Query query = new Query();

            query.Get("Patients");

            int row_count = query.CountRows();

            query.Records();
            //ComboBox pp = t_patients;
            // object[] selected_value = new object[row_count];
            //string[] selected_value_path = new string[row_count];
            //t_patients.SelectedValue = new object();
            //Object[] p = new object[que.CountRows()];


            for (int r = 0; r < row_count; r++)
            {
                object p = query.Results[r, 1];
                //  t_patients.Items.Add(p[r]);
                t_patients.Items.Add(p);
                //  t_patients.SelectedValuePath = new string[row_count];
                // t_patients.SelectedValue = new object[que.CountRows()];

                // t_patients.SelectedValue[r] = "s";
                //   t_patients.SelectedValuePath = query.Results[r, 1];
                //   t_patients.SelectedValue = t_patients.SelectedValuePath;
                // selected_value[r] = t_patients.SelectedValuePath;
                //editing box
                t_patients_e.Items.Add(p);
            }

            query.Get("Doctors");
            query.Records();
            for (int r = 0; r < query.CountRows(); r++)
            {
                Object d = query.Results[r, 1];
                t_doctors.Items.Add(d);
                //editing box
                t_doctors_e.Items.Add(d);
                //  t_doctors.SelectedIndex
            }
        }
        public Patients()
        {
            this.InitializeComponent();
            //start displaying the patients records
            Query q       = new Query();
            Query inner_q = new Query();

            q.GetExtra("SELECT name,dob,address,Gender,_added_by FROM patients");
            q.Records();
            int   patients_row = q.CountRows();
            Query patient_id   = new Query();

            patient_id.Get("Patients");
            patient_id.Records();
            //AMOUNT OF COLUMN DEFINITIONS
            int    col_num       = Convert.ToInt32(patients_r.ColumnDefinitions.Count);
            Filter f             = new Filter();
            bool   check_records = q.CheckRecords();

            //  RowDefinition[] rd = new RowDefinition[q.CountRows()];
            // RowDefinition rd;


            //STACKPANEL TO HOLD THE ROWS
            // StackPanel parent_row_panel;
            //WE'RE ADDING +1 CAUSE THERE'S ALREADY A ROW DEFINED WHICH IT'S VALUE WOULD BE ZERO
            //SO IF WE DONT INCREMENT IT, IT STARTS WITH 0, WHICH MIGHT BE A BAD IDEA :(.
            //int i = 0;
            //now check the number of rows
            //keep adding rows as long as it doesn't exceed the row limit from the stupid database.
            if (check_records)
            {
                int i = 0;
                for (i = 0; i < (patients_row); i++)
                {
                    RowDefinition rd = new RowDefinition();
                    //rd.Height = new GridLength(50);
                    patients_r.RowDefinitions.Add(rd);

                    /*
                     * COLUMN DEFINITION
                     * CREATE COLUMNS ACCORDING TO THE PARENT COLUMN OF THE FIRST ROW, WHICH IS col_num.
                     */

                    //////////////////////////////////
                    int k = 0;
                    for (k = 0; k < col_num; k++)
                    {
                        ColumnDefinition cd = new ColumnDefinition();
                        //cd.Width = new GridLength();
                        //cd.MinWidth = 150;

                        patients_r.ColumnDefinitions.Add(cd);

                        //reset column def so that when it starts looping the for again, it creates a new set of column definition
                        //column_def = 0;


                        //////////////////////////////////////////////////////////
                        Border border = new Border();

                        TextBlock n = new TextBlock();
                        n.FontSize = 17.3;

                        n.Foreground = new SolidColorBrush(Color.FromArgb(180, 0, 0, 0));


                        ///////////////////////////////////////
                        //stackpanel
                        StackPanel pa = new StackPanel();
                        pa.Orientation = Orientation.Horizontal;
                        // pa.Style = new Style();
                        //StackPanel m_pa = new StackPanel();
                        // m_pa.Name = "p";// + i.ToString();
                        StackPanel row_holder = new StackPanel();
                        //row_holder.Orientation = Orientation.Horizontal;
                        // row_holder.HorizontalAlignment = HorizontalAlignment.Stretch;
                        //row_holder.Orientation = new Orientation();
                        // Orientation orie = row_holder1.Orientation;

                        //add
                        //pa.
                        pa.Children.Add(n);
                        pa.Margin = new Thickness(10);
                        //pa.MaxWidth = 115;
                        pa.HorizontalAlignment = HorizontalAlignment.Center;
                        //border.Style = new Windows.UI.Xaml.Style();
                        //border.Style.TargetType = typeof(Border);
                        border.BorderThickness = new Thickness(0, 0, 0, 1);
                        border.BorderBrush     = new SolidColorBrush(Color.FromArgb(50, 0, 0, 0));
                        //calculate odd and even ish
                        int calc = i % 2;
                        //border.MaxWidth = 115;
                        // border.MinHeight = 61;
                        border.Child = pa;
                        row_holder.Children.Add(border);



                        int calcu = col_num - k;
                        //CHECK WHAT TO INPUT
                        if (k == 1)
                        {
                            n.Text = f.Date(q.Results[i, k], "dd/MM/yyyy");
                        }
                        else if (k == 2)
                        {
                            n.Text = q.Results[i, k];

                            pa.Loaded += (y, u) =>
                            {
                                n.MaxWidth = 80;
                                // n.TextWrapping = TextWrapping.WrapWholeWords;
                                n.TextTrimming = TextTrimming.CharacterEllipsis;
                            };

                            pa.PointerExited += (y, u) =>
                            {
                                n.MaxWidth = 80;
                                // n.TextWrapping = TextWrapping.WrapWholeWords;
                                n.TextTrimming = TextTrimming.CharacterEllipsis;
                            };
                            pa.PointerEntered += (y, u) => {
                                //  n.Width = 0;
                                n.MaxWidth     = 250;
                                n.MinWidth     = 80;
                                n.TextTrimming = TextTrimming.None;
                            };
                        }
                        else if (k == 3)
                        {
                            n.Text = f.Gender(q.Results[i, k]);
                        }
                        else if (k == 4)
                        {//tests results
                            inner_q.Get("tests", "WHERE patient_id = '" + patient_id.Results[i, 0] + "'");
                            n.Text = f.Numbers(inner_q.CountRows());
                        }
                        else if (k == 5)
                        {//purchases
                            inner_q.Get("purchases", "Where patient_id = '" + patient_id.Results[i, 0] + "'");
                            n.Text = f.Numbers(inner_q.CountRows());
                        }
                        else if (k == 6)
                        {//NO OF REPORTS
                            //report is related to test_id, so we have to get the test id results first, before, we know the patient
                            inner_q.Get("tests", "Where patient_id = '" + patient_id.Results[i, 0] + "'");
                            int tests_no = inner_q.CountRows();
                            //hold the value of reports gotten
                            int report_count = 0;
                            int report_only  = 0;
                            int l            = 0;
                            //LOOP THROUGH THE QUERY
                            inner_q.Records();
                            for (l = 0; l < tests_no; l++)
                            {
                                //get the number of reports for the tests returned
                                inner_q.Get("reports", "Where test_id = '" + inner_q.Results[l, 0] + "'");
                                //n.Text = q.CountRows().ToString();
                                if (inner_q.CheckRecords() == true)
                                {
                                    report_only += inner_q.CountRows();
                                }
                            }
                            //HOW MANY TIMES THE LOOP EXCECUTED SHOWS THE NUMBER OF TESTS VALID FOR THAT PATIENT

                            report_count = report_only;
                            n.Text       = f.Numbers(report_count);
                        }
                        else if (calcu == 2)
                        {//second to the last value, add added by
                            inner_q.Get("staffs", "WHERE staff_id ='" + q.Results[i, 4] + "'");
                            if (inner_q.CheckRecords() == true)
                            {
                                inner_q.Record();
                                string person = "";
                                if ((App.Current as App).User_token.ToString() == inner_q.Result[0])
                                {
                                    person = "You";
                                }
                                else
                                {
                                    person = inner_q.Result[1];
                                }

                                n.Text = person;
                            }
                            else
                            {
                                n.Text = "Not Available";
                            }
                        }
                        else if (calcu == 1)
                        {//LAST VALUE
                        }
                        else
                        {
                            n.Text = q.Results[i, k];
                        }
                        //TextBlock



                        //////////////OPTION
                        StackPanel option_panel  = new StackPanel();
                        Border     option_border = new Border();
                        //////////////////////////////////////////////////////

                        ////FOR CHANGING THE ROW BACKGROUND.
                        if (calc == 1)
                        {
                            border.Background        = new SolidColorBrush(Color.FromArgb(250, 215, 215, 215));
                            option_border.Background = new SolidColorBrush(Color.FromArgb(250, 215, 215, 215));
                        }
                        else
                        {
                            border.Background        = new SolidColorBrush(Color.FromArgb(250, 236, 254, 251));
                            option_border.Background = new SolidColorBrush(Color.FromArgb(250, 226, 246, 241));
                        }

                        //DETERMINE WHEN TO ADD THE OPTION STUFF

                        if (calcu == 1)
                        {//CREATE THE OPTIONS STUFF
                            StackPanel option_inner_panel = new StackPanel();
                            //TO MAKE THINGS EASY JARE,LOOP IT THROUGH THE ARRAY
                            string[] stuff_text  = { "Edit", "Delete" };
                            string[] stuff_image = { "", "" };
                            HyperlinkButton[,] link = new HyperlinkButton[patients_row, stuff_text.Length];
                            int reduce = i;
                            if (i == patients_row)
                            {
                                reduce = i - 1;
                            }

                            for (int t = 0; t < stuff_text.Length; t++)
                            {
                                option_border.BorderThickness = new Thickness(0, 0, 0, 1);
                                option_border.BorderBrush     = new SolidColorBrush(Color.FromArgb(50, 0, 0, 0));
                                TextBlock option_txt = new TextBlock();
                                option_txt.Text              = stuff_text[t];
                                option_txt.Foreground        = new SolidColorBrush(Color.FromArgb(150, 0, 0, 0));
                                option_txt.FontSize          = 15;
                                option_txt.Margin            = new Thickness(10, 0, 0, 0);
                                option_txt.VerticalAlignment = VerticalAlignment.Center;
                                // Button button = new Button();
                                link[i, t] = new HyperlinkButton();

                                //HyperlinkButton[] link = new HyperlinkButton[tests_row];
                                link[i, t].Content = option_txt.Text;
                                // link.Click = RoutedEventHandler.Combine(sender, RoutedEventArgs e);
                                //button.ClickMode = ClickMode.Hover;
                                //CLICK EVENT
                                int reduce_t = t;
                                if (t == stuff_text.Length)
                                {
                                    reduce_t = t - 1;
                                }
                                //link[i].Click += new RoutedEventHandler(EditRecord_Click("E",));
                                link[i, t].Click += (s, e) =>
                                {
                                    if ((string)link[reduce, reduce_t].Content == stuff_text[0])
                                    {//IT's edit
                                        tracker = new EditTracker("Patients", "patient_id", patient_id.Results[(reduce), 0]);
                                        //track the row.
                                        tracker.Track();

                                        Auth auth = new Auth();
                                        if (auth.CheckOwner("Patients", "patient_id", patient_id.Results[reduce, 0]) != true)
                                        {
                                            PopUp p = new PopUp("Sorry, You can't edit " + f.FirstName(tracker.TrackResult[1]) + "'s record cause you didn't add the record");
                                        }
                                        else
                                        {
                                            if (!Editing.IsOpen)
                                            {
                                                //OPEN
                                                this.Frame.Opacity = .4;

                                                //this.Opacity = .4;
                                                parent.IsEnabled = false;
                                                //SET THE EDIT TRACKER
                                                //I DID (i-1) BECAUSE IT WAS INCREASE BY ONE, THEREFORE OUT OF BOUND ISH.
                                                this.p_id        = tracker.TrackResult[0];//set the id to the global var, so that we know what to edit.
                                                p_name_e.Text    = tracker.TrackResult[1];
                                                p_address_e.Text = tracker.TrackResult[2];
                                                p_phone_e.Text   = tracker.TrackResult[3];
                                                p_dob_e.Text     = f.Date(tracker.TrackResult[5], "MM/dd/yyyy");
                                                //CHECK GENDER
                                                if (tracker.TrackResult[4].ToLower() == "true")
                                                {//male
                                                    p_gender_e.SelectedIndex = 1;
                                                    //p_gender_e.SelectedItem = "Male";
                                                }
                                                else if (tracker.TrackResult[4].ToLower() == "false")
                                                {//female
                                                    p_gender_e.SelectedIndex = 2;
                                                }
                                                Editing.IsOpen = true;
                                            }
                                        }
                                    }
                                    else if ((string)link[reduce, reduce_t].Content == stuff_text[1])
                                    {//it's the delete.
                                        //CALL THE DELETE QUERY
                                        //track first
                                        tracker = new EditTracker("Patients", "patient_id", patient_id.Results[(reduce), 0]);
                                        //track
                                        tracker.Track();

                                        Auth auth = new Auth();
                                        if (auth.CheckOwner("patients", "patient_id", patient_id.Results[reduce, 0]) != true)
                                        {
                                            PopUp p = new PopUp("Sorry, You can't delete " + f.FirstName(tracker.TrackResult[1]) + "'s record cause you didn't add the record");
                                        }
                                        else
                                        {
                                            this.Frame.Opacity = .4;

                                            //this.Opacity = .4;
                                            parent.IsEnabled = false;

                                            Messages msg = new Messages();
                                            msg.Confirm("Are you sure you want to delete " + f.FirstName(tracker.TrackResult[1]) + "'s record?");
                                            msg.p_container.IsOpen = true;
                                            parent_grid.Children.Add(msg.p_container);

                                            msg.TrueBtn.Click += (z, x) =>
                                            {
                                                //CALL THE DELETE QUERY
                                                Query que = new Query();
                                                que.successMessage = "Patient " + f.FirstName(tracker.TrackResult[1]) + " has been deleted successfully.";
                                                que.Remove("patients", "where patient_id = '" + tracker.TrackResult[0] + "'");
                                                this.Frame.Opacity = 1;
                                                this.Frame.Navigate(typeof(Patients), null);
                                            };


                                            msg.FalseBtn.Click += (z, x) =>
                                            {
                                                this.Frame.Opacity = 1;

                                                parent.IsEnabled = true;
                                            };
                                        }
                                    }
                                };
                                ////ADDING
                                option_inner_panel.Children.Add(link[i, t]);
                            }
                            option_panel.Children.Add(option_inner_panel);
                            option_inner_panel.Orientation = Orientation.Horizontal;
                            option_panel.VerticalAlignment = VerticalAlignment.Center;
                            option_border.Child            = option_panel;
                            Grid.SetColumn(option_border, k);
                            Grid.SetRow(option_border, i + 1);
                            patients_r.Children.Add(option_border);
                        }

                        else
                        {
                            Grid.SetRow(row_holder, i + 1);

                            Grid.SetColumn(row_holder, k);
                            patients_r.Children.Add(row_holder);
                        }
                    }
                }
            }
            else
            {
                //
                Messages msg = new Messages();
                msg.Note("No Patients Record Available.");
                patients_r.Children.Add(msg._b_Container);
                RowDefinition rd = new RowDefinition();
                // rd.Height = new GridLength(50);
                patients_r.RowDefinitions.Add(rd);
                Grid.SetColumnSpan(msg._b_Container, col_num);
                Grid.SetColumn(msg._b_Container, 0);
                Grid.SetRow(msg._b_Container, 1);
            }
        }
Esempio n. 6
0
        public Items()
        {
            this.InitializeComponent();

            //start displaying the items records
            Query q = new Query();

            q.GetExtra("SELECT item_name,item_cost,quantity_left,quantity_consumed,date_time,_added_by FROM items");
            q.Records();
            int   items_row = q.CountRows();
            Query item_id   = new Query();

            item_id.Get("items");
            item_id.Records();
            //AMOUNT OF COLUMN DEFINITIONS
            int    col_num = Convert.ToInt32(items_r.ColumnDefinitions.Count);
            Filter f       = new Filter();

            //  RowDefinition[] rd = new RowDefinition[q.CountRows()];
            // RowDefinition rd;

            bool check_records = q.CheckRecords();

            //STACKPANEL TO HOLD THE ROWS
            // StackPanel parent_row_panel;
            //WE'RE ADDING +1 CAUSE THERE'S ALREADY A ROW DEFINED WHICH IT'S VALUE WOULD BE ZERO
            //SO IF WE DONT INCREMENT IT, IT STARTS WITH 0, WHICH MIGHT BE A BAD IDEA :(.
            //int i = 0;
            //now check the number of rows
            //keep adding rows as long as it doesn't exceed the row limit from the stupid database.

            int i = 0;

            if (check_records)
            {
                for (i = 0; i < (items_row); i++)
                {
                    RowDefinition rd = new RowDefinition();
                    //rd.Height = new GridLength(50);
                    items_r.RowDefinitions.Add(rd);

                    /*
                     * COLUMN DEFINITION
                     * CREATE COLUMNS ACCORDING TO THE PARENT COLUMN OF THE FIRST ROW, WHICH IS col_num.
                     */

                    //////////////////////////////////
                    int k = 0;
                    for (k = 0; k < col_num; k++)
                    {
                        ColumnDefinition cd = new ColumnDefinition();
                        //cd.Width = new GridLength();
                        //cd.MinWidth = 150;

                        items_r.ColumnDefinitions.Add(cd);

                        //reset column def so that when it starts looping the for again, it creates a new set of column definition
                        //column_def = 0;


                        //////////////////////////////////////////////////////////
                        Border border = new Border();

                        TextBlock n = new TextBlock();
                        n.FontSize = 17.3;

                        n.Foreground = new SolidColorBrush(Color.FromArgb(180, 0, 0, 0));


                        ///////////////////////////////////////
                        //stackpanel
                        StackPanel pa = new StackPanel();
                        // pa.Style = new Style();
                        //StackPanel m_pa = new StackPanel();
                        // m_pa.Name = "p";// + i.ToString();
                        StackPanel row_holder = new StackPanel();
                        //row_holder.Orientation = new Orientation();
                        // Orientation orie = row_holder1.Orientation;

                        //add
                        //pa.
                        pa.Children.Add(n);
                        pa.Margin = new Thickness(10);
                        //pa.MaxWidth = 115;
                        pa.HorizontalAlignment = HorizontalAlignment.Center;
                        //border.Style = new Windows.UI.Xaml.Style();
                        //border.Style.TargetType = typeof(Border);
                        border.BorderThickness = new Thickness(0, 0, 0, 1);
                        border.BorderBrush     = new SolidColorBrush(Color.FromArgb(50, 0, 0, 0));
                        //calculate odd and even ish
                        int calc = i % 2;
                        //border.MaxWidth = 115;
                        // border.MinHeight = 61;
                        border.Child = pa;
                        row_holder.Children.Add(border);



                        int calcu = col_num - k;
                        //CHECK WHAT TO INPUT

                        if (calcu == 1)
                        {//LAST VALUE
                        }
                        else if (k == 2 || k == 3)
                        {
                            if (q.Results[i, k] == "0")
                            {
                                n.Text = "None";
                            }
                            else
                            {
                                n.Text = f.Numbers(Convert.ToInt32(q.Results[i, k]));
                            }
                        }
                        else if (k == 4)
                        {
                            n.Text = f.Date(q.Results[i, k], "dd/MM/yyyy");
                        }
                        else if (calcu == 2)
                        {//second to the last value, add added by
                            Query inner_q = new Query();
                            inner_q.Get("staffs", "WHERE staff_id ='" + q.Results[i, 5] + "'");
                            if (inner_q.CheckRecords() == true)
                            {
                                inner_q.Record();
                                string person = "";
                                if ((App.Current as App).User_token.ToString() == inner_q.Result[0])
                                {
                                    person = "You";
                                }
                                else
                                {
                                    person = inner_q.Result[1];
                                }

                                n.Text = person;
                            }
                            else
                            {
                                n.Text = "Not Available";
                            }
                        }
                        else
                        {
                            n.Text = q.Results[i, k];
                        }
                        //TextBlock



                        //////////////OPTION
                        StackPanel option_panel  = new StackPanel();
                        Border     option_border = new Border();
                        //////////////////////////////////////////////////////

                        ////FOR CHANGING THE ROW BACKGROUND.
                        if (calc == 1)
                        {
                            border.Background        = new SolidColorBrush(Color.FromArgb(250, 215, 215, 215));
                            option_border.Background = new SolidColorBrush(Color.FromArgb(250, 215, 215, 215));
                        }
                        else
                        {
                            border.Background        = new SolidColorBrush(Color.FromArgb(250, 236, 254, 251));
                            option_border.Background = new SolidColorBrush(Color.FromArgb(250, 226, 246, 241));
                        }

                        //DETERMINE WHEN TO ADD THE OPTION STUFF

                        if (calcu == 1)
                        {//CREATE THE OPTIONS STUFF
                            StackPanel option_inner_panel = new StackPanel();
                            //TO MAKE THINGS EASY JARE,LOOP IT THROUGH THE ARRAY
                            string[] stuff_text  = { "Edit", "Delete" };
                            string[] stuff_image = { "", "" };
                            HyperlinkButton[,] link = new HyperlinkButton[items_row, stuff_text.Length];
                            int reduce = i;
                            if (i == items_row)
                            {
                                reduce = i - 1;
                            }

                            for (int t = 0; t < stuff_text.Length; t++)
                            {
                                option_border.BorderThickness = new Thickness(0, 0, 0, 1);
                                option_border.BorderBrush     = new SolidColorBrush(Color.FromArgb(50, 0, 0, 0));
                                TextBlock option_txt = new TextBlock();
                                option_txt.Text              = stuff_text[t];
                                option_txt.Foreground        = new SolidColorBrush(Color.FromArgb(150, 0, 0, 0));
                                option_txt.FontSize          = 15;
                                option_txt.Margin            = new Thickness(10, 0, 0, 0);
                                option_txt.VerticalAlignment = VerticalAlignment.Center;
                                // Button button = new Button();
                                link[i, t] = new HyperlinkButton();

                                //HyperlinkButton[] link = new HyperlinkButton[tests_row];
                                link[i, t].Content = option_txt.Text;
                                // link.Click = RoutedEventHandler.Combine(sender, RoutedEventArgs e);
                                //button.ClickMode = ClickMode.Hover;
                                //CLICK EVENT
                                int reduce_t = t;
                                if (t == stuff_text.Length)
                                {
                                    reduce_t = t - 1;
                                }
                                //link[i].Click += new RoutedEventHandler(EditRecord_Click("E",));
                                link[i, t].Click += (s, e) =>
                                {
                                    if ((string)link[reduce, reduce_t].Content == stuff_text[0])
                                    {//IT's edit
                                        tracker = new EditTracker("items", "item_id", item_id.Results[(reduce), 0]);
                                        //track the row.
                                        tracker.Track();

                                        Auth auth = new Auth();
                                        if (auth.CheckOwner("Items", "item_id", item_id.Results[reduce, 0]) != true)
                                        {
                                            PopUp p = new PopUp("Sorry, You can't edit Item " + tracker.TrackResult[1] + "'s record cause you didn't add the record");
                                        }

                                        else
                                        {
                                            if (!Editing.IsOpen)
                                            {
                                                //OPEN
                                                this.Frame.Opacity = .4;

                                                //this.Opacity = .4;
                                                parent.IsEnabled = false;
                                                //SET THE EDIT TRACKER
                                                //I DID (i-1) BECAUSE IT WAS INCREASE BY ONE, THEREFORE OUT OF BOUND ISH.
                                                this.i_id         = tracker.TrackResult[0];//set the id to the global var, so that we know what to edit.
                                                i_name_e.Text     = tracker.TrackResult[1];
                                                i_cost_e.Text     = tracker.TrackResult[2];
                                                i_quantity_e.Text = tracker.TrackResult[3];

                                                Editing.IsOpen = true;
                                            }
                                        }
                                    }
                                    else if ((string)link[reduce, reduce_t].Content == stuff_text[1])
                                    {//it's the delete.
                                        tracker = new EditTracker("items", "item_id", item_id.Results[(reduce), 0]);
                                        //track the row
                                        tracker.Track();

                                        Auth auth = new Auth();
                                        if (auth.CheckOwner("Items", "item_id", item_id.Results[reduce, 0]) != true)
                                        {
                                            PopUp p = new PopUp("Sorry, You can't delete this item's record cause you didn't add the record");
                                        }
                                        else
                                        {
                                            this.Frame.Opacity = .4;

                                            //this.Opacity = .4;
                                            parent.IsEnabled = false;

                                            Messages msg = new Messages();
                                            msg.Confirm("Are you sure you want to delete this item's record?");
                                            msg.p_container.IsOpen = true;
                                            parent_grid.Children.Add(msg.p_container);

                                            msg.TrueBtn.Click += (z, x) =>
                                            {
                                                //CALL THE DELETE QUERY
                                                Query que = new Query();
                                                que.successMessage = "Item " + tracker.TrackResult[1] + " with id(" + tracker.TrackResult[0] + ") has been deleted.";

                                                que.Remove("Items", "Where item_id = '" + item_id.Results[(reduce), 0] + "'");
                                                this.Frame.Opacity = 1;

                                                this.Frame.Navigate(typeof(Items), null);
                                            };

                                            msg.FalseBtn.Click += (z, x) =>
                                            {
                                                this.Frame.Opacity = 1;

                                                parent.IsEnabled = true;
                                            };
                                        }
                                    }
                                };

                                ////ADDING
                                option_inner_panel.Children.Add(link[i, t]);
                            }
                            option_panel.Children.Add(option_inner_panel);
                            option_inner_panel.Orientation = Orientation.Horizontal;
                            option_panel.VerticalAlignment = VerticalAlignment.Center;
                            option_border.Child            = option_panel;
                            Grid.SetColumn(option_border, k);
                            Grid.SetRow(option_border, i + 1);
                            items_r.Children.Add(option_border);
                        }

                        else
                        {
                            Grid.SetRow(row_holder, i + 1);

                            Grid.SetColumn(row_holder, k);
                            items_r.Children.Add(row_holder);
                        }
                    }
                }
            }
            else
            {
                //NO RECORD
                Messages msg = new Messages();
                msg.Note("No items record available.");
                items_r.Children.Add(msg._b_Container);
                RowDefinition rd = new RowDefinition();
                // rd.Height = new GridLength(50);
                items_r.RowDefinitions.Add(rd);
                Grid.SetColumnSpan(msg._b_Container, col_num);
                Grid.SetColumn(msg._b_Container, 0);
                Grid.SetRow(msg._b_Container, 1);
            }
        }