private void lstSpecialistList_KeyDown(object sender, KeyEventArgs e) { if (e.Control && e.KeyCode == Keys.Delete && lstSpecialistList.SelectedIndex != -1) { if (MessageBox.Show("Вы уверены, что хотите удалить специалиста\n" + ((INamedEntity)lstSpecialistList.SelectedItem).Name + "\nиз базы?\nОтменить удаление невозможно!", "Удаление специалиста из Базы", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.No) { return; } try { SpecialistList.Remove((ISpecialist)lstSpecialistList.SelectedItem); } catch (Exception ex) { if (ex.Message.Substring(0, 4) == "1451") { System.Windows.Forms.MessageBox.Show("Произошла ошибка удаления. Удаляемый специалист используется.", "Удаление невозможно.", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Stop); } else { throw ex; } } lstSpecialistList.DataSource = SpecialistList.List.Cast <INamedEntity>().ToList(); } }
protected void SpecializationList_SelectedIndexChanged(object sender, EventArgs e) { try { DropDownList s = sender as DropDownList; string specialization = s.SelectedValue; string sqlConnString = ConfigurationManager.ConnectionStrings["ConnString"].ToString(); SqlConnection sqlConn = new SqlConnection(sqlConnString); sqlConn.Open(); String sql = "select s.specialist_name, s.specialist_id, sp.specialization_name, sp.specialization_id from specialist s, specialization sp where s.specialization_id = sp.specialization_id and sp.specialization_id ='" + specialization + " 'order by specialist_name"; SqlCommand sqlCmd = new SqlCommand(sql, sqlConn); SqlDataAdapter da = new SqlDataAdapter(sqlCmd); DataSet ds = new DataSet(); da.Fill(ds); SpecialistList.DataTextField = ds.Tables[0].Columns["specialist_name"].ToString(); SpecialistList.DataValueField = ds.Tables[0].Columns["specialist_id"].ToString(); SpecialistList.DataSource = ds.Tables[0]; SpecialistList.DataBind(); sqlConn.Close(); } catch (Exception ex) { Response.Write("Error:" + ex.ToString()); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { try { string sqlConnString = ConfigurationManager.ConnectionStrings["ConnString"].ToString(); SqlConnection sqlConn = new SqlConnection(sqlConnString); sqlConn.Open(); SqlCommand sqlCmd = new SqlCommand("select * from specialist order by 2", sqlConn); SqlDataAdapter da = new SqlDataAdapter(sqlCmd); DataSet ds = new DataSet(); da.Fill(ds); SpecialistList.DataTextField = ds.Tables[0].Columns["specialist_name"].ToString(); SpecialistList.DataValueField = ds.Tables[0].Columns["specialist_id"].ToString(); SpecialistList.DataSource = ds.Tables[0]; SpecialistList.DataBind(); //LocationList.SelectedIndex = 1; } catch (Exception ex) { Response.Write("Error:" + ex.ToString()); } } }
private void SpecialistListEdit_FormClosing(object sender, FormClosingEventArgs e) { SpecialistList.ValidateAndUpdate(); }