예제 #1
0
    public Boolean deleteMembership(String pUser, String pGroup)
    {
        DataBaseConnection _dbc = new DataBaseConnection();

        _dbc.SetConnectionString(_ConnectionString);
        _dbc.OpenConnection();
        List <object> _result;

        try
        {
            _result = _dbc.ExecuteProcedures("Exec sp_DeleteMembership " + pUser + "," + pGroup, 1);
        }
        catch (Exception ex)
        {
            _dbc.CloseConnection();
            return(false);
        }
        _dbc.CloseConnection();
        if (_result != null)
        {
            if (((int)_result[0]) == 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        return(false);
    }
예제 #2
0
    public Boolean updateUser(String pFirstName, String pSecondName, String pSurName, String pSurName2, String pStatus, String pLoginName, int pActualUser)
    {
        DataBaseConnection _dbc = new DataBaseConnection();

        _dbc.SetConnectionString(_ConnectionString);
        _dbc.OpenConnection();
        List <object> _result;

        try
        {
            _result = _dbc.ExecuteProcedures("Exec sp_UpdateUser N'" + pFirstName + "', N'" + pSecondName + "', N'" + pSurName + "', N'" + pSurName2 + "', '" + pStatus + "', NULL, NULL, NULL, " + pActualUser + ", N'" + pLoginName + "', NULL, NULL, 0", 1);
        }
        catch (Exception ex)
        {
            _dbc.CloseConnection();
            return(false);
        }
        _dbc.CloseConnection();
        if (_result != null)
        {
            if (((int)_result[0]) == 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        return(false);
    }
예제 #3
0
    public Boolean passwordChange(String pLoginName, String pOldPass, String pNewPass, String pCurrentUser)
    {
        DataBaseConnection _dbc = new DataBaseConnection();

        _dbc.SetConnectionString(_ConnectionString);
        _dbc.OpenConnection();
        List <object> _result;

        try
        {
            _result = _dbc.ExecuteProcedures("Exec sp_UpdatePassword N'" + pLoginName + "', N'" + pOldPass + "', N'" + pNewPass + "', " + pCurrentUser, 1);
        }
        catch (Exception e)
        {
            _dbc.CloseConnection();
            return(false);
        }
        _dbc.CloseConnection();
        if (_result != null)
        {
            if (((int)_result[0]) == 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        return(false);
    }
예제 #4
0
    public List <object> searchForUsers(String pHint, int pType)
    {
        DataBaseConnection _dbc = new DataBaseConnection();

        _dbc.SetConnectionString(_ConnectionString);
        _dbc.OpenConnection();
        List <object> _result;

        try
        {
            if (pType == 5)
            {
                _result = _dbc.ExecuteProcedures("Exec sp_SearchForUsers N'" + pHint + "', " + pType, 2);
            }
            else
            {
                _result = _dbc.ExecuteProcedures("Exec sp_SearchForUsers N'" + pHint + "', " + pType, 7);
            }
            _dbc.CloseConnection();
            return(_result);
        }
        catch (Exception e)
        {
            _dbc.CloseConnection();
            _result = null;
            return(_result);
        }
    }
예제 #5
0
    public Boolean Login(String pPassword, String pUserName)
    {
        DataBaseConnection _dbc = new DataBaseConnection();

        _dbc.SetConnectionString(_ConnectionString);
        _dbc.OpenConnection();
        List <object> _result;

        try
        {
            _result = _dbc.ExecuteProcedures("Exec sp_Login N'" + pUserName + "', N'" + pPassword + "'", 1);
        }
        catch (Exception e)
        {
            _dbc.CloseConnection();
            return(false);
        }
        _dbc.CloseConnection();
        if (_result != null)
        {
            if (((int)_result[0]) == 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        return(false);
    }
예제 #6
0
        public Boolean Validate(String username, String passwd)
        {
            db.OpenConnection();
            string       stmt = "select * from users where username=@username and passwd=@passwd";
            MySqlCommand cmd  = new MySqlCommand(stmt, db.myConnection);

            cmd.Parameters.AddWithValue("@username", username);
            cmd.Parameters.AddWithValue("@passwd", passwd);

            //Get the element of the query

            var reader = cmd.ExecuteReader();

            if (reader.HasRows)
            {
                Console.WriteLine("Connected");
                reader.Close();
                db.CloseConnection();
                return(true);
            }
            else
            {
                Console.WriteLine("Wrong username/pass");
            }
            db.CloseConnection();
            reader.Close();

            return(false);
        }
예제 #7
0
    public Boolean updateGroup(String pName, String pDescription, int pStatus)
    {
        DataBaseConnection _dbc = new DataBaseConnection();

        _dbc.SetConnectionString(_ConnectionString);
        _dbc.OpenConnection();
        List <object> _result;

        try
        {
            _result = _dbc.ExecuteProcedures("Exec sp_UpdateUserGroups N'" + pName + "'," + pStatus + ", N'" + pDescription + "'", 1);
        }
        catch (Exception ex)
        {
            _dbc.CloseConnection();
            return(false);
        }
        _dbc.CloseConnection();
        if (_result != null)
        {
            if (((int)_result[0]) == 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        return(false);
    }
예제 #8
0
    public Boolean insertUser(String pLoginName, String pPassword, String pName, String pMName, String pSurName1, String pSurName2, String pCurrentUser)
    {
        DataBaseConnection _dbc = new DataBaseConnection();

        _dbc.SetConnectionString(_ConnectionString);
        _dbc.OpenConnection();
        List <object> _result;

        try
        {
            _result = _dbc.ExecuteProcedures("Exec sp_SearchForUsers N'" + pCurrentUser + "', " + 5, 3);
            _result = _dbc.ExecuteProcedures("Exec sp_InsertUser N'" + pLoginName + "', " + "N'" + pName + "', " + "N'" + pMName + "', " + "N'" + pSurName1 + "', N' " + pSurName2 + "'," + "N'" + pPassword + "', " + _result[0], 1);
        }
        catch (Exception ex)
        {
            _dbc.CloseConnection();
            return(false);
        }
        _dbc.CloseConnection();
        if (_result != null)
        {
            if (((int)_result[0]) == 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        return(false);
    }
        //menu tab control
        private void TabControlSystem_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (TabControlSystem.SelectedTab == TabControlSystem.TabPages["Movies"])
                {
                    MoviesTableGridDataBind();

                    groupBoxMovie.Visible = true;
                    CustomerBox.Visible   = false;
                }
                else if (TabControlSystem.SelectedTab == TabControlSystem.TabPages["Customers"])
                {
                    groupBoxMovie.Visible = false;
                    CustomerBox.Visible   = true;


                    BindGridCustomersTbl();
                }
                else if (TabControlSystem.SelectedTab == TabControlSystem.TabPages["RentedMovies"])
                {
                    RentedMovieGridData(); //show all rented movies
                    groupBoxMovie.Visible = false;
                    CustomerBox.Visible   = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                DataBaseConnection.CloseConnection(); // close connection with database when error occured
            }
        }
예제 #10
0
 public void AfterAllTests()
 {
     _driver.Close();
     _driver.Quit();
     HelperSet.DeleteAllTestData(UserEmail);
     _dbConn.CloseConnection();
 }
예제 #11
0
    public Boolean DeleteRights(String pGroup, String pType, String pIdentifier)
    {
        DataBaseConnection _dbc = new DataBaseConnection();

        _dbc.SetConnectionString(_ConnectionString);
        _dbc.OpenConnection();
        String _query = "";
        int    plap   = String.Compare("Category", "Category");
        int    plop   = String.Compare(pType, "Category");

        if (pType == "Section")
        {
            _query = "Exec sp_DeleteSectionRights ";
        }
        else if (pType == "Category")
        {
            _query = "Exec sp_DeleteCategoryRights ";
        }
        else if (pType == "Page")
        {
            _query = "Exec sp_DeletePageRights ";
        }
        List <object> _result;

        try
        {
            _result = _dbc.ExecuteProcedures(_query + pIdentifier + ", " + pGroup, 1);
        }
        catch (Exception ex)
        {
            _dbc.CloseConnection();
            return(false);
        }
        _dbc.CloseConnection();
        if (_result != null)
        {
            if (((int)_result[0]) == 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        return(false);
    }
예제 #12
0
    public List <String> getUserRights(String pIdUser, String pType)
    {
        DataBaseConnection _dbc = new DataBaseConnection();

        _dbc.SetConnectionString(_ConnectionString);
        _dbc.OpenConnection();
        List <object> _queryResult;
        List <String> _result = new List <string>();
        String        _query  = "";

        if (pType == "Section")
        {
            _query = "Exec sp_SelectSectionsByUser ";
        }
        else if (pType == "Category")
        {
            _query = "Exec sp_SelectCategoriesByUser ";
        }
        else if (pType == "Page")
        {
            _query = "Exec sp_SelectPagesByUser ";
        }
        try
        {
            _queryResult = _dbc.ExecuteProcedures(_query + pIdUser, 1);
        }
        catch (Exception e)
        {
            _dbc.CloseConnection();
            _result = null;
            return(_result);
        }
        _dbc.CloseConnection();
        if (_queryResult != null)
        {
            for (int i = 0; i < _queryResult.Count; i++)
            {
                _result.Add((String)_queryResult[i]);
            }
        }
        return(_result);
    }
예제 #13
0
    public List <object> searchForGroups(String pHint, int ptype)
    {
        DataBaseConnection _dbc = new DataBaseConnection();

        _dbc.SetConnectionString(_ConnectionString);
        _dbc.OpenConnection();
        List <object> _result;

        try
        {
            _result = _dbc.ExecuteProcedures("Exec sp_SearchForGroups N'" + pHint + "', " + ptype, 4);
            _dbc.CloseConnection();
            return(_result);
        }
        catch (Exception e)
        {
            _dbc.CloseConnection();
            _result = null;
            return(_result);
        }
    }
예제 #14
0
        protected override void OnExit(ExitEventArgs e)
        {
            try
            {
                DataBaseConnection.CloseConnection();
            }
            catch (System.Exception exception)
            {
                Log.LogException(exception);
            }

            base.OnExit(e);
        }
예제 #15
0
        public List <Game> ReturnGames()
        {
            List <Game> games = new List <Game>();

            db.OpenConnection();
            string stmt = "SELECT * FROM game g";

            MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand(stmt, db.myConnection);

            var reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                Game game = new Game {
                    id = reader.GetInt32("game_id"), team1 = reader.GetString("home"), team2 = reader.GetString("away"), title = reader.GetString("title"), tickets = reader.GetInt16("nr_seats"), price = reader.GetInt32("price")
                };
                games.Add(game);
            }

            db.CloseConnection();
            reader.Close();
            return(games);
        }
예제 #16
0
    public int searchForGroup(String pHint, int ptype)
    {
        DataBaseConnection _dbc = new DataBaseConnection();

        _dbc.SetConnectionString(_ConnectionString);
        _dbc.OpenConnection();
        List <object> _result;

        try
        {
            _result = _dbc.ExecuteProcedures("Exec sp_SearchForGroups N'" + pHint + "', " + ptype, 3);
        }
        catch (Exception e)
        {
            _dbc.CloseConnection();
            return(-1);
        }
        _dbc.CloseConnection();
        if (_result != null)
        {
            return((int)_result[0]);
        }
        return(-1);
    }
예제 #17
0
        public void Buy(string name_client, int nr_seats, int game_id)
        {
            db.OpenConnection();
            string stmt = "insert into clients(name_client, nr_seats, game_id) values(@name_client, @nr_seats, @game_id)";

            MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand(stmt, db.myConnection);

            cmd.Parameters.AddWithValue("@name_client", name_client);
            cmd.Parameters.AddWithValue("@nr_seats", nr_seats);
            cmd.Parameters.AddWithValue("@game_id", game_id);
            var reader = cmd.ExecuteReader();

            GameRepository sRepo = new GameRepository(db);

            db.CloseConnection();
            sRepo.UpdateSeats(nr_seats, game_id);

            //Get the element of the query

            //  db.CloseConnection();
            reader.Close();
        }
        //Delete Customer from db
        private void DeleteCustomer_Click(object sender, EventArgs e)
        {
            try
            {
                string custId = tbxCustomerID.Text;

                if (new Customer().DeleteCustomerTblData(custId))
                {
                    BindDdlWithCustomer();     // method calling to Bind comboBox Customer
                    BindGridCustomersTbl();    // method calling to Bind GridView Customer

                    AddCustomer.Enabled = true;
                    MessageBox.Show("Customer Deleted Successfully!");
                    TextBoxFirstName.Text   = "";
                    textBoxLastName.Text    = "";
                    textBox1FatherName.Text = "";
                    textBoxAddress.Text     = "";
                    textBoxPhone.Text       = "";
                    tbxCustomerID.Text      = "";
                }
                else
                {
                    MessageBox.Show("Unable to delete this customer");
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("REFERENCE"))
                {
                    MessageBox.Show("Can not delete this customer as the customer rented a movie!");
                }
                else
                {
                    MessageBox.Show(ex.Message);
                    DataBaseConnection.CloseConnection(); // close connection with database when error occured
                }
            }
        }
예제 #19
0
        // Lets Fire the GUN
        private void btFire_Click(object sender, EventArgs e)
        {
            try
            {
                try
                {
                    if (tryFire == 2) // Only 2 chances
                    {
                        btFire.Enabled = false;
                        btLoad.Enabled = false;
                        btSpin.Enabled = false;
                    }
                    else
                    {
                        bool       status = new PlayerTask().BulletFire(NewChamber);
                        PlayerData data;

                        // when Bullet Fired
                        if (status == true)
                        {
                            // get Player's win count
                            data          = new PlayerTask().GetPlayerRecord(PlayerID);
                            data.PlayerID = PlayerID;
                            data.Win      = data.Win + 1;
                            data.Loss     = 0;

                            // update player's score
                            if (new PlayerTask().UpdatePlayerData(data))
                            {
                                lbBullectCOunt.Text = "";
                                KilledCount         = data.Win;;
                                lbScore.Text        = "Killed: " + KilledCount.ToString();
                                btFire.Enabled      = false;
                                btLoad.Enabled      = true;
                                lbWasted.Text       = "Good Job! Load 1 Bullet Again";
                            }
                        }
                        else
                        {
                            // when Bullet NOT Fired
                            tryFire    = tryFire + 1;
                            NewChamber = NewChamber + 1;

                            if (tryFire == 2)
                            {
                                // get Player's record
                                data          = new PlayerTask().GetPlayerRecord(PlayerID);
                                data.Win      = KilledCount;
                                data.Loss     = 1;
                                data.PlayerID = PlayerID;

                                if (new PlayerTask().UpdatePlayerData(data))
                                {
                                    btFire.Enabled    = true;
                                    lbScore.Text      = "Killed: " + data.Win;
                                    lbTotalScore.Text = "Total Score: " + KilledCount.ToString();

                                    btSpin.Enabled = false;
                                    btFire.Enabled = false;
                                    DataBaseConnection.CloseConnection();

                                    if (KilledCount > 0)
                                    {
                                        lbWasted.Text     = "You Dead! Your Total Score: " + KilledCount;
                                        lbTotalScore.Text = "";
                                    }
                                    else
                                    {
                                        lbWasted.Text = "Wasted Youth!";

                                        DataBaseConnection.CloseConnection();
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #20
0
 private void OnConnectButtonClicked(object sender, RoutedEventArgs e)
 {
     DataBaseConnection.CloseConnection();
     DataBaseConnection.OpenConnection();
 }
예제 #21
0
        //Update movie
        private void BtnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                string MovieId = TextBoxMovieID.Text;

                string Title, RentCost, Year, Rating, Genre, StoryLine;
                Title     = TextBoxMOvieTitle.Text;
                RentCost  = TextBoxRent.Text;
                Rating    = TextBoxStarRating.Text;
                Year      = TextBoxYear.Text;
                Genre     = TextBoxGenre.Text;
                StoryLine = textBoxStoryLine.Text;

                if (Title == "")
                {
                    MessageBox.Show("Movie title is required!");
                    TextBoxMOvieTitle.Focus();
                }
                else if (Year == "")
                {
                    MessageBox.Show("Movie released year is required!");
                    TextBoxYear.Focus();
                }

                else if (Genre == "")
                {
                    MessageBox.Show("Movie genre is required!");
                    TextBoxGenre.Focus();
                }
                else if (RentCost == "")
                {
                    MessageBox.Show("Movie rent cost is required!");
                }
                else if (StoryLine == "")
                {
                    MessageBox.Show("Story Line is required!");
                    textBoxStoryLine.Focus();
                }
                else if (Rating == "")
                {
                    MessageBox.Show("Movie rating is required!");
                    TextBoxStarRating.Focus();
                }

                else
                {
                    MoviesData data = new MoviesData
                    {
                        Title     = Title,
                        Year      = Year,
                        Rating    = Rating,
                        Genre     = Genre,
                        RentCost  = int.Parse(RentCost),
                        MovieId   = int.Parse(MovieId),
                        StoryLine = StoryLine
                    };
                    if (new Movies().UpdateMovie(data))
                    {
                        MoviesGridViewDataBind();
                        BindDropDownMovie();

                        btnAddMOvie.Enabled = true; // enable Add movie button
                        MessageBox.Show("Movie Updated Successfully!");
                        TextBoxMovieID.Text    = "";
                        TextBoxMOvieTitle.Text = "Movie Title...";
                        TextBoxYear.Text       = "Release Year...";
                        TextBoxStarRating.Text = "Star Rating...";
                        TextBoxGenre.Text      = "Genre...";
                        TextBoxRent.Text       = "($)Rent... ";
                        textBoxStoryLine.Text  = "Story Line...";
                    }
                    else
                    {
                        MessageBox.Show("Unable to update this movie!");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                DataBaseConnection.CloseConnection(); // close connection with database when error occured
            }
        }
예제 #22
0
        //Update Customer Information
        private void UpdateCustomer_Click(object sender, EventArgs e)
        {
            try
            {
                string custId = tbxCustomerID.Text;
                string FirstName, LastName, address, phone;
                LastName  = textBoxLastName.Text;
                FirstName = TextBoxFirstName.Text;
                address   = textBoxAddress.Text;
                phone     = textBoxPhone.Text;

                if (FirstName == "")
                {
                    MessageBox.Show("First name is required!");
                    TextBoxFirstName.Focus();
                }
                else if (LastName == "")
                {
                    MessageBox.Show("Last name is required!");
                    textBoxLastName.Focus();
                }
                else if (address == "")
                {
                    MessageBox.Show("Address is required!");
                    textBoxAddress.Focus();
                }
                else if (phone == "")
                {
                    MessageBox.Show("Phone number is required!");
                    textBoxPhone.Focus();
                }
                else
                {
                    CustomerData data = new CustomerData
                    {
                        FirstName = FirstName,
                        LastName  = LastName,
                        Address   = address,
                        Phone     = phone,
                        CustId    = int.Parse(custId)
                    };
                    if (new Customer().UpdateCustomerInformation(data))
                    {
                        AddCustomer.Enabled = true;
                        BindDdlCustomer();       // method calling to Bind comboBox Customer
                        BindGridCustomersInfo(); // method calling to Bind GridView Customer
                        MessageBox.Show("Customer Updated Successfully!");
                        TextBoxFirstName.Text = "First Name...";
                        textBoxLastName.Text  = "Last Name...";
                        textBoxAddress.Text   = "Address...";
                        textBoxPhone.Text     = "Phone...";
                        tbxCustomerID.Text    = "";
                    }
                    else
                    {
                        MessageBox.Show("Unable to update this customer!");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                DataBaseConnection.CloseConnection(); // close connection with database when error occured
            }
        }
        //Update movie
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                string MovieId = TextBoxMovieID.Text;

                string Title, RentCost, Year, Rating, Genre, StoryLine;
                Title     = TextBoxMOvieTitle.Text;
                RentCost  = TextBoxRent.Text;
                Rating    = TextBoxStarRating.Text;
                Year      = TextBoxYear.Text;
                Genre     = TextBoxGenre.Text;
                StoryLine = textBoxStoryLine.Text;

                if (Title == "")
                {
                    MessageBox.Show("Movie title required!");
                    TextBoxMOvieTitle.Focus();
                }
                else if (Year == "")
                {
                    MessageBox.Show("Movie released year required!");
                    TextBoxYear.Focus();
                }

                else if (Genre == "")
                {
                    MessageBox.Show("Movie genre required!");
                    TextBoxGenre.Focus();
                }
                else if (RentCost == "")
                {
                    MessageBox.Show("Movie rent cost required!");
                }
                else if (StoryLine == "")
                {
                    MessageBox.Show("Story required!");
                    textBoxStoryLine.Focus();
                }
                else if (Rating == "")
                {
                    MessageBox.Show("Movie rating required!");
                    TextBoxStarRating.Focus();
                }

                else
                {
                    MoviesDataTbl data = new MoviesDataTbl();
                    data.Title     = Title;
                    data.Year      = Year;
                    data.Rating    = Rating;
                    data.Genre     = Genre;
                    data.RentCost  = int.Parse(RentCost);
                    data.MovieId   = int.Parse(MovieId);
                    data.StoryLine = StoryLine;
                    if (new Movies().UpdateMovie(data))
                    {
                        MoviesTableGridDataBind();
                        BindDropDownMovie();

                        btnAddMOvie.Enabled = true; // enable Add movie button
                        MessageBox.Show("Movie Updated!!");
                        TextBoxMovieID.Text    = "";
                        TextBoxMOvieTitle.Text = "";
                        TextBoxYear.Text       = "";
                        TextBoxStarRating.Text = "";
                        TextBoxGenre.Text      = "";
                        TextBoxRent.Text       = "";
                        textBoxStoryLine.Text  = "";
                    }
                    else
                    {
                        MessageBox.Show("Unable to update this movie!");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                DataBaseConnection.CloseConnection(); // close connection with database when error occured
            }
        }
        //Add Customers to database
        private void AddCustomer_Click(object sender, EventArgs e)
        {
            try
            {
                string Firstname, Lastname, address, phone, fatherName;
                Firstname  = TextBoxFirstName.Text;
                Lastname   = textBoxLastName.Text;
                address    = textBoxAddress.Text;
                phone      = textBoxPhone.Text;
                fatherName = textBox1FatherName.Text;

                if (Firstname == "")
                {
                    MessageBox.Show("First name required!");
                    TextBoxFirstName.Focus();
                }
                else if (Lastname == "")
                {
                    MessageBox.Show("Last name required!");
                    textBoxLastName.Focus();
                }
                else if (fatherName == "")
                {
                    MessageBox.Show("Father's name required!");
                    textBox1FatherName.Focus();
                }
                else if (address == "")
                {
                    MessageBox.Show("Address required!");
                    textBoxAddress.Focus();
                }
                else if (phone == "")
                {
                    MessageBox.Show("Phone number required!");
                    textBoxPhone.Focus();
                }

                else
                {
                    CustomerDataTbl data = new CustomerDataTbl();
                    data.FirstName  = Firstname;
                    data.LastName   = Lastname;
                    data.fatherName = fatherName;
                    data.Address    = address;
                    data.Phone      = phone;
                    if (new Customer().AddCustomerData(data))
                    {
                        BindDdlWithCustomer();  // bind customer table to combobox
                        BindGridCustomersTbl(); // Bind GridView with Customer table

                        MessageBox.Show("Customer Saved to Database!!");

                        TextBoxFirstName.Text   = "";
                        textBoxLastName.Text    = "";
                        textBoxAddress.Text     = "";
                        textBox1FatherName.Text = "";
                        textBoxPhone.Text       = "";
                    }
                    else
                    {
                        MessageBox.Show("Unable to add this customer!");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                DataBaseConnection.CloseConnection(); // close DB connection when error occured
            }
        }
        //Update Customer table data
        private void UpdateCustomer_Click(object sender, EventArgs e)
        {
            try
            {
                string custId = tbxCustomerID.Text;
                string FirstName, LastName, fatherName, address, phone;
                LastName   = textBoxLastName.Text;
                FirstName  = TextBoxFirstName.Text;
                address    = textBoxAddress.Text;
                phone      = textBoxPhone.Text;
                fatherName = textBox1FatherName.Text;

                if (FirstName == "")
                {
                    MessageBox.Show("First name required!");
                    TextBoxFirstName.Focus();
                }
                else if (LastName == "")
                {
                    MessageBox.Show("Last name required!");
                    textBoxLastName.Focus();
                }
                else if (fatherName == "")
                {
                    MessageBox.Show("Father's name required!");
                    textBox1FatherName.Focus();
                }
                else if (address == "")
                {
                    MessageBox.Show("Address required!");
                    textBoxAddress.Focus();
                }
                else if (phone == "")
                {
                    MessageBox.Show("Phone number required!");
                    textBoxPhone.Focus();
                }
                else
                {
                    CustomerDataTbl data = new CustomerDataTbl();
                    data.FirstName  = FirstName;
                    data.LastName   = LastName;
                    data.Address    = address;
                    data.Phone      = phone;
                    data.fatherName = fatherName;
                    data.CustId     = int.Parse(custId);
                    if (new Customer().UpdateCustomerInformation(data))
                    {
                        AddCustomer.Enabled = true;
                        BindDdlWithCustomer();  // Bind comboBox with Customer table
                        BindGridCustomersTbl(); // BindGridView with Customer table
                        MessageBox.Show("Customer Data Updated!");
                        TextBoxFirstName.Text   = "";
                        textBoxLastName.Text    = "";
                        textBoxAddress.Text     = "";
                        textBox1FatherName.Text = "";
                        textBoxPhone.Text       = "";
                        tbxCustomerID.Text      = "";
                    }
                    else
                    {
                        MessageBox.Show("Unable to update this customer!!");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                DataBaseConnection.CloseConnection(); // close connection with database when error occured
            }
        }
예제 #26
0
 //Exit from Game
 private void btExit_Click(object sender, EventArgs e)
 {
     DataBaseConnection.CloseConnection();
     Application.ExitThread();
 }