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

📄 formjhyw.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.Text;
using System.Windows.Forms;

namespace _10901BS
{
    public partial class formJhyw : Form
    {

        SqlConnection con = new SqlConnection();//全局连接对象
        SqlCommand com = new SqlCommand();//全局的命令对象
        SqlDataAdapter da;  //全局的数据适配器
        SqlDataReader dr;
        DataSet ds = new DataSet();//全局的数据集<在客户端>
        DataSet ds1 = new DataSet();//全局的数据集<在客户端>
        DataSet dssp = new DataSet();//全局的数据集<在客户端>
        DataSet dsyg = new DataSet();//全局的数据集<在客户端>
        DataSet dsgys = new DataSet();//全局的数据集<在客户端>


        int m = 1;
        int i, idx = 0;

        public formJhyw()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.btn.Enabled = false;
            this.button6.Enabled = false;
            this.textBox4.Enabled = false;
            this.toolStripButton6.Enabled = false;
            if (con.State == ConnectionState.Closed)
            {
                con.ConnectionString = "server=.;database=110901DB;Integrated Security=True";
                con.Open();
                //MessageBox.Show("连接成功");				
            }

            da = new SqlDataAdapter("select spID from spxqBiao", con);
            ds.Clear();
            da.Fill(dssp);
            this.comboBox2.Items.Clear();
            foreach (DataRow row in dssp.Tables[0].Rows)
            {
                this.comboBox2.Items.Add(row.ItemArray[0]);
            }
           
            da = new SqlDataAdapter("select gysID from ghsBiao ", con);
            ds.Clear();
            da.Fill(dsgys);
            this.comboBox1.Items.Clear();
            foreach (DataRow row in dsgys.Tables[0].Rows)
            {
                this.comboBox1.Items.Add(row.ItemArray[0]);
            }

            da = new SqlDataAdapter("select jhDjID '进货单据编号',jhSpZsl '进货商品总数量', jhZje '进货总金额', jhRq '进货日期',jhJsr '经手人' from  jhzBiao  where 1=2", con);
            ds.Clear();
            da.Fill(ds);
            this.dataGridView1.DataSource = ds.Tables[0];
            this.dataGridView1.Columns[0].Width = 200;
            da = new SqlDataAdapter("select jhID '进货编号',jhDjID '进货单据编号',gysID '供应商编号', spID '商品编号', jhSl '进货数量', jhDjia '进货单价', jhZje '进货总金额', beiZhu '备注' from jhxqBiao where 1=2", con);
            ds1.Clear();
            da.Fill(ds1);
            this.dataGridView2.DataSource = ds1.Tables[0];
            this.dataGridView2.Columns[0].Width = 120;
            this.dataGridView2.Columns[2].Width = 200;
            this.dataGridView2.Columns[6].Width = 120;


            timer1.Start();
            this.statusStrip1.Items[0].Text = "当前时间:" + DateTime.Now.ToString();

            toolStripButton1.Enabled = false;
            toolStripButton7.Enabled = false;
            this.txtJHBH.Text = "JH" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString().PadLeft(2, '0') + DateTime.Now.Day.ToString().PadLeft(2, '0') + DateTime.Now.Hour.ToString().PadLeft(2, '0') + DateTime.Now.Minute.ToString().PadLeft(2, '0');


        }

