Ejemplo n.º 1
0
        private void 作者EToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form A = null;

            if (sender.Equals(预览XToolStripMenuItem))
            {
                A = new MainForm();
            }
            else if (sender.Equals(管理BToolStripMenuItem))
            {
                A = new ReadInfoForm();
            }
            else if (sender.Equals(搜索CToolStripMenuItem))
            {
                A = new SearchInfoForm();
            }
            else if (sender.Equals(说明DToolStripMenuItem))
            {
                A = new ExplanationForm();
            }
            else if (sender.Equals(作者EToolStripMenuItem))
            {
                A = new Anthor();
            }
            this.ForMF.Dispose();
            this.Hide();
            A.Show();
        }
Ejemplo n.º 2
0
        static public void MoreSearch(string No, string Name, string Sex, string Age, string Dept, SearchInfoForm This)
        {
            string SelectText = "select * from Information where ";
            bool   First      = false;

            if (No == "" && Name == "" && Sex == "" && Age == "" && Dept == "")
            {
                MessageBox.Show("必须查询一项信息!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (No != "")
            {
                SelectText += "No='" + No + "'"; First = true;
            }
            if (Name != "")
            {
                if (First)
                {
                    SelectText += " and ";
                }
                else
                {
                    First = true;
                }
                SelectText += "Name like '%" + Name + "%'";
            }
            if (Sex != "")
            {
                if (First)
                {
                    SelectText += " and ";
                }
                else
                {
                    First = true;
                }
                SelectText += "Sex='" + Sex + "'";
            }
            if (Age != "")
            {
                if (First)
                {
                    SelectText += " and ";
                }
                else
                {
                    First = true;
                }
                SelectText += "Age='" + Age + "'";
            }
            if (Dept != "")
            {
                if (First)
                {
                    SelectText += " and ";
                }
                SelectText += "Dept='" + Dept + "'";
            }

            SqlConnection Con = new SqlConnection("server=.;database=StudentPlus;integrated security=true");

            try { Con.Open(); }
            catch { MessageBox.Show("数据库连接失败!请检查您的数据库!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); System.Environment.Exit(0); }
            SqlCommand    Com    = new SqlCommand(SelectText, Con);
            SqlDataReader Reader = null;

            Reader = Com.ExecuteReader();

            This.tabControl1.SelectedIndex = 1;
            This.dataGridView2.Rows.Clear();
            try
            {
                while (Reader.Read())
                {
                    foreach (DataGridViewRow Row in This.dataGridView1.Rows)
                    {
                        if (Row.Cells[0].Value.ToString().CompareTo(Reader["No"].ToString()) == 0)
                        {
                            DataGridViewRow Result = (DataGridViewRow)(Row.Clone());
                            for (int i = 0; i < Row.Cells.Count; ++i)
                            {
                                Result.Cells[i].Value = Row.Cells[i].Value;
                            }
                            This.dataGridView2.Rows.Add(Result);
                            break;
                        }
                    }
                }
            }
            catch (Exception e) { MessageBox.Show(e.Message); }
            if (This.dataGridView2.Rows[0].Cells[0].Value == null)
            {
                MessageBox.Show("没有查到相关数据!", "Result", MessageBoxButtons.OK);
            }
            Con.Dispose();
            Com.Dispose();
            Reader.Close();
        }