protected void ButtonAddContact_Click(object sender, EventArgs e) { if (IsValid) { string firstName = textBoxFirstname.Text; string lastName = textBoxLastname.Text; string ssn = textBoxSSN.Text; SQLStuff sqlStuff = new SQLStuff(); try { sqlStuff.CreateContact(new SqlLibrary.Contact(firstName, lastName, ssn)); textBoxFirstname.Text = ""; textBoxLastname.Text = ""; textBoxSSN.Text = ""; LoadContacts(); } catch (Exception ex) { //TODO : Write to logfile throw ex; } } }
protected void Page_Load(object sender, EventArgs e) { if (Request["cid"] != null) { int cid = int.Parse(Request["cid"]); SqlLibrary.Contact contact = SQLStuff.ReadAllContacts().FirstOrDefault(x => x.ID == cid); if (contact != null) { TextBoxFirstname.Text = contact.Firstname; TextBoxLastname.Text = contact.Lastname; TextBoxSSN.Text = contact.SSN; } } if (Request["action"] != null) { string action = Request["action"]; if (action == "update") { ButtonContact.Text = "Update contact"; } else if (action == "delete") { TextBoxFirstname.Enabled = false; TextBoxLastname.Enabled = false; TextBoxSSN.Enabled = false; ButtonContact.Text = "Delete contact"; } } }
protected void Page_Load(object sender, EventArgs e) { if (Request["all"] != null) { SQLStuff sqlStuff = new SQLStuff(); jsonLiteral.Text = JsonConvert.SerializeObject(sqlStuff.ReadAllContacts(), Formatting.Indented); } else if (Request["deleteCID"] != null) { int cid = int.Parse(Request["deleteCID"].ToString()); SQLStuff sqlStuff = new SQLStuff(); int result = sqlStuff.DeleteContact(cid); if (result == 0) { jsonLiteral.Text = "error"; } else { jsonLiteral.Text = "ok"; } } }
protected void Page_Load(object sender, EventArgs e) { SQLStuff sqlStuff = new SQLStuff(); if (Request["action"] == "loadArticles") { string jsonString = JsonConvert.SerializeObject(sqlStuff.ReadAllArticles()); literalArticles.Text = jsonString; } if (Request["action"] == "addToCart") { int aid = Convert.ToInt32(Request["aid"]); int result = sqlStuff.AddArticleToOrder(2, aid); if (result > 0) { literalArticles.Text = "Hurra!!!"; } else { literalArticles.Text = "Error"; } } }
protected void Page_Load(object sender, EventArgs e) { if (Request["all"] != null) { SQLStuff sqlStuff = new SQLStuff(); infoLiteral.Text = JsonConvert.SerializeObject(sqlStuff.ReadAllContacts(), Formatting.Indented); } }
private void LoadContacts() { List <SqlLibrary.Contact> myContacts = SQLStuff.ReadAllContacts(); listBoxContacts.Items.Clear(); foreach (var contact in myContacts) { ListItem myItem = new ListItem($"{contact.Firstname} {contact.Lastname}", contact.ID.ToString()); listBoxContacts.Items.Add(myItem); } }
protected void ButtonAddAddress_Click(object sender, EventArgs e) { if (IsValid) { string type = textBoxType.Text; string street = textBoxStreet.Text; string city = textBoxCity.Text; int cid = int.Parse(dropDownListContacts.SelectedValue); SQLStuff.AddAddressToContact(cid, new SqlLibrary.Adress(type, street, city)); } }
private void LoadContacts() { SQLStuff sqlStuff = new SQLStuff(); List <SqlLibrary.Contact> myContacts = sqlStuff.ReadAllContacts(); foreach (var contact in myContacts) { TableRow tableRow = new TableRow(); TableCell cellID = new TableCell(); cellID.Text = contact.ID.ToString(); tableRow.Cells.Add(cellID); TableCell cellFirstname = new TableCell(); cellFirstname.Text = contact.Firstname; tableRow.Cells.Add(cellFirstname); TableCell cellLastname = new TableCell(); cellLastname.Text = contact.Lastname; tableRow.Cells.Add(cellLastname); TableCell cellSSN = new TableCell(); cellSSN.Text = contact.SSN; tableRow.Cells.Add(cellSSN); // Some edit/create/delete stuff TableCell cellInfo = new TableCell(); string cellInfoHTML = ""; cellInfoHTML += "<a href=\"/contact.aspx?action=update&cid=" + contact.ID + "\" class=\"btn btn-success btn-sm\">"; cellInfoHTML += "<span class=\"glyphicon glyphicon-pencil\"> Update</span>"; cellInfoHTML += "</a>"; cellInfoHTML += " "; cellInfoHTML += "<a href=\"/contact.aspx?action=delete&cid=" + contact.ID + "\" class=\"btn btn-danger btn-sm\">"; cellInfoHTML += "<span class=\"glyphicon glyphicon-remove\"> Delete</span>"; cellInfoHTML += "</a>"; cellInfoHTML += " "; cellInfo.Text = cellInfoHTML; tableRow.Cells.Add(cellInfo); TableContacts.Rows.Add(tableRow); ListItem myItem = new ListItem($"{contact.Firstname} {contact.Lastname}", contact.ID.ToString()); } }
protected void ButtonLogin_Click(object sender, EventArgs e) { if (IsValid) { string username = TextBoxUsername.Text; string password = TextBoxPassword.Text; User user = SQLStuff.ValidateLogin(username, password); if (user != null) { Session["user"] = user; Response.Redirect("/index.aspx"); } else { LabelInfo.Text = "Wrong username/password! (Try Academy/Password1 :)"; } } }