Exemplo n.º 1
0
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            //MessageBox.Show(mac);
            try
            {
                string mac1 = null, ip, pc_no;
                foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
                {
                    // Only consider Ethernet network interfaces
                    if ((nic.NetworkInterfaceType == NetworkInterfaceType.Ethernet &&
                         nic.OperationalStatus == OperationalStatus.Up))
                    {
                        mac1 = nic.GetPhysicalAddress().ToString();
                    }
                }
                //Because i am not connected with lan
                //string mac = mac1.Substring(0, 2) + "-"+ mac1.Substring(2, 2) + "-" + mac1.Substring(4, 2) + "-" + mac1.Substring(6, 2) + "-" + mac1.Substring(8, 2) + "-" + mac1.Substring(10, 2);

                string mac = "5C-26-0A-55-8F-46";

                con.Open();
                String           query1   = "SELECT * FROM in_use_pc WHERE mac_id = @enrol";
                MySqlCommand     command1 = new MySqlCommand(query1, con);
                MySqlDataAdapter da       = new MySqlDataAdapter(command1);
                DataTable        dt       = new DataTable();
                command1.Parameters.AddWithValue("@enrol", mac);
                da.Fill(dt);
                if (dt.Rows.Count > 0)
                {
                    ip     = dt.Rows[0][1].ToString();
                    enroll = dt.Rows[0][2].ToString();
                    pc_no  = dt.Rows[0][3].ToString();
                    con.Close();
                    con.Open();
                    String       query   = "INSERT INTO not_use_pc (ip_address, pc_number, mac_id) VALUES (@ip, @pc_no, @mac);";
                    MySqlCommand command = new MySqlCommand(query, con);

                    command.Parameters.AddWithValue("@ip", ip);
                    command.Parameters.AddWithValue("@pc_no", pc_no);
                    command.Parameters.AddWithValue("@mac", mac);

                    command.ExecuteNonQuery();
                    con.Close();
                    con.Open();
                    DataTable        dt1      = new DataTable();
                    MySqlCommand     command2 = new MySqlCommand("DELETE FROM in_use_pc WHERE mac_id=@Name1", con);
                    MySqlDataAdapter da1      = new MySqlDataAdapter(command2);
                    command2.Parameters.AddWithValue("@Name1", mac);
                    da1.Fill(dt1);
                    con.Close();

                    con.Open();
                    String       query3   = "INSERT INTO log (pc_number, mac_id, enrol, start_time, end_time) VALUES (@pc_no,@mac, @enrol3,@start,@end);";
                    MySqlCommand command3 = new MySqlCommand(query3, con);
                    command3.Parameters.AddWithValue("@pc_no", pc_no);
                    command3.Parameters.AddWithValue("@mac", mac);
                    command3.Parameters.AddWithValue("@enrol3", enroll);
                    command3.Parameters.AddWithValue("@start", start_time);
                    command3.Parameters.AddWithValue("@end", DateTime.Now.ToString());
                    command3.ExecuteNonQuery();
                    con.Close();
                }
            }
            catch (Exception)
            {
                MessageBox.Show(e.ToString());
            }
            finally
            {
                con.Close();
            }
        }
Exemplo n.º 2
0
 private void AjtVente_FormClosing(object sender, FormClosingEventArgs e)
 {
     try{
         FrmAcc.RefreshAccui();
         if (isModification)
         {
             frm.RefreshFactures();
         }
         if (!saved)
         {
             if (ex)
             {
                 var rep = MessageBox.Show("لم تقم بحفض المعلومات, سيتم إلغاء الإضافات الجديدة !, هل تريد الإستمرار في الخروج ؟ ", "إلغاء العملية", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign);
                 e.Cancel = (rep == DialogResult.No);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("هناك خطأ أثناء العملية المرجوا إعادة المحاولة");
         string Err = "[" + DateTime.Now + "] [Exception] __ [Form :" + this.Name + " ; Control: " + sender.ToString() + " ; Event: " + e.ToString() + "] __ ExceptionMessage : " + ex.Message;
         Acceuil.WriteLog(Err);
     }
 }
Exemplo n.º 3
0
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     Log.debug("OnClosing : " + e.ToString());
 }