protected void btnSellerAdd_Click(object sender, EventArgs e) { string sellerName = "Продавец"; var db = new ssmDataContext(); seller seller = new seller { isActive = false, fullName = sellerName, isAdmin = false, password = "******", login = "******" }; db.sellers.InsertOnSubmit(seller); db.SubmitChanges(); seller.Refresh(); lstsellersFill(); if (lstSellers.Items.FindByText(sellerName) != null) { lstSellers.SelectedIndex = lstSellers.Items.IndexOf(lstSellers.Items.FindByText(sellerName)); lstSeller_SelectedIndexChanged(new object(), new EventArgs()); } }
protected void btnSellerUpdate_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(lstSellers.SelectedValue)) { string sellerName = txtSellerName.Text; int sellerID = int.Parse(lstSellers.SelectedValue); var db = new ssmDataContext(); seller seller = db.sellers.First(b => b.id == sellerID); seller.fullName = txtSellerName.Text; seller.login = txtSellerLogin.Text; seller.password = txtSellerPass.Text; seller.isActive = chkIsActive.Checked; seller.isAdmin = chkIsAdmin.Checked; db.SubmitChanges(); seller.Refresh(); lstsellersFill(); if (lstSellers.Items.FindByText(sellerName) != null) { lstSellers.SelectedIndex = lstSellers.Items.IndexOf(lstSellers.Items.FindByText(sellerName)); lstSeller_SelectedIndexChanged(new object(), new EventArgs()); } } }