protected void Button1_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(DropDownList1.SelectedValue)) { context = new ContextModelEntity(); bool coutBool = false; var storeKepper = context.StoreKeeperSet .Where(c => c.LastFierstName == DropDownList1.SelectedValue.ToString()).FirstOrDefault(); var dateils = context.DitailsSet .Where(c => c.StoreKeeper == storeKepper.Id).ToList(); foreach (Ditails iteDitails in storeKepper.Ditails.ToArray()) { if (iteDitails.DateDelete != null) { context.DitailsSet.Remove(iteDitails); coutBool = true; } } if (coutBool) { context.StoreKeeperSet.Remove(storeKepper); context.SaveChanges(); Response.Redirect("Default2.aspx"); } List <int> numberDetails = new List <int>(); int count = 0; int count2 = 0; foreach (var itemDitailse in context.DitailsSet) { if (itemDitailse.StoreKeeper == storeKepper.Id) { count++; if (itemDitailse.DateDelete != null) { count2++; } } } if (count == count2) { context.StoreKeeperSet.Remove(storeKepper); context.SaveChanges(); Response.Redirect("Default2.aspx"); } } }
protected void Button2_Click1(object sender, EventArgs e) { if ((!IsNullOrEmpty((Request.Form[TextBox5.UniqueID])))) { Label3.Text = ""; context = new ContextModelEntity(); var dstoreKepper = context.StoreKeeperSet .Where(c => c.LastFierstName == DropDownList1.SelectedValue.ToString()).FirstOrDefault(); if (context.DitailsSet != null) { int num; if (TextBox3 != null) { num = Convert.ToInt32(TextBox3.Text); var details = context.DitailsSet .Where(c => c.NameIdCode == TextBox1.Text) .Where(c => c.NameDetails == TextBox2.Text) .Where(c => c.Quantity == num) .Where(c => c.StoreKeeper == dstoreKepper.Id).FirstOrDefault(); DateTime dob = DateTime.Parse(Request.Form[TextBox5.UniqueID]); details.DateDelete = dob; } context.SaveChanges(); Response.Redirect("Default.aspx"); } } else { Label3.Text = "Выберите дату"; } }
protected void Button2_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(TextBox1.Text)) { context = new ContextModelEntity(); if (context.StoreKeeperSet != null) { List <string> listKeeper = new List <string>(); var kepper = context.StoreKeeperSet; foreach (var itemKeeper in kepper) { listKeeper.Add(itemKeeper.LastFierstName); } if (!listKeeper.Contains(TextBox1.Text)) { StoreKeeper storeKeeper = new StoreKeeper(); storeKeeper.LastFierstName = TextBox1.Text; context.StoreKeeperSet.Add(storeKeeper); context.SaveChanges(); Response.Redirect("Default2.aspx"); } } } }
protected void Button1_Click(object sender, EventArgs e) { if (DropDownList1.SelectedValue.ToString() != "Выберите кладовщика") { if (!IsNullOrEmpty(TextBox3.Text)) { if (!IsNullOrEmpty((Request.Form[TextBox4.UniqueID]))) { if (Page.IsValid) { Ditails details = new Ditails(); DateTime dob = DateTime.Parse(Request.Form[TextBox4.UniqueID]); details.DateAdd = dob; details.NameIdCode = TextBox1.Text; details.NameDetails = TextBox2.Text; int quantity; if (int.TryParse(TextBox3.Text, out quantity)) { details.Quantity = quantity; } context = new ContextModelEntity(); if (context.StoreKeeperSet != null) { foreach (var storKeeper in context.StoreKeeperSet) { if (storKeeper.LastFierstName == DropDownList1.SelectedValue.ToString()) { details.StoreKeeper = storKeeper.Id; } } context.DitailsSet.Add(details); context.SaveChanges(); } Response.Redirect("Default.aspx"); } } } } }