protected void btnFinalizareComanda_Click(object sender, EventArgs e) { lbFinalizare.Visible = true; using (var context = new Biciclete()) { int userId = Int32.Parse(Session["UserId"].ToString()); var com = new Comenzi(); com.UserId = userId; com.Data = DateTime.Now; context.Comenzis.Add(com); if (Session["dataTableComenzi"] != null) { DataTable dataTableComenzi = (DataTable)Session["dataTableComenzi"]; for (int i = 0; i < dataTableComenzi.Rows.Count; i++) { var comp = new ComandaProdu(); comp.ComandaId = com.ComandaId; comp.ProdusId = Int32.Parse(dataTableComenzi.Rows[i]["ProdusId"].ToString()); comp.Cantitate = Int32.Parse(dataTableComenzi.Rows[i]["Cantitate"].ToString()); comp.PretCumparare = Decimal.Parse(dataTableComenzi.Rows[i]["Pret"].ToString()); context.ComandaProdus.Add(comp); var culoare = new CuloareProdu(); culoare.CuloareId = Int32.Parse(dataTableComenzi.Rows[i]["Culoare"].ToString()); culoare.ProdusId = Int32.Parse(dataTableComenzi.Rows[i]["ProdusId"].ToString()); context.CuloareProdus.Add(culoare); } } context.SaveChanges(); } }
protected void btnSalvareCont_Click(object sender, EventArgs e) { using (var context = new Biciclete()) { var user = new User() { Nume = tbNume.Text, Parola = tbParola.Text, Email = tbEmail.Text, Data = DateTime.Now, Activ = null, Aprobat = null, Admin = null }; context.Users.Add(user); context.SaveChanges(); } tbNume.Text = string.Empty; tbParola.Text = string.Empty; tbConfirmareParola.Text = string.Empty; tbEmail.Text = string.Empty; lbInregistrare.Visible = true; if ((ResourceSet)Session["resourceSet"] != null) { ResourceSet resourceSet = (ResourceSet)Session["resourceSet"]; foreach (DictionaryEntry entry in resourceSet) { if (entry.Key.ToString().Equals("InregistrareSucces")) { lbInregistrare.Text = entry.Value.ToString(); } } } }
//Gestioneaza butoane de actiuni protected void gvUsers_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Activ") { string id = e.CommandArgument.ToString(); int idi = Int32.Parse(id); using (var context = new Biciclete()) { var user = context.Users.Where(u => u.UserId == idi).SingleOrDefault(); user.Activ = true; context.SaveChanges(); } if (RadioButton1.Checked) { RadioButton1_CheckedChanged(sender, e); } else if (RadioButton2.Checked) { RadioButton2_CheckedChanged(sender, e); } else if (RadioButton3.Checked) { RadioButton3_CheckedChanged(sender, e); } else { ShowGrid(); } } if (e.CommandName == "Inactiv") { string id = e.CommandArgument.ToString(); int idi = Int32.Parse(id); using (var context = new Biciclete()) { var user = context.Users.Where(u => u.UserId == idi).SingleOrDefault(); user.Activ = false; context.SaveChanges(); } if (RadioButton1.Checked) { RadioButton1_CheckedChanged(sender, e); } else if (RadioButton2.Checked) { RadioButton2_CheckedChanged(sender, e); } else if (RadioButton3.Checked) { RadioButton3_CheckedChanged(sender, e); } else { ShowGrid(); } } if (e.CommandName == "Aprobat") { string id = e.CommandArgument.ToString(); int idi = Int32.Parse(id); using (var context = new Biciclete()) { var user = context.Users.Where(u => u.UserId == idi).SingleOrDefault(); user.Aprobat = true; context.SaveChanges(); } if (RadioButton1.Checked) { RadioButton1_CheckedChanged(sender, e); } else if (RadioButton2.Checked) { RadioButton2_CheckedChanged(sender, e); } else if (RadioButton3.Checked) { RadioButton3_CheckedChanged(sender, e); } else { ShowGrid(); } } if (e.CommandName == "Respins") { string id = e.CommandArgument.ToString(); int idi = Int32.Parse(id); using (var context = new Biciclete()) { var user = context.Users.Where(u => u.UserId == idi).SingleOrDefault(); user.Aprobat = false; context.SaveChanges(); } LinkButton ctrl = e.CommandSource as LinkButton; if (ctrl != null) { GridViewRow row = ctrl.Parent.NamingContainer as GridViewRow; row.BackColor = System.Drawing.Color.Red; LinkButton btnRespins = (LinkButton)row.FindControl("btnRespins"); gvUsers.Controls.Remove(btnRespins); } if (RadioButton1.Checked) { RadioButton1_CheckedChanged(sender, e); } else if (RadioButton2.Checked) { RadioButton2_CheckedChanged(sender, e); } else if (RadioButton3.Checked) { RadioButton3_CheckedChanged(sender, e); } else { ShowGrid(); } } }