void Application_Start(object sender, EventArgs e) { //Для инициализации таблиц - иначе не создаются GoodContext db = new GoodContext(); Good good = db.Goods.Find(1); // Code that runs on application startup RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); }
protected void ButtonInsert_Command(object sender, CommandEventArgs e) { decimal vPrice = 0; if (db == null) { db = new GoodContext(); } /* pnlAddEdit.Visible = true; PopupHeader.Attributes["Text"] = "Добавить товар"; txtName.Text = "0.00"; txtName.Focus(); txtPrice.Text = Convert.ToString(vPrice); popup.Show(); */ }
protected void ButtonDelete33_Command(object sender, CommandEventArgs e) { string sId = (string)e.CommandArgument; int iid = Convert.ToInt32(sId); if (db == null) { db = new GoodContext(); } good = this.db.Goods.Find(iid); if (good != null) { db.Goods.Remove(good); db.SaveChanges(); ListView2.DataBind(); return; } }
protected void Save(object sender, CommandEventArgs e) { string err; string vName, vPrice; decimal dPrice; //string sId = (string)e.CommandArgument; string sId = goodID.Value; //Во избежании if (sId == "-1") return; ChkDataOnServer(out err); if (err != "") { ShowError(err); return; } int iid = Convert.ToInt32(sId); vName = txtName.Text; vPrice = txtPrice.Text.Replace(".", ","); dPrice = decimal.Parse(vPrice); if (db == null) { db = new GoodContext(); } if (iid == 0) //Вставка { this.good = new Good(); } else // Редактирование { this.good = this.db.Goods.Find(iid); } this.good.Name = vName; this.good.Price = dPrice; if (good != null) { if (iid == 0) //Вставка db.Goods.Add(good); db.SaveChanges(); //if (iid == 0) goodID.Value = "-1"; //return RedirectToAction("Index"); ; UpdatePanel1.Update(); ListView2.DataBind(); return; } }
//protected decimal vPrice = 0; //protected string InvalidDataMessage; protected void Page_Load(object sender, EventArgs e) { if (db == null) { GoodContext db = new GoodContext(); Good good = db.Goods.Find(1); } // txtPrice.Text = Convert.ToString(vPrice); }