Ejemplo n.º 1
0
        public Tuple <int> LoadCashiers(repositories.Cashier cashiers)
        {
            List <string[]> lines = ParseCsv(GetCsvString("cashiers"));

            int added = 0;

            foreach (string[] line in lines)
            {
                int    id   = Convert.ToInt32(line[0]);
                string name = line[1];

                entities.Cashier cashier = cashiers.FindOne(id);

                if (cashier == null)
                {
                    entities.Cashier addCashier = new entities.Cashier(id, name);
                    cashiers.SaveWithSql(addCashier);
                }
                else
                {
                    cashier.SetId(id);
                    cashier.SetName(name);

                    cashiers.SaveWithSql(cashier);

                    added++;
                }
            }

            return(new Tuple <int>(added));
        }
Ejemplo n.º 2
0
        public int DeleteWithSql(entities.Cashier cashier)
        {
            entities.Cashier hasCashier = FindOne(cashier.GetId());

            SQLiteCommand command;

            command = new SQLiteCommand("DELETE FROM cashier WHERE id = @id", db.connection);

            command.Parameters.AddWithValue("@id", cashier.GetId());

            int num = command.ExecuteNonQuery();

            return(num);
        }
Ejemplo n.º 3
0
        public bool FillCashiers(repositories.Cashier cashierRepository)
        {
            SQLiteCommand command = new SQLiteCommand("SELECT * FROM cashier", db.connection);

            SQLiteDataReader reader = command.ExecuteReader();

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    //MessageBox.Show(reader["name"].ToString());
                    entities.Cashier cashbox = new entities.Cashier(Convert.ToInt32(reader["id"].ToString()), reader["name"].ToString());
                    cashierRepository.Add(cashbox);
                }
            }

            reader.Close();

            return(true);
        }
Ejemplo n.º 4
0
        public int SaveWithSql(entities.Cashier cashier)
        {
            entities.Cashier hasCashier = FindOne(cashier.GetId());

            SQLiteCommand command;

            if (cashier.GetId() == 0 | hasCashier == null)
            {
                Add(cashier);
                command = new SQLiteCommand("INSERT INTO cashier(name) VALUES(@name)", db.connection);
            }
            else
            {
                command = new SQLiteCommand("UPDATE cashier SET name = @name WHERE id = @id ", db.connection);
            }

            command.Parameters.AddWithValue("@id", cashier.GetId());
            command.Parameters.AddWithValue("@name", cashier.GetName());

            int num = command.ExecuteNonQuery();

            return(num);
        }
Ejemplo n.º 5
0
 public void Delete(entities.Cashier cashbox)
 {
     cashiers.Remove(cashbox);
 }
Ejemplo n.º 6
0
 public void Add(entities.Cashier cashier)
 {
     cashiers.Add(cashier);
 }