Example #1
0
        //检查添加的人员是否在总的用户表中
        private Boolean checkPeopleExist()
        {
            Boolean       b      = true;
            string        strCon = "server=" + Parameter.IP_port + ";database=user;MultipleActiveResultSets=true;Uid=" + Parameter.sql_user + ";Pwd=" + Parameter.sql_pwd;
            SqlConnection conn   = new SqlConnection(strCon);

            conn.Open();
            SqlCommand comm = new SqlCommand();

            comm.Connection = conn;

            foreach (DataRow dr in dt人员.Rows)
            {
                //判断行状态
                DataRowState state = dr.RowState;
                if (state.Equals(DataRowState.Deleted))
                {
                    continue;
                }
                else
                {
                    String name = dr["用户名"].ToString();
                    comm.CommandText = "select * from [users] where 姓名 = " + "'" + name + "'";
                    SqlDataReader reader = comm.ExecuteReader();
                    if (!reader.HasRows)
                    {
                        b = false;
                        MessageBox.Show("员工" + "“" + name + "”" + "不存在!");
                    }
                    reader.Dispose();
                }
            }

            comm.Dispose();
            conn.Dispose();
            return(b);
        }
Example #2
0
 private void salvarContatos(object sender, EventArgs e)
 {
     if (stt.Equals(DataRowState.Added))
     {
         int     id  = RetornarIdContatos();
         DataRow row = tbl.NewRow();
         row["Id"]       = id;
         row["Nome"]     = textBox1.Text;
         row["Fone"]     = textBox2.Text;
         row["Endereco"] = textBox3.Text;
         tbl.Rows.Add(row);
         Contact c = new Contact();
         c.Id     = id;
         c.Name   = textBox1.Text;
         c.Phone  = long.Parse(textBox2.Text);
         c.Adress = textBox3.Text;
         contatos.Add(c);
     }
     else if (stt.Equals(DataRowState.Modified))
     {
         int idx        = SelecionarIndex();
         int indexLista = int.Parse(tbl.Rows[idx]["Id"].ToString());
         tbl.Rows[idx]["Nome"]     = textBox1.Text;
         tbl.Rows[idx]["Fone"]     = textBox2.Text;
         tbl.Rows[idx]["Endereco"] = textBox3.Text;
         foreach (Contact c in contatos)
         {
             if (c.Id == indexLista)
             {
                 c.Name   = textBox1.Text;
                 c.Phone  = long.Parse(textBox2.Text);
                 c.Adress = textBox3.Text;
             }
         }
     }
     HabilitarClick(sender, e);
     LimparCampos();
 }