⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 formpos.cs

📁 超市进销存管理系统 Visual Studio 2005+SQL Sever2005
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Text;


namespace _10901BS
{
    public partial class formPos : Form
    {
        SqlConnection myCon = new SqlConnection();
        SqlCommand myCom = new SqlCommand();
        SqlDataAdapter da;
        DataSet ds = new DataSet();
        SqlDataReader dr;
        string str;
        decimal y, k,h,a,b;
        Graphics g;
        LinearGradientBrush myBrush, myBrush1;
        Font myFont;
        int j,m;
        //decimal u;




        public formPos()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();

        }

        private void Form3_Load(object sender, EventArgs e)
        {
            dbcon();
            shijian();
            //创建绘图表面
            g = this.CreateGraphics();
            //准备好矩形区域
            Rectangle rec = new Rectangle(10, 10, 400, 400);
            //准备渐变笔刷
            myBrush
            = new LinearGradientBrush(rec, Color.Yellow, Color.Green, LinearGradientMode.Horizontal);
            //准备渐变笔刷
            myBrush1
= new LinearGradientBrush(rec, Color.HotPink, Color.DeepPink, LinearGradientMode.Vertical);
            //准备字体
            myFont = new Font("Times New Roman", 36);
            timer1.Start();
            label19.Text = "登陆时间:" + DateTime.Now.ToShortTimeString();
            da = new SqlDataAdapter("Select spxqBiao.spID'商品编号',spxqBiao.spName'商品名称',spxqBiao.spBzsj'商品单价',spxqBiao.spGgxh'商品规格',spxqBiao.spJldw'商品单位',''as'商品数量',''as'商品总额'from spxqBiao where 1=2 ", myCon);
            ds.Clear();
            da.Fill(ds);
            this.dataGridView1.DataSource = ds.Tables[0];
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";
            this.textBox1.Focus();
            
            
        }
        public void shijian()
        {
            label12.Text = "XS_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + "_" + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();
            label1.Text = "DJ_" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + "_" + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();
        }
        public void dbcon()
        {
            if (myCon.State != ConnectionState.Open)
            {
                myCon.ConnectionString = "server=.;database=110901DB;Integrated Security=True";

                myCon.Open();
                //MessageBox.Show("连接成功!");
                

            }

        }

        private void button3_Click(object sender, EventArgs e)
        {
            //连接数据库,查询并建造字段
            myCom = new SqlCommand();
            myCom.Connection = myCon;
            myCom.CommandText = "select spxqBiao.spID as 商品编号,spxqBiao.spName as 商品名称,spxqBiao.spBzsj as 商品单价,spxqBiao.spGgxh as 商品规格,spxqBiao.spJldw as 商品单位,''as 商品数量,''as'商品总额' from spxqBiao where spID='" + textBox1.Text + "'";
            dr = myCom.ExecuteReader();
           
            //读出这条商品信息
            if (dr.Read())
            {
                
                
                    ds.Tables[0].Rows.Add(textBox1.Text, dr["商品名称"].ToString(), (dr["商品单价"].ToString()), dr["商品规格"].ToString(), dr["商品单位"].ToString(), textBox2.Text, dr["商品总额"].ToString());
                    dr.Close();
                
            }
            dr.Close();
            if(textBox1.Text!=""&&textBox2.Text!="")
            {
                for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
                {
                    //根据数据集查找字段的值,将两个值相乘
                    k = k + (Convert.ToDecimal(dataGridView1.Rows[i].Cells[2].Value) * Convert.ToInt32(dataGridView1.Rows[i].Cells[5].Value));
                    //相乘的值付给应收金额
                    textBox3.Text = Convert.ToString(k);
                }

                k = 0;
            }
            else
            { MessageBox.Show("数据不完整!请重新输入!"); }
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            for (int p = 0; p < dataGridView1.Rows.Count - 1; p++)
            {
                this.textBox1.Text = this.dataGridView1.Rows[p].Cells[0].Value.ToString();
                this.textBox2.Text = this.dataGridView1.Rows[p].Cells[1].Value.ToString();
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if (this.textBox1.Text == "")
            {
                MessageBox.Show("商品编号不能为空!", "提示对话框", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.textBox1.Text = "";
                this.textBox1.Focus();
                this.textBox3.Text = "";
                this.textBox4.Text = "";
                this.textBox5.Text = "";
            }
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            if (this.textBox2.Text == "")
            {
                MessageBox.Show("商品编号不能为空!", "提示对话框", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.textBox2.Text = "";
                this.textBox2.Focus();
            }

        }

        //建造一个计时器
        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                //不同的时间来回刷
                if (j == 0)
                {
                    g.DrawString("欢迎光临", myFont, myBrush1, 400, 80);
                    j = 1;
                }
                else
                {
                    g.DrawString("欢迎光临", myFont, myBrush, 400, 80);
                    j = 0;
                }
                label3.Text = "" + DateTime.Now.ToString();
            }
            catch
            { }
        }

        
        private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!(e.KeyChar >= '0' && e.KeyChar <= '9') && (int)e.KeyChar != 8)
            {
                e.Handled = true;
            }
            label19.Text = "";
            if (this.textBox1.Text == "")
            {
                MessageBox.Show("商品编号不能为空!", "提示对话框", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.textBox1.Text = "";
                this.textBox1.Focus();
                this.textBox3.Text = "";
                this.textBox4.Text = "";
                this.textBox5.Text = "";
            }
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            textBox2.Text = "";
            textBox5.Text = "";
            if (!(e.KeyChar >= '0' && e.KeyChar <= '9') && (int)e.KeyChar != 8)
            {
                e.Handled = true;
            }
        }

