private void ComboBox1_SelectedIndexChanged(object sender, EventArgs e) { dt.Columns.Clear(); dt.Rows.Clear(); DataRow dr = dt.NewRow(); string[] words = Cmb_workers.SelectedItem.ToString().Split(' '); string worker_name = words[0]; string worker_surname = words[1]; string worker_id = api.getWorkerId(api.getAllWorkers(), worker_name, worker_surname); List <Time> listek = api.returnListTime(api.getAllTime(), worker_id); for (int x = 0; x < listek.Count; x++) { if (dt.Rows.Count <= 0) { if (listek[x].worker_id == worker_id) { DataColumn dc1 = new DataColumn("Ime", typeof(string)); DataColumn dc2 = new DataColumn("Priimek", typeof(string)); DataColumn dc3 = new DataColumn("Ime gradbišča", typeof(string)); DataColumn dc4 = new DataColumn("Datum", typeof(string)); DataColumn dc5 = new DataColumn("Število opravljenih minut", typeof(string)); dt.Columns.Add(dc1); dt.Columns.Add(dc2); dt.Columns.Add(dc3); dt.Columns.Add(dc4); dt.Columns.Add(dc5); dt.Rows.Add(worker_name, worker_surname, api.getConstructionName(api.getAllConstructions(), listek[x].construction_id), listek[x].Timestamp_date, listek[x].Shift); dataGridView1.DataSource = dt; } } else { if (listek[x].worker_id == worker_id) { dt.Rows.Add(worker_name, worker_surname, api.getConstructionName(api.getAllConstructions(), listek[x].construction_id), listek[x].Timestamp_date, listek[x].Shift); dataGridView1.DataSource = dt; } } } }
private void Btn_addTime_Click(object sender, EventArgs e) { string iDate = DateTimePickerShift.Value.ToString("yyyy-MM-dd"); int Shift = Convert.ToInt32(Txt_minutes.Text); string[] words = CmbBx_worker.SelectedItem.ToString().Split(' '); string worker_name = words[0]; string worke_surname = words[1]; string worker_id = api.getWorkerId(api.getAllWorkers(), worker_name, worke_surname); string construction_site_name = CmbBx_construction.SelectedItem.ToString(); string construction_id = api.getConstructionsId(api.getAllConstructions(), construction_site_name); api.addTime(admin_id, worker_id, construction_id, Shift, iDate); }