コード例 #1
0
        public int createNewCustomer(string[] stab)
        {
            CITIES_Manager cm = new CITIES_Manager(Configuration);

            string[] citiesTab = new string[2] {
                stab[4], stab[5]
            };
            int citiesId = cm.getCitiesId(citiesTab);

            if (citiesId == 0)
            {
                citiesId = cm.createNewCities(citiesTab);
            }

            string login = $"{stab[0].ToLower().Substring(0, 1)}.{stab[1].ToLower()}";

            if (CUSTOMERS_DB.CheckExistingCUSTOMERS(login) == 0)
            {
                return(0);
            }

            CUSTOMERS customers = new CUSTOMERS();

            customers.FirstName    = stab[0];
            customers.LastName     = stab[1];
            customers.Phone_Number = stab[2];
            customers.Address      = stab[3];
            customers.Login        = login;
            customers.Password     = "******";
            customers.Fk_Id_Cities = citiesId;

            return((CUSTOMERS_DB.AddCUSTOMERS(customers)).Id);
        }
コード例 #2
0
        public CUSTOMERS AddCUSTOMERS(CUSTOMERS customers)
        {
            string connectionString = Config.GetConnectionString("DefaultConnection");

            try
            {
                using (SqlConnection cn = new SqlConnection(connectionString))
                {
                    string     query = "INSERT INTO CUSTOMERS VALUES (@FirstName, @LastName, @Phone_Number, @Address, @Login, @Password, GETDATE(), @Fk_Id_Cities); SELECT SCOPE_IDENTITY()";
                    SqlCommand cmd   = new SqlCommand(query, cn);
                    cmd.Parameters.AddWithValue("@FirstName", customers.FirstName);
                    cmd.Parameters.AddWithValue("@LastName", customers.LastName);
                    cmd.Parameters.AddWithValue("@Phone_Number", customers.Phone_Number);
                    cmd.Parameters.AddWithValue("@Address", customers.Address);
                    cmd.Parameters.AddWithValue("@Login", customers.Login);
                    cmd.Parameters.AddWithValue("@Password", customers.Password);
                    cmd.Parameters.AddWithValue("@Fk_Id_Cities", customers.Fk_Id_Cities);

                    cn.Open();

                    customers.Id = Convert.ToInt32(cmd.ExecuteScalar());
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(customers);
        }
コード例 #3
0
        public int checkCustomerLogin(string[] stab)
        {
            CUSTOMERS customers = CUSTOMERS_DB.GetCUSTOMERS(stab[0]);

            if (stab[1].Equals(customers.Password))
            {
                return(customers.Id);
            }

            return(0);
        }
コード例 #4
0
        public CUSTOMERS GetCUSTOMERS(string login)
        {
            CUSTOMERS customers        = null;
            string    connectionString = Config.GetConnectionString("DefaultConnection");

            try
            {
                using (SqlConnection cn = new SqlConnection(connectionString))
                {
                    string     query = "SELECT * FROM CUSTOMERS where Login = @login";
                    SqlCommand cmd   = new SqlCommand(query, cn);
                    cmd.Parameters.AddWithValue("@login", login);

                    cn.Open();

                    using (SqlDataReader dr = cmd.ExecuteReader())
                    {
                        if (dr.Read())
                        {
                            customers = new CUSTOMERS();

                            if (dr["Id"] != DBNull.Value)
                            {
                                customers.Id = (int)dr["Id"];
                            }

                            if (dr["FirstName"] != DBNull.Value)
                            {
                                customers.FirstName = (string)dr["FirstName"];
                            }

                            if (dr["LastName"] != DBNull.Value)
                            {
                                customers.LastName = (string)dr["LastName"];
                            }

                            if (dr["Phone_Number"] != DBNull.Value)
                            {
                                customers.Phone_Number = (string)dr["Phone_Number"];
                            }

                            if (dr["Address"] != DBNull.Value)
                            {
                                customers.Address = (string)dr["Address"];
                            }

                            if (dr["Login"] != DBNull.Value)
                            {
                                customers.Login = (string)dr["Login"];
                            }

                            if (dr["Password"] != DBNull.Value)
                            {
                                customers.Password = (string)dr["Password"];
                            }

                            if (dr["Created_At"] != DBNull.Value)
                            {
                                customers.Created_At = (DateTime)dr["Created_At"];
                            }

                            if (dr["Fk_Id_Cities"] != DBNull.Value)
                            {
                                customers.Fk_Id_Cities = (int)dr["Fk_Id_Cities"];
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(customers);
        }