コード例 #1
0
        public static int Update(TymZamestnance tz, MyDatabase pDb = null)
        {
            MyDatabase db;

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

            SqlCommand command = db.CreateCommand(SQL_UPDATE);

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

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

            return(ret);
        }
コード例 #2
0
        private void button4_Click(object sender, EventArgs e)
        {
            string zaznam = TymZamestnanceLB.GetItemText(TymZamestnanceLB.SelectedItem);

            string[] casti          = zaznam.Split(' ');
            int      ID_zamestnance = int.Parse(casti[0]);

            string zaznam2 = TymyLB.GetItemText(TymyLB.SelectedItem);

            string[] casti2  = zaznam2.Split(' ');
            int      ID_tymu = int.Parse(casti2[0]);

            MyDatabase db = new MyDatabase();

            db.Connect();

            if (TymyLB.Items.Count > 0 && TymyLB.SelectedIndex != -1)
            {
                zaznam2 = TymyLB.GetItemText(TymyLB.SelectedItem);
                casti2  = zaznam2.Split(' ');
                ID_tymu = int.Parse(casti2[0]);

                if (TymZamestnanceLB.Items.Count > 0 && TymZamestnanceLB.SelectedIndex != -1)
                {
                    zaznam         = TymyLB.GetItemText(TymyLB.SelectedItem);
                    casti          = zaznam2.Split(' ');
                    ID_zamestnance = int.Parse(casti2[0]);

                    TymZamestnance tz = new TymZamestnance();
                    tz.ID_zamestnance = ID_zamestnance;
                    tz.ID_tym         = ID_tymu;

                    TymZamestnanceTable.DeleteJednohoZamestnance(ID_zamestnance, ID_tymu, db);
                    DateTime DatumTymu = DateTime.Parse(casti2[2]);

                    NacistVhodneZamestnance(ID_tymu, DatumTymu);
                    NacistZamestnanceZTymu(ID_tymu);

                    db.Close();
                }
                else
                {
                    MessageBox.Show("Nebyl vybrán zaměstnanec, kterého chcete odstranit z týmu");
                    db.Close();
                    return;
                }
            }
            else
            {
                MessageBox.Show("Nebyl vybrán tým, na kterém chcete odebrat zaměstnance");
                db.Close();
                return;
            }
        }
コード例 #3
0
        private static Collection <TymZamestnance> ReadZamestnance(SqlDataReader reader)
        {
            Collection <TymZamestnance> tzC = new Collection <TymZamestnance>();

            while (reader.Read())
            {
                int            i  = -1;
                TymZamestnance tz = new TymZamestnance();
                tz.ID_zamestnance = reader.GetInt32(++i);
                tzC.Add(tz);
            }
            return(tzC);
        }
コード例 #4
0
        public static TymZamestnance Select(int id, MyDatabase pDb = null)
        {
            MyDatabase db;

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

            SqlCommand command = db.CreateCommand(SQL_SELECT_ID);

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

            Collection <TymZamestnance> tzC = Read(reader);
            TymZamestnance tz = null;

            if (tzC.Count == 1)
            {
                tz = tzC[0];
            }
            reader.Close();

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

            if (tz == null)
            {
                Console.WriteLine("Tym zamestnance neexistuje");
            }

            return(tz);
        }
コード例 #5
0
 private static void PrepareCommand(SqlCommand command, TymZamestnance tz)
 {
     command.Parameters.AddWithValue("@ID_tymZamestnance", tz.ID_tymZamestnance);
     command.Parameters.AddWithValue("@ID_zamestnance", tz.ID_zamestnance);
     command.Parameters.AddWithValue("@ID_tym", tz.ID_tym);
 }