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

📄 serveform.cs

📁 主要实现仓库的入库与出库的基本功能
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Elysian
{
    public partial class serveForm : Form
    {
        SqlConnection sqlconn;
        SqlDataAdapter adapter;
        DataSet ds = new DataSet();
        public serveForm()
        {
            InitializeComponent();
        }

        private void serveForm_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“elysianDBDataSet1.供应商基本信息”中。您可以根据需要移动或移除它。
            this.供应商基本信息TableAdapter.Fill(this.elysianDBDataSet1.供应商基本信息);
            dispalyDB();
            //this.serverGroupBox.Visible = true;
            serverGroupBox.Show();
        }

        private static string GetConnectionString()
        {
            return "data source=.;initial catalog=ElysianDB;integrated security=true";
        }

        private void dispalyDB()
        {
            sqlconn = new SqlConnection(GetConnectionString());
            SqlCommand sqlcomm = new SqlCommand("select * from 供应商基本信息", sqlconn);
            adapter = new SqlDataAdapter(sqlcomm);
            sqlconn.Open();
            ds.Clear();
            adapter.Fill(ds, "供应商基本信息");
            dataGridView1.DataSource = ds.Tables["供应商基本信息"];

            sqlconn.Close();
        }

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

        private void 增加ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string insertStr = string.Format("insert into 供应商基本信息 values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')", textBox1.Text, textBox2.Text,
                 textBox3.Text, textBox4.Text, textBox5.Text, textBox6.Text, comboBox1.Text, textBox7.Text);
            SqlCommand insertCommond = new SqlCommand(insertStr, sqlconn);
            sqlconn.Open();
            try
            {
                if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || textBox5.Text == "" || textBox6.Text == "" || comboBox1.Text == "")
                {
                    MessageBox.Show("请您输入完整信息!");
                }
                else
                {
                    insertCommond.ExecuteNonQuery();
                    MessageBox.Show("添加成功!");
                    textBox1.Text = "";
                    textBox2.Text = "";
                    textBox3.Text = "";
                    textBox4.Text = "";
                    textBox5.Text = "";
                    textBox6.Text = "";
                    comboBox1.Text = "=所属地区=";
                    textBox7.Text = "";
                }
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message, "添加失败!", MessageBoxButtons.OK);
            }
            sqlconn.Close();
            dispalyDB();
        }

        private void 导出保存ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.AddExtension = true;
            sfd.CheckFileExists = true;
            sfd.CheckPathExists = true;
            
            sfd.Filter = "所有文件类型(*.*)|*.*|Excel 工作簿(*.xlsx)|*.xlsx";
            sfd.ShowHelp = true;
            sfd.Title = "另存为";
            sfd.ShowDialog();
        }

        private void 返回ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void 打印ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            PrintDialog pd = new PrintDialog();
            PrintDocument pdm = new PrintDocument();
            pd.Document = pdm;
            pd.ShowHelp = true;
            pd.PrintToFile = true;
            pd.ShowDialog();

        }


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

        private void 修改ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string updateStr = string.Empty;
            if (textBox10.Text == "" || textBox11.Text == "" || textBox12.Text == "" || textBox13.Text == ""
                || textBox14.Text == "" || textBox15.Text == "" || comboBox2.Text == "")
            {
                MessageBox.Show("请您输入完整的信息");
                return;
            }
            sqlconn = new SqlConnection(GetConnectionString());
            sqlconn.Open();
            SqlCommand sqlcomm = new SqlCommand();
            sqlcomm.CommandText = "update 供应商基本信息 set 供应商名称='" + textBox11.Text + "',供应商地址='" + textBox12.Text + "',联系人='" + textBox13.Text + "',联系电话='" + textBox14.Text + "',邮政编码='" + textBox15.Text + "',所属地区='" + comboBox2.Text + "',备注='" + textBox16.Text + "'where 供应商编号='" + textBox10.Text + "'";
            sqlcomm.Connection = sqlconn;
            int n = sqlcomm.ExecuteNonQuery();
            if (n > 0)
            {
                MessageBox.Show("信息修改成功");
                textBox10.Text = "";
                textBox11.Text = "";
                textBox12.Text = "";
                textBox13.Text = "";
                textBox14.Text = "";
                textBox15.Text = "";
                comboBox2.Text = "=所属地区=";
                textBox16.Text = "";
            }
            else
            {
                MessageBox.Show("信息修改失败");
            }
            sqlconn.Close();
        }

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

        private void button3_Click(object sender, EventArgs e)
        {
            string selectStr = string.Empty;
            selectStr = "select * from 供应商基本信息_view";
            if (textBox8.Text.ToString().Trim() != "")
            {
                selectStr = selectStr + " " + "where 供应商编号" + " " + comboBox3.Text + " " + "'" + textBox8.Text + "'";
                if (textBox9.Text.ToString().Trim() != "")
                {
                    selectStr = selectStr + " " + "and 供应商名称" + " " + comboBox3.Text + " " + "'" + textBox9.Text + "'";
                }
            }
            else
            {
                if (textBox9.Text.ToString().Trim() != "")
                {
                    selectStr = selectStr + " " + "where 供应商名称" + " " + comboBox3.Text + " " + "'" + textBox9.Text + "'";
                }
                else
                {
                    MessageBox.Show("请您输入要查询的信息");
                }
            }
            sqlconn = new SqlConnection(GetConnectionString());
            SqlCommand sqlcomm = new SqlCommand();
            sqlcomm.CommandText = selectStr;
            sqlcomm.Connection = sqlconn;
            try
            {

                sqlconn.Open();
            }
            catch (SqlException ex)
            {
                MessageBox.Show("连接数据库出错"+ex.ToString(),"提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Information);
            }
            ds.Clear();
            adapter = new SqlDataAdapter(sqlcomm);
            adapter.Fill(ds, "供应商基本信息");
            dataGridView2.DataSource = ds.Tables[0];
            sqlconn.Close();
            textBox8.Text = "";
            textBox9.Text = "";
        }

        private void button5_Click(object sender, EventArgs e)
        {
            string insertStr = string.Format("insert into 供应商基本信息 values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')", textBox1.Text, textBox2.Text,
                             textBox3.Text, textBox4.Text, textBox5.Text, textBox6.Text, comboBox1.Text, textBox7.Text);
            SqlCommand insertCommond = new SqlCommand(insertStr, sqlconn);
            sqlconn.Open();
            try
            {
                if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || textBox5.Text == "" || textBox6.Text == "" || comboBox1.Text == "")
                {
                    MessageBox.Show("请您输入完整信息!");
                }
                else
                {
                    insertCommond.ExecuteNonQuery();
                    MessageBox.Show("添加成功!");
                    textBox1.Text = "";
                    textBox2.Text = "";
                    textBox3.Text = "";
                    textBox4.Text = "";
                    textBox5.Text = "";
                    textBox6.Text = "";
                    comboBox1.Text = "=所属地区=";
                    textBox7.Text = "";
                }
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message, "添加失败!", MessageBoxButtons.OK);
            }
            sqlconn.Close();
            dispalyDB();
        }

    }
}

⌨️ 快捷键说明

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