void PopulateGridview(String acc) { ClassDatabase obj = new ClassDatabase(); DataTable dtbl = new DataTable(); using (SqlConnection sqlCon = new SqlConnection(obj.locate)) { sqlCon.Open(); SqlDataAdapter sqlDa = new SqlDataAdapter("SELECT * FROM pc_customer_accounts_1_A join pc_customers_1_A on pc_customer_accounts_1_A.customer_id = pc_customers_1_A.customer_id where pc_customer_accounts_1_A.account_id = '" + acc + "'", sqlCon); sqlDa.Fill(dtbl); sqlCon.Close(); } if (dtbl.Rows.Count > 0) { gvPhoneBook.DataSource = dtbl; gvPhoneBook.DataBind(); } else { dtbl.Rows.Add(dtbl.NewRow()); gvPhoneBook.DataSource = dtbl; gvPhoneBook.DataBind(); gvPhoneBook.Rows[0].Cells.Clear(); gvPhoneBook.Rows[0].Cells.Add(new TableCell()); gvPhoneBook.Rows[0].Cells[0].ColumnSpan = dtbl.Columns.Count; gvPhoneBook.Rows[0].Cells[0].Text = "No Customer Linked to the Account ..!"; gvPhoneBook.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Center; gvPhoneBook.Enabled = false; } }
protected void gvPhoneBook_RowCommand(object sender, GridViewCommandEventArgs e) { System.Web.UI.WebControls.Label str = Master.FindControl("branch_label") as System.Web.UI.WebControls.Label; System.Web.UI.WebControls.Label str2 = Master.FindControl("checker_label") as System.Web.UI.WebControls.Label; System.Web.UI.WebControls.Label str3 = Master.FindControl("Label3") as System.Web.UI.WebControls.Label; System.Web.UI.WebControls.Label str4 = Master.FindControl("last_row") as System.Web.UI.WebControls.Label; System.Web.UI.WebControls.Label str5 = Master.FindControl("major_branch") as System.Web.UI.WebControls.Label; if (e.CommandName.Equals("Delete") && gvPhoneBook.Rows[0].Cells[0].Text != "No Customer Linked to the Account ..!") { // MessageBox.Show(gvPhoneBook.Rows[0].Cells[0].Text); String row = (Convert.ToDouble(str4.Text) + 1).ToString(); string customer_id = e.CommandArgument.ToString(); ClassDatabase obj = new ClassDatabase(); obj.conn.ConnectionString = obj.locate1; using (SqlConnection sqlCon = new SqlConnection(obj.locate1)) { sqlCon.Open(); string query = " insert into postilion_portal_changes (maker,date,change_made,pan,account,branch,reason,checker,view_status) values ('" + str3.Text + "','" + time.ToString(format) + "','UNLINK USER FROM ACCOUNT','','" + TextBox1.Text + "','" + str.Text + "','0','" + str2.Text + "' , '0')"; SqlCommand sqlCmd = new SqlCommand(query, sqlCon); sqlCmd.ExecuteNonQuery(); string query2 = " insert into postilion_hold_data (action,id,branch_code,hold_rsp_code,customer_id ,place_hold ,account_id ,pan,card_status ,reason_for_reason ,mail_destination ,seq_nr ,expiry_date ,title,first_name,middle_initial,last_name,name_on_card,other,account_product,mobile,issuer_nr,account_type,last_updated_date,last_updated_user,address_1_1,city) values ('UNLINK USER FROM ACCOUNT','" + row + "','','','" + customer_id + "','" + DropDownList1.Text + "','','','','','','','','','','','','','','','','','','','','','')"; SqlCommand sqlCmd2 = new SqlCommand(query2, sqlCon); sqlCmd2.ExecuteNonQuery(); ClientScript.RegisterStartupScript(this.GetType(), "randomtext", "alertme('UNLINKED')", true); // ClientScript.RegisterStartupScript(this.GetType(), "randomtext", "save('UNLINKED')", true); sqlCon.Close(); } } if (e.CommandName.Equals("CUST_id") && gvPhoneBook.Rows[0].Cells[0].Text != "No Customer Linked to the Account ..!") { Response.Redirect("Edit_Account_Details.aspx?cust_id=" + e.CommandArgument.ToString()); } }
private DataTable getBranches() { ClassDatabase obj = new ClassDatabase(); DataTable dtbl = new DataTable(); using (SqlConnection sqlCon = new SqlConnection(obj.locate1)) { sqlCon.Open(); SqlDataAdapter sqlDa = new SqlDataAdapter("SELECT * FROM postilion_branch ", sqlCon); sqlDa.Fill(dtbl); sqlCon.Close(); } dtbl.DefaultView.Sort = "branch ASC"; return(dtbl); }
protected void Button4_Click(object sender, EventArgs e) { bool userExists = false; using (var ctx = new PrincipalContext(ContextType.Domain)) { using (var user = UserPrincipal.FindByIdentity(ctx, username.Text.ToLower())) { if (user != null) { userExists = true; // ClientScript.RegisterStartupScript(this.GetType(), "randomtext", "alertme('FULL NAME :'+'"+user.DisplayName+"')", true); ClassDatabase obj = new ClassDatabase(); obj.conn.ConnectionString = obj.locate1; obj.conn.Open(); SqlDataAdapter adapter = new SqlDataAdapter("SELECT COUNT (*) FROM postilion_users WHERE username = '******' ", obj.conn); DataTable dt = new DataTable(); adapter.Fill(dt); if (dt.Rows[0][0].ToString() != "1") { using (SqlConnection sqlCon = new SqlConnection(obj.locate1)) { sqlCon.Open(); string query = " insert into postilion_users(username,first_name,branch,role,active) values ('" + username.Text.ToLower() + "','" + user.DisplayName.ToLower() + "','" + DropDownList2.Text.Substring(0, 3) + "','" + role.Text + "','active')"; SqlCommand sqlCmd = new SqlCommand(query, sqlCon); sqlCmd.ExecuteNonQuery(); string query2 = " insert into postilion_user_list(username,role,create_date,last_updated,last_login,status,branch) values ('" + username.Text.ToLower() + "','" + role.Text + "','" + time.ToString(format) + "','" + time.ToString(format) + "','','active','" + DropDownList2.Text.Substring(0, 3) + "')"; SqlCommand sqlCmd2 = new SqlCommand(query2, sqlCon); sqlCmd2.ExecuteNonQuery(); } ClientScript.RegisterStartupScript(this.GetType(), "randomtext", "alertme('NEW USER ADDED :'+'" + user.DisplayName + "')", true); username.Text = ""; } else { ClientScript.RegisterStartupScript(this.GetType(), "randomtext", "alertme('USER ALREADY EXIST')", true); } user.Dispose(); } else { ClientScript.RegisterStartupScript(this.GetType(), "randomtext", "alertme('NEW USER DOES NOT EXIST')", true); } } } /* System.Web.UI.WebControls.Label str = Master.FindControl("branch_label") as System.Web.UI.WebControls.Label; * System.Web.UI.WebControls.Label str2 = Master.FindControl("checker_label") as System.Web.UI.WebControls.Label; * * System.Web.UI.WebControls.Label str3 = Master.FindControl("Label3") as System.Web.UI.WebControls.Label; * System.Web.UI.WebControls.Label str4 = Master.FindControl("last_row") as System.Web.UI.WebControls.Label; * * const int big = 8; * if (username.Text != "" && first.Text != "" && surname.Text != "" && password1.Text != "" && DropDownList2.Text.Substring(0, 3) != "" && DropDownList2.Text != "None") * { * try * { * // set up domain context * PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "FBC.CORP"); * * // find a user * UserPrincipal user = UserPrincipal.FindByIdentity(ctx, username.Text); * * if (user != null) * { * // check user lockout state * if (user.IsAccountLockedOut()) * { * Session["Message"] = "You are locked out"; * ClientScript.RegisterStartupScript(this.GetType(), "randomtext", "alertme('YOU ARE LOCKED OUT')", true); * * return ; * } * else * { * * //Authenticate user * * bool authentic = false; * try * { * DirectoryEntry entry = new DirectoryEntry("LDAP://10.170.8.20:389/OU=FBC,DC=fbc,DC=corp", username, password); * DirectoryEntry ldapConnection = new DirectoryEntry("FBC.CORP"); * ldapConnection.Path = "LDAP://"; * ldapConnection.Username = "******";// "Mashingat"; * ldapConnection.Password = "******";//"password1*" * ldapConnection.AuthenticationType = AuthenticationTypes.Secure; * * //Login with user * object nativeObject = entry.NativeObject; * authentic = true; * * if (authentic == true) * { * //Navigate to home * Session["USER"] = username; * return View("HomePage2"); * } * else * { * //MsgBox("Insufficient rights to login!", this.Page, this); * // Session["Message"] = "You are locked out"; * ViewBag.Message = "FAILED TO LOGIN INSUFFICIENT LOGIN RIGHTS"; * return View(); * } * * } * catch (DirectoryServicesCOMException ex) * { * // MsgBox("Login failure. " + ex.Message, this.Page, this); * Session["Message"] = "You are locked out"; * ViewBag.Message = "FAILED TO LOGIN"; * return View(); * } * } * * } * else * { * Session["Message"] = "You are locked out"; * ViewBag.Message = "FAILED TO LOGIN USER NOT AVAILABLE"; * return View(); * // MsgBox("Could not locate user " + Session["Mutumwa"].ToString() + " from FBC.CORP Domain", this.Page, this); * } * } * catch (Exception ex) * { * // MsgBox("An excaption have been caught. Exception: " + ex.Message, this.Page, this); * Session["Message"] = "You are locked out"; * ViewBag.Message = "FAILED TO LOGIN" + ex.ToString(); * return View(); * } * * bool isDigitPresent = password1.Text.Any(c => char.IsDigit(c)); * * if (password1.Text == password2.Text) * { * if (password1.Text.Length >= big && isDigitPresent ) * { * * ClassDatabase obj = new ClassDatabase(); * obj.conn.ConnectionString = obj.locate1; * obj.conn.Open(); * SqlDataAdapter adapter = new SqlDataAdapter("SELECT COUNT (*) FROM postilion_users WHERE username = '******' ", obj.conn); * DataTable dt = new DataTable(); * adapter.Fill(dt); * if (dt.Rows[0][0].ToString() != "1") * { * * * string insertUser = "******" + username.Text.ToLower() + "','" + first.Text.ToLower() + "','"+surname.Text.ToLower() + "','" + encrypt(password1.Text) + "','" + DropDownList2.Text.Substring(0, 3) + "','" + role.Text + "')"; * obj.cmd.Connection = obj.conn; * obj.cmd.CommandText = insertUser; * obj.cmd.ExecuteNonQuery(); * obj.cmd.CommandTimeout = 60; * * string insertUser_list = " insert into postilion_user_list(username,role,create_date,last_updated,late_login,status,branch) values ('" + username.Text.ToLower() + "','" + DropDownList2.Text + "','" + time.ToString(format) + "','','" + DropDownList2.Text.Substring(0, 3) + "','" + role.Text + "')"; * obj.cmd.Connection = obj.conn; * obj.cmd.CommandText = insertUser_list; * obj.cmd.ExecuteNonQuery(); * obj.cmd.CommandTimeout = 60; * * obj.conn.Close(); * * ClientScript.RegisterStartupScript(this.GetType(), "randomtext", "alertme('NEW USER ADDED')", true); * * username.Text = ""; * first.Text = ""; * surname.Text = ""; * } * else * { * ClientScript.RegisterStartupScript(this.GetType(), "randomtext", "alertme('USER ALREADY EXIST USE ANOTHER USERNAME')", true); * * } * * * } * else * { * ClientScript.RegisterStartupScript(this.GetType(), "randomtext", "alertme('PASSWORD TOO SHORT AND ALSO INCLUDE A NUMBER ')", true); * * } * } * else * { * ClientScript.RegisterStartupScript(this.GetType(), "randomtext", "alertme('ENTER SAME PASSWORD')", true); * * } * } * else * { * ClientScript.RegisterStartupScript(this.GetType(), "randomtext", "alertme('ENTER ALL FIELDS')", true); * * }*/ }