public FormAngajat() { InitializeComponent(); MyOracleConnection.getAngId(); MyOracleConnection.collectPontaj(MyOracleConnection.utilizatorId, dataGridPontaj); labelCounterObjects.Text = dataGridPontaj.RowCount.ToString(); }
/** Sterge un element.Pontaj din tabel **/ private void buttonDeleteUserObject_Click(object sender, EventArgs e) { // daca tabela de pontaj nu este goala if (dataGridPontaj.RowCount > 0) { string proiectNume = ""; int oraStart = 0; int oraStop = 0; int totalOre = 0; string dateTimePontaj = ""; foreach (DataGridViewRow row in dataGridPontaj.SelectedRows) { proiectNume = row.Cells[1].Value.ToString(); oraStart = int.Parse(row.Cells[2].Value.ToString()); oraStop = int.Parse(row.Cells[3].Value.ToString()); totalOre = int.Parse(row.Cells[4].Value.ToString()); dateTimePontaj = row.Cells[5].Value.ToString(); } int buffer = 3079; OracleCommand command = MyOracleConnection.con.CreateCommand(); try { command.CommandText = "userDBA.ANGAJAT_PACKAGE.FUNC_STERGE_PONTAJ"; // seteaza flag command.Parameters.Add("flag", OracleDbType.Int32, buffer); command.Parameters["flag"].Direction = ParameterDirection.ReturnValue; // asigneaza valori parametrilor command.Parameters.Add(new OracleParameter("dataPontaj", OracleDbType.Date)).Value = DateTime.ParseExact(dateTimePontaj, "dd-MM-yyyy", CultureInfo.InvariantCulture); command.Parameters.Add(new OracleParameter("oraStart", OracleDbType.Int32)).Value = oraStart; command.Parameters.Add(new OracleParameter("oraStop", OracleDbType.Int32)).Value = oraStop; command.Parameters.Add(new OracleParameter("proiect_nume", OracleDbType.Varchar2)).Value = proiectNume; command.Parameters.Add(new OracleParameter("numeAngajat", OracleDbType.Varchar2)).Value = MyOracleConnection.utilizatorId; command.Parameters.Add(new OracleParameter("pro_ore_efec", OracleDbType.Int32)).Value = totalOre; command.CommandType = CommandType.StoredProcedure; command.ExecuteNonQuery(); } catch (Exception exc) { MessageBox.Show("[Eroare-Exception] " + exc); } string flag_insert = Convert.ToString(command.Parameters["flag"].Value); if (flag_insert == "1") { MyOracleConnection.collectPontaj(MyOracleConnection.utilizatorId, dataGridPontaj); MessageBox.Show("[Log] Stergere cu succes."); } else { MessageBox.Show("[Eroare] Nu s-a sters elementul nou.\n"); } } else { MessageBox.Show("[Eroare] Nu exista elemente.\nTabel gol."); } }
/** Editeaza pontajul **/ private void buttonEditeazaPontaj_Click(object sender, EventArgs e) { int oraStart = -1; int oraStop = -1; int indexOraStart = comboBoxOraStartEdit.SelectedIndex; int indexOraStop = comboBoxOraStopEdit.SelectedIndex; int totalOrePontate = 0; /** validare date inainte de a executa procedura **/ // daca orele nu sunt selectate if (indexOraStart == -1 || indexOraStop == -1) { MessageBox.Show("[Eroare] Va rugam sa selectati intervalul orar corect."); } else { oraStart = comboBoxOraStartEdit.Items[indexOraStart].ToString().Length > 0 ? Int32.Parse(comboBoxOraStartEdit.Items[indexOraStart].ToString()) : -1; oraStop = comboBoxOraStopEdit.Items[indexOraStop].ToString().Length > 0 ? Int32.Parse(comboBoxOraStopEdit.Items[indexOraStop].ToString()) : -1; totalOrePontate += oraStop - oraStart; // verifica turele de noapte if ((oraStop >= 1 && oraStop <= 6) || oraStop == 24) { MessageBox.Show("[Eroare] Turele de noapte nu sunt admise.\n Nu se poate ponta in intervalul 24:00 - 6:00"); totalOrePontate = 0; } else { // verifica daca numarul de ore pontate pe zi este depasit if (totalOrePontate > 8 || totalOrePontate <= 0) { MessageBox.Show("[Eroare] Nu se pot ponta mai mult de 8 h/zi sau mai putin de o 1 h/zi."); totalOrePontate = 0; } else { int buffer = 3079; OracleCommand command = MyOracleConnection.con.CreateCommand(); try { command.CommandText = "userDBA.ANGAJAT_PACKAGE.FUNC_EDITEAZA_PONTAJ"; command.Parameters.Add("flag", OracleDbType.Int32, buffer); command.Parameters["flag"].Direction = ParameterDirection.ReturnValue; // asigneaza valori parametrilor Console.Write(projectMapping.FirstOrDefault(x => x.Value == oldValueNumeProiect).Key); command.Parameters.Add(new OracleParameter("dataPontaj", OracleDbType.Date)).Value = dateTimePickerEdit.Value; command.Parameters.Add(new OracleParameter("numeAngajat", OracleDbType.Varchar2)).Value = MyOracleConnection.utilizatorId; command.Parameters.Add(new OracleParameter("idProiect", OracleDbType.Int32)).Value = projectMapping.FirstOrDefault(x => x.Value == oldValueNumeProiect).Key; command.Parameters.Add(new OracleParameter("oldOraStart", OracleDbType.Int32)).Value = oldValueOraStart; command.Parameters.Add(new OracleParameter("oldOraStop", OracleDbType.Int32)).Value = oldValueOraStop; command.Parameters.Add(new OracleParameter("newOraStart", OracleDbType.Int32)).Value = oraStart; command.Parameters.Add(new OracleParameter("newOraStop", OracleDbType.Int32)).Value = oraStop; command.Parameters.Add(new OracleParameter("old_pro_ore_efec", OracleDbType.Int32)).Value = oldValueTotalOre; command.Parameters.Add(new OracleParameter("new_pro_ore_efec", OracleDbType.Int32)).Value = oraStop - oraStart; // executa funtia command.CommandType = CommandType.StoredProcedure; command.ExecuteNonQuery(); string flag_insert = Convert.ToString(command.Parameters["flag"].Value); // verifica ce returneaza functia pl/sql switch (flag_insert) { case "0": { MyOracleConnection.collectPontaj(MyOracleConnection.utilizatorId, parentForm.getGridObject()); MessageBox.Show("[Log] Editare cu succes."); totalOrePontate = 0; break; } case "1": { MessageBox.Show("[Log] Orele pe care le adaugati suprapun alte ore deja pontate.\n Verificati din nou cu atentie!"); totalOrePontate = 0; break; } case "2": { MessageBox.Show("[Log] Data not found."); totalOrePontate = 0; break; } } } catch (Exception exc) { MessageBox.Show("[Log - Exception] " + exc); } } } } }