Exemple #1
0
        public bool save()
        {
            db db = new db();

            if (!db.dbOpen())
            {
                return(false);
            }

            string saveQuery = "";

            if (id_equipment < 0)
            {
                saveQuery = getQuery("i");
            }
            else
            {
                saveQuery = getQuery("u");
            }

            if (!db.executeParamQuery(saveQuery,
                                      new DictionaryEntry("@brand", brand),
                                      new DictionaryEntry("@model", model),
                                      new DictionaryEntry("@color", color),
                                      new DictionaryEntry("@size", size),
                                      new DictionaryEntry("@number", number),
                                      new DictionaryEntry("@cost", cost),
                                      new DictionaryEntry("@in_stock", in_stock),
                                      new DictionaryEntry("@type", type)

                                      ))
            {
                db.dbClose(); return(false);
            }
            if (id_equipment < 0)
            {
                id_equipment = Convert.ToInt32(db.executeScalar("SELECT last_insert_rowid()"));
            }
            db.dbClose();

            return(true);
        }
Exemple #2
0
        public bool save()
        {
            db db = new db();

            if (!db.dbOpen())
            {
                return(false);
            }

            string saveQuery = "";

            if (id_contract_hire < 0)
            {
                saveQuery = getQuery("i");
            }
            else
            {
                saveQuery = getQuery("u");
            }

            if (!db.executeParamQuery(saveQuery,
                                      new DictionaryEntry("@id_client", id_client),
                                      new DictionaryEntry("@equipment_in_contract", equipment_in_contract),
                                      new DictionaryEntry("@object_of_pledge", object_of_pledge),
                                      new DictionaryEntry("@rent", rent),
                                      new DictionaryEntry("@start_time", start_time),
                                      new DictionaryEntry("@end_time", end_time),
                                      new DictionaryEntry("@returned", returned)
                                      ))
            {
                db.dbClose(); return(false);
            }
            if (id_contract_hire < 0)
            {
                id_contract_hire = Convert.ToInt32(db.executeScalar("SELECT last_insert_rowid()"));
            }
            db.dbClose();

            return(true);
        }
Exemple #3
0
        public bool reduceStock()
        {
            db db = new db();

            if (!db.dbOpen())
            {
                return(false);
            }

            string saveQuery = string.Format("UPDATE equipments SET in_stock = @in_stock  WHERE id_equipment = {0}", id_equipment);


            if (!db.executeParamQuery(saveQuery,
                                      new DictionaryEntry("@in_stock", in_stock - 1)
                                      ))
            {
                db.dbClose(); return(false);
            }
            db.dbClose();

            return(true);
        }
Exemple #4
0
        public List <cEquipment> getEquipment()
        {
            List <cEquipment> equipList = new List <cEquipment>();
            db db;
            SQLiteDataReader dbRdr;
            cEquipment       equip;

            equipList.Clear();
            string query = "SELECT * FROM equipments ";

            query += "INNER JOIN equioments_in_contract ON equipments.id_equipment = equioments_in_contract.id_equipment ";
            query += String.Format("WHERE equioments_in_contract.equioment_in_contract = {0} ", equipment_in_contract);
            db     = new db();
            try
            {
                if (!db.dbOpen())
                {
                    throw new Exception("Ошибка подключения к БД.");
                }
                dbRdr = db.getReader(query);
                while (dbRdr.Read())
                {
                    equip = new cEquipment();
                    equip.setEquipment(dbRdr);
                    equipList.Add(equip);
                }
                dbRdr.Close();
                db.dbClose();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка чтения из базы данных: " + ex.Message, "Ошибка базы данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally { db.dbClose(); }


            return(equipList);
        }
Exemple #5
0
        public bool save()
        {
            db db = new db();

            if (!db.dbOpen())
            {
                return(false);
            }

            string saveQuery = "";

            if (id_client < 0)
            {
                saveQuery = getQuery("i");
            }
            else
            {
                saveQuery = getQuery("u");
            }

            if (!db.executeParamQuery(saveQuery,
                                      new DictionaryEntry("@fio", fio),
                                      new DictionaryEntry("@phone", phone),
                                      new DictionaryEntry("@address", address),
                                      new DictionaryEntry("@passport", passport)

                                      ))
            {
                db.dbClose(); return(false);
            }
            if (id_client < 0)
            {
                id_client = Convert.ToInt32(db.executeScalar("SELECT last_insert_rowid()"));
            }
            db.dbClose();

            return(true);
        }
Exemple #6
0
        public bool addStock()
        {
            db db = new db();

            if (!db.dbOpen())
            {
                return(false);
            }
            in_stock = Convert.ToInt32(db.executeScalar(string.Format("SELECT in_stock FROM equipments WHERE id_equipment = {0}", id_equipment)));

            string saveQuery = string.Format("UPDATE equipments SET in_stock = @in_stock  WHERE id_equipment = {0}", id_equipment);


            if (!db.executeParamQuery(saveQuery,
                                      new DictionaryEntry("@in_stock", in_stock + 1)
                                      ))
            {
                db.dbClose(); return(false);
            }
            db.dbClose();

            return(true);
        }