Ejemplo n.º 1
0
        public void Insert(Client client)
        {
            using (MySqlConnection conn = new MySqlConnection(connString))
            {
                conn.Open();
                MySqlCommand command = new MySqlCommand(INSERT, conn);

                /* Add parameters into the command */
                command.Parameters.AddWithValue("@name", client.client_name);
                command.Parameters.AddWithValue("@surname", client.client_surname);
                command.Parameters.AddWithValue("@email", client.client_email);

                if (client.client_phone != null)
                    command.Parameters.AddWithValue("@phone", client.client_phone);
                else
                    command.Parameters.AddWithValue("@phone", DBNull.Value);

                command.Parameters.AddWithValue("@birthDate", client.client_birth_date);
                command.Parameters.AddWithValue("@memberFrom", client.client_member_from);

                if (client.client_member_to != null)
                    command.Parameters.AddWithValue("@memberTo", client.client_member_to);
                else
                    command.Parameters.AddWithValue("@memberTo", DBNull.Value);

                if (client.client_street != null)
                    command.Parameters.AddWithValue("@street", client.client_street);
                else
                    command.Parameters.AddWithValue("@street", DBNull.Value);

                if (client.client_city != null)
                    command.Parameters.AddWithValue("@city", client.client_city);
                else
                    command.Parameters.AddWithValue("@city", DBNull.Value);

                if (client.client_zip != null)
                    command.Parameters.AddWithValue("@zip", client.client_zip);
                else
                    command.Parameters.AddWithValue("@zip", DBNull.Value);

                if (client.client_country != null)
                    command.Parameters.AddWithValue("@country", client.client_country);
                else
                    command.Parameters.AddWithValue("@country", DBNull.Value);

                command.Parameters.AddWithValue("@isEmp", client.client_isEmp);
                command.Parameters.AddWithValue("@isActive", client.client_is_active);
                command.Parameters.AddWithValue("@login", client.client_login);
                command.Parameters.AddWithValue("@passHash", client.client_pass_hash);

                if (client.client_last_act != null)
                    command.Parameters.AddWithValue("@lastAct", client.client_last_act);
                else
                    command.Parameters.AddWithValue("@lastAct", DBNull.Value);

                /* Executes the command */
                command.ExecuteNonQuery();
            }
        }
