欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C#超市收银系统设计

程序员文章站 2023-11-24 12:53:58
本文实例为大家分享了c#超市收银系统设计的具体代码,供大家参考,具体内容如下 1.登录界面 代码如下: using system; using syst...

本文实例为大家分享了c#超市收银系统设计的具体代码,供大家参考,具体内容如下

1.登录界面

C#超市收银系统设计

代码如下:

using system;
using system.collections.generic;
using system.componentmodel;
using system.data;
using system.data.sqlclient;
using system.drawing;
using system.linq;
using system.text;
using system.threading.tasks;
using system.windows.forms;
 
namespace 梦之翼小组项目
{
 public partial class denglu : form
 {
  public denglu()
  {
   initializecomponent();
  }
  model db = new model(); //实例化数据库对象
 
  private void button1_click(object sender, eventargs e)
  {
   string strconn = "data source=.;initial catalog=shopinfo;integrated security=true"; //连接数据库
   sqlconnection connection = new sqlconnection(strconn);
 
   try
   {
 
    string sqlstr = "select username,userpassword from register where username=@username"; //查询
    dataset ds = new dataset();
 
    connection.connectionstring = connection.connectionstring;
    connection.open();
 
    sqlcommand cmd = new sqlcommand(sqlstr, connection);
    cmd.parameters.add(new sqlparameter("@username", sqldbtype.varchar, 30)); //传参
    cmd.parameters["@username"].value = username.text;   //给user文本框赋值
    sqldatareader dater = cmd.executereader();
 
    if (username.text.trim() == "")   //如果user的值等于空
    {
     messagebox.show( "用户名不允许为空!");
 
    }
    else if (password.text.trim() == "")   //同上
    {
     messagebox.show( "密码不能为空!");
    }
    else if (!dater.read())    //如果输入的用户名没有被dater读到,则用户名不存在
    {
     messagebox.show( "用户名不存在!");
     username.text = "";
     password.text = "";
    }
    else if (dater["userpassword"].tostring().trim() == password.text.trim()) //输入密码等于数据库密码登录成功且弹出音乐框
    {
     messagebox.show( "登录成功!");
     username.text = "";
     password.text = "";
     caozuoyemain frm = new caozuoyemain();
     frm.showdialog();
    }
    else
    {
     messagebox.show("密码错误!");  //否则密码错误
     username.text = "";
     password.text = "";
 
    }
   }
   catch (exception)
   {
    throw;    //抛出异常
   }
   finally
   {
    connection.close();  //关闭数据库
   }
 
  }
 
  private void label4_click(object sender, eventargs e)
  {
   zhuce fra = new zhuce();
   fra.showdialog();
  }
 
  private void label6_click(object sender, eventargs e)
  {
   zhaohuimima fra = new zhaohuimima();
   fra.showdialog();
  }
 
  private void denglu_load(object sender, eventargs e)
  {
 
  }
 }
}


2.操作界面:

C#超市收银系统设计

代码如下:

using system;
using system.collections.generic;
using system.componentmodel;
using system.data;
using system.drawing;
using system.linq;
using system.text;
using system.threading.tasks;
using system.windows.forms;
 
namespace 梦之翼小组项目
{
 public partial class caozuoyemain : form
 {
  public caozuoyemain()
  {
   initializecomponent();
  }
  public double totalprice;//每种商品的总价
  public double total; //所有商品的总价
  public double shijijin;//顾客给的钱数
  public double yingzhao;// 找给顾客的钱数
  public string mingcheng;//每件商品的名称
  public double shuliang;//每件商品的数量
  public double jiage;//每件商品的价格
  public int i = 0; //商品收费的id
 
  model db = new model(); //实例化数据库对象
 
  public void fanli() //单件物品的返利方法
  {
   if (jiage * shuliang < 600 && jiage * shuliang > 300)
   {
    totalprice = jiage * shuliang - 100;
   }
   else
   {
    totalprice = jiage * shuliang;
   }
  }
 
  private void confirm_click(object sender, eventargs e) //单击确定按钮的事件
  {
   totalprice = 0; //每一次商品的单个金额
 
   jiage = convert.todouble(price.text);
   shuliang = convert.todouble(number.text); //数据类型的转换
   
   switch (jisuanfangshi.selectedindex)
   {
    case 0:
     totalprice = jiage * shuliang;
      
     break;
    case 1:
      totalprice = jiage * shuliang*0.8;
      
     break;
    case 2:
     fanli(); //调用单个物品的返利方法
     
     break;
   }
 
 
   total = totalprice + total; //所有商品的总金额
 
   zongjine.text = total.tostring();//总金额转换数据类型,显示到文本框里面
 
   
   i++; //每一次的商品id加1,为了调出所有商品的最后一个数据
 
   db.dbcon();
   try
   {
    string insertinfo = "insert wupin values('" + i.tostring() + "','" + tradename.text + "','" + price.text + "','" +
     number.text + "','" + jisuanfangshi.text + "','" + totalprice.tostring() + "')";
    db.dbinsert(insertinfo);
 
    string selstr = "select top "+i+" * from wupin order by 物品id desc";
    db.dbfill(selstr);
    datagridview1.datasource = db.dt;  
   }
   catch (exception)
   {
    messagebox.show("不好意思,信息有误,注册失败");
   }
  }  
 
  private void caozuoyemain_load(object sender, eventargs e)
  {
   db.dbcon();
   string qingkong = "truncate table wupin";
   db.dbinsert(qingkong);
   jisuanfangshi.selectedindex = 0;  
  }
 
