/// <summary> /// Completeaza campurile unei tari /// </summary> private void FillEditForm() { try { int taraId = Convert.ToInt32(txtTaraID.Text); Salaries.Business.AdminTari tara = new Salaries.Business.AdminTari(); tara.TaraId = taraId; DataSet ds = tara.GetTaraInfo(); DataRow rowTara = ds.Tables[0].Rows[0]; txtNume.Text = rowTara["NumeTara"].ToString(); txtSimbol.Text = rowTara["Simbol"].ToString(); txtNationalitate.Text = rowTara["Nationalitate"].ToString(); chkTaraBaza.Checked = bool.Parse(rowTara["TaraDeBaza"].ToString()); txtTaraID.Text = rowTara["TaraId"].ToString(); td_addLine.Visible = false; listDataGrid.Visible = false; td_editLine.Visible = true; add_form.Style.Add("display", ""); add_buttonLine.Visible = false; tdTitle.InnerText = "Editare tara"; //Daca pagina de administrare a fost deschisa din AddAngajat cream functia care va face refresh la combo-ul cu tari //In acest caz va fi goala ... CreateEmptyRefreshFunctionForAddAngajat(); } catch (Exception ex) { litError.Text = "The following error occurred: <br>"; litError.Text += ex.Message; } }
/// <summary> /// Tari /// </summary> /// <returns></returns> private string GetSirTari() { string sirTari = ""; string sirTariText = "["; string sirTariValue = "["; Salaries.Business.AdminTari tari = new Salaries.Business.AdminTari(); DataSet ds = tari.LoadInfoTari(); for (int i = 0; i < ds.Tables[0].Rows.Count - 1; i++) { DataRow dr = ds.Tables[0].Rows[i]; sirTariText += "'" + dr["NumeTara"].ToString() + "', "; sirTariValue += dr["TaraID"].ToString() + ", "; } if (ds.Tables[0].Rows.Count > 0) { sirTariText += "'" + ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1]["NumeTara"].ToString() + "']"; sirTariValue += ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1]["TaraID"].ToString() + "]"; sirTari = "[" + sirTariText + "," + sirTariValue + "]"; } else { sirTari = "[[],[]]"; } return(sirTari); }
/// <summary> /// Sterge o tara /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDelete_Click(object sender, System.EventArgs e) { try { int taraId = Convert.ToInt32(txtTaraID.Text); Salaries.Business.AdminTari tara = new Salaries.Business.AdminTari(); tara.TaraId = taraId; if (tara.CheckIfTaraCanBeDeleted()) { tara.DeleteTara(); //ListareTari(); CompletareTitlu(); PopulareTabela(); } else { lblMessage.Text = "Tara nu poate fi stearsa! Este inca asociata unor angajati!"; lblMessage.Visible = true; FillEditForm(); } //Daca pagina de administrare a fost deschisa din AddAngajat cream functia care va face refresh la combo-ul cu tari CreateRefreshFunctionForAddAngajat(); } catch (Exception ex) { litError.Text = "The following error occurred: <br>"; litError.Text += ex.Message; } }
/// <summary> /// Populeaza lista cu tari /// </summary> public void PopulareTabela() { Index = listDataGrid.CurrentPageIndex * 30 + 1; Salaries.Business.AdminTari tari = new Salaries.Business.AdminTari(); listDataGrid.DataSource = tari.LoadInfoTari(); listDataGrid.DataBind(); }
/// <summary> /// Se trece la urmatoarea pagina in lista /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void listDataGrid_PageIndexChanged(Object sender, DataGridPageChangedEventArgs e) { Salaries.Business.AdminTari tari = new Salaries.Business.AdminTari(); DataSet dt = tari.LoadInfoTari(); CompletareTitlu(); listDataGrid.CurrentPageIndex = e.NewPageIndex; DataView dv = dt.Tables[0].DefaultView; listDataGrid.DataSource = dv; Index = (e.NewPageIndex * listDataGrid.PageSize) + 1; listDataGrid.DataBind(); }
/// <summary> /// Valorile judetelor /// </summary> /// <returns></returns> private string GetSirJudeteValue() { string sirJudVal = ""; string sirJudValFinal = ""; Salaries.Business.AdminTari tari = new Salaries.Business.AdminTari(); DataSet dsTari = tari.LoadInfoTari(); foreach (DataRow drTari in dsTari.Tables[0].Rows) { Salaries.Business.AdminJudete judete = new Salaries.Business.AdminJudete(); judete.TaraId = int.Parse(drTari["TaraID"].ToString()); DataSet ds = judete.GetAllJudeteTara(); if (ds.Tables[0].Rows.Count > 0) { sirJudVal = "["; for (int i = 0; i < ds.Tables[0].Rows.Count - 1; i++) { DataRow dr = ds.Tables[0].Rows[i]; sirJudVal += dr["JudetID"].ToString() + ", "; } sirJudVal += ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1]["JudetID"].ToString() + "]"; } else { sirJudVal = "[]"; } sirJudValFinal += sirJudVal + ", "; } if (sirJudValFinal == "") { sirJudValFinal += "[[]]"; } else { sirJudValFinal = sirJudValFinal.Substring(0, sirJudValFinal.Length - 2); sirJudValFinal = "[" + sirJudValFinal + "]"; } return(sirJudValFinal); }
/// <summary> /// Daca TaraID = -1 atunci e insert; TaraID > 0 at e update si TaraID e id-ul tarii careia i se face update /// </summary> /// <param name="taraID">Id-ul tarii</param> /// <returns>Returneaza true daca exista si false altfel</returns> private bool ExistaTaraDeBaza(int taraID) { try { Salaries.Business.AdminTari tari = new Salaries.Business.AdminTari(); DataSet dsTaraBaza = tari.GetTaraDeBaza(); if ((taraID == -1 && dsTaraBaza.Tables[0].Rows.Count > 0) || (taraID != -1 && taraID != int.Parse(dsTaraBaza.Tables[0].Rows[0]["TaraID"].ToString()))) { return(true); } else { return(false); } } catch { return(false); } }
/// <summary> /// Modifica o tara /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnModify_Click(object sender, System.EventArgs e) { try { int taraId = Convert.ToInt32(txtTaraID.Text); Salaries.Business.AdminTari tara = new Salaries.Business.AdminTari(); tara.TaraId = taraId; tara.NumeTara = txtNume.Text; tara.Simbol = txtSimbol.Text; tara.Nationalitate = txtNationalitate.Text; tara.TaraDeBaza = chkTaraBaza.Checked; if (!tara.TaraDeBaza || !ExistaTaraDeBaza(taraId)) { if (tara.CheckIfTaraCanBeAdded()) { tara.UpdateTara(); //Daca pagina de administrare a fost deschisa din AddAngajat cream functia care va face refresh la combo-ul cu tari CreateRefreshFunctionForAddAngajat(); } else { Response.Write("<script> alert('Mai exista o tara cu acest nume!'); </script>"); } } else { Response.Write("<script>alert( 'Tara nu a fost salvata, deoarece exista o alta tara de baza!' );</script>"); } } catch (Exception ex) { litError.Text = "The following error occurred: <br>"; litError.Text += ex.Message; } //ListareTari(); CompletareTitlu(); PopulareTabela(); }
/// <summary> /// Daca pagina de administrare a fost deschisa din AddAngajat cream functia care va face refresh la combo-ul cu titluri /// </summary> private void CreateRefreshFunctionForAddAngajat() { string outStr = ""; //tb resetate sirurile cu tari si judete din AddAngajat din cauza actualizarii tarilor string sirTari = GetSirTari(); string sirJudeteText = GetSirJudeteText(); string sirJudeteValue = GetSirJudeteValue(); Response.Write("<script>var tari1 = " + sirTari + ";</script>"); Response.Write("<script>var judeteText1 = " + sirJudeteText + ";</script>"); Response.Write("<script>var judeteValue1 = " + sirJudeteValue + ";</script>"); //cream scriptul care va contine functia de refresh //ne bazam pe faptul ca se cunoaste numele selectului care contine titlurile //initial se sterg toate intrarile din combo outStr += "<script> \r\n function RefreshAddAngajatPage() \r\n" + "{ \r\n" + "window.opener.RecreateArray_TariJudete( 'tari', tari1.length); \r\n" + "for(i=0;i<tari1.length;i++) \r\n" + " window.opener.RecreateLine_TariJudete( 'tari', i, tari1[i].length); \r\n" + "for(i=0;i<tari1.length;i++) \r\n" + "for(j=0;j<tari1[i].length;j++) \r\n" + "window.opener.SetTari( i, j, tari1[i][j]); \r\n" + "window.opener.RecreateArray_TariJudete('judeteText',judeteText1.length); \r\n" + "for(i=0;i<judeteText1.length;i++) \r\n" + " window.opener.RecreateLine_TariJudete( 'judeteText' ,i, judeteText1[i].length); \r\n" + "for(i=0;i<judeteText1.length;i++) \r\n" + "{ \r\n" + " if ( judeteText1[i].length == 0) \r\n" + " window.opener.SetJudeteText( i, 0, null); \r\n"+ " else \r\n" + " for(j=0;j<judeteText1[i].length;j++) \r\n"+ " window.opener.SetJudeteText( i, j, judeteText1[i][j]); \r\n"+ "} \r\n" + "window.opener.RecreateArray_TariJudete('judeteValue',judeteValue1.length); \r\n" + "for(i=0;i<judeteValue1.length;i++) \r\n" + " window.opener.RecreateLine_TariJudete( 'judeteValue' ,i, judeteValue1[i].length); \r\n" + "for(i=0;i<judeteValue1.length;i++) \r\n" + "for(j=0;j<judeteValue1[i].length;j++) \r\n" + "window.opener.SetJudeteValue( i, j, judeteValue1[i][j]); \r\n" + "window.opener.DeleteTariCombo(); \r\n" + " FillTariCOmbo(); \r\n" + "} \r\n"; //acum se creeaza functie care adauga titlurile din recordset //se foloseste o functie din AddAngajat ... FillTaraCombo Salaries.Business.AdminTari tari = new Salaries.Business.AdminTari(); outStr += " function FillTariCOmbo() \r\n" + "{ \r\n"; foreach (DataRow dataRow in tari.LoadInfoTari().Tables[0].Rows) { outStr += "window.opener.FillTaraCombo('" + dataRow["NumeTara"].ToString() + "'," + dataRow["TaraID"].ToString() + ");"; } outStr += " window.opener.SyncronizeTaraJudete(); \r\n"; outStr += "} \r\n" + "</script>"; Response.Write(outStr); }
private void Page_Load(object sender, System.EventArgs e) { if (!IsPostBack) { //se obtine tipul de autentificare la aplicatie string authentication = Salaries.Configuration.CryptographyClass.getSettingsWithoutDecode("authentication"); //daca utilizatorul nu are acces la aplicatie atunci este redirectat catre o pagina in care este afisat un mesaj de avertizare if (authentication == "0") { ErrHandler.MyErrHandler.WriteError("Index.aspx - utilizatorul nu are acces la aplicatie"); Response.Redirect("Unauthorized.aspx"); } //este sters tot din sesine Session.RemoveAll(); try { //se preia stringul de conexiune din web.config settings = Salaries.Configuration.ModuleConfig.GetSettings(); UtilitiesDb utilDb = new UtilitiesDb(settings.ConnectionString); //daca lipseste una din datele strinct necesare pentru conectare la baza, //utilizatorul este redirectat catre pagina pentru introducerea acestor valori string[] s = settings.ConnectionString.Split(';'); if ((s[2] == "data source=") || (s[4] == "initial catalog=") || (s[5] == "user id=") || (s[6] == "pwd=")) { Response.Redirect("AdminSetari.aspx"); } //se verifica daca se pot obtine date din baza de date int angajatorId = 0; try { //daca nu se pot atunci stringul de conexiune nu este corect si utilizatorul este redirectat pentru //introducerea unui string de conexiune corect Salaries.Business.AdminTari tari = new Salaries.Business.AdminTari(); int TaraID = int.Parse(tari.LoadInfoTari().Tables[0].Rows[0]["TaraID"].ToString()); } catch (Exception e1) { Response.Redirect("AdminSetari.aspx"); string msg = e1.Message; } //se selecteaza un angajator Salaries.Business.AdminAngajator angajator = new Salaries.Business.AdminAngajator(); try { //daca nu se poate face acest lucru atunci in baza nu exista angajatori si utilizatorul este //redirectat catre pagina pentru introducerea primului angajator angajatorId = int.Parse(angajator.LoadInfoAngajatori().Tables[0].Rows[0]["AngajatorID"].ToString()); } catch { Response.Redirect("Administrare/AdminPrimulAngajator.aspx"); } Session["AngajatorID"] = angajatorId.ToString(); Session["AngajatorDenumire"] = angajator.LoadInfoAngajatori().Tables[0].Rows[0]["Denumire"].ToString(); //autentificarea este de tip windows prin Active Directory if (authentication == "1") { //este preluat user-ul loginat user = new WindowsPrincipal(WindowsIdentity.GetCurrent()); //daca utilizatorul face parte din grupul HR if (Salaries.Business.Authentication.IsUserInHRgroup(user)) { Session["administrare_departamente"] = ""; Response.Redirect("Home.aspx"); } else { //daca user-ul faca parte din grupul de manageri if (Salaries.Business.Authentication.IsUserInManagersGroup(user)) { Response.Redirect("Managers/Managers.aspx"); } else { //daca user-ul faca parte din grupul de recrutori if (Salaries.Business.Authentication.IsUserInRecrutoriGroup(user)) { Response.Redirect("Recrutori/Recrutori.aspx"); } else { ErrHandler.MyErrHandler.WriteError("Index.aspx - autentificare windows fara drepturi - " + user.Identity.Name); Response.Redirect("Unauthorized.aspx"); } } } } //autentificarea este cu user si parola else { Response.Redirect("AdminUserParola.aspx"); } } catch (Exception ex) { string msg = ex.Message; } } }