Ejemplo n.º 2
0
        protected void BtnInsertClient_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                DatabaseLibrary.Client client = new DatabaseLibrary.Client();

                /*
                 * Precteni udaju z registracniho formulare
                 */
                client.client_name = TxtBoxName.Text;
                client.client_surname = TxtBoxSurname.Text;
                client.client_email = TxtBoxEmail.Text;
                client.client_phone = TxtBoxPhone.Text;

                // Parsovani data narozeni
                string birthDate = TxtBoxBirthDate.Text;
                string[] items = birthDate.Split('/');
                DateTime dateBirth = new DateTime(Int32.Parse(items[2]), Int32.Parse(items[1]), Int32.Parse(items[0]));
                client.client_birth_date = dateBirth;

                client.client_street = TxtBoxStreet.Text;
                client.client_city = TxtBoxCity.Text;
                client.client_zip = TxtBoxZIP.Text;
                client.client_country = TxtBoxCountry.Text;

                client.client_login = TxtBoxLogin.Text;

                /*
                 * Registrace klienta podle UC1: (vice info v komentari k metode BusinessClient.RegisterClient(Client client))
                 */
                try
                {
                    BusinessClient.RegisterClient(client);
                    LabelInfo.Text = "Registrace uspesna. Heslo Vam bylo poslano emailem.";
                }
                catch (InputDataException ex)
                {
                    // Email nebo login j*z v systemu existuje
                    LabelInfo.Text = ex.Message;
                }
                catch (Exception ex)
                {
                    LabelInfo.Text = "Behem registrace doslo k chybe.";
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Provede registraci klienta podle UC1: Registrace klienta. 
        /// Oproti UC1 jsou zde dve zmeny:
        /// 1) Neposila se aktivacni email - pouze se posle email s vygenerovanym heslem
        /// 2) Login se negeneruje, uzivatel si ho zada sam. Uz vidim, jak nekdo bude chtit mit login treba CKFdjfnr154 :)
        /// </summary>
        /// <param name="client"></param>
        public static void RegisterClient(Client client)
        {
            // Doplnime udaje, ktere nebyly zadany v registracnim formulari

            string password = GeneratePassword(6);
            client.client_pass_hash = CalculateHashMD5(password);
            client.client_member_from = DateTime.Now;
            client.client_member_to = DateTime.Now.AddDays(1);
            client.client_isEmp = false;
            client.client_is_active = true;

            ClientTable cTab = new ClientTable();

            // Muze vyhodit vyjimku - catch blok v aspx strance
            cTab.Insert(client);

            // Odeslani emailu [zatim nebude odesilat nic]
            SendEmailToClient(client.client_email, password);
        }
Ejemplo n.º 4
0
        protected void BtnInsertClient_Click(object sender, EventArgs e)
        {
            // Vlozeni noveho klienta do systemu
            if (IsValid)
            {

                DatabaseLibrary.Client c = new DatabaseLibrary.Client();

                c.client_name = TxtBoxName.Text;
                c.client_surname = TxtBoxSurname.Text;
                c.client_email = TxtBoxEmail.Text;
                c.client_phone = TxtBoxPhone.Text;

                // Parsovani data narozeni
                string birthDate = TxtBoxBirthDate.Text;
                string[] items = birthDate.Split('/');
                DateTime dateBirth = new DateTime(Int32.Parse(items[2]), Int32.Parse(items[1]), Int32.Parse(items[0]));
                c.client_birth_date = dateBirth;
                c.client_member_from = DateTime.Now;

                // TODO Predelat, pridat clenstvi treba na mesic, nevim... zatim jen tak, aby to fungovalo
                c.client_member_to = DateTime.Now;

                c.client_street = TxtBoxStreet.Text;
                c.client_city = TxtBoxCity.Text;
                c.client_zip = TxtBoxZIP.Text;
                c.client_country = TxtBoxCountry.Text;

                // Pridavame klienta skrze obycejnou stranku, nemuze to byt zamestnanec. Vkladani zamestancu bude asi nekde v nejake administraci.
                c.client_isEmp = false;

                // Pri vytvoreni bude ucet patrne aktivni
                c.client_is_active = true;

                c.client_login = TxtBoxLogin.Text;
                c.client_pass_hash = Cryptography.CalculateHashMD5(TxtBoxPass.Text);

                new DatabaseLibrary.ClientTable().Insert(c);
            }
        }
Ejemplo n.º 5
0
        private Client ReadClientData(MySqlDataReader reader)
        {
            Client client = new Client();

            client.client_id = reader.GetInt32("client_id");
            client.client_name = reader.GetString("client_name");
            client.client_surname = reader.GetString("client_surname");
            client.client_email = reader.GetString("client_email");
            client.client_phone = !reader.IsDBNull(4) ? reader.GetString("client_phone") : null;
            client.client_birth_date = reader.GetDateTime("client_birth_date");
            client.client_member_from = reader.GetDateTime("client_member_from");
            client.client_member_to = !reader.IsDBNull(7) ? reader.GetDateTime("client_member_to") : DateTime.MinValue;
            client.client_street = !reader.IsDBNull(8) ? reader.GetString("client_street") : null;
            client.client_city = !reader.IsDBNull(9) ? reader.GetString("client_city") : null;
            client.client_zip = !reader.IsDBNull(10) ? reader.GetString("client_zip") : null;
            client.client_country = !reader.IsDBNull(11) ? reader.GetString("country") : null;
            client.client_isEmp = reader.GetBoolean("client_isEmp");
            client.client_is_active = reader.GetBoolean("client_is_active");
            client.client_login = reader.GetString("client_login");
            client.client_pass_hash = reader.GetString("client_pass_hash");
            client.client_last_act = !reader.IsDBNull(16) ? reader.GetDateTime("client_last_act") : DateTime.MinValue;

            return client;
        }
Ejemplo n.º 6
0
        public Client SelectOne(int clientId)
        {
            Client client = new Client();
            using (MySqlConnection conn = new MySqlConnection(connString))
            {
                conn.Open();
                MySqlCommand command = new MySqlCommand(SELECT_ONE, conn);
                command.Parameters.AddWithValue("@id", clientId);

                MySqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    client = ReadClientData(reader);
                }
                reader.Close();
            }
            return client;
        }