From Mammoth Mockingbird, 1 Week ago, written in VB.NET.
Embed
  1. Imports System.Data.SqlClient
  2. Imports System.IO
  3.  
  4. Public Class Main
  5.     Dim SQL As New SQL_Connection
  6.     Dim clog As New clslogin
  7.     Private BGImgs As Image()
  8.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  9.         'BGImgs = New Image() {
  10.         '                My.Resources.minimize_white_32, '0
  11.         '                My.Resources.maximize_white_32, ' 1
  12.         '                My.Resources.server_connection_blue_64, ' 2
  13.         '                My.Resources.server_connection_red_64, '3
  14.         '                My.Resources.card_1_64, ' 4
  15.         '                My.Resources.Facebook_white_55, ' 5
  16.         '                My.Resources.Facebook_blue_55, '6
  17.         '                My.Resources.Twitter_Blue_55, ' 7
  18.         '                My.Resources.Twitter_White_55, '8
  19.         '                My.Resources.Email_Green_55,'9
  20.         '                My.Resources.Email_white_55, '10
  21.         '                My.Resources.card_64 '11
  22.         '              }
  23.         Control.CheckForIllegalCrossThreadCalls = False
  24.         Me.Top = 0
  25.         Me.Left = 0
  26.         Me.Height = Screen.PrimaryScreen.WorkingArea.Height
  27.         Me.Width = Screen.PrimaryScreen.WorkingArea.Width
  28.         dx = My.Computer.Screen.Bounds.Width
  29.         dy = My.Computer.Screen.Bounds.Height
  30.         SQL.Connection()
  31.         autoS()
  32.         Timer2.Start() ' this timer for the clock
  33.  
  34.         user_txt.AutoCompleteMode = AutoCompleteMode.SuggestAppend
  35.         user_txt.AutoCompleteSource = AutoCompleteSource.CustomSource
  36.         Dim DataCollection As New AutoCompleteStringCollection()
  37.         getData(DataCollection)
  38.         user_txt.AutoCompleteCustomSource = DataCollection
  39.         username_txt.Text = username_txt.Text
  40.  
  41.         day_txt.Text = DateAndTime.Day(Now)
  42.         month_txt.Text = DateTime.Today.ToString("MMMM")
  43.         user_txt.Select()
  44.         Me.Opacity = 0.98
  45.     End Sub
  46.  
  47.     Private Sub FadingForm()
  48.         Dim iCount As Integer
  49.         For iCount = 90 To 10 Step -10
  50.             Me.Opacity = iCount / 100
  51.             Me.Refresh()
  52.             Threading.Thread.Sleep(50)
  53.         Next
  54.         Me.Close()
  55.     End Sub
  56.  
  57.     Private Sub getData(ByVal dataCollection As AutoCompleteStringCollection)
  58.  
  59.         Dim adapter As New SqlDataAdapter()
  60.         Dim ds As New DataSet()
  61.         ' Dim sql As String = "SELECT DISTINCT [fname] FROM [employee]"
  62.         Try
  63.             Dim cmd As New SqlCommand
  64.             'فحص الاتصال بقاعدة البيانات
  65.             If SQL.conn.State = ConnectionState.Open Then
  66.                 SQL.conn.Close()
  67.             End If
  68.             SQL.conn.Open()
  69.             cmd.Connection = SQL.conn
  70.             cmd.CommandType = CommandType.Text
  71.             cmd.CommandText = "SELECT DISTINCT [uname] FROM [users]"
  72.  
  73.             adapter.SelectCommand = cmd
  74.             adapter.Fill(ds)
  75.             adapter.Dispose()
  76.             cmd.Dispose()
  77.             SQL.conn.Close()
  78.             For Each row As DataRow In ds.Tables(0).Rows
  79.                 dataCollection.Add(row(0).ToString())
  80.             Next
  81.         Catch ex As Exception
  82.             MessageBox.Show("Can not open connection ! ")
  83.         End Try
  84.     End Sub
  85.  
  86.     Private Sub unlocked_but_Click(sender As Object, e As EventArgs) Handles unlocked_but.Click
  87.         locked_but.Visible = True
  88.         unlocked_but.Visible = False
  89.         butt_panel.Visible = False
  90.         Lpassword_txt.Text = ""
  91.         Login_Panel.Visible = True
  92.         username_txt.Text = ""
  93.         user_Panel.Visible = False
  94.         date_Panel.Visible = False
  95.     End Sub
  96.  
  97.     '//////////////////////////////// Bar Buttons START////////////////////////////////////
  98.     Private Sub close_butt_Click(sender As Object, e As EventArgs) Handles close_butt.Click
  99.         Me.Close()
  100.     End Sub
  101.     Private Sub close_butt_MouseEnter(sender As Object, e As EventArgs) Handles close_butt.MouseEnter
  102.         close_butt.BackColor = Color.Red
  103.     End Sub
  104.     Private Sub close_butt_MouseLeave(sender As Object, e As EventArgs) Handles close_butt.MouseLeave
  105.         close_butt.BackColor = Nothing
  106.     End Sub
  107.     Private Sub MinimizeWindow_butt_Click(sender As Object, e As EventArgs) Handles MinimizeWindow_butt.Click
  108.         Me.WindowState = FormWindowState.Minimized
  109.     End Sub
  110.  
  111.     Private Sub MinimizeWindow_butt_MouseEnter(sender As Object, e As EventArgs) Handles MinimizeWindow_butt.MouseEnter
  112.         MinimizeWindow_butt.BackColor = Color.MediumSeaGreen
  113.     End Sub
  114.     Private Sub MinimizeWindow_butt_MouseLeave(sender As Object, e As EventArgs) Handles MinimizeWindow_butt.MouseLeave
  115.         MinimizeWindow_butt.BackColor = Nothing
  116.     End Sub
  117.     Private Sub maximaize_butt_MouseEnter(sender As Object, e As EventArgs) Handles maximaize_butt.MouseEnter
  118.         If Me.Top = 0 And Me.Left = 0 And Me.Height = Screen.PrimaryScreen.WorkingArea.Height And Me.Width = Screen.PrimaryScreen.WorkingArea.Width Then
  119.             ''maximaize_butt.Image = BGImgs(0)
  120.             maximaize_butt.BackColor = Color.MediumSeaGreen
  121.         ElseIf Me.WindowState = FormWindowState.Normal Then
  122.             ''maximaize_butt.Image = BGImgs(1)
  123.             maximaize_butt.BackColor = Color.MediumSeaGreen
  124.         End If
  125.     End Sub
  126.  
  127.     Private Sub maximaize_butt_MouseLeave(sender As Object, e As EventArgs) Handles maximaize_butt.MouseLeave
  128.         If Me.Top = 0 And Me.Left = 0 And Me.Height = Screen.PrimaryScreen.WorkingArea.Height And Me.Width = Screen.PrimaryScreen.WorkingArea.Width Then
  129.             ''maximaize_butt.Image = BGImgs(0)
  130.             maximaize_butt.BackColor = Nothing
  131.         ElseIf Me.WindowState = FormWindowState.Normal Then
  132.             ''maximaize_butt.Image = BGImgs(1)
  133.             maximaize_butt.BackColor = Nothing
  134.         End If
  135.     End Sub
  136.     Dim dx, dy As Integer
  137.     Private Sub maximaize_butt_Click(sender As Object, e As EventArgs) Handles maximaize_butt.Click
  138.         If Me.Top = 0 And Me.Left = 0 And Me.Height = Screen.PrimaryScreen.WorkingArea.Height And Me.Width = Screen.PrimaryScreen.WorkingArea.Width Then
  139.             'Me.WindowState = FormWindowState.Normal
  140.             Me.Height = 750
  141.             Me.Width = 1000
  142.             ''maximaize_butt.Image = BGImgs(1)
  143.             Dim x, y As Integer
  144.             x = Me.Width / 2
  145.             y = Me.Height / 2
  146.             Me.Location = New Point(dx / 2 - x, dy / 2 - y)
  147.         Else
  148.             Me.Top = 0
  149.             Me.Left = 0
  150.             Me.Height = Screen.PrimaryScreen.WorkingArea.Height
  151.             Me.Width = Screen.PrimaryScreen.WorkingArea.Width
  152.             ''maximaize_butt.Image = BGImgs(0)
  153.         End If
  154.     End Sub
  155.     '//////////////////////////////// Bar Buttons END ////////////////////////////////////
  156.     '+++++++++++++++++++++++++ Moving the form from uper panel START ++++++++++++++++++'
  157.     Private mouseOffset As Point
  158.     Private Sub uperpanel_MouseDown(sender As Object, e As MouseEventArgs) Handles uperpanel.MouseDown
  159.         mouseOffset = New Point(-e.X, -e.Y)
  160.     End Sub
  161.     Private Sub uperpanel_MouseMove(sender As Object, e As MouseEventArgs) Handles uperpanel.MouseMove
  162.         If e.Button = MouseButtons.Left Then
  163.             Dim mousePos As Point = Control.MousePosition
  164.             mousePos.Offset(mouseOffset.X, mouseOffset.Y)
  165.             Location = mousePos
  166.             Me.Height = 750
  167.             Me.Width = 1000
  168.             ''maximaize_butt.Image = BGImgs(1)
  169.         End If
  170.     End Sub
  171.     '+++++++++++++++++++++++++ Moving the form from uper panel END ++++++++++++++++++'
  172.  
  173.     '//////////////////////////////// MAIN Buttons START////////////////////////////////////
  174.     Private Sub customers_button_MouseEnter(sender As Object, e As EventArgs) Handles customers_button.MouseEnter
  175.         customers_button.Visible = False
  176.         customers_button1.Visible = True
  177.         Customers_Panel.Visible = True
  178.     End Sub
  179.     Private Sub customers_button1_MouseLeave(sender As Object, e As EventArgs) Handles customers_button1.MouseLeave
  180.         customers_button.Visible = True
  181.         customers_button1.Visible = False
  182.         Customers_Panel.Visible = False
  183.     End Sub
  184.  
  185.     Private Sub Store_button_MouseEnter(sender As Object, e As EventArgs) Handles Store_button.MouseEnter
  186.         Store_button.Visible = False
  187.         Store_button1.Visible = True
  188.         Stores_Panel.Visible = True
  189.     End Sub
  190.  
  191.     Private Sub Store_button1_MouseLeave(sender As Object, e As EventArgs) Handles Store_button1.MouseLeave
  192.         Store_button.Visible = True
  193.         Store_button1.Visible = False
  194.         Stores_Panel.Visible = False
  195.     End Sub
  196.  
  197.     Private Sub contract_button_MouseEnter(sender As Object, e As EventArgs) Handles contract_button.MouseEnter
  198.         contract_button.Visible = False
  199.         contract_button1.Visible = True
  200.         contracts_Panel.Visible = True
  201.     End Sub
  202.     Private Sub contract_button1_MouseLeave(sender As Object, e As EventArgs) Handles contract_button1.MouseLeave
  203.         contract_button.Visible = True
  204.         contract_button1.Visible = False
  205.         contracts_Panel.Visible = False
  206.     End Sub
  207.     Private Sub Payments_button_MouseEnter(sender As Object, e As EventArgs) Handles Payments_button.MouseEnter
  208.         Payments_button.Visible = False
  209.         Payments_button1.Visible = True
  210.         Payments_Panel.Visible = True
  211.     End Sub
  212.     Private Sub Payments_button1_MouseLeave(sender As Object, e As EventArgs) Handles Payments_button1.MouseLeave
  213.         Payments_button.Visible = True
  214.         Payments_button1.Visible = False
  215.         Payments_Panel.Visible = False
  216.     End Sub
  217.     Private Sub Cheque_button_MouseEnter(sender As Object, e As EventArgs) Handles Cheque_button.MouseEnter
  218.         Cheque_button.Visible = False
  219.         Cheque_button1.Visible = True
  220.         Cheque_Panel.Visible = True
  221.     End Sub
  222.     Private Sub Cheque_button1_MouseLeave(sender As Object, e As EventArgs) Handles Cheque_button1.MouseLeave
  223.         Cheque_button.Visible = True
  224.         Cheque_button1.Visible = False
  225.         Cheque_Panel.Visible = False
  226.     End Sub
  227.     Private Sub Employees_button_MouseEnter(sender As Object, e As EventArgs) Handles Employees_button.MouseEnter
  228.         Employees_button.Visible = False
  229.         Employees_button1.Visible = True
  230.         Employees_Panel.Visible = True
  231.     End Sub
  232.     Private Sub Employees_button1_MouseLeave(sender As Object, e As EventArgs) Handles Employees_button1.MouseLeave
  233.         Employees_button.Visible = True
  234.         Employees_button1.Visible = False
  235.         Employees_Panel.Visible = False
  236.     End Sub
  237.     Private Sub Expenses_button_MouseEnter(sender As Object, e As EventArgs) Handles Expenses_button.MouseEnter
  238.         Expenses_button.Visible = False
  239.         Expenses_button1.Visible = True
  240.         Expenses_Panel.Visible = True
  241.     End Sub
  242.     Private Sub Expenses_button1_MouseLeave(sender As Object, e As EventArgs) Handles Expenses_button1.MouseLeave
  243.         Expenses_button.Visible = True
  244.         Expenses_button1.Visible = False
  245.         Expenses_Panel.Visible = False
  246.     End Sub
  247.     Private Sub Money_button_MouseEnter(sender As Object, e As EventArgs) Handles Money_button.MouseEnter
  248.         Money_button.Visible = False
  249.         Money_button1.Visible = True
  250.         Money_Panel.Visible = True
  251.     End Sub
  252.     Private Sub Money_button1_MouseLeave(sender As Object, e As EventArgs) Handles Money_button1.MouseLeave
  253.         Money_button.Visible = True
  254.         Money_button1.Visible = False
  255.         Money_Panel.Visible = False
  256.     End Sub
  257.     Private Sub Diagrams_button_MouseEnter(sender As Object, e As EventArgs) Handles Diagrams_button.MouseEnter
  258.         Diagrams_button.Visible = False
  259.         Diagrams_button1.Visible = True
  260.         Diagrams_Panel.Visible = True
  261.     End Sub
  262.     Private Sub Diagrams_button1_MouseLeave(sender As Object, e As EventArgs) Handles Diagrams_button1.MouseLeave
  263.         Diagrams_button.Visible = True
  264.         Diagrams_button1.Visible = False
  265.         Diagrams_Panel.Visible = False
  266.     End Sub
  267.  
  268.     '//////////////////////////////// MAIN Buttons END ////////////////////////////////////
  269.  
  270.     '//////////////////////////////// Connection Panel Start ///////////////////////////////////
  271.     Private Sub Checkbox1_OnChange(sender As Object, e As EventArgs) Handles Checkbox1.OnChange
  272.         Checkbox1.Checked = True
  273.         Checkbox2.Checked = False
  274.         Label_WA.ForeColor = Color.Lime
  275.         Label_SA.ForeColor = Color.White
  276.         ID_txt.Enabled = False
  277.         Password_txt.Enabled = False
  278.         Password_txt.Text = ""
  279.         Save_butt.Enabled = True
  280.         'Save_butt.Image = My.Resources.Save_White_32
  281.     End Sub
  282.     Private Sub BunifuCheckbox1_OnChange(sender As Object, e As EventArgs) Handles Checkbox2.OnChange
  283.         Checkbox1.Checked = False
  284.         Checkbox2.Checked = True
  285.         Label_SA.ForeColor = Color.Lime
  286.         Label_WA.ForeColor = Color.White
  287.         ID_txt.Enabled = True
  288.         Password_txt.Enabled = True
  289.         'ID_txt.Text = ""
  290.         Password_txt.Text = ""
  291.         Save_butt.Enabled = True
  292.         'Save_butt.Image = My.Resources.Save_White_32
  293.     End Sub
  294.     Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Save_butt.Click
  295.         If MessageBox.Show("تم حفظ التغيرات،هل تريد اعادة تشغيل البرنامج لتطبيق التغيرات ؟", "أعادة تشغيل", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.No Then
  296.             Return
  297.         Else
  298.             My.Settings.server = Server_txt.Text
  299.             My.Settings.database = Database_txt.Text
  300.             If Checkbox1.Checked = True Then
  301.                 My.Settings.mode = "Windows"
  302.             Else
  303.                 My.Settings.mode = "SQL"
  304.             End If
  305.             My.Settings.ID = ID_txt.Text
  306.             My.Settings.password = Password_txt.Text
  307.             My.Settings.Save()
  308.             Application.Restart()
  309.         End If
  310.     End Sub
  311.  
  312.     Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
  313.         If connection_Panel.Width = 0 Then
  314.             Do While connection_Panel.Width < 372
  315.                 ''PictureBox1.Image = BGImgs(2)
  316.                 connection_Panel.Width = connection_Panel.Width + 3
  317.             Loop
  318.  
  319.             Server_txt.Text = My.Settings.server
  320.             Database_txt.Text = My.Settings.database
  321.             If My.Settings.mode = "SQL" Then
  322.                 Checkbox2.Checked = True
  323.                 Checkbox1.Checked = False
  324.                 Label_SA.ForeColor = Color.Lime
  325.                 Label_WA.ForeColor = Color.White
  326.                 ID_txt.Text = My.Settings.ID
  327.                 Password_txt.Text = My.Settings.password
  328.                 ID_txt.Enabled = True
  329.                 Password_txt.Enabled = True
  330.             Else
  331.                 Checkbox1.Checked = True
  332.                 Checkbox2.Checked = False
  333.                 Label_WA.ForeColor = Color.Lime
  334.                 Label_SA.ForeColor = Color.White
  335.                 'ID_txt.Text = ""
  336.                 Password_txt.Text = ""
  337.                 ID_txt.Enabled = False
  338.                 Password_txt.Enabled = False
  339.             End If
  340.             'Save_butt.Image = My.Resources.Save_Black_32
  341.             Save_butt.Enabled = False
  342.             Save_butt.FlatAppearance.BorderColor = System.Drawing.ColorTranslator.FromHtml("#333333")
  343.         ElseIf connection_Panel.Width = 372 Then
  344.             Do While connection_Panel.Width > 0
  345.                 connection_Panel.Width = connection_Panel.Width - 3
  346.                 ''PictureBox1.Image = BGImgs(17)
  347.                 Save_butt.Enabled = False
  348.                 'Save_butt.Image = My.Resources.Save_Black_32
  349.                 Save_butt.FlatAppearance.BorderColor = System.Drawing.ColorTranslator.FromHtml("#333333")
  350.             Loop
  351.  
  352.         End If
  353.     End Sub
  354.  
  355.     Private Sub PictureBox1_MouseEnter(sender As Object, e As EventArgs) Handles PictureBox1.MouseEnter
  356.         ''PictureBox1.Image = BGImgs(2)
  357.     End Sub
  358.  
  359.     Private Sub PictureBox1_MouseLeave(sender As Object, e As EventArgs) Handles PictureBox1.MouseLeave
  360.         ''PictureBox1.Image = BGImgs(3)
  361.     End Sub
  362.  
  363.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  364.         If SQL.HasConnection = True Then
  365.             MsgBox("Connected")
  366.             'Checkconn_txt.Image = My.Resources.Connected_White_32
  367.         End If
  368.     End Sub
  369.     '//////////////////////////////// Connection Panel END ////////////////////////////////////
  370.  
  371.     '//////////////////////////////// my Info Panel START ////////////////////////////////////
  372.     Private Sub info_but_MouseEnter(sender As Object, e As EventArgs) Handles info_but.MouseEnter
  373.         ''info_but.Image = BGImgs(4)
  374.     End Sub
  375.  
  376.     Private Sub Email_butt_Click(sender As Object, e As EventArgs) Handles Email_butt.Click
  377.         Process.Start("mailto:R-23@live.com")
  378.         'Open the default email client and send with a certain address and subject.
  379.         Process.Start("mailto:R-23@live.com?subject=Hello Rabeea Qabha")
  380.     End Sub
  381.     Private Sub facebook_butt_MouseLeave(sender As Object, e As EventArgs) Handles facebook_butt.MouseLeave
  382.         ''facebook_butt.Image = BGImgs(5)
  383.     End Sub
  384.  
  385.     Private Sub facebook_butt_MouseEnter(sender As Object, e As EventArgs) Handles facebook_butt.MouseEnter
  386.         ''facebook_butt.Image = BGImgs(6)
  387.     End Sub
  388.  
  389.     Private Sub Twitter_butt_MouseEnter(sender As Object, e As EventArgs) Handles Twitter_butt.MouseEnter
  390.         ''Twitter_butt.Image = BGImgs(7)
  391.     End Sub
  392.  
  393.     Private Sub Twitter_butt_MouseLeave(sender As Object, e As EventArgs) Handles Twitter_butt.MouseLeave
  394.         ''Twitter_butt.Image = BGImgs(8)
  395.     End Sub
  396.  
  397.     Private Sub Email_butt_MouseEnter(sender As Object, e As EventArgs) Handles Email_butt.MouseEnter
  398.         ''Email_butt.Image = BGImgs(9)
  399.     End Sub
  400.  
  401.     Private Sub Email_butt_MouseLeave(sender As Object, e As EventArgs) Handles Email_butt.MouseLeave
  402.         ''Email_butt.Image = BGImgs(10)
  403.     End Sub
  404.  
  405.     Private Sub facebook_butt_MouseClick(sender As Object, e As MouseEventArgs) Handles facebook_butt.MouseClick
  406.         Dim facebook As String = "https://www.facebook.com/Rabee3.Q"
  407.         Process.Start(facebook)
  408.     End Sub
  409.  
  410.     Private Sub Twitter_butt_MouseClick(sender As Object, e As MouseEventArgs) Handles Twitter_butt.MouseClick
  411.         Dim twitter As String = "https://twitter.com/23Qabha"
  412.         Process.Start(twitter)
  413.     End Sub
  414.  
  415.     Private Sub info_but_Click(sender As Object, e As EventArgs) Handles info_but.Click
  416.         If about_panel.Width = 0 Then
  417.             ''info_but.Image = BGImgs(4)
  418.             While about_panel.Width < 339
  419.                 about_panel.Width = about_panel.Width + 3
  420.             End While
  421.  
  422.             If about_panel.Width = 339 Then
  423.                 While about_panel.Height < 481
  424.                     about_panel.Height = about_panel.Height + 3
  425.                 End While
  426.             End If
  427.             Email_butt.Visible = True
  428.             Twitter_butt.Visible = True
  429.             facebook_butt.Visible = True
  430.  
  431.         ElseIf about_panel.Width = 339 Then
  432.             If about_panel.Height = 481 Then
  433.                 While about_panel.Height > 10
  434.                     about_panel.Height = about_panel.Height - 1
  435.                 End While
  436.             End If
  437.  
  438.             If about_panel.Height = 10 Then
  439.                 While about_panel.Width > 0
  440.                     about_panel.Width = about_panel.Width - 1
  441.                 End While
  442.             End If
  443.  
  444.             ''info_but.Image = BGImgs(11)
  445.             Email_butt.Visible = False
  446.             Twitter_butt.Visible = False
  447.             facebook_butt.Visible = False
  448.         End If
  449.     End Sub
  450.  
  451.     Private Sub info_but_MouseLeave(sender As Object, e As EventArgs) Handles info_but.MouseLeave
  452.         ''info_but.Image = BGImgs(11)
  453.     End Sub
  454.  
  455.     '//////////////////////////////// my Info Panel END ////////////////////////////////////
  456.  
  457.     '//////////////////////////////// Login Panel START ////////////////////////////////////
  458.     Private Sub close_pb_butt_Click(sender As Object, e As EventArgs) Handles close_pb_butt.Click
  459.         Me.Close()
  460.     End Sub
  461.     Private Sub close_pb_butt_MouseEnter(sender As Object, e As EventArgs) Handles close_pb_butt.MouseEnter
  462.         close_pb_butt.BackColor = Color.MediumSeaGreen
  463.     End Sub
  464.  
  465.     Private Sub close_pb_butt_MouseLeave(sender As Object, e As EventArgs) Handles close_pb_butt.MouseLeave
  466.         close_pb_butt.BackColor = Nothing
  467.     End Sub
  468.  
  469.     Dim login_status As Boolean
  470.     Private Sub Signin_butt_Click(sender As Object, e As EventArgs) Handles Signin_butt.Click
  471.         Try
  472.  
  473.             username_txt.Text = user_txt.Text
  474.             show_image()
  475.  
  476.             Dim cmd As New SqlCommand
  477.             Dim dr As SqlDataReader
  478.             'فحص الاتصال بقاعدة البيانات
  479.             If SQL.conn.State = ConnectionState.Open Then
  480.                 SQL.conn.Close()
  481.             End If
  482.             SQL.conn.Open()
  483.             cmd.Connection = SQL.conn
  484.             cmd.CommandType = CommandType.Text
  485.             cmd.CommandText = "select * from users where uname= '" & user_txt.Text & "'"
  486.  
  487.             dr = cmd.ExecuteReader
  488.             If dr.HasRows Then
  489.                 While dr.Read
  490.                     If Lpassword_txt.Text <> dr(4) Then
  491.                         Lerrorlabel.Text = "أسم المستخدم أو كلمة المرور غير صحيحة"
  492.                     ElseIf Lpassword_txt.Text = dr(4) Then
  493.                         Login_Panel.Visible = False
  494.                         butt_panel.Visible = True
  495.                         locked_but.Visible = False
  496.                         unlocked_but.Visible = True
  497.                         login_status = True
  498.  
  499.                         user_Panel.Visible = True
  500.                         date_Panel.Visible = True
  501.                         If username_txt.TextLength > 1 Then
  502.                             username_txt.Text = username_txt.Text.Substring(0, 1).ToUpper() + username_txt.Text.Substring(1)
  503.                         ElseIf username_txt.TextLength = 1 Then
  504.                             username_txt.Text = username_txt.Text.ToUpper()
  505.                         End If
  506.  
  507.                         'اسناد الوقت المطلوب للخروج الآلي
  508.                         Logoutc1.TimeReq = 600 ' SECONDS
  509.                         Timer1.Start()
  510.                     End If
  511.                 End While
  512.             End If
  513.             SQL.conn.Close()
  514.  
  515.             If login_status = True Then
  516.                 'notification()
  517.             End If
  518.         Catch ex As Exception
  519.             MsgBox(ex.Message)
  520.         End Try
  521.     End Sub
  522.     Private Sub show_image()
  523.         Dim dr As SqlDataReader
  524.         Dim cmd As SqlCommand
  525.         Dim stream As New MemoryStream()
  526.         Dim query As String
  527.         query = "select * from users where uname= '" & username_txt.Text & "'"
  528.         'فحص الاتصال بقاعدة البيانات
  529.         If SQL.conn.State = ConnectionState.Open Then
  530.             SQL.conn.Close()
  531.         End If
  532.         SQL.conn.Open()
  533.         cmd = New SqlCommand(query, SQL.conn)
  534.         'dr = Cmd.ExecuteReader
  535.         dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
  536.         While dr.Read
  537.             If dr("image").ToString() <> "" Then
  538.                 Dim image As [Byte]() = DirectCast(dr("image"), [Byte]())
  539.                 stream.Write(image, 0, image.Length)
  540.                 Dim bitmap As New Bitmap(stream)
  541.                 'PictureBox1.Image = bitmap
  542.                 SetPicture(bitmap, PictureBox4)
  543.             End If
  544.         End While
  545.         SQL.conn.Close()
  546.  
  547.     End Sub
  548.     Private Sub SetPicture(ByVal imgSrc As Bitmap, ByVal target As PictureBox)
  549.         Dim imgDest As Bitmap = New Bitmap(target.ClientSize.Width, target.ClientSize.Height)
  550.         Dim source_aspect, dest_aspect, k_aspect, K As Double
  551.         source_aspect = imgSrc.Width / imgSrc.Height
  552.         dest_aspect = imgDest.Width / imgSrc.Height
  553.         k_aspect = dest_aspect / source_aspect
  554.         If (k_aspect > 1) Then
  555.             K = imgSrc.Height / imgDest.Height
  556.         Else
  557.             K = imgSrc.Width / imgDest.Width
  558.         End If
  559.         Dim x_new, y_new, w_new, h_new As Integer
  560.         w_new = CInt(imgSrc.Width / K)
  561.         h_new = CInt(imgSrc.Height / K)
  562.         x_new = CInt(imgDest.Width / 2 - w_new / 2)
  563.         y_new = CInt(imgDest.Height / 2 - h_new / 2)
  564.         Dim g As Graphics = Graphics.FromImage(imgDest)
  565.         g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
  566.         g.DrawImage(imgSrc, New Rectangle(x_new, y_new, w_new, h_new))
  567.         g.Dispose()
  568.         target.Image = imgDest
  569.     End Sub
  570.  
  571.     Private Sub Creat_user_butt_Click(sender As Object, e As EventArgs) Handles Creat_user_butt.Click
  572.         Login_Panel.Visible = False
  573.         Code_Registration.Dispose()
  574.         Code_Registration.ShowDialog()
  575.     End Sub
  576.     Private Sub forget_butt_Click(sender As Object, e As EventArgs) Handles forget_butt.Click
  577.         Login_Panel.Visible = False
  578.         Forget_Password.Dispose()
  579.         Forget_Password.ShowDialog()
  580.     End Sub
  581.  
  582.     Private Sub Lemail_txt_KeyUp(sender As Object, e As KeyEventArgs)
  583.         If e.KeyCode = Keys.Enter Then
  584.             Signin_butt_Click(sender, e)
  585.         End If
  586.     End Sub
  587.     Private Sub Lpassword_txt_KeyDown(sender As Object, e As KeyEventArgs) Handles Lpassword_txt.KeyDown
  588.         If e.KeyCode = Keys.Enter Then
  589.             Signin_butt_Click(sender, e)
  590.         End If
  591.     End Sub
  592.  
  593.     Friend Shared Function Notifyicon() As Object
  594.         Throw New NotImplementedException()
  595.     End Function
  596.  
  597.     Private Sub Lpassword_txt_KeyUp(sender As Object, e As KeyEventArgs) Handles Lpassword_txt.KeyUp
  598.         If e.KeyCode = Keys.Enter Then
  599.             Signin_butt_Click(sender, e)
  600.         End If
  601.     End Sub
  602.  
  603.     Private Sub Creat_user_butt_MouseEnter(sender As Object, e As EventArgs) Handles Creat_user_butt.MouseEnter
  604.         Creat_user_butt.FlatAppearance.BorderColor = System.Drawing.ColorTranslator.FromHtml("#e67e22")
  605.     End Sub
  606.  
  607.     Private Sub Creat_user_butt_MouseLeave(sender As Object, e As EventArgs) Handles Creat_user_butt.MouseLeave
  608.         Creat_user_butt.FlatAppearance.BorderColor = Color.White
  609.     End Sub
  610.  
  611.     Private Sub forget_butt_MouseEnter(sender As Object, e As EventArgs) Handles forget_butt.MouseEnter
  612.         forget_butt.FlatAppearance.BorderColor = System.Drawing.ColorTranslator.FromHtml("#e67e22")
  613.     End Sub
  614.  
  615.     Private Sub forget_butt_MouseLeave(sender As Object, e As EventArgs) Handles forget_butt.MouseLeave
  616.         forget_butt.FlatAppearance.BorderColor = Color.White
  617.     End Sub
  618.  
  619.     Sub autoS()
  620.         Try
  621.             Dim cmd As New SqlCommand("SELECT uname FROM users", SQL.conn)
  622.             Dim ds As New DataSet
  623.             Dim da As New SqlDataAdapter(cmd)
  624.             da.Fill(ds, "list")
  625.             Dim col As New AutoCompleteStringCollection
  626.             Dim i As Integer
  627.             For i = 0 To ds.Tables(0).Rows.Count - 1
  628.                 col.Add(ds.Tables(0).Rows(i)("uname").ToString())
  629.             Next
  630.             user_txt.AutoCompleteSource = AutoCompleteSource.CustomSource
  631.             user_txt.AutoCompleteCustomSource = col
  632.             user_txt.AutoCompleteMode = AutoCompleteMode.SuggestAppend
  633.  
  634.         Catch ex As Exception
  635.  
  636.         End Try
  637.     End Sub
  638.  
  639.     Private Sub customers_but_Click(sender As Object, e As EventArgs)
  640.         Try
  641.             Customers.Dispose()
  642.             Customers.ShowDialog()
  643.         Catch ex As OutOfMemoryException
  644.  
  645.         End Try
  646.     End Sub
  647.     Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
  648.  
  649.         'اظهار الوقت المستقطع عند الخمول
  650.         Label3.Text = Logoutc1.CounterTime.ToString
  651.         If Logoutc1.CounterTime = 600 Then
  652.  
  653.             If Application.OpenForms().OfType(Of Cheque).Any Then
  654.                 Dim frm = Application.OpenForms.OfType(Of Cheque)().FirstOrDefault()
  655.                 frm.Close()
  656.             End If
  657.  
  658.             If Application.OpenForms().OfType(Of Contracts_image).Any Then
  659.                 Dim frm = Application.OpenForms.OfType(Of Contracts_image)().FirstOrDefault()
  660.                 frm.Close()
  661.             End If
  662.             If Application.OpenForms().OfType(Of Contracts).Any Then
  663.                 Dim frm = Application.OpenForms.OfType(Of Contracts)().FirstOrDefault()
  664.                 frm.Close()
  665.             End If
  666.  
  667.  
  668.             If Application.OpenForms().OfType(Of Customers_image).Any Then
  669.                 Dim frm = Application.OpenForms.OfType(Of Customers_image)().FirstOrDefault()
  670.                 frm.Close()
  671.             End If
  672.  
  673.             If Application.OpenForms().OfType(Of Customers_info).Any Then
  674.                 Dim frm = Application.OpenForms.OfType(Of Customers_info)().FirstOrDefault()
  675.                 frm.Close()
  676.             End If
  677.  
  678.             If Application.OpenForms().OfType(Of Customers).Any Then
  679.                 Dim frm = Application.OpenForms.OfType(Of Customers)().FirstOrDefault()
  680.                 frm.Close()
  681.             End If
  682.  
  683.  
  684.             If Application.OpenForms().OfType(Of Contracts_image).Any Then
  685.                 Dim frm = Application.OpenForms.OfType(Of Contracts_image)().FirstOrDefault()
  686.                 frm.Close()
  687.             End If
  688.             If Application.OpenForms().OfType(Of Contracts).Any Then
  689.                 Dim frm = Application.OpenForms.OfType(Of Contracts)().FirstOrDefault()
  690.                 frm.Close()
  691.             End If
  692.  
  693.  
  694.             If Application.OpenForms().OfType(Of Employee_Expenses).Any Then
  695.                 Dim frm = Application.OpenForms.OfType(Of Employee_Expenses)().FirstOrDefault()
  696.                 frm.Close()
  697.             End If
  698.             If Application.OpenForms().OfType(Of Employees).Any Then
  699.                 Dim frm = Application.OpenForms.OfType(Of Employees)().FirstOrDefault()
  700.                 frm.Close()
  701.             End If
  702.  
  703.             If Application.OpenForms().OfType(Of Fast_payments).Any Then
  704.                 Dim frm = Application.OpenForms.OfType(Of Fast_payments)().FirstOrDefault()
  705.                 frm.Close()
  706.             End If
  707.             If Application.OpenForms().OfType(Of Payments).Any Then
  708.  
  709.                 If Application.OpenForms().OfType(Of Customers_info).Any Then
  710.                     Dim frm1 = Application.OpenForms.OfType(Of Customers_info)().FirstOrDefault()
  711.                     frm1.Close()
  712.                 End If
  713.                 Dim frm = Application.OpenForms.OfType(Of Payments)().FirstOrDefault()
  714.                 frm.Close()
  715.             End If
  716.  
  717.             If Application.OpenForms().OfType(Of Shops).Any Then
  718.                 Dim frm = Application.OpenForms.OfType(Of Shops)().FirstOrDefault()
  719.                 frm.Close()
  720.             End If
  721.  
  722.             locked_but.Visible = True
  723.             unlocked_but.Visible = False
  724.             butt_panel.Visible = False
  725.             user_Panel.Visible = True
  726.             date_Panel.Visible = True
  727.             Login_Panel.Visible = True
  728.             If Lpassword_txt.Text <> "" Then
  729.                 Lpassword_txt.Text = ""
  730.             End If
  731.             Lpassword_txt.Select()
  732.             Lpassword_txt.Focus()
  733.             Timer1.Stop()
  734.             Lpassword_txt.Select()
  735.         End If
  736.     End Sub
  737.  
  738.     Private Sub PictureBox2_Click(sender As Object, e As EventArgs)
  739.         If clog.isadmin(username_txt.Text) Then
  740.             Users_info.Show()
  741.         Else
  742.             MsgBox("لايوجد تصريح بدخول نموذج ادارة الصلاحيات", MsgBoxStyle.Exclamation, "لايوجد تصريح")
  743.         End If
  744.     End Sub
  745.  
  746.     Private Sub PictureBox3_Click(sender As Object, e As EventArgs)
  747.  
  748.         Dim someDay As Date = Date.Today
  749.  
  750.         Dim nextSunday As Date = someDay.AddDays(5 - someDay.DayOfWeek)
  751.  
  752.         Dim prevSaturday As Date = someDay.AddDays(DayOfWeek.Saturday - someDay.DayOfWeek - 7)
  753.  
  754.         MsgBox(nextSunday + "  " + prevSaturday)
  755.  
  756.     End Sub
  757.     Private Sub Server_txt_TextChanged(sender As Object, e As EventArgs) Handles Server_txt.TextChanged
  758.         Save_butt.Enabled = True
  759.     End Sub
  760.  
  761.     Private Sub Database_txt_TextChanged(sender As Object, e As EventArgs) Handles Database_txt.TextChanged
  762.         Save_butt.Enabled = True
  763.     End Sub
  764.  
  765.     Private Sub ID_txt_TextChanged(sender As Object, e As EventArgs) Handles ID_txt.TextChanged
  766.         Save_butt.Enabled = True
  767.     End Sub
  768.  
  769.     Private Sub Password_txt_TextChanged(sender As Object, e As EventArgs) Handles Password_txt.TextChanged
  770.         Save_butt.Enabled = True
  771.     End Sub
  772.     Private Sub Main_Click(sender As Object, e As EventArgs) Handles MyBase.Click
  773.         If connection_Panel.Width = 372 Then
  774.             Do While connection_Panel.Width > 0
  775.                 connection_Panel.Width = connection_Panel.Width - 3
  776.                 ''PictureBox1.Image = BGImgs(3)
  777.                 Save_butt.Enabled = False
  778.                 'Save_butt.Image = My.Resources.Save_Black_32
  779.                 Save_butt.FlatAppearance.BorderColor = System.Drawing.ColorTranslator.FromHtml("#333333")
  780.             Loop
  781.         End If
  782.  
  783.         If about_panel.Width = 339 Then
  784.             If about_panel.Height = 481 Then
  785.                 While about_panel.Height > 10
  786.                     about_panel.Height = about_panel.Height - 1
  787.                 End While
  788.             End If
  789.  
  790.             If about_panel.Height = 10 Then
  791.                 While about_panel.Width > 0
  792.                     about_panel.Width = about_panel.Width - 1
  793.                 End While
  794.             End If
  795.         End If
  796.     End Sub
  797.     Private Sub customers_button1_Click(sender As Object, e As EventArgs) Handles customers_button1.Click
  798.         Customers.Dispose()
  799.         Customers.ShowDialog()
  800.     End Sub
  801.  
  802.     Private Sub Store_button1_Click(sender As Object, e As EventArgs) Handles Store_button1.Click
  803.         Shops.Dispose()
  804.         Shops.ShowDialog()
  805.     End Sub
  806.  
  807.     Private Sub Cheque_button1_Click(sender As Object, e As EventArgs) Handles Cheque_button1.Click
  808.         Cheque.Dispose()
  809.         Cheque.ShowDialog()
  810.     End Sub
  811.  
  812.     Private Sub contract_button1_Click(sender As Object, e As EventArgs) Handles contract_button1.Click
  813.         Contracts.Dispose()
  814.         Contracts.ShowDialog()
  815.     End Sub
  816.  
  817.     '//////////////////////////////// Login Panel END //////////////////////////////////////
  818.  
  819.     '//////////////////////////////// Clock Panel Start ////////////////////////////////////
  820.  
  821.     Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
  822.         Try
  823.             Label5.Text = DateTime.Now.ToString("ss")
  824.             Time_lable.Text = DateTime.Now.ToString("hh:mm:ss tt")
  825.             day_Label.Text = DateTime.Now.ToString("dddd", New System.Globalization.CultureInfo("ar-AE"))
  826.             'Label4.Text = DateTime.Now.ToString("dd/M/yyyy")
  827.  
  828.             ProgressBar1.Value = Convert.ToInt32(Label5.Text)
  829.         Catch generatedExceptionName As Exception
  830.             Return
  831.         End Try
  832.     End Sub
  833.  
  834.     '//////////////////////////////// Clock Panel END ////////////////////////////////////
  835. End Class
  836.