Exemple #1
0
        /// <summary>
        /// Update the record.
        /// </summary>
        public static int Update(Zavody zavody, Database pDb = null)
        {
            Database db;

            if (pDb == null)
            {
                db = new Database();
                db.Connect();
            }
            else
            {
                db = (Database)pDb;
            }

            if (zavody.datum <= DateTime.Now)
            {
                return(0);
            }

            SqlCommand command = db.CreateCommand(SQL_UPDATE);

            PrepareCommand(command, zavody);
            int ret = db.ExecuteNonQuery(command);

            if (pDb == null)
            {
                db.Close();
            }

            return(ret);
        }
Exemple #2
0
        /// <summary>
        /// Delete the record.
        /// </summary>
        /// <param name="idZavodye">zavody id</param>
        /// <returns></returns>
        public static int Delete(Zavody zavody, Database pDb = null)
        {
            Database db;

            if (pDb == null)
            {
                db = new Database();
                db.Connect();
            }
            else
            {
                db = (Database)pDb;
            }

            if (zavody.datum <= DateTime.Now)
            {
                return(800);
            }

            SoutezTable.DeleteZid(zavody.zid, db);

            SqlCommand command = db.CreateCommand(SQL_DELETE_ID);

            command.Parameters.AddWithValue("@id", zavody.zid);
            int ret = db.ExecuteNonQuery(command);

            if (pDb == null)
            {
                db.Close();
            }

            return(ret);
        }
Exemple #3
0
        /// <summary>
        /// Insert the record.
        /// </summary>
        public static Zavody Insert(Zavody zavody, Database pDb = null)
        {
            Database db;

            if (pDb == null)
            {
                db = new Database();
                db.Connect();
            }
            else
            {
                db = (Database)pDb;
            }

            SqlCommand command = db.CreateCommand(SQL_INSERT);

            PrepareCommand(command, zavody);
            db.ExecuteNonQuery(command);

            command = db.CreateCommand(SQL_SELECT_LAST);
            SqlDataReader reader = db.Select(command);

            reader.Read();
            zavody.zid = reader.GetInt32(0);
            reader.Close();

            if (pDb == null)
            {
                db.Close();
            }

            return(zavody);
        }
Exemple #4
0
        /// <summary>
        /// Select the record.
        /// </summary>
        /// <param name="id">zavody id</param>
        public static Zavody Select(int id, Database pDb = null)
        {
            Database db;

            if (pDb == null)
            {
                db = new Database();
                db.Connect();
            }
            else
            {
                db = (Database)pDb;
            }

            SqlCommand command = db.CreateCommand(SQL_SELECT_ID);

            command.Parameters.AddWithValue("@id", id);
            SqlDataReader reader = db.Select(command);

            Collection <Zavody> zavody = Read(reader);
            Zavody zavod = null;

            if (zavody.Count == 1)
            {
                zavod = zavody[0];
            }
            reader.Close();

            if (pDb == null)
            {
                db.Close();
            }

            return(zavod);
        }
Exemple #5
0
        private static Collection <Zavody> Read(SqlDataReader reader)
        {
            Collection <Zavody> zavody = new Collection <Zavody>();

            while (reader.Read())
            {
                Zavody zavod = new Zavody();

                int i = -1;
                zavod.zid      = reader.GetInt32(++i);
                zavod.sid      = reader.GetInt32(++i);
                zavod.datum    = reader.GetDateTime(++i);
                zavod.stajName = JISdata.DAO.StajTable.SelectNazev(zavod.sid);
                zavod.info     = zavod.stajName + " " + zavod.datum.ToShortDateString();
                zavody.Add(zavod);
            }
            return(zavody);
        }
Exemple #6
0
        private void button3_Click(object sender, EventArgs e)
        {
            Zavody newZavody = new Zavody();

            newZavody.sid   = model.staj.sid;
            newZavody.datum = dateTimePicker1.Value;

            newZavody = ZavodyTable.Insert(newZavody);

            foreach (var soutez in model.newSouteze)
            {
                soutez.zid = newZavody.zid;
                SoutezTable.Insert(soutez);
            }
            textObtiznost.ResetText();
            textLimit.ResetText();
            dateTimePicker1.ResetText();
            model.newSouteze.Clear();
            BindingList <Soutez> bindingList = new BindingList <Soutez>(model.newSouteze);

            dataGridView3.AutoGenerateColumns = false;
            dataGridView3.DataSource          = bindingList;
            StajPrihlasen_Load(sender, e);
        }
Exemple #7
0
 /// <summary>
 ///  Prepare a command.
 /// </summary>
 private static void PrepareCommand(SqlCommand command, Zavody zavody)
 {
     command.Parameters.AddWithValue("@zid", zavody.zid);
     command.Parameters.AddWithValue("@sid", zavody.sid);
     command.Parameters.AddWithValue("@datum", zavody.datum);
 }