        //************************保存***********************
        private void toolStripButton1_Click(object sender, EventArgs e)
        {

            com.Connection = con;
            com.CommandText = "insert into djczBiao( djid, zdRq, djName)values ( '" + txtJHBH.Text + "', '" + this.dtp1.Text + "', '进货单据')";
            com.ExecuteNonQuery();
            MessageBox.Show("单据操作表数据成功增加", "增加成功", MessageBoxButtons.OK, MessageBoxIcon.Information);

            com.Connection = con;
            com.CommandText = "insert into jhzBiao( jhDjID, jhSpZsl, jhZje, jhrq, jhjsr) values ('" + this.txtJHBH.Text + "','" + this.textBox2.Text + "','" + this.textBox3.Text + "','" + this.dtp1.Text + "','" + this.cboJsr.Text + "')";
            com.ExecuteNonQuery();
            MessageBox.Show("进货总表数据成功增加", "增加成功", MessageBoxButtons.OK, MessageBoxIcon.Information);

            //*****************************

            for (int i = 0; i < this.dataGridView2.Rows.Count; i++)
            {
                

                string c1 = this.dataGridView2.Rows[i].Cells[1].Value.ToString();
                string c2 = this.dataGridView2.Rows[i].Cells[2].Value.ToString();
                string c3 = this.dataGridView2.Rows[i].Cells[3].Value.ToString();
                string c4 = this.dataGridView2.Rows[i].Cells[4].Value.ToString();
                string c5 = this.dataGridView2.Rows[i].Cells[5].Value.ToString();

                com.CommandText = "insert into jhxqBiao( jhDjID, gysID, spID, jhSl, jhDjia) values ('" + c1 + "', '" + c2 + "', '" + c3 + "','" + c4 + "','" + c5 + "')";
                com.ExecuteNonQuery();
            }

            MessageBox.Show("进货明细数据成功增加", "增加成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.toolStripButton1.Enabled = false;  //置灰保存按钮


            ClearAll();
            this.txtJHBH.Text = "JH" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();


            this.tabControl1.SelectedTab = tabPage1;
            this.button1.Enabled = true;

        }

        private void ClearAll()
        {
            foreach (Control obj in this.Controls)
            {
                if (!(obj is DataGridView))
                    obj.Text = "";
            }

            this.textBox2.Text = "";
            this.textBox3.Text = "";

            ds.Clear();
            ds1.Clear();

        }


        //------------------删除-------------------// 
        private void toolStripButton6_Click(object sender, EventArgs e)
        {
            //MessageBox.Show(idx.ToString());

            //**************删除进货总表提交网格的信息***************
            if (idx == 0)
            {
                if (this.dataGridView1.SelectedRows.Count == 0)
                {
                    MessageBox.Show("网格中没有选中行,请先在网格选中行,再删除", "不能删除", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;  //退出本过程
                }

                DialogResult dlg = MessageBox.Show("真的要删除吗?", "删除", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dlg == DialogResult.Yes)
                {
                    foreach (DataGridViewRow kk in this.dataGridView1.SelectedRows)
                    {
                        this.dataGridView1.Rows.Remove(kk);
                        Clear();
                    }

                    MessageBox.Show("删除成功!", "删除", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //提交按钮可用
                    this.button1.Enabled = true; 
                    this.txtJHBH.Text = "JH" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();

                }
            }

            // **************删除进货详情表提交网格的信息***************           
            if (idx == 1)
            {

                if (this.dataGridView2.SelectedRows.Count == 0)
                {
                    MessageBox.Show("网格中没有选中行,请先在网格选中行,再删除", "不能删除", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //退出本过程
                    return;  
                }

                DialogResult dlg = MessageBox.Show("真的要删除吗?", "删除", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dlg == DialogResult.Yes)
                {
                    foreach (DataGridViewRow kk in this.dataGridView2.SelectedRows)
                    {
                        this.dataGridView2.Rows.Remove(kk);
                    }


                    this.comboBox1.Text = "";
                    this.comboBox2.Text = "";

                    this.textBox6.Text = "";
                    this.textBox7.Text = "";
                    this.textBox8.Text = "";

                    int k;
                    //把dataGridView2中的所有详情按顺序编号
                    for (k = 0; k < this.dataGridView2.Rows.Count; k++)
                    {
                        this.dataGridView2.Rows[k].Cells[0].Value = k + 1;
                    }

                    this.textBox4.Text = (k + 1).ToString(); //产生新的进货详情之编号

                    MessageBox.Show("删除成功!", "删除", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
            }
        }

        //**************修改进货总表**************
        private void toolStripButton7_Click(object sender, EventArgs e)
        {
            if (idx == 0)
            {
                if (this.txtJHBH.Text != "" && this.textBox2.Text != "" && this.textBox3.Text != "")
                {

                    i = this.dataGridView1.CurrentCell.RowIndex;
                    this.dataGridView1.Rows[i].Cells[0].Value = this.txtJHBH.Text;
                    this.dataGridView1.Rows[i].Cells[1].Value = this.textBox2.Text;
                    this.dataGridView1.Rows[i].Cells[2].Value = this.textBox3.Text;

                    MessageBox.Show("进货总表修改成功!", "修改", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
            }

            if (idx == 1)
            {
                if (this.textBox4.Text != "" && this.textBox6.Text != "" && this.textBox7.Text != "" && this.comboBox1.Text != "" && this.comboBox2.Text != "" && this.txtJHBH_1.Text != "")
                {

                    i = this.dataGridView2.CurrentCell.RowIndex;
                    this.dataGridView2.Rows[i].Cells[0].Value = this.textBox4.Text;
                    this.dataGridView2.Rows[i].Cells[1].Value = this.txtJHBH_1.Text;
                    this.dataGridView2.Rows[i].Cells[2].Value = this.comboBox1.Text;
                    this.dataGridView2.Rows[i].Cells[3].Value = this.comboBox2.Text;
                    this.dataGridView2.Rows[i].Cells[4].Value = this.textBox6.Text;
                    this.dataGridView2.Rows[i].Cells[5].Value = this.textBox7.Text;
                    this.dataGridView2.Rows[i].Cells[6].Value = Convert.ToInt32(this.textBox6.Text) * Convert.ToDecimal(this.textBox7.Text);  //进货金额
                    this.dataGridView2.Rows[i].Cells[7].Value = this.textBox8.Text;

                    MessageBox.Show("进货详情修改成功!", "修改", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    this.comboBox1.Text = "";
                    this.comboBox2.Text = "";

                    this.textBox6.Text = "";
                    this.textBox7.Text = "";
                    this.textBox8.Text = "";

                    this.textBox4.Text = Convert.ToString(Convert.ToInt32(this.textBox4.Text) + 1);

                }
            }
        }


        //*********刷新***********
        private void toolStripButton9_Click(object sender, EventArgs e)
        {
            DialogResult dlg = MessageBox.Show("刷新将在清空窗体中的所有数据后重新加载窗体,确定?", "清除所有数据并加载", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (dlg == DialogResult.Yes)
            {
                Clear();
                Form1_Load(sender, e);
            }

        }
        //**************清空***********
        private void Clear()
        {
            this.txtJHBH.Text = "";
            this.textBox2.Text = "";
            this.textBox3.Text = "";

            this.txtJHBH_1.Text = "";
            this.textBox4.Text = "";
            this.comboBox1.Text = "";
            this.comboBox2.Text = "";
            this.textBox6.Text = "";
            this.textBox7.Text = "";

            this.cboJsr.Text = "";
            this.dtp1.Text = "";

            ds.Clear();
            ds1.Clear();

        }
        //************绑定 dataGridView1网格********
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (idx == 0)
                {
                    this.txtJHBH.Text = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
                    this.textBox2.Text = this.dataGridView1.CurrentRow.Cells[1].Value.ToString();
                    this.textBox3.Text = this.dataGridView1.CurrentRow.Cells[2].Value.ToString();
                    this.dtp1.Text = this.dataGridView1.CurrentRow.Cells[3].Value.ToString();
                    this.cboJsr.Text = this.dataGridView1.CurrentRow.Cells[4].Value.ToString();

                }
            }
            catch
            { }
        }
        //************绑定 dataGridView2网格********
        private void dataGridView2_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (idx == 1)
            {
                this.textBox4.Text = this.dataGridView2.CurrentRow.Cells[0].Value.ToString();
                this.txtJHBH_1.Text = this.dataGridView2.CurrentRow.Cells[1].Value.ToString();
                this.comboBox1.Text = this.dataGridView2.CurrentRow.Cells[2].Value.ToString();
                this.comboBox2.Text = this.dataGridView2.CurrentRow.Cells[3].Value.ToString();
                this.textBox6.Text = this.dataGridView2.CurrentRow.Cells[4].Value.ToString();

⌨️ 快捷键说明

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