Exemple #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            List<Client> list = new List<Client>();
            list = cnn.Select();
            foreach (Client cli in list)
            {
                cli.calculateCurrentWeek(DateTime.Now);
            }
            dataGridClients.DataSource = list;

            if (list.Count != 0)
            {
                int id = (Int32)dataGridClients.Rows[0].Cells[0].Value;

                Client clie = new Client();
                clie = cnn.SelectId(id);

                mpK_Calendar.SelectedDate = DateTime.Now;
                mpK_Calendar.StartingDateClient = clie.DateStarted;
                mpK_Calendar.CycleLength = clie.CycleLength;
                mpK_Calendar.Refresh();
            }
            else
            {
                mpK_Calendar.SelectedDate = DateTime.Now;
            }
        }
Exemple #2
0
        public Client SelectId(int id)
        {
            string query = "SELECT * FROM clients WHERE idClients ='" + id + "';";

            //Create a list to store the result
            Client cli = new Client();

            //Open connection
            if (this.OpenConnection() == true)
            {
                //Create Command
                MySqlCommand cmd = new MySqlCommand(query, connection);
                //Create a data reader and Execute the command
                MySqlDataReader dataReader = cmd.ExecuteReader();

                //Read the data and store them in the list
                while (dataReader.Read())
                {

                    //Client row = new Client();
                    cli.ClientId = (Int32)dataReader["idClients"];
                    cli.ClientName = dataReader["clientName"].ToString();
                    cli.DateStarted = (DateTime)dataReader["startingDate"];
                    cli.CycleLength = (Int32)dataReader["cycleLength"];
                    //list.Add(row);
                }

                //close Data Reader
                dataReader.Close();

                //close Connection
                this.CloseConnection();

                //return list to be displayed
                return cli;
            }
            else
            {
                return cli;
            }
        }
Exemple #3
0
        //Select statement with condition
        public List<Client> SelectWithCond(string name)
        {            
            string query = "SELECT * FROM clients WHERE clientName LIKE'%" + name + "%';";
            
            //Create a list to store the result
            List<Client> list = new List<Client>();

            //Open connection
            if (this.OpenConnection() == true)
            {
                //Create Command
                MySqlCommand cmd = new MySqlCommand(query, connection);
                //Create a data reader and Execute the command
                MySqlDataReader dataReader = cmd.ExecuteReader();

                //Read the data and store them in the list
                while (dataReader.Read())
                {

                    Client row = new Client();
                    row.ClientId = (Int32)dataReader["idClients"];
                    row.ClientName = dataReader["clientName"].ToString();
                    row.DateStarted = (DateTime)dataReader["startingDate"];
                    row.CycleLength = (Int32)dataReader["cycleLength"];
                    list.Add(row);
                }

                //close Data Reader
                dataReader.Close();

                //close Connection
                this.CloseConnection();

                //return list to be displayed
                return list;
            }
            else
            {
                return list;
            }
        }
Exemple #4
0
        private void dataGridClients_CellClick(object sender, DataGridViewCellEventArgs e)
        {

            if (e.RowIndex >= 0)
            {
                int rowClicked = e.RowIndex;
                int id = (Int32)dataGridClients.Rows[rowClicked].Cells[0].Value;

                Client cli = new Client();
                cli = cnn.SelectId(id);

                mpK_Calendar.SelectedDate = DateTime.Now;
                mpK_Calendar.StartingDateClient = cli.DateStarted;
                mpK_Calendar.CycleLength = cli.CycleLength;
                mpK_Calendar.Refresh();
            }
        }