Ejemplo n.º 1
0
        //添加
        private void button4_Click(object sender, EventArgs e)
        {
            if (Check())
            {
                try
                {
                    conn = dh.Connection;
                    dh.OpenConnection();
                    string vnum      = textBox1.Text.Trim(); //1编号
                    string name      = textBox2.Text.Trim();
                    string begintime = textBox3.Text.Trim();
                    string shortname = textBox4.Text.Trim();
                    string endtime   = textBox5.Text.Trim();
                    string stock     = textBox6.Text.Trim();

                    string sql = string.Format(@"insert into thingsInfo(vnum,name,shortname,begintime,endtime,stock) values ('{0}','{1}','{2}','{3}','{4}','{5}')",
                                               vnum, name, shortname, begintime, endtime, stock);
                    cmd = new MySqlCommand(sql, conn);
                    if (cmd.ExecuteNonQuery() == 1)
                    {
                        MessageBox.Show("添加成功!            ", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Close();
                        this.Dispose();
                    }
                    else
                    {
                        MessageBox.Show("添加失败!            ", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "异常提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    cmd.Dispose();
                    dh.CloseConnection();//关闭数据库连接
                }
            }
        }
Ejemplo n.º 2
0
        //保存
        private void button4_Click(object sender, EventArgs e)
        {
            if (Check())
            {
                try
                {
                    conn = dh.Connection;
                    dh.OpenConnection();

                    string vnum      = textBox1.Text.Trim();
                    string name      = textBox2.Text.Trim();
                    string begintime = textBox3.Text.Trim();
                    string shortname = textBox4.Text.Trim();
                    string endtime   = textBox5.Text.Trim();
                    //int stock = 0;
                    string sql = "UPDATE thingsinfo set vnum='" + vnum + "',name='" + name + "',begintime='" + begintime + "',shortname='" + shortname + "',endtime='" + endtime + "'where vnum ='" + vnums + "'";
                    cmd = new MySqlCommand(sql, conn);
                    if (cmd.ExecuteNonQuery() == 1)
                    {
                        MessageBox.Show("修改成功!            ", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Close();
                        this.Dispose();
                    }
                    else
                    {
                        MessageBox.Show("修改失败!            ", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "异常提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    cmd.Dispose();
                    dh.CloseConnection();//关闭数据库连接
                }
            }
        }
Ejemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (Check())
            {
                try
                {
                    conn = dh.Connection;
                    dh.OpenConnection();
                    string name     = textBox1.Text.Trim();
                    string username = textBox2.Text.Trim();
                    string pwd      = textBox3.Text.Trim();
                    string id       = textBox4.Text.Trim();
                    string sql      = "update admin set name='" + name + "',username='******',pwd='" + pwd + "',id='" + id + "'where name ='" + names + "'";

                    cmd = new MySqlCommand(sql, conn);
                    if (cmd.ExecuteNonQuery() == 1)
                    {
                        MessageBox.Show("修改成功!            ", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Close();
                        this.Dispose();
                    }
                    else
                    {
                        MessageBox.Show("修改失败!            ", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "异常提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    cmd.Dispose();
                    dh.CloseConnection();//关闭数据库连接
                }
            }
        }
Ejemplo n.º 4
0
 //添加
 private void button1_Click(object sender, EventArgs e)
 {
     if (Check())
     {
         try
         {
             conn = dh.Connection;
             dh.OpenConnection();
             string name     = textBox1.Text.Trim();
             string username = textBox2.Text.Trim();
             string pwd      = textBox3.Text.Trim();
             string id       = textBox4.Text.Trim();
             string sql      = string.Format(@"insert into admin(name,username,pwd,id) values ('{0}','{1}','{2}','{3}')",
                                             name, username, pwd, id);
             cmd = new MySqlCommand(sql, conn);
             if (cmd.ExecuteNonQuery() == 1)
             {
                 MessageBox.Show("添加成功!            ", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 this.Close();
                 this.Dispose();
             }
             else
             {
                 MessageBox.Show("添加失败!            ", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "异常提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         finally
         {
             cmd.Dispose();
             dh.CloseConnection();//关闭数据库连接
         }
     }
 }