        private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
        {
            try
            {
                if (!(e.KeyChar >= '0' && e.KeyChar <= '9') && (int)e.KeyChar != 8 && (int)e.KeyChar != 46 && (int)e.KeyChar != '.')
                {
                    e.Handled = true;
                }
                else if (e.KeyChar == '.')
                {
                    if (textBox3.Text.IndexOf('.') >= 0)  //如果已经有小数点存在,则不能再输入小数点
                        e.Handled = true;
                    //如果小数点不存在,但是文本框没有任何字符,则也禁用'.'
                    //禁止文本框的第一个字符为'.'
                    else if (textBox3.Text.Length == 0)
                        e.Handled = true;

                }

                int dian = textBox3.Text.IndexOf('.');
                if (dian != -1)  //表示点存在 
                { 
                    if (textBox3.Text.Substring(dian + 1).Length >=2)
                        e.Handled = true;
                }

                textBox1.Text = "";
                textBox2.Text = "";
            }
            catch
            {
                MessageBox.Show("对不起你您输入的金币的格式不正确。请从新输入");
                this.textBox3.Focus();
                textBox3.Clear();
            }
        }

        private void textBox4_KeyPress(object sender, KeyPressEventArgs e)
        {
            try
            {
                if (!(e.KeyChar >= '0' && e.KeyChar <= '9') && (int)e.KeyChar != 8 && (int)e.KeyChar != 46 && (int)e.KeyChar !='.')
                {
                    e.Handled = true;
                }
                else if (e.KeyChar == '.')
                {
                    if (textBox4.Text.IndexOf('.') >= 0)  //如果已经有小数点存在,则不能再输入小数点
                        e.Handled = true;
                    //如果小数点不存在,但是文本框没有任何字符,则也禁用'.'
                    //禁止文本框的第一个字符为'.'
                    else if (textBox4.Text.Length == 0)
                        e.Handled = true;
                      
                
                }
                int c = textBox4.Text.IndexOf('.');
                if (c != -1)  //表示点存在 
                {
                    if (textBox4.Text.Substring(c + 1).Length >= 2)
                        e.Handled = true;
                }
                //this.textBox5.Focus();
                //textBox1.Text = "";
                //textBox2.Text = "";
            }
            catch
            {
                MessageBox.Show("对不起你您输入的金币的格式不正确。请从新输入");
                this.textBox4.Focus();
                textBox4.Clear();
            }
        }

        private void textBox5_KeyPress(object sender, KeyPressEventArgs e)
        {
            try
            {
                if (!(e.KeyChar >= '0' && e.KeyChar <= '9') && (int)e.KeyChar != 8 && (int)e.KeyChar != 46 && (int)e.KeyChar != '.')
                {
                    e.Handled = true;
                }
                else if (e.KeyChar == '.')
                {
                    if (textBox5.Text.IndexOf('.') >= 0)
                    {//如果已经有小数点存在,则不能再输入小数点
                        e.Handled = true;
                        textBox5.Text.Substring(0,'.'.ToString().IndexOf('.') + 3);
                    }
                    //如果小数点不存在,但是文本框没有任何字符,则也禁用'.'
                    //禁止文本框的第一个字符为'.'
                    else if (textBox5.Text.Length == 0)
                        e.Handled = true;
                     
                }
                int v = textBox5.Text.IndexOf('.');
                if (v != -1)  //表示点存在 
                {
                    if (textBox5.Text.Substring(v + 1).Length >= 2)
                        e.Handled = true;
                }
                //this.textBox5.Focus();
                //textBox1.Text = "";
                //textBox2.Text = "";
            }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -