private static void PrinterWithScaling(PrintPage obj)
        {

            PrintDialog printDlg = new System.Windows.Controls.PrintDialog();

            if (printDlg.ShowDialog() == true)
            {

                //get selected printer capabilities

                System.Printing.PrintCapabilities capabilities = printDlg.PrintQueue.GetPrintCapabilities(printDlg.PrintTicket);



                //get scale of the print wrt to screen of WPF visual

                double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / obj.print_form.ActualWidth, capabilities.PageImageableArea.ExtentHeight /

                               obj.print_form.ActualHeight);



                //Transform the Visual to scale

                obj.print_form.LayoutTransform = new ScaleTransform(scale, scale);



                //get the size of the printer page

                Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);



                //update the layout of the visual to the printer page size.

                obj.print_form.Measure(sz);

                obj.print_form.Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));



                //now print the visual to printer to fit on the one page.

                printDlg.PrintVisual(obj.print_form, "First Fit to Page WPF Print");



            }
        }
        private static void printPage2(PrintPage obj)
        {
            PrintDialog prnt = new PrintDialog();
            if (prnt.ShowDialog() == true)
            {
                Size pageSize = new Size(prnt.PrintableAreaWidth - 30, prnt.PrintableAreaHeight - 30);

                obj.print_form.Measure(pageSize);
                obj.print_form.Arrange(new Rect(15, 15, pageSize.Width, pageSize.Height));
                prnt.PrintVisual(obj.print_form, "Work Request");
            }
        }
        private int printAllInfoAndSaveInDatabase()
        {
            long _id =0;

            if(testCount == 0)
            {

                MessageBox.Show("You didn't add any test yet","MDC",MessageBoxButton.OK,MessageBoxImage.Error);
                return 0;
            }

            // PrintPage obj = print_page();
            PrintPage obj = new PrintPage();



            _id = printBillIDGenerator(_id) + 1;






            obj.print_bill_id.Text = _id.ToString();
            obj.print_name.Text = name_textfield.Text;
            obj.print_age.Text = age_textbox.Text;
            obj.print_date.Text = DateTime.Now.ToString("dd/MM/yyyy");
            obj.print_time.Text = DateTime.Now.ToString("hh:mm:ss tt");
            obj.print_refd_by.Text = doctor_textfield.Text;
            obj.print_delivery_date.Text = home_datepicker.Text;
            obj.print_phone_no.Text = phone_textbox.Text;
            obj.print_dayofweek.Text = DateTime.Today.DayOfWeek.ToString();
            //obj.print_test_textblock.Text = name_textfield.Text;
            obj.print_sex_textblock.Text = home_sex_combobox.Text;
            
            //test name and price
            /*obj.print_test_name_1.Text = combo_box.Text;
            obj.print_amount_1.Text = test_cost_textfield.Text;

            obj.print_test_name_2.Text = combo_box.Text;
            obj.print_amount_2.Text = test_cost_textfield.Text;

            obj.print_test_name_3.Text = combo_box.Text;
            obj.print_amount_3.Text = test_cost_textfield.Text;

            obj.print_test_name_4.Text = combo_box.Text;
            obj.print_amount_4.Text = test_cost_textfield.Text;

            obj.print_test_name_5.Text = combo_box.Text;
            obj.print_amount_5.Text = test_cost_textfield.Text;
            */



            SaveTestNameAndPrice(_id, obj);

            // PrinterWithScaling(obj);

            //obj.print_sub_total.Text = sumTestCost.ToString();
            //obj.print_discount.Text = sumDiscount.ToString();


            obj.print_sub_total.Text =  net_cost_textfield.Text;
            obj.print_discount.Text =   discount_textfield.Text;



            //int netPayable = sumTestCost - sumDiscount;


            int netPayable = int.Parse(net_cost_textfield.Text) - int.Parse(discount_textfield.Text);

            obj.print_net_total.Text = netPayable.ToString();

            obj.print_ammount_receive.Text =  paid_textbox.Text;

            //obj.print_due.Text = sumDue.ToString();

            string _due = (netPayable - int.Parse(paid_textbox.Text)).ToString();

            obj.print_due.Text = _due;


            TotalCostSave(_id, _due);




           

            obj.Show();
            obj.Close();
            printPage2(obj);
            SaveInDatabase(_due);
            ClearFormData();

             index = 0;
             sumTestCost = 0;
             sumDiscount = 0;
             sumDue = 0;
             sumPaid = 0;

            return 1;
        }
        private void SaveTestNameAndPrice(long _id, PrintPage obj)
        {

            string dbConnectionString = @"Data Source=patient.db;Version=3;";
            SQLiteConnection sqlite_connection = new SQLiteConnection(dbConnectionString);

            try
            {
                sqlite_connection.Open();
                //all test information for printing

                TextBlock[] printSerialNo = { obj.print_no_1, obj.print_no_2, obj.print_no_3, obj.print_no_4, obj.print_no_5, obj.print_no_6, obj.print_no_7, obj.print_no_8, obj.print_no_9, obj.print_no_10 };
                TextBlock[] printTestName = { obj.print_test_name_1, obj.print_test_name_2, obj.print_test_name_3, obj.print_test_name_4, obj.print_test_name_5, obj.print_test_name_6, obj.print_test_name_7, obj.print_test_name_8, obj.print_test_name_9, obj.print_test_name_10 };
                TextBlock[] printTestPrice = { obj.print_amount_1, obj.print_amount_2, obj.print_amount_3, obj.print_amount_4, obj.print_amount_5, obj.print_amount_6, obj.print_amount_7, obj.print_amount_8, obj.print_amount_9, obj.print_amount_10 };
                //file read from output.txt


                string line;
                using (StreamReader file = new StreamReader("output.txt"))
                    //while((line = file.ReadLine()) != null )
                    for (int i = 0; i < testCount; i++)
                    {

                        int cost, due, discount, paid;

                        printSerialNo[i].Text = (i + 1).ToString();
                        string test_name = file.ReadLine(); // test name read from file
                        printTestName[i].Text = test_name;

                        //read test cost as string and convert it to int and save it for calculation
                        line = file.ReadLine();// read test cost
                        cost = int.Parse(line);
                        printTestPrice[i].Text = line;

                        //read due cost as string and convert it to int and save it for calculation
                        line = file.ReadLine();
                        //  due = int.Parse(line);

                        line = file.ReadLine();
                        // discount = int.Parse(line);

                        line = file.ReadLine();
                        //  paid = int.Parse(line);


                        //sumTestCost += cost;
                        //sumDue += due;
                        //sumDiscount += discount;
                        //sumPaid += paid;

                        //This is file data serial
                        //combo_box.Text = "";
                        //test_cost_textfield.Text = "";
                        //due_textfield.Text = "";
                        //discount_textfield.Text = "";
                        //paid_textbox.Text = "";

                        //dummy line
                        //line = file.ReadLine();
                        //line = file.ReadLine();
                        //line = file.ReadLine();
                        //index++;



                        string query = "INSERT INTO test_id_cost (_id,cost,name)   VALUES('" + _id.ToString() + "','" + cost.ToString() + "','" + test_name + "')";

                        SQLiteCommand create_command = new SQLiteCommand(query, sqlite_connection);
                        create_command.ExecuteNonQuery();
                    }



                sqlite_connection.Close();
                //MessageBox.Show("Successfully saved in database");

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void printAllInfoAndSaveInDatabase()
        {

            // PrintPage obj = print_page();
            PrintPage obj = new PrintPage();

            obj.print_name.Text = name_textfield.Text;
            obj.print_age.Text = age_textbox.Text;
            obj.print_date.Text = DateTime.Now.ToString("dd/MM/yyyy");
            obj.print_time.Text = DateTime.Now.ToString("hh:mm:ss tt");
            obj.print_refd_by.Text = doctor_textfield.Text;
            obj.print_delivery_date.Text = home_datepicker.Text;
            obj.print_phone_no.Text = phone_textbox.Text;
            obj.print_dayofweek.Text = DateTime.Today.DayOfWeek.ToString();
            //obj.print_test_textblock.Text = name_textfield.Text;
            obj.print_sex_textblock.Text = home_sex_combobox.Text;
            //test name and price
            obj.print_test_name_1.Text = combo_box.Text;
            obj.print_amount_1.Text = test_cost_textfield.Text;

            obj.print_test_name_2.Text = combo_box.Text;
            obj.print_amount_2.Text = test_cost_textfield.Text;

            obj.print_test_name_3.Text = combo_box.Text;
            obj.print_amount_3.Text = test_cost_textfield.Text;

            obj.print_test_name_4.Text = combo_box.Text;
            obj.print_amount_4.Text = test_cost_textfield.Text;

            obj.print_test_name_5.Text = combo_box.Text;
            obj.print_amount_5.Text = test_cost_textfield.Text;

            // PrinterWithScaling(obj);
            obj.Show();
            obj.Close();
            printPage2(obj);
            SaveInDatabase();
        }