Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            string        con   = "Server=localhost;DataBase=demo;user id=sa;password=123456789;"; //数据库的信息
            SqlConnection mycon = new SqlConnection(con);                                          //连接数据库

            mycon.Open();                                                                          //打开数据库

            //删除数据
            string sel;

            //GeneralMethod.IsNumberic()这个函数判断字符串是否为数字
            if (rem == 0 && GeneralMethod.IsNumberic(textBox1.Text))//rem=0表示选择按订单号删除
            {
                sel = "delete from lianxi where 订单号 =" + textBox1.Text;
                SqlCommand com = new SqlCommand(sel, mycon); //将执行代码放入命令中
                com.ExecuteReader();                         //执行
            }
            if (rem == 1)                                    // rem = 1表示选择按客户名删除
            {
                string a = textBox1.Text;
                string b = @"‘a’";
                sel = "delete from lianxi where 客户 =" + "\'" + textBox1.Text + "\'";
                SqlCommand com = new SqlCommand(sel, mycon); //将执行代码放入命令中
                com.ExecuteReader();                         //执行
            }
            if (rem == 2)                                    // rem = 2表示选择按商品删除
            {
                sel = "delete from lianxi where 商品 =" + "\'" + textBox1.Text + "\'";
                SqlCommand com = new SqlCommand(sel, mycon); //将执行代码放入命令中
                com.ExecuteReader();                         //执行
            }
            Close();
        }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            int           orderNumber;
            string        con   = "Server=localhost;DataBase=demo;user id=sa;password=123456789;"; //数据库的信息
            SqlConnection mycon = new SqlConnection(con);                                          //连接数据库

            mycon.Open();                                                                          //打开数据库

            //增加数据
            string sql = "insert into lianxi(订单号,客户,商品)" +
                         "values('{0}','{1}','{2}')";
            string     sel;
            SqlCommand com;//将执行代码放入命令中

            if (GeneralMethod.IsNumberic(textBox1.Text))
            {
                orderNumber = Int32.Parse(textBox1.Text);
                sel         = string.Format(sql, orderNumber, textBox2.Text, comboBox1.Text);
                com         = new SqlCommand(sel, mycon);
                com.ExecuteReader();//执行
            }

            else
            {
                MessageBox.Show("请输入正确的订单号", "输入错误!!!");
            }
            Close();
        }
Exemplo n.º 3
0
 private void button1_Click(object sender, EventArgs e)
 {
     for (int i = 0; i < Program.form1.students.ToArray().Length; i++)
     {
         if (rem == 0 && GeneralMethod.IsNumberic(textBox1.Text) &&
             Program.form1.students[i].OrderNumber == int.Parse(textBox1.Text))
         {
             item = Program.form1.students[i];
         }
         if (rem == 1 && Program.form1.students[i].ClientName == textBox1.Text)
         {
             item = Program.form1.students[i];
         }
         if (rem == 2 && Program.form1.students[i].GoodsName == textBox1.Text)
         {
             item = Program.form1.students[i];
         }
     }
     orderitem.DataSource  = null;
     orderitem.DataSource  = item;
     dataGridView2.Visible = true;
 }
Exemplo n.º 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            string        con   = "Server=localhost;DataBase=demo;user id=sa;password=123456789;"; //数据库的信息
            SqlConnection mycon = new SqlConnection(con);                                          //连接数据库

            mycon.Open();                                                                          //打开数据库

            string sel;

            //按订单号修改
            if (rem == 0 && GeneralMethod.IsNumberic(textBox1.Text) && GeneralMethod.IsNumberic(textBox2.Text))
            {                                                                                    //rem=0表示按订单号修改,GeneralMethod.IsNumberic(string)函数用来判断字符串是否为数字
                sel = "update lianxi set 订单号 =" + textBox2.Text + "where 订单号 =" + textBox1.Text; //修改项目的代码
                SqlCommand com = new SqlCommand(sel, mycon);                                     //将执行代码放入命令中
                com.ExecuteReader();                                                             //执行
            }

            //按客户修改
            if (rem == 1)//rem=1表示按客户修改
            {
                sel = "update lianxi set 客户 =" +
                      "\'" + textBox2.Text + "\'" + "where 客户 =" + "\'" + textBox1.Text + "\'"; //修改项目的代码
                SqlCommand com = new SqlCommand(sel, mycon);                                    //将执行代码放入命令中
                com.ExecuteReader();                                                            //执行
            }

            //按商品修改
            if (rem == 2)//rem=2表示按商品修改
            {
                sel = "update lianxi set 商品 =" +
                      "\'" + textBox2.Text + "\'" + "where 商品 =" + "\'" + textBox1.Text + "\'"; //修改项目的代码
                SqlCommand com = new SqlCommand(sel, mycon);                                    //将执行代码放入命令中
                com.ExecuteReader();                                                            //执行
            }
            Close();
        }