private void dgFields_EditCommand(object source, DataGridCommandEventArgs e) { dgFields.EditItemIndex = e.Item.ItemIndex; dgFields.DataKeyField = "FieldId"; BindValues(); int sid = int.Parse(e.Item.Cells[0].Text); LdapField lf = LdapField.Load(sid); foreach (DataGridItem dgi in dgFields.Items) { DropDownList ddEqual = (DropDownList)dgi.FindControl("ddEqual"); if (ddEqual != null) { ddEqual.SelectedValue = lf.Equal ? "true" : "false"; } DropDownList ddIbnName = (DropDownList)dgi.FindControl("ddIbnName"); if (ddIbnName != null) { ddIbnName.SelectedValue = lf.IbnName; } DropDownList ddLdapName = (DropDownList)dgi.FindControl("ddLdapName"); if (ddLdapName != null) { try { ddLdapName.SelectedValue = lf.LdapName; } catch { } ddLdapName.Attributes.Add("onchange", "ChangeLdap(this)"); } } }
public LdapField ReadConfigLdap() { using (StreamReader streamReader = new StreamReader("ConfigConnect")) { ldap = new LdapField(); string text; while ((text = streamReader.ReadLine()) != null) { if (text.Contains("=")) { string text2 = text.Substring(0, text.IndexOf("=")); switch (text2.ToLower()) { case "urlldap": ldap.UrlLdap = getField(text); break; case "bindldap": ldap.BindLdap = getField(text); break; case "binddn": ldap.BindDn = getField(text); break; case "bindcredential": ldap.BindCredential = getField(text); break; } } } } return(ldap); }
private void dgFields_DeleteCommand(object source, DataGridCommandEventArgs e) { int sid = int.Parse(e.Item.Cells[0].Text); LdapField.Delete(sid); Response.Redirect("~/Admin/LdapSettingsView.aspx?SetId=" + SetId); }
private bool ValidatePingHostLdap() { ldapField = new ReadWriterConfig().ReadConfigLdap(); int numberStart = ldapField.UrlLdap.IndexOf("LDAP://") + 7; int numberEnd = ldapField.UrlLdap.LastIndexOf(":"); string hostUri = ldapField.UrlLdap.Substring(numberStart, numberEnd - numberStart); int portNumber = int.Parse(ldapField.UrlLdap.Substring(numberEnd + 1)); return(validateLdap = new CheckUrl().PingHost(hostUri, portNumber)); }
private void UpdateConfigDatabase() { List <string> list = new List <string>(); using (StreamReader streamReader = new StreamReader("ConfigConnect")) { string item; while ((item = streamReader.ReadLine()) != null) { list.Add(item); } } using (StreamWriter streamWriter = new StreamWriter("ConfigConnect")) { ldap = new LdapField(); ldap.UrlLdap = txtLdap.Text; ldap.BindLdap = txtBindLdap.Text; ldap.BindDn = txtBindDn.Text; ldap.BindCredential = txtBindCredential.Text; foreach (string item2 in list) { if (!item2.Contains("=")) { streamWriter.WriteLine(item2); } else { string text = item2.Substring(0, item2.IndexOf("=")); switch (text.ToLower()) { case "urlldap": streamWriter.WriteLine("UrlLdap=" + ldap.UrlLdap); break; case "bindldap": streamWriter.WriteLine("BindLdap=" + ldap.BindLdap); break; case "binddn": streamWriter.WriteLine("BindDn=" + ldap.BindDn); break; case "bindcredential": streamWriter.WriteLine("BindCredential=" + ldap.BindCredential); break; default: streamWriter.WriteLine(item2); break; } } } } MessageBox.Show("Lưu thành công"); }
private bool TestConnecting() { bool result = false; try { LdapField ldapField = new LdapField(); ldapField.UrlLdap = txtLdap.Text; ldapField.BindLdap = txtBindLdap.Text; ldapField.BindDn = txtBindDn.Text; ldapField.BindCredential = txtBindCredential.Text; result = new ConectLdap().checkLdapServer(ldapField); } catch (Exception ex) { lbStatus.ForeColor = Color.Red; lbStatus.Text = "Connection failed"; MessageBox.Show("Lỗi: " + ex.Message, "Thông báo!"); } return(result); }
private void dgFields_UpdateCommand(object source, DataGridCommandEventArgs e) { int ItemID = (int)dgFields.DataKeys[e.Item.ItemIndex]; CheckBox cbIsBit = (CheckBox)e.Item.FindControl("cbIsBit"); DropDownList ddIbnName = (DropDownList)e.Item.FindControl("ddIbnName"); DropDownList ddLdapName = (DropDownList)e.Item.FindControl("ddLdapName"); TextBox txtLdapName = (TextBox)e.Item.FindControl("txtLdapName"); TextBox txtBitMask = (TextBox)e.Item.FindControl("txtBitMask"); TextBox txtCompare = (TextBox)e.Item.FindControl("txtCompare"); Label lblError = (Label)e.Item.FindControl("lblError"); DropDownList ddEqual = (DropDownList)e.Item.FindControl("ddEqual"); if (cbIsBit != null && ddIbnName != null && txtLdapName != null && txtBitMask != null && txtCompare != null && ddEqual != null) { int iMask = 0; int iCompare = 0; if (cbIsBit.Checked) { try { iMask = int.Parse(txtBitMask.Text); iCompare = int.Parse(txtCompare.Text); } catch { lblError.Visible = true; return; } } LdapField.CreateUpdate(ItemID, SetId, cbIsBit.Checked, ddIbnName.SelectedValue, (txtLdapName.Text != "") ? txtLdapName.Text : ddLdapName.SelectedValue, iMask, bool.Parse(ddEqual.SelectedValue), iCompare); } Response.Redirect("~/Admin/LdapSettingsView.aspx?SetId=" + SetId); }