示例#1
0
        private void Tree_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (e.Node.Text == "Nupp-Button")
            {
                this.Controls.Add(btn);
            }
            else if (e.Node.Text == "Silt-Label")
            {
                this.Controls.Add(lbl);
            }
            else if (e.Node.Text == "Markeruut-CheckBox")
            {
                box_btn          = new CheckBox();
                box_btn.Text     = "Näita nupp";
                box_btn.Location = new Point(200, 30);
                this.Controls.Add(box_btn);
                box_btn.CheckedChanged += Box_btn_CheckedChanged;

                box_lbl          = new CheckBox();
                box_lbl.Text     = "Näita silt";
                box_lbl.Location = new Point(200, 70);
                this.Controls.Add(box_lbl);
                box_lbl.CheckedChanged += Box_lbl_CheckedChanged;
            }
            else if (e.Node.Text == "Radionupp-Radiobutton")
            {
                r1                 = new RadioButton();
                r1.Text            = "nupp vasakule";
                r1.Location        = new Point(300, 30);
                r1.CheckedChanged += new EventHandler(RadioButton_Changed);
                r2                 = new RadioButton();
                r2.Text            = "nupp paremale";
                r2.Location        = new Point(300, 70);
                r2.CheckedChanged += new EventHandler(RadioButton_Changed);


                this.Controls.Add(r1);
                this.Controls.Add(r2);
            }
            else if (e.Node.Text == "Tekstast-TextBox")
            {
                string text_file;
                try
                {
                    StreamReader from_file = new StreamReader(@"C:\Users\Game\RiderProjects\FormsApp\FormsApp\bin\Debug\file.txt");
                    text_file = from_file.ReadToEnd();
                }
                catch (DirectoryNotFoundException)
                {
                    text_file = "Fail puudub";
                }
                textbox           = new TextBox();
                textbox.Multiline = true;
                textbox.Text      = text_file;
                textbox.Location  = new Point(300, 300);
                textbox.Width     = 200;
                textbox.Height    = 200;
                Controls.Add(textbox);
            }
            else if (e.Node.Text == "PictureBox-Pildikast")
            {
                pic_box             = new PictureBox();
                pic_box.Image       = new Bitmap("pict.png");
                pic_box.Location    = new Point(450, 10);
                pic_box.Size        = new Size(100, 100);
                pic_box.SizeMode    = PictureBoxSizeMode.Zoom;
                pic_box.BorderStyle = BorderStyle.FixedSingle;

                this.Controls.Add(pic_box);
            }
            else if (e.Node.Text == "Kaart-TabControl")
            {
                tabControl          = new TabControl();
                tabControl.Location = new Point(350, 150);
                tabControl.Size     = new Size(150, 100);
                page1           = new TabPage("Esimene");
                page2           = new TabPage("Teine");
                page3           = new TabPage("Kolmas");
                page1.BackColor = Color.Red;
                page2.BackColor = Color.Blue;
                page3.BackColor = Color.Yellow;

                tabControl.Controls.Add(page1);
                tabControl.Controls.Add(page2);
                tabControl.Controls.Add(page3);


                string inpu = Interaction.InputBox("");
                if (inpu == "1")
                {
                    tabControl.SelectedIndex = 0;
                    //tabControl.SelectedTab = this.page1;
                }
                else if (inpu == "2")
                {
                    tabControl.SelectedIndex = 1;
                    //tabControl.SelectedTab = this.page2;
                }
                else if (inpu == "3")
                {
                    tabControl.SelectedIndex = 2;
                    //tabControl.SelectedTab = this.page3;
                }

                this.Controls.Add(tabControl);
            }
            else if (e.Node.Text == "MessageBox")
            {
                MessageBox.Show("MesageBox", "Kõige lithsam aken");

                var anwser = MessageBox.Show("Tahad InputBoxi näha?", "Aken koos nupuga", MessageBoxButtons.YesNo);

                if (anwser == DialogResult.Yes)
                {
                    string inpu = Interaction.InputBox("Sisesta siia mingi tekst", "InputBox", "Mingi tekst");
                    if (MessageBox.Show("Kas tahad tekst saada Tekskatisse?", "Teksti salvestamine", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        lbl.Text = inpu;
                        this.Controls.Add(lbl);
                    }
                }
            }
            else if (e.Node.Text == "ListBox")
            {
                string[] colors_nim = new string [] { "Sinine", "Kollane", "Roheline", "Punane" };

                lbox = new ListBox();
                int sizeOfList;
                int maxLength;
                maxLength = colors_nim.Select(x => x.Length).Max();
                foreach (var item in colors_nim)
                {
                    lbox.Items.Add(item);
                }

                sizeOfList    = colors_nim.Length;
                lbox.Click   += Lbox_Click;
                lbox.Location = new Point(150, 300);
                lbox.Width    = maxLength * 10;
                lbox.Height   = sizeOfList * 15;

                Controls.Add(lbox);
            }
            else if (e.Node.Text == "DataGridView")
            {
                DataSet dataSet = new DataSet("Näide");
                dataSet.ReadXml("..//..Files//XMLFile1.xml");
                DataGridView dgv = new DataGridView();
                dgv.Location            = new Point(200, 200);
                dgv.Width               = 250;
                dgv.Height              = 250;
                dgv.AutoGenerateColumns = true;
                dgv.DataMember          = "CATALOG";
                dgv.DataSource          = dataSet;
                Controls.Add(dgv);
            }
            else if (e.Node.Text == "Menu")
            {
                MainMenu menu      = new MainMenu();
                MenuItem menuItem1 = new MenuItem("File");
                menuItem1.MenuItems.Add("Exit", new EventHandler(menuItem1_Exit));

                MenuItem menuItem = new MenuItem("My");
                menuItem.MenuItems.Add("BagroundColor", new EventHandler(menuItem_backColor));

                menuItem.MenuItems.Add("TreeView Color", new EventHandler(menuItem_treeColor));

                menuItem.MenuItems.Add("TreeView Bottom", new EventHandler(menuItem_treeBottom));


                menu.MenuItems.Add(menuItem1);
                menu.MenuItems.Add(menuItem);

                this.Menu = menu;
            }
        }
示例#2
0
      private void btnSend_Click(object sender, EventArgs e)
      {
          sqlcmd.CommandText = "INSERT into Invoice (PaymentDate, Type, Description, Total, Status) VALUES (@txtPaymentDate, @txtType, @txtDescription, @txtTotal, @txtStatus)";
          sqlcmd.Parameters.AddWithValue("@txtPaymentDate", lbDate.Text);
          sqlcmd.Parameters.AddWithValue("@txtType", ddType.Text);
          sqlcmd.Parameters.AddWithValue("@txtDescription", txtDesc.Text);
          sqlcmd.Parameters.AddWithValue("@txtTotal", txtTotal.Text);
          sqlcmd.Parameters.AddWithValue("@txtStatus", ddStatus.Text);

          try
          {
              sqlconn.Open();
              int recordsAffected = sqlcmd.ExecuteNonQuery();
              if (recordsAffected > 0)
              {
                  MessageBox.Show("DONE", "Congrats", MessageBoxButtons.OK, MessageBoxIcon.Information);
                  this.Hide();
                  MainMenu mainMenu = new MainMenu();
                  mainMenu.Closed += (s, args) => this.Close();
                  mainMenu.Show();
              }
          }
          catch (SqlException)
          {
              MessageBox.Show("Error Creating New Invoice", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
          }
          finally
          {
              sqlconn.Close();
          }

          try
          {
              MailMessage mail       = new MailMessage();
              SmtpClient  SmtpServer = new SmtpClient("smtp.gmail.com");

              mail.From = new MailAddress("*****@*****.**");
              mail.To.Add(oldEmail);
              mail.Subject = "Invoice";

              mail.IsBodyHtml = true;
              mail.Body       = "<style type=\"text/css\">" +
                                ".tg  {border-collapse:collapse;border-spacing:0;}" +
                                ".tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;}" +
                                ".tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;}" +
                                ".tg .tg-0lax{text-align:left;vertical-align:top}" +
                                "</style>" +
                                "<table class=\"tg\">" +
                                "  <tr>" +
                                "    <th class=\"tg-0lax\">Invoice Number</th>" +
                                "    <th class=\"tg-0lax\">" + lbInvoiceNumber.Text + "</th>" +
                                "  </tr>" +
                                "  <tr>" +
                                "    <td class=\"tg-0lax\">Payment Date</td>" +
                                "    <td class=\"tg-0lax\">" + lbDate.Text + "</td>" +
                                "  </tr>" +
                                "  <tr>" +
                                "    <td class=\"tg-0lax\">Type</td>" +
                                "    <td class=\"tg-0lax\">" + ddType.Text + "</td>" +
                                "  </tr>" +
                                "  <tr>" +
                                "    <td class=\"tg-0lax\">Description</td>" +
                                "    <td class=\"tg-0lax\">" + txtDesc.Text + "</td>" +
                                "  </tr>" +
                                "  <tr>" +
                                "    <td class=\"tg-0lax\">Total</td>" +
                                "    <td class=\"tg-0lax\">" + txtTotal.Text + "</td>" +
                                "  </tr>" +
                                "  <tr>" +
                                "    <td class=\"tg-0lax\">Status</td>" +
                                "    <td class=\"tg-0lax\">" + ddStatus.Text + "</td>" +
                                "  </tr>" +
                                "</table>";
              SmtpServer.Port        = 587;
              SmtpServer.Credentials = new System.Net.NetworkCredential("htmangmt", "H0tel4901");
              SmtpServer.EnableSsl   = true;

              SmtpServer.Send(mail);

              MessageBox.Show("Email Sent", "Congrats", MessageBoxButtons.OK, MessageBoxIcon.Information);

              this.Hide();
              MainMenu mainMenu = new MainMenu();
              mainMenu.Closed += (s, args) => this.Close();
              mainMenu.Show();
          }
          catch (Exception ex)
          {
              MessageBox.Show(ex.ToString());
          }
      }