1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > c#窗体点餐系统 使用sql server 数据库保存数据

c#窗体点餐系统 使用sql server 数据库保存数据

时间:2023-12-09 09:22:34

相关推荐

c#窗体点餐系统 使用sql server 数据库保存数据

c#窗体点餐系统 使用sql server 数据库保存数据

登录界面

using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Data.SqlClient;namespace Dian_chai_system{public partial class 登录界面 : Form{public 登录界面(){InitializeComponent();}private void pictureBox1_Click(object sender, EventArgs e){}private void label3_Click(object sender, EventArgs e){注册界面 form2 = new 注册界面();form2.Show();this.Hide();}private void button1_Click(object sender, EventArgs e){if (textBox2.Text == ""){MessageBox.Show("手机号不能为空");textBox2.Focus();return;}if (textBox3.Text == ""){MessageBox.Show("密码不能为空");textBox3.Focus();return;}string SqlStr = null;SqlConnection conn = null;string strsql = null;SqlCommand comm = null;SqlDataReader sql = null;if (radioButton1.Checked){SqlStr = "Server=LAPTOP-NGTPLSQG;User Id=sa;Pwd=123456;DataBase=用户信息数据库";conn = new SqlConnection(SqlStr);//数据库连接conn.Open();//打开数据库strsql = "select * from text1 where 商家手机号='" + textBox2.Text + "'and 商家密码='" + textBox3.Text + "'";comm = new SqlCommand(strsql, conn);sql = comm.ExecuteReader();if (sql.HasRows)//满足用户名和密码一致{商家管理界面 form3 = new 商家管理界面();form3.Show();this.Hide();}else{DialogResult dr = MessageBox.Show("登陆失败");this.Show();}conn.Close();}if (radioButton2.Checked){SqlStr = "Server=LAPTOP-NGTPLSQG;User Id=sa;Pwd=123456;DataBase=用户信息数据库";conn = new SqlConnection(SqlStr);//数据库连接conn.Open();strsql = "select * from text where 手机号='" + textBox2.Text + "'and 密码='" + textBox3.Text + "'";comm = new SqlCommand(strsql, conn);sql = comm.ExecuteReader();if (sql.HasRows)//满足用户名和密码一致{//DialogResult dr = MessageBox.Show("登录成功");用户购买界面 form4 = new 用户购买界面();form4.Show();this.Hide();}else{DialogResult dr = MessageBox.Show("登陆失败");this.Show();}conn.Close();}}private void button2_Click(object sender, EventArgs e){用户账号修改界面 f = new 用户账号修改界面();f.Show();this.Hide();}private void 登录界面_Load(object sender, EventArgs e){}}}

using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Data.SqlClient;namespace Dian_chai_system{public partial class 用户购买界面 : Form{public 用户购买界面(){InitializeComponent();}SqlConnection conn = null;private void Form4_Load(object sender, EventArgs e){string SqlStr = "Server=LAPTOP-NGTPLSQG;User Id=sa;Pwd=123456;DataBase=用户信息数据库";//数据库连接conn = new SqlConnection(SqlStr);//打开数据库conn.Open();SqlCommand cmd = conn.CreateCommand();mandText = "select *from text3";SqlDataReader dr = cmd.ExecuteReader();while (dr.Read()){ListViewItem lt = new ListViewItem();lt.Text = dr["商品编号"].ToString();lt.SubItems.Add(dr["商品名称"].ToString());lt.SubItems.Add(dr["商品价格"].ToString());listView1.Items.Add(lt);}conn.Close();}double sum =0;string temp =null;string bian = null;private void listView1_DoubleClick(object sender, EventArgs e){if (this.listView1.SelectedItems.Count>0){DataGridViewRow row = new DataGridViewRow();int index = dataGridView1.Rows.Add(row);dataGridView1.Rows[index].Cells[0].Value = this.listView1.FocusedItem.SubItems[0].Text;dataGridView1.Rows[index].Cells[1].Value = this.listView1.FocusedItem.SubItems[1].Text;dataGridView1.Rows[index].Cells[2].Value = this.listView1.FocusedItem.SubItems[2].Text;bian += this.listView1.FocusedItem.SubItems[1].Text+",";temp= temp+this.listView1.FocusedItem.SubItems[2].Text+",";sum+=Double.Parse(this.listView1.FocusedItem.SubItems[2].Text);textBox1.Text = System.Convert.ToString(sum);}}private void button1_Click(object sender, EventArgs e){if (textBox2.Text == ""|| textBox3.Text ==""){MessageBox.Show("请将信息补充完整!");}else{string SqlStr = "Server=LAPTOP-NGTPLSQG;User Id=sa;Pwd=123456;DataBase=用户信息数据库";//数据库连接SqlConnection conn = new SqlConnection(SqlStr);//打开数据库conn.Open();DialogResult rt = MessageBox.Show("商品名称:" + bian + "\n" + "对应的商品价格:" + temp, "是否确认购买?", MessageBoxButtons.YesNo);if (rt == DialogResult.Yes){SqlCommand com = new SqlCommand("insert into text4(商品名称,商品价格,合计,手机号,地址) values('" + bian + "','" + temp + "','" + Convert.ToString(textBox1.Text) + "','" + Convert.ToString(textBox3.Text) + "','" + Convert.ToString(textBox2.Text) + "')", conn);com.ExecuteNonQuery();conn.Close();MessageBox.Show("购买成功!");}elseMessageBox.Show("购买失败!");}}private void 用户购买界面_FormClosed(object sender, FormClosedEventArgs e){登录界面 s1 = new 登录界面();s1.Show();this.Hide();}}}

using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Data.SqlClient;using System.IO;using ;namespace Dian_chai_system{public partial class 注册界面 : Form{public 注册界面(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){string SqlStr = "Server=LAPTOP-NGTPLSQG;User Id=sa;Pwd=123456;DataBase=用户信息数据库";SqlConnection conn = new SqlConnection(SqlStr);//数据库连接conn.Open();//打开数据库if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "") {MessageBox.Show("请不要遗漏信息!");}if ((textBox3.Text == textBox4.Text)&&textBox3.Text!=""){string strsql = "insert into text(手机号,用户名,密码) values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "')";SqlCommand comm = new SqlCommand(strsql, conn);if (conn.State == ConnectionState.Closed){conn.Open();}try{if (Convert.ToInt32(comm.ExecuteNonQuery()) > 0){登录界面 form1 = new 登录界面();MessageBox.Show("注册成功!");form1.Show();this.Hide();}else{登录界面 form1 = new 登录界面();MessageBox.Show("注册失败!");form1.Show();this.Hide();}}catch (SqlException ex){MessageBox.Show(ex.ToString());}finally{conn.Close();//关闭数据库连接conn.Dispose();//释放数据库连接}}if(textBox3.Text!=textBox4.Text) {MessageBox.Show("密码不一致,请重新输入");}}private void button2_Click(object sender, EventArgs e){if (!CallPhone(textBox1.Text.ToString())){MessageBox.Show("发送失败!");}else{MessageBox.Show("发送成功!");}}private bool CallPhone(string Recipient_Mobile_Num){string PostUrl = "/webservice/sms.php?method=Submit";//登录“互亿无线网站”查看用户名 登录用户中心->验证码通知短信>产品总览->API接口信息->APIIDstring account = "C63753195";//登录“互亿无线网站”查看密码 登录用户中心->验证码通知短信>产品总览->API接口信息->APIKEYstring password = "38d578a70b772cc944d5561eccc917b1";//接收短信的用户的手机号码string mobile = Recipient_Mobile_Num;//随机生成四位数 可以模仿向用户发送验证码Random rad = new Random();int mobile_code = rad.Next(1000, 10000); //生成随机数string content = "您的验证码是:" + mobile_code + "。请不要把验证码泄露给其他人。";string postStrTpl = "account={0}&password={1}&mobile={2}&content={3}"; //用户名+密码+注册的手机号+验证码UTF8Encoding encoding = new UTF8Encoding(); //万国码//将 account, password, mobile, content 这四个内容添加到postStrTpl字符串当中//并利用encoding.GetBytes()将括号里面的字符串转化为二进制类型byte[] postData = encoding.GetBytes(string.Format(postStrTpl, account, password, mobile, content)); //将字符串postStrTpl中的格式项替换为四个个指定的 Object 实例的值的文本等效项。再转为二进制数据//新建一个请求对象HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(PostUrl);//对统一资源标识符 (URI) 发出请求。 这是一个 abstract 类。myRequest.Method = "POST";myRequest.ContentType = "application/x-www-form-urlencoded";myRequest.ContentLength = postData.Length;Stream newStream = myRequest.GetRequestStream();//间postData合并到 PostUrl中去newStream.Write(postData, 0, postData.Length);newStream.Flush();newStream.Close();//以/webservice/sms.php?method=Submit&account=你的APIID&password=你的APIKEY&mobile=接收短信的用户的手机号码&content=您的验证码是:" + mobile_code + " 。请不要把验证码泄露给其他人。" 发起https请求 并获取请求结果HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();if (myResponse.StatusCode == HttpStatusCode.OK){return true;}else{return false;//访问失败}}private void 注册界面_Load(object sender, EventArgs e){}}}

using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Data.SqlClient;namespace Dian_chai_system{public partial class 用户账号修改界面 : Form{public 用户账号修改界面(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){string SqlStr = "Server=LAPTOP-NGTPLSQG;User Id=sa;Pwd=123456;DataBase=用户信息数据库";//数据库连接SqlConnection conn = new SqlConnection(SqlStr);//打开数据库conn.Open();string strsql = "update text set 手机号='" + textBox3.Text + "',密码='" + textBox4.Text + "' where 手机号='" + textBox1.Text + "' and 密码='" + textBox2.Text + "'";SqlCommand comm = new SqlCommand(strsql, conn);int i = comm.ExecuteNonQuery();//SqlDataReader sql = comm.ExecuteReader();if (i > 0)//满足用户名和密码一致{MessageBox.Show("修改成功!");}else{DialogResult dr = MessageBox.Show("修改失败");this.Show();}conn.Close();}private void 用户账号修改界面_FormClosed(object sender, FormClosedEventArgs e){登录界面 f = new 登录界面();f.Show();this.Hide();}}}

using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Data.SqlClient;namespace Dian_chai_system{public partial class 商家管理界面 : Form{SqlDataAdapter adapter = null;DataSet ds = null;public 商家管理界面(){InitializeComponent();}private void Form3_Load(object sender, EventArgs e){Show1();}private void Show1(){string SqlStr = "Server=LAPTOP-NGTPLSQG;User Id=sa;Pwd=123456;DataBase=用户信息数据库";//数据库连接SqlConnection conn = new SqlConnection(SqlStr);//打开数据库conn.Open();String sql = "select *from text3";//查询数据库后,将数据源绑定到dataGridView控件,使用数据集Datset 和适配器 DataAdapterds = new DataSet();adapter = new SqlDataAdapter(sql, conn);//将获取的数据填充到数据集ds中adapter.Fill(ds, "text3");//数据源绑定到dataGridViewdataGridView1.DataSource = ds.Tables["text3"];conn.Close();}private void 删除ToolStripMenuItem_Click(object sender, EventArgs e){int i = dataGridView1.CurrentRow.Index;string stuNo = dataGridView1.Rows[i].Cells["商品编号"].Value.ToString();string stuNo1 = dataGridView1.Rows[i].Cells["商品名称"].Value.ToString();string stuNo2 = dataGridView1.Rows[i].Cells["商品价格"].Value.ToString();DialogResult result = MessageBox.Show("确定要删除" + stuNo+stuNo1+stuNo2+ "的信息吗?", "提示信息", MessageBoxButtons.YesNo);if (result == DialogResult.Yes){string SqlStr = "Server=LAPTOP-NGTPLSQG;User Id=sa;Pwd=123456;DataBase=用户信息数据库";//数据库连接SqlConnection conn = new SqlConnection(SqlStr);//打开数据库conn.Open();string sql = "delete from text3 where 商品编号='" + stuNo + "'";SqlCommand command = new SqlCommand(sql,conn);int s= command.ExecuteNonQuery();if (s > 0){MessageBox.Show("删除成功!");Show1();}}}private void 商家管理界面_FormClosed(object sender, FormClosedEventArgs e){登录界面 s = new 登录界面();s.Show();this.Hide();}private void 订单信息ToolStripMenuItem_Click(object sender, EventArgs e){Form5 form5 = new Form5();form5.Show();this.Hide();}private void button1_Click_1(object sender, EventArgs e){DialogResult result = MessageBox.Show("确定要修改吗?", "提示信息", MessageBoxButtons.YesNo);if (result == DialogResult.Yes){//执行修改SqlCommandBuilder builder = new SqlCommandBuilder(adapter);//需要参数;适配器(具有数据源的)adapter.Update(ds, "text3");//要设置一个主键,不然报错。MessageBox.Show("修改成功!");Show1();}}private void 修改账号ToolStripMenuItem_Click(object sender, EventArgs e){商家账号修改页面 f = new 商家账号修改页面();f.Show();this.Hide();}}}

using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Data.SqlClient;namespace Dian_chai_system{public partial class Form5 : Form{SqlDataAdapter adapter = null;DataSet ds = null;public Form5(){InitializeComponent();}private void Form5_Load(object sender, EventArgs e){Show1();}private void Show1(){string SqlStr = "Server=LAPTOP-NGTPLSQG;User Id=sa;Pwd=123456;DataBase=用户信息数据库";//数据库连接SqlConnection conn = new SqlConnection(SqlStr);//打开数据库conn.Open();String sql = "select *from text4";//查询数据库后,将数据源绑定到dataGridView控件,使用数据集Datset 和适配器 DataAdapterds = new DataSet();adapter = new SqlDataAdapter(sql, conn);//将获取的数据填充到数据集ds中adapter.Fill(ds, "text4");//数据源绑定到dataGridViewdataGridView1.DataSource = ds.Tables["text4"];conn.Close();}private void contextMenuStrip1_Opening(object sender, CancelEventArgs e){}private void 派送ToolStripMenuItem_Click(object sender, EventArgs e){int i = dataGridView1.CurrentRow.Index;string stuNo1 = dataGridView1.Rows[i].Cells["商品名称"].Value.ToString();string stuNo2 = dataGridView1.Rows[i].Cells["商品价格"].Value.ToString();string stuNo3 = dataGridView1.Rows[i].Cells["合计"].Value.ToString();string stuNo4 = dataGridView1.Rows[i].Cells["手机号"].Value.ToString();string stuNo5 = dataGridView1.Rows[i].Cells["地址"].Value.ToString();DialogResult result = MessageBox.Show("商品名称为:" + stuNo1+"\n" + "对应的商品价格:"+stuNo2+"\n"+"总金额:"+ stuNo3+"\n"+"手机号为:"+ stuNo4+"\n"+"买家地址:"+ stuNo5+ "\n"+"是否派送?", "提示信息", MessageBoxButtons.YesNo);if (result == DialogResult.Yes){string SqlStr = "Server=LAPTOP-NGTPLSQG;User Id=sa;Pwd=123456;DataBase=用户信息数据库";//数据库连接SqlConnection conn = new SqlConnection(SqlStr);//打开数据库conn.Open();string sql = "delete from text4 where 手机号='" + stuNo4 + "'";SqlCommand command = new SqlCommand(sql, conn);int s = command.ExecuteNonQuery();if (s > 0){MessageBox.Show("派送成功!");Show1();}}}private void Form5_FormClosed(object sender, FormClosedEventArgs e){商家管理界面 s = new 商家管理界面();s.Show();this.Hide();}private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e){}}}

using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Data.SqlClient;namespace Dian_chai_system{public partial class 商家账号修改页面 : Form{public 商家账号修改页面(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){string SqlStr = "Server=LAPTOP-NGTPLSQG;User Id=sa;Pwd=123456;DataBase=用户信息数据库";//数据库连接SqlConnection conn = new SqlConnection(SqlStr);//打开数据库conn.Open();string strsql = "update text1 set 商家手机号='" + textBox3.Text + "',商家密码='" + textBox4.Text + "' where 商家手机号='" + textBox1.Text + "' and 商家密码='" + textBox2.Text + "'";SqlCommand comm = new SqlCommand(strsql, conn);int i= comm.ExecuteNonQuery();//SqlDataReader sql = comm.ExecuteReader();if (i>0)//满足用户名和密码一致{MessageBox.Show("修改成功!");}else{DialogResult dr = MessageBox.Show("修改失败");this.Show();}conn.Close();}private void 商家账号修改页面_FormClosed(object sender, FormClosedEventArgs e){商家管理界面 f = new 商家管理界面();f.Show();this.Hide();}}}

textBox1.Text + “’ and 商家密码=’” + textBox2.Text + “’”;

SqlCommand comm = new SqlCommand(strsql, conn);

int i= comm.ExecuteNonQuery();

//SqlDataReader sql = comm.ExecuteReader();

if (i>0)//满足用户名和密码一致

{

MessageBox.Show(“修改成功!”);

}

else

{

DialogResult dr = MessageBox.Show(“修改失败”);

this.Show();

}

conn.Close();

}private void 商家账号修改页面_FormClosed(object sender, FormClosedEventArgs e){商家管理界面 f = new 商家管理界面();f.Show();this.Hide();}

}

}

- 演示视频在抖音:364449446

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。