  private void jiesuan_click(object sender, eventargs e)
  {
   shijijin = convert.todouble(shishoujine.text);
   yingzhao=convert.todouble(zongjine.text) ;
   yingzhao = shijijin - total;
   zhaojine.text = yingzhao.tostring()+"元";
  }
 
  private void resetting_click(object sender, eventargs e)
  {
   tradename.text = "";
   price.text = "";
   number.text = "";
  }  
 }
}


3.收银员注册界面:

C#超市收银系统设计

代码如下:

using system;
using system.collections.generic;
using system.componentmodel;
using system.data;
using system.drawing;
using system.linq;
using system.text;
using system.text.regularexpressions;
using system.threading.tasks;
using system.windows.forms;
 
namespace 梦之翼小组项目
{
 public partial class zhuce : form
 {
  public zhuce()
  {
   initializecomponent();
  }
  public string sexvalue; //接收性别的字段
  model db = new model(); //实例化数据库对象
 
  private bool testusername(string strusername) //检测用户名的方法
  {
   bool strresult;// 判断结果的接收
   regex exstrusername = new regex(@"^[a-za-z][a-za-z0-9]{3,8}$");
   //正则表达式的书写
   if (strresult = exstrusername.match(strusername).success)
   {
    yonghuming_test.text = "✔";
   }
   else
   {
    messagebox.show("用户名由3—6位的字母和数字组成,必须以字母开头");
 
   }
   return strresult;
  }
 
  private bool testpassword(string strusername) //检测密码的方法
  {
   bool strresult;// 判断结果的接收
   regex exstrusername = new regex(@"^[\w\-~!@#$%^&*()+{}[ \]:]{6,16}");
   //正则表达式的书写
   if (strresult = exstrusername.match(strusername).success)
   {
    mima_test.text = "✔";
   }
   else
   {
    mima_test.text = "✘";
    messagebox.show("密码由6—16位的字母和数字或符号组成");
 
   }
   return strresult;
  }
  private bool testname(string strusername) //检测姓名的方法
  {
   bool strresult;// 判断结果的接收
   regex exstrusername = new regex(@"^([a-za-z0-9\u4e00-\u9fa5\·]{2,3})$");
   //正则表达式的书写
   if (strresult = exstrusername.match(strusername).success)
   {
    name_test.text = "✔";
   }
   else
   {
    name_test.text = "✘";
    messagebox.show("请文明用语,输入合法的中文姓名哦");
 
   }
 
   if (name_text.text == "小猫" || name_text.text == "小狗" || name_text.text == "傻逼")
   {
    name_test.text = "✘";
    messagebox.show("请文明用语,输入合法的中文姓名哦");
   }
   return strresult;
  }
 
  private bool testphonnumber(string strusername) //检测手机号的方法
  {
   bool strresult;// 判断结果的接收
   regex exstrusername = new regex(@"^(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$");
   //正则表达式的书写
   if (strresult = exstrusername.match(strusername).success)
   {
    phonnumber_test.text = "✔";
   }
   else
   {
    phonnumber_test.text = "✘";
    messagebox.show("请输入正确的手机号码");
 
   }
   return strresult;
  }
 
  private void nan_rb_checkedchanged(object sender, eventargs e) //选择性别的事件
  {
   sexvalue = nan_rb.text;
  }
  private void nv_rb_checkedchanged(object sender, eventargs e)
  {
   sexvalue = nv_rb.text;
  }
   
 
  private void zhuce_bt_click(object sender, eventargs e) //注册的点击事件
  {
   db.dbcon();
   try
   {
    string insertinfo = "insert register values('" + username_text.text + "','" + password_text.text+ "','" + name_text.text+
      "','" + sexvalue + "','" + phonnumber_text.text + "')";
    db.dbinsert(insertinfo);
    dialogresult dr=messagebox.show("恭喜你注册成功,是否转到登录界面","注册成功对话框",messageboxbuttons.okcancel,messageboxicon.information);
    if (dr == dialogresult.ok)
    {
     this.close();
     denglu fra = new denglu();
     fra.showdialog();
     
    }
    else if (dr == dialogresult.cancel)
    {
     this.close();
    }
 
   }
   catch (exception)
   {
    messagebox.show("不好意思,信息有误,注册失败");
   }
  }
 
  private void username_text_leave(object sender, eventargs e) //用户名文本框的光标事件
  {
   if (username_text.text == "")
   {
    messagebox.show("用户名不能为空");
   }
   else
   {
    testusername(username_text.text);
   }
  }
 
  private void password_text_leave(object sender, eventargs e)//密码文本框的光标事件
  {
   if (password_text.text == "")
   {
    messagebox.show("密码不能为空");
   }
   else
   {
    testpassword(password_text.text);
   }
  }
 
  private void name_text_leave(object sender, eventargs e)//姓名文本框的光标事件
  {
   if (name_text.text == "")
   {
    messagebox.show("姓名不能为空");
   }
   else
   {
    testname(name_text.text);
   }
  }
 
  private void phonnumber_text_leave(object sender, eventargs e)//手机号文本框的光标事件
  {
   if (phonnumber_text.text == "")
   {
    messagebox.show("手机号不能为空");
   }
   else
   {
    testphonnumber(phonnumber_text.text);
   }
  }
 
  private void chongzhi_bt_click(object sender, eventargs e) //重置按钮
  {
   username_text.text = "";
   phonnumber_text.text = "";
   name_text.text = "";
   phonnumber_text.text = "";
  }
 
  private void quxiao_bt_click(object sender, eventargs e)// 取消事件
  {
   this.close();
  }
 
  private void zhuce_load(object sender, eventargs e)
  {
 
  }
  
 }
}


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。