예제 #1
0
        private CustomersList ReadFromFile()
        {
            FileStream    fs = null;
            CustomersList c = new CustomersList();
            int           type, size, outlets, bulbs;
            string        cc;

            try
            {
                fs = new FileStream("customers.txt", FileMode.OpenOrCreate, FileAccess.Read);
                BinaryReader br = new BinaryReader(fs);
                while (br.BaseStream.Position != br.BaseStream.Length)
                {
                    type    = br.ReadInt32();
                    size    = br.ReadInt32();
                    outlets = br.ReadInt32();
                    bulbs   = br.ReadInt32();
                    cc      = br.ReadString();
                    switch (type)
                    {
                    case 1:
                        c.Add(new Barn(size, bulbs, outlets, cc));
                        break;

                    case 2:
                        c.Add(new Garage(size, bulbs, outlets, cc));
                        break;

                    case 3:
                        c.Add(new House(size, bulbs, outlets, cc));
                        break;
                    }
                }
                return(c);
            }
            catch (IOException ioe)
            {
                string ex = ioe.ToString();
                return(null);
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }
예제 #2
0
        private void OnAddCustomerCommandExecute()
        {
            Customer customer = new Customer();

            customer.Name    = CurrentCustomerName;
            customer.MVZList = new ObservableCollection <MVZ>();
            foreach (var item in MVZList)
            {
                customer.MVZList.Add(item);
            }
            CustomersList.Add(customer);
            db.SaveChanges();
        }
예제 #3
0
        public static string GET_ALL_CUSTOMERS()
        {
            try
            {
                conn.Open();
                //utworzenie zapytania do bazy o pozycję użytkownika
                MySqlCommand command = conn.CreateCommand();
                command.CommandType = System.Data.CommandType.Text;
                command.CommandText = "SELECT * FROM customers";

                //sprawdzenie, czy baza zwróciła cokolwiek
                object result = command.ExecuteScalar();
                //jeśli zwróciła
                if (result != null)
                {
                    var reader = command.ExecuteReader();
                    reader.Read();
                    while (reader.Read())
                    {
                        CustomersList.Add(new Customer(reader));
                    }
                    return("customers-loaded");
                }
                //jeśli nie zwróciła - brak klientów w bazie
                else
                {
                    return("no-customer");
                }
            }
            //obsługa błędu połączenia z bazą
            catch (MySqlException)
            {
                return("no-connection");
            }
            finally
            {
                conn.Close();
            }
        }
예제 #4
0
        private void BtnAdd_Click(object sender, RoutedEventArgs e)
        {
            bool   result  = true;
            int    size    = 0;
            int    bulbs   = 0;
            int    outlets = 0;
            int    i       = -1;
            string cc      = string.Empty;

            if ((!int.TryParse(TxtSize.Text.Trim(), out size)) || (size < 1000) || (size > 50000))
            {
                result             = false;
                TxtSize.Foreground = Brushes.Red;
            }
            if (!(int.TryParse(TxtBulbs.Text.Trim(), out bulbs)) || (bulbs < 1) || (bulbs > 20))
            {
                result = false;
                TxtBulbs.Foreground = Brushes.Red;
            }
            if (!(int.TryParse(TxtOutlets.Text.Trim(), out outlets)) || (outlets < 1) || (outlets > 50))
            {
                result = false;
                TxtOutlets.Foreground = Brushes.Red;
            }
            cc = TxtCC.Text.Trim();
            if (!Program.CheckCard(cc))
            {
                result           = false;
                TxtCC.Foreground = Brushes.Red;
            }
            switch (TxtType.Text.Trim())
            {
            default:
                TxtType.Foreground = Brushes.Red;
                break;

            case "Barn":
                if (result)
                {
                    customers.Add(new Barn(size, bulbs, outlets, cc));
                    i++;
                    WriteToFile(customers[i]);
                    ClearData();
                }
                break;

            case "Garage":
                if (result)
                {
                    customers.Add(new Garage(size, bulbs, outlets, cc));
                    i++;
                    WriteToFile(customers[i]);
                    ClearData();
                }
                break;

            case "House":
                if (result)
                {
                    customers.Add(new House(size, bulbs, outlets, cc));
                    i++;
                    WriteToFile(customers[i]);
                    ClearData();
                }
                break;
            }
        }
예제 #5
0
 public void AddCustomer(Customer customer)
 {
     CustomersList.Add(customer);
 }