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(); } } } }
protected void btnLogin_Click(object sender, EventArgs e) { using (var ctx = new Biciclete()) { string name = tbUsername.Text; string parola = tbPassword.Text; var user = ctx.Users.Where(s => s.Nume == name && s.Parola == parola && s.Aprobat == true && s.Activ == true).FirstOrDefault <User>(); if (user != null) { Session["UserId"] = user.UserId; FormsAuthentication.RedirectFromLoginPage(user.Nume, true); Response.Redirect("HomePage.aspx"); tbPassword.Text = string.Empty; tbUsername.Text = string.Empty; } else { lbValidation.Visible = true; if ((ResourceSet)Session["resourceSet"] != null) { ResourceSet resourceSet = (ResourceSet)Session["resourceSet"]; foreach (DictionaryEntry entry in resourceSet) { if (entry.Key.ToString().Equals("ValidareLogin")) { lbValidation.Text = entry.Value.ToString(); } } } } } }
public static List <string> PopUpDetaliiComanda(int param) { var myList = new List <string>(); using (var context = new Biciclete()) { var lista = (from comenziProduse in context.ComandaProdus join comenzi in context.Comenzis on comenziProduse.ComandaId equals comenzi.ComandaId join produse in context.Produses on comenziProduse.ProdusId equals produse.ProdusId where comenzi.ComandaId == param group new { comenzi, comenziProduse, produse } by new { produse.Denumire, produse.Producator, comenziProduse.Cantitate, comenziProduse.PretCumparare } into x select new { x.Key.Denumire, x.Key.Producator, x.Key.Cantitate, x.Key.PretCumparare, Total = x.Key.Cantitate * x.Key.PretCumparare }).ToList(); foreach (var itm in lista) { myList.Add("{\"Denumire\":\"" + itm.Denumire + "\",\"Producator\":\"" + itm.Producator + "\",\"Cantitate\":\"" + itm.Cantitate + "\",\"Pret\":\"" + itm.PretCumparare + "\",\"Total\":\"" + itm.Total + "\"}"); } return(myList); } }
public static List <string> GetCompletionList(string prefixText, int count) { using (var context = new Biciclete()) { var listaProduse = context.Produses.Where(p => p.Denumire.StartsWith(prefixText)) .Select(p => String.Concat(p.Denumire, ",", p.Producator)).ToList(); return(listaProduse); } }
protected void btnAutocomplete_Click(object sender, EventArgs e) { //make labels visible lbSalvareSucces.Visible = false; btnCresteCantitate.Visible = true; btnScadeCantitate.Visible = true; btnAdauga.Visible = true; lPret.Visible = true; lProducator.Visible = true; lDenumire.Visible = true; lCuloare.Visible = true; lCantitate.Visible = true; lbDenumire.Visible = true; lbPret.Visible = true; lbProducator.Visible = true; string tbAutocompleteText = tbAutocomplete.Text; string[] splitText = tbAutocompleteText.Split(','); String denumire = (String)splitText[0].ToString(); String producator = (String)splitText[1].ToString(); using (var context = new Biciclete()) { //gasire produsul selectat din lista var id = context.Produses.Where(p => p.Denumire == denumire.Trim() && p.Producator == producator.Trim()).FirstOrDefault(); Session["produsId"] = id.ProdusId; //completarea campurilor var produsSelectat = context.Produses.Where(p => p.ProdusId == id.ProdusId).FirstOrDefault(); lbDenumire.Text = produsSelectat.Denumire; lbPret.Text = produsSelectat.Pret.ToString(); lbProducator.Text = produsSelectat.Producator; dt = new DataTable(); dt.Columns.Add("Url", typeof(string)); dt.Rows.Add(produsSelectat.Url); dtCulori = new DataTable(); dtCulori.Columns.Add("CuloareId", typeof(Int32)); dtCulori.Columns.Add("Denumire", typeof(string)); var culori = context.Culoris.ToList(); foreach (var itm in culori) { dtCulori.Rows.Add(itm.CuloareId, itm.Denumire); } Session["dtCulori"] = dtCulori; stringBuilder = new StringBuilder(); stringBuilder.Append("<ul style='margin-left:250px'>"); for (int i = 0; i < dtCulori.Rows.Count; i++) { stringBuilder.Append("<li id='id" + dtCulori.Rows[i]["CuloareId"].ToString() + "' style='background-color:" + dtCulori.Rows[i]["Denumire"].ToString() + ";border-width:2px;border-style:solid; border-color:white; width:5%;' onclick='getSelectedLi(" + dtCulori.Rows[i]["CuloareId"].ToString() + "); return false;'></li>"); } stringBuilder.Append("</ul"); } }
protected void ddlProduse_SelectedIndexChanged(object sender, EventArgs e) { int selectedIndex = Int32.Parse(ddlProduse.SelectedValue); using (var context = new Biciclete()) { var produs = context.Produses.Where(p => p.ProdusId == selectedIndex).FirstOrDefault(); tbId.Text = produs.ProdusId.ToString(); tbDenumire.Text = produs.Denumire.ToString(); tbProducator.Text = produs.Producator.ToString(); tbPret.Text = produs.Pret.ToString(); } }
//Filtreaza AllUsers pe RadioButton protected void RadioButton4_CheckedChanged(object sender, EventArgs e) { using (var context = new Biciclete()) { var lista = context.Users.ToList(); DataTable dt = new DataTable(); dt.Columns.Add("UserId", typeof(Int32)); dt.Columns.Add("Nume", typeof(string)); dt.Columns.Add("Parola", typeof(string)); dt.Columns.Add("Email", typeof(string)); dt.Columns.Add("Data", typeof(DateTime)); dt.Columns.Add("Activ", typeof(bool)); dt.Columns.Add("Aprobat", typeof(bool)); dt.Columns.Add("Admin", typeof(bool)); foreach (var item in lista) { dt.Rows.Add(item.UserId, item.Nume, item.Parola, item.Email, item.Data, item.Activ, item.Aprobat, item.Admin); } gvUsers.DataSource = dt; gvUsers.DataBind(); } }
protected void btnAdministreazaConturi_Click(object sender, EventArgs e) { if (Session["UserId"] != null) { if ((Session["UserId"].ToString()) != null) { int userId = Int32.Parse(Session["UserId"].ToString()); using (var context = new Biciclete()) { var user = context.Users.Where(u => u.UserId == userId).FirstOrDefault(); if (user.Admin == true) { string redirect = "<script>window.open('http://localhost:58241/AdministreazaConturi','AdministrareCont','menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes,width=1000,height=800');</script>"; Response.Write(redirect); } else { lbNuAdmin.Visible = true; } } } } }
protected void OnUpdate(object sender, EventArgs e) { //Find the reference of the Repeater Item. HtmlTable tabelUpdate = (HtmlTable)FindControl("tabelUpdate"); tabelUpdate.Attributes.Add("style", "visibility:visible"); RepeaterItem item = (sender as LinkButton).Parent as RepeaterItem; lbModificaComanda.Visible = true; btnModificaComanda.Visible = true; int idProdus = int.Parse((item.FindControl("lbId") as Label).Text); Session["idProdusSelectat"] = idProdus; tbId.Text = (item.FindControl("lbId") as Label).Text; tbDenumire.Text = (item.FindControl("lbDenumire") as Label).Text; tbProducator.Text = (item.FindControl("lbProducator") as Label).Text; tbPret.Text = (item.FindControl("lbPret") as Label).Text; tbCuloare.BackColor = (item.FindControl("lbCuloare") as TextBox).BackColor; tbCantitate.Text = (item.FindControl("lbCantitate") as Label).Text; using (var context = new Biciclete()) { var listaProduse = context.Produses.Select(p => new { p.ProdusId, Denumire = string.Concat(p.Denumire, ",", p.Producator) }).ToList(); DataTable dt = new DataTable(); dt.Columns.Add("ProdusId", typeof(Int32)); dt.Columns.Add("Denumire", typeof(string)); foreach (var p in listaProduse) { dt.Rows.Add(p.ProdusId, p.Denumire.ToString()); } ddlProduse.DataSource = dt; ddlProduse.DataTextField = "Denumire"; ddlProduse.DataValueField = "ProdusId"; ddlProduse.DataBind(); } }
//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(); } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if ((ResourceSet)Session["resourceSet"] != null) { ResourceSet resourceSet = (ResourceSet)Session["resourceSet"]; foreach (DictionaryEntry entry in resourceSet) { if (entry.Key.ToString().Equals("GestioneazaCereri")) { lbGestionareUseri.Text = entry.Value.ToString(); } if (entry.Key.ToString().Equals("Nume")) { gvUsers.Columns[1].HeaderText = entry.Value.ToString(); } if (entry.Key.ToString().Equals("Parola")) { gvUsers.Columns[2].HeaderText = entry.Value.ToString(); } if (entry.Key.ToString().Equals("Email")) { gvUsers.Columns[3].HeaderText = entry.Value.ToString(); } if (entry.Key.ToString().Equals("Data")) { gvUsers.Columns[4].HeaderText = entry.Value.ToString(); } if (entry.Key.ToString().Equals("Activ")) { gvUsers.Columns[5].HeaderText = entry.Value.ToString(); } if (entry.Key.ToString().Equals("Aprobat")) { gvUsers.Columns[6].HeaderText = entry.Value.ToString(); } if (entry.Key.ToString().Equals("Admin")) { gvUsers.Columns[7].HeaderText = entry.Value.ToString(); } if (entry.Key.ToString().Equals("Actiuni")) { gvUsers.Columns[8].HeaderText = entry.Value.ToString(); } if (entry.Key.ToString().Equals("Inactivi")) { RadioButton1.Text = entry.Value.ToString(); } if (entry.Key.ToString().Equals("Neaprobati")) { RadioButton2.Text = entry.Value.ToString(); } if (entry.Key.ToString().Equals("Filtre")) { lbFiltreazaGridView.Text = entry.Value.ToString(); } if (entry.Key.ToString().Equals("InactiviNeaprobati")) { RadioButton3.Text = entry.Value.ToString(); } if (entry.Key.ToString().Equals("TotiUtilizatorii")) { RadioButton4.Text = entry.Value.ToString(); } } } using (var context = new Biciclete()) { var lista = context.Users.ToList(); DataTable dt = new DataTable(); dt.Columns.Add("UserId", typeof(Int32)); dt.Columns.Add("Nume", typeof(string)); dt.Columns.Add("Parola", typeof(string)); dt.Columns.Add("Email", typeof(string)); dt.Columns.Add("Data", typeof(DateTime)); dt.Columns.Add("Activ", typeof(bool)); dt.Columns.Add("Aprobat", typeof(bool)); dt.Columns.Add("Admin", typeof(bool)); foreach (var item in lista) { dt.Rows.Add(item.UserId, item.Nume, item.Parola, item.Email, item.Data, item.Activ, item.Aprobat, item.Admin); } gvUsers.DataSource = dt; gvUsers.DataBind(); } } }
protected void Page_Load(object sender, EventArgs e) { if (Session["UserId"] != null) { int id = Int32.Parse(Session["UserId"].ToString()); using (var context = new Biciclete()) { if (ViewState["top"] == null) { ViewState.Add("top", 3); var listaComenzi = (from comenzi in context.Comenzis join comenziProdus in context.ComandaProdus on comenzi.ComandaId equals comenziProdus.ComandaId where comenzi.UserId == id group new { comenzi, comenziProdus } by new { comenzi.ComandaId, comenzi.Data } into x select new { x.Key.ComandaId, x.Key.Data, Valoare = x.Sum(c => c.comenziProdus.Cantitate * c.comenziProdus.PretCumparare) }).ToList().OrderByDescending(x => x.Data).Take(3); DataTable dt = new DataTable(); dt.Columns.Add("ComandaId", typeof(Int32)); dt.Columns.Add("Data", typeof(DateTime)); dt.Columns.Add("Valoare", typeof(Decimal)); foreach (var itm in listaComenzi) { dt.Rows.Add(itm.ComandaId, itm.Data, itm.Valoare); } if (dt.Rows.Count > 0) { gvComenzi.DataSource = dt; gvComenzi.DataBind(); } else { lbNuExistaComenzi.Visible = true; } } else { var controlName = Request.Form["__EVENTTARGET"]; if (controlName.Equals("btnMaiMult")) { int top = Int32.Parse(ViewState["top"].ToString()); top += 3; ViewState.Add("top", top); var listaComenzi = (from comenzi in context.Comenzis join comenziProdus in context.ComandaProdus on comenzi.ComandaId equals comenziProdus.ComandaId where comenzi.UserId == id group new { comenzi, comenziProdus } by new { comenzi.ComandaId, comenzi.Data } into x select new { x.Key.ComandaId, x.Key.Data, Valoare = x.Sum(c => c.comenziProdus.Cantitate * c.comenziProdus.PretCumparare) }).ToList().OrderByDescending(x => x.Data).Take(top); DataTable dt = new DataTable(); dt.Columns.Add("ComandaId", typeof(Int32)); dt.Columns.Add("Data", typeof(DateTime)); dt.Columns.Add("Valoare", typeof(Decimal)); foreach (var itm in listaComenzi) { dt.Rows.Add(itm.ComandaId, itm.Data, itm.Valoare); } gvComenzi.DataSource = dt; gvComenzi.DataBind(); } } } if (!IsPostBack) { if ((ResourceSet)Session["resourceSet"] != null) { ResourceSet resourceSet = (ResourceSet)Session["resourceSet"]; foreach (DictionaryEntry entry in resourceSet) { if (entry.Key.ToString().Equals("AdministreazaConturi")) { btnAdministreazaConturi.Text = entry.Value.ToString(); } if (entry.Key.ToString().Equals("NuAdmin")) { lbNuAdmin.Text = entry.Value.ToString(); } if (entry.Key.ToString().Equals("maiMult")) { btnMaiMult.Text = entry.Value.ToString(); } if (entry.Key.ToString().Equals("Data")) { gvComenzi.Columns[1].HeaderText = entry.Value.ToString(); } if (entry.Key.ToString().Equals("ValoareComanda")) { gvComenzi.Columns[2].HeaderText = entry.Value.ToString(); } if (entry.Key.ToString().Equals("Detalii")) { gvComenzi.Columns[3].HeaderText = entry.Value.ToString(); } if (entry.Key.ToString().Equals("AdaugaComanda")) { btnAdaugaComanda.Text = entry.Value.ToString(); } if (entry.Key.ToString().Equals("NuExistaComenzi")) { lbNuExistaComenzi.Text = entry.Value.ToString(); } gvComenzi.DataBind(); } } } } }