protected void btnIlmoittaudu_Click(object sender, EventArgs e) { //luodaan kontekstiin uusi entiteetti ja päivitetään muutos kantaan if (txtAsioid.Text.Length * txtEtunimi.Text.Length * txtSukunimi.Text.Length > 0) { try { //luodaan uusi entiteetti DemoxOyEntities ctx = new DemoxOyEntities(); lasnaolot lasnaolo = new lasnaolot(); lasnaolo.asioid = txtAsioid.Text; lasnaolo.course = "IIO13200"; lasnaolo.firstname = txtEtunimi.Text; lasnaolo.lastname = txtSukunimi.Text; lasnaolo.date = DateTime.Now; //lisätään se kontekstiin ctx.lasnaolots.Add(lasnaolo); //tallennus kantaan ctx.SaveChanges(); lbMessages.Text = "Ilmoittautuminen tehty."; } catch (Exception ex) { lbMessages.Text = ex.Message; } } }
protected void bttCreateA_Click(object sender, EventArgs e) { try { demoxOyEntities.asiakas.Add(new asiakas { asnimi = txtName.Text, astunnus = txtCode.Text, asvuosi = short.Parse(txtYear.Text), maa = txtCountry.Text, ostot = double.Parse(txtPurchase.Text), postinro = txtPostCode.Text, postitmp = txtPostOffice.Text, yhteyshlo = txtContact.Text }); demoxOyEntities.SaveChanges(); gvCustomer.DataBind(); } catch (Exception ex) { lblMessage.Text = string.Format("Virhe: {0}", ex.Message); } }
protected void btnSend_Click(object sender, EventArgs e) { bool isThere = ctx.asiakas.Any(c => (c.astunnus.Contains(txtAsTunnus.Text) | c.asnimi.Contains(txtAsNimi.Text))); if (isThere) { lblMessages.Text = string.Format("Asiakas {0} tai {1} on jo olemassa", txtAsNimi.Text, txtAsTunnus.Text); } else { //luodaan kontekstiin uusi asiakas entiteetti try { asiakas cus = new asiakas(); cus.asnimi = txtAsNimi.Text; cus.astunnus = txtAsTunnus.Text; cus.asvuosi = Convert.ToInt16(txtAsVuosi.Text); cus.ostot = Convert.ToInt16(txtOstot.Text); cus.maa = txtMaa.Text; cus.postinro = txtPostiNro.Text; cus.postitmp = txtPostiTmp.Text; cus.yhteyshlo = txtAsYhtHlo.Text; ctx.asiakas.Add(cus); ctx.SaveChanges(); lblMessages.Text = string.Format("uusi asiakas {0} luotu onnistuneesti", cus.asnimi); } catch (Exception) { } } Panel1.Visible = false; gvAsiakkaat.Visible = true; }
protected void btnIlmottaudu_Click(object sender, EventArgs e) { if (txtboxMyAsioid.Text.Length * txtboxEtunimi.Text.Length * txtboxSukunimi.Text.Length > 0) { DemoxOyEntities ctx = new DemoxOyEntities(); lasnaolot lasnaolo = new lasnaolot(); lasnaolo.asioid = txtboxMyAsioid.Text; lasnaolo.course = "IIO13200"; lasnaolo.firstname = txtboxEtunimi.Text; lasnaolo.lastname = txtboxSukunimi.Text; lasnaolo.date = DateTime.Now; //lisätään se kontekstiin ctx.lasnaolots.Add(lasnaolo); //tallennus kantaan ctx.SaveChanges(); } }
protected void btnCreateCustomer_Click(object sender, EventArgs e) { using (DemoxOyEntities db = new DemoxOyEntities()) { asiakas a = new asiakas(); a.asnimi = txtNimi.Text; a.astunnus = txtTunnus.Text; a.asvuosi = short.Parse(txtVuosi.Text); a.maa = txtMaa.Text; a.ostot = double.Parse(txtOstot.Text); a.postinro = txtPostinro.Text; a.postitmp = txtPostitmp.Text; a.yhteyshlo = txtYhtHlo.Text; db.asiakas.Add(a); db.SaveChanges(); lblMessages.Text = "Asiakas " + a.asnimi + " luotu onnistuneesti."; } }
protected void SaveCustomer() { using (DemoxOyEntities entities = new DemoxOyEntities()) { asiakas uusiAsiakas = new asiakas(); uusiAsiakas.asnimi = txtNimi.Text; uusiAsiakas.astunnus = txtTunnus.Text; uusiAsiakas.asvuosi = short.Parse(txtVuosi.Text); uusiAsiakas.maa = txtMaa.Text; uusiAsiakas.ostot = double.Parse(txtOstot.Text); uusiAsiakas.postinro = txtPostinr.Text; uusiAsiakas.postitmp = txtPostitmp.Text; uusiAsiakas.yhteyshlo = txtYht.Text; entities.asiakas.Add(uusiAsiakas); entities.SaveChanges(); lblFooter.Text = "Asiakas " + uusiAsiakas.asnimi + " tallennettu onnistuneesti!"; } }
protected void btnIlmoittaudu_Click(object sender, EventArgs e) { //Luodaan kontekstiin uusi entiteetti ja päivitetään muutos kantaan if (txtAsioid.Text.Length * txtEtunimi.Text.Length * txtSukunimi.Text.Length > 0) { //Luodaan uusi entiteetti DemoxOyEntities ctx = new DemoxOyEntities(); lasnaolot lasnaolo = new lasnaolot(); lasnaolo.asioid = txtAsioid.Text; lasnaolo.course = "IIO13200"; lasnaolo.firstname = txtEtunimi.Text; lasnaolo.lastname = txtSukunimi.Text; lasnaolo.date = DateTime.Now; //new DateTime(2013, 10, 10); //Lisätään se kontekstiin ctx.lasnaolots.Add(lasnaolo); //tallennus kantaan ctx.SaveChanges(); } }
protected void btnLuoAsiakas_Click(object sender, EventArgs e) { bool inputsvalid = checkUserInputs(); if (inputsvalid == true) { using (DemoxOyEntities db = new DemoxOyEntities()) { asiakas cust = new asiakas(); cust.astunnus = txtTunnus.Text; cust.asnimi = txtNimi.Text; cust.yhteyshlo = txtYhteysHlo.Text; cust.maa = ddlCountries.SelectedValue; cust.postinro = txtPostiNro.Text; cust.postitmp = txtPostiTmp.Text; cust.ostot = double.Parse(txtOstot.Text); cust.asvuosi = Int16.Parse(txtVuosi.Text); db.asiakas.Add(cust); db.SaveChanges(); lbMessages.Text = string.Format("Uusi Asiakas {0} tallennettu tietokantaan!", cust.asnimi); } } }
protected void CreateNew() { if (txtID.Text != "" && txtCustomerName.Text != "" && txtContactPerson.Text != "" && txtCountryCode.Text != "" && txtPostalCode.Text != "" && txtPostOffice.Text != "" && txtPurchases.Text != "" && txtCustomerYear.Text != "") { try { asiakas asiakas; asiakas = new asiakas(); asiakas.astunnus = txtID.Text; asiakas.asnimi = txtCustomerName.Text; asiakas.yhteyshlo = txtContactPerson.Text; asiakas.maa = txtCountryCode.Text; asiakas.postinro = txtPostalCode.Text; asiakas.postitmp = txtPostOffice.Text; asiakas.ostot = double.Parse(txtPurchases.Text); asiakas.asvuosi = (Int16)int.Parse(txtCustomerYear.Text); ctx.asiakas.Add(asiakas); ctx.SaveChanges(); lblMessage.ForeColor = System.Drawing.Color.Green; lblMessage.Text = "Asiakas lisättiin onnistuneesti."; } catch (Exception ex) { lblMessage.ForeColor = System.Drawing.Color.Red; lblMessage.Text = ex.Message; } } else { lblMessage.ForeColor = System.Drawing.Color.Red; lblMessage.Text = "Täytä kaikki kentät."; } }