コード例 #1
0
        private void btnLogin_Click_1(object sender, EventArgs e)
        {
            dbconn.CloseConnection();
            dbconn.OpenConnection();
            bool isExecute = true;

            if (txtUserName.Text.Equals("") || txtPassword.Text.Equals(""))
            {
                MessageBox.Show("User name or password can't be Empty !!!");
                isExecute = false;
            }
            if (dbconn.OpenConnection() == false)
            {
                MessageBox.Show("Cant connect to the database contact system Administrator.");
                isExecute = false;
            }

            if (isExecute == true)
            {
                string qr_getUserDetails = "SELECT * FROM users WHERE BINARY username = '******' && userpw ='"
                                           + txtPassword.Text + "';";
                MySqlCommand    cm_getUserDetails = new MySqlCommand(qr_getUserDetails, dbconn.connection);
                MySqlDataReader dr_getUserDetails = cm_getUserDetails.ExecuteReader();

                if (dr_getUserDetails.HasRows)
                {
                    //MessageBox.Show("Success!!");
                    loggedUser = txtUserName.Text;

                    this.Hide();
                    DashBoard mainForm = new DashBoard();
                    mainForm.Show();
                }
                else
                {
                    MessageBox.Show("Username and Password are not Matched !!!");
                    txtUserName.Clear();
                    txtPassword.Clear();
                    txtUserName.Focus();
                }

                dbconn.CloseConnection();
            }
        }
コード例 #2
0
        private void btnLogin_Click_1(object sender, EventArgs e)
        {
            //  $ mysqldump -u root -p1234 sm > dateTime.sql
            string fileName = DateTime.Now.ToString("yyyy-MM-dd-HHmm");

            //string strCmdText = "mysqldump -u root -p1234 sm > d:/backup/"+fileName+".sql";
            //System.Diagnostics.Process.Start("CMD.exe", strCmdText);


            System.Diagnostics.Process          process   = new System.Diagnostics.Process();
            System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
            startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            startInfo.FileName    = "cmd.exe";
            startInfo.Arguments   = "/C mysqldump -u root -p1234 sm > d:/backup/" + fileName + ".sql";
            process.StartInfo     = startInfo;
            process.Start();

            dbconn.CloseConnection();
            dbconn.OpenConnection();

            string          isDateAvailable    = "SELECT * FROM totalbillday where day='" + DateTime.Now.ToString("yyyy-MM-dd") + "';";
            MySqlCommand    cmdisDateAvailable = new MySqlCommand(isDateAvailable, dbconn.connection);
            MySqlDataReader drisDateAvailable  = cmdisDateAvailable.ExecuteReader();

            if (drisDateAvailable.HasRows)
            {
            }
            else
            {
                dbconn.CloseConnection();
                dbconn.OpenConnection();
                string       qAddToBill1    = "INSERT INTO totalbillday VALUES ('" + DateTime.Now.ToString("yyyy-MM-dd") + "', 0);";
                MySqlCommand cAddToBill1    = new MySqlCommand(qAddToBill1, dbconn.connection);
                int          queryAffected1 = cAddToBill1.ExecuteNonQuery();
            }



            dbconn.CloseConnection();
            dbconn.OpenConnection();
            bool isExecute = true;

            if (txtUserName.Text.Equals("") || txtPassword.Text.Equals(""))
            {
                MessageBox.Show("User name or password can't be Empty !!!");
                isExecute = false;
            }
            if (dbconn.OpenConnection() == false)
            {
                MessageBox.Show("Cant connect to the database contact system Administrator.");
                isExecute = false;
            }

            if (isExecute == true)
            {
                string qr_getUserDetails = "SELECT * FROM users WHERE BINARY username = '******' && userpw ='"
                                           + txtPassword.Text + "';";
                MySqlCommand    cm_getUserDetails = new MySqlCommand(qr_getUserDetails, dbconn.connection);
                MySqlDataReader dr_getUserDetails = cm_getUserDetails.ExecuteReader();

                if (dr_getUserDetails.HasRows)
                {
                    //MessageBox.Show("Success!!");
                    loggedUser = txtUserName.Text;
                    deleteOldbills();
                    this.Hide();
                    DashBoard mainForm = new DashBoard();
                    mainForm.Show();
                }
                else
                {
                    MessageBox.Show("Username and Password are not Matched !!!");
                    txtUserName.Clear();
                    txtPassword.Clear();
                    txtUserName.Focus();
                }

                dbconn.CloseConnection();
            }
        }