设计思路及框架设计:

项目结构:

.net仓库管理系统源代码佳 c#仓库管理系统设计_visual studio

1.默认登录界面、注册功能设计

.net仓库管理系统源代码佳 c#仓库管理系统设计_c#_02

通过SqlConnection连接数据库,SqlCommand执行查询语句,ExecuteScalar()方法返回的结果判断是否查询到数据,决定是否登录!

.net仓库管理系统源代码佳 c#仓库管理系统设计_sql_03

判断是否查询到用户,决定是否注册成功!

2.主界面设计

.net仓库管理系统源代码佳 c#仓库管理系统设计_sql_04

主界面提供各管理页面的入口链接以及仓库环境监测功能!

.net仓库管理系统源代码佳 c#仓库管理系统设计_c#_05

环境监测采用用户控件的方式,通过SerialPort获取外设串口,再监测BytesToRead获取串口数据,最后传入的数据进行字符串解析,把相应值传入DrawLine,实现动态折线图页面!

3.商品管理页面设计

.net仓库管理系统源代码佳 c#仓库管理系统设计_sql_06

商品管理主页面,由SqlDataAdapter获取数据,通过DataTable展示页面,Fill填充数据到页面,ItemsSource设置页面的资源列表!
商品添加页面:

.net仓库管理系统源代码佳 c#仓库管理系统设计_sql_07

添加数据不能为空,获取填充数据进行insert SQL语句插入。
商品删除、修改操作:

.net仓库管理系统源代码佳 c#仓库管理系统设计_sql_08

通过cs验证库存,库存不为0的不可进行删改操作!

4.入库管理界面设计

.net仓库管理系统源代码佳 c#仓库管理系统设计_数据库_09

入库功能界面采用DataTable显示入库表,采用comboBox控件显示仓库中的商品,入库时插入入库记录并刷新仓库中的库存,达到入库功能!
删除入库记录功能:

.net仓库管理系统源代码佳 c#仓库管理系统设计_.net仓库管理系统源代码佳_10

删除不必要的入库记录!并刷新页面数据!

5.出库管理界面设计

.net仓库管理系统源代码佳 c#仓库管理系统设计_数据库_11

出库功能与入库功能相似,主要是修改库存之中的数据!

.net仓库管理系统源代码佳 c#仓库管理系统设计_visual studio_12

但当库存不足时,通过先行查找库存之中的数据进行校验,不足时提示出库失败!

6.用户管理界面

.net仓库管理系统源代码佳 c#仓库管理系统设计_visual studio_13

通过用户管理界面方便进行管理登录仓库账号!

因云盘易失效,故附项目源码如下:

MainWindow.xaml

<Window x:Class="goodsdb.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:goodsdb"
        mc:Ignorable="d"
        Title="登录界面" Height="450" Width="860">
    <Grid>
        <TextBox x:Name="username" HorizontalAlignment="Left" Margin="360,146,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
        <PasswordBox x:Name="password" HorizontalAlignment="Left" Margin="360,187,320,0" VerticalAlignment="Top" Width="120"/>
        <TextBlock HorizontalAlignment="Left" Margin="292,146,0,0" TextWrapping="Wrap" VerticalAlignment="Top"><Run Language="zh-cn" Text="用户名:"/></TextBlock>
        <TextBlock HorizontalAlignment="Left" Margin="292,187,0,0" TextWrapping="Wrap" VerticalAlignment="Top"><Run Language="zh-cn" Text="密码:"/></TextBlock>
        <Button Content="注册" HorizontalAlignment="Left" Margin="324,241,0,0" VerticalAlignment="Top" Click="Button_Click"/>
        <Button Content="登录" HorizontalAlignment="Left" Margin="423,242,0,0" VerticalAlignment="Top" Click="Button_Click_1"/>
    </Grid>
</Window>

MainWindow.xaml.cs

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace goodsdb
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            view.regist user = new view.regist();
            user.Show();
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            if (username.Text != "" | password.Password != "")
            {
                SqlConnection connection = new SqlConnection("Address=localhost;Database=commoditydb;integrated security=SSPI");
                connection.Open();
                SqlCommand command = new SqlCommand("select * from user_t where username = '" + username.Text + "' and password = '" + password.Password + "'", connection);
                if (command.ExecuteScalar() != null)
                {
                    MessageBox.Show("用户: "+username.Text +" 登陆成功!");
                    view.main user2 = new view.main();
                    user2.Show();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("用户名或密码错误!");
                }
            }
            else
            {
                MessageBox.Show("用户名或密码不能为空!");
            }
        }
    }
}

main.xaml

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:goodsdb.view"
        xmlns:tu="clr-namespace:goodsdb.tu" x:Class="goodsdb.view.main"
        mc:Ignorable="d"
        Title="主界面" Height="450" Width="800" Loaded="Window_Loaded_1" Closing="Window_Closing_1">
    <Grid>
        <Button Content="用户管理" HorizontalAlignment="Left" Margin="78,70,0,0" VerticalAlignment="Top" Height="30" Width="74" Click="Button_Click_2"/>
        <Button Content="商品管理" HorizontalAlignment="Left" Margin="78,133,0,0" VerticalAlignment="Top" Height="30" Width="74" Click="Button_Click_11"/>
        <Button Content="入库管理" HorizontalAlignment="Left" Margin="78,0,0,0" VerticalAlignment="Center" Height="30" Width="74" Click="Button_Click_4"/>
        <Button Content="出库管理" HorizontalAlignment="Left" Margin="78,262,0,0" VerticalAlignment="Top" Height="30" Width="74" Click="Button_Click_7"/>
        <Button Content="退出" HorizontalAlignment="Left" Margin="78,332,0,0" VerticalAlignment="Top"  Width="71" Height="30" Click="Button_Click"/>

        <Label Content="请选择串口" HorizontalAlignment="Left" Margin="197,61,0,0" VerticalAlignment="Top" Height="25" Width="82"/>
        <ComboBox x:Name="cb_port" HorizontalAlignment="Left" Margin="277,65,0,0" VerticalAlignment="Top" Width="138" Height="21"/>
        <Button Content="打开串口" HorizontalAlignment="Left" Margin="480,67,0,0" VerticalAlignment="Top" Width="74" Click="Button_Click_1" Height="19"/>
        <ListBox x:Name="lb_message" HorizontalAlignment="Left" Height="22" Margin="200,150,0,0" VerticalAlignment="Top" Width="486"/>
        <Label Content="温度" HorizontalAlignment="Left" Margin="196,92,0,0" VerticalAlignment="Top" Height="24" Width="40"/>
        <Label Content="湿度" HorizontalAlignment="Left" Margin="335,91,0,0" VerticalAlignment="Top" Height="24" Width="40"/>
        <Label Content="光照度" HorizontalAlignment="Left" Margin="475,91,0,0" VerticalAlignment="Top" Height="24" Width="53"/>
        <Label x:Name="lb_wd" Content="N/A" HorizontalAlignment="Left" Margin="248,92,0,0" VerticalAlignment="Top" Height="24" Width="39"/>
        <Label x:Name="lb_sd" Content="N/A" HorizontalAlignment="Left" Margin="384,92,0,0" VerticalAlignment="Top" Height="24" Width="39"/>
        <Label x:Name="lb_gzd" Content="N/A" HorizontalAlignment="Left" Margin="538,94,0,0" VerticalAlignment="Top" Height="24" Width="44"/>
        <Label Content="LED1" HorizontalAlignment="Left" Margin="195,122,0,0" VerticalAlignment="Top" Height="24" Width="45"/>
        <Label x:Name="lb_led1" Content="N/A" HorizontalAlignment="Left" Margin="247,122,0,0" VerticalAlignment="Top" Height="24" Width="39"/>
        <Label Content="LED2" HorizontalAlignment="Left" Margin="477,122,0,0" VerticalAlignment="Top" Height="24" Width="45"/>
        <Label x:Name="lb_led2" Content="N/A" HorizontalAlignment="Left" Margin="540,122,0,0" VerticalAlignment="Top" Height="24" Width="38"/>
        <Button x:Name="bt_led1" Content="N/A" HorizontalAlignment="Left" Margin="300,126,0,0" VerticalAlignment="Top" Width="87" Click="bt_led1_Click" Height="18"/>
        <Button x:Name="bt_led2" Content="N/A" HorizontalAlignment="Left" Margin="600,125,0,0" VerticalAlignment="Top" Width="87" Click="bt_led2_Click" Height="18"/>
        <Button Content="关闭串口" HorizontalAlignment="Left" Margin="580,66,0,0" VerticalAlignment="Top" Width="69" Click="Button_Click_3" Height="19"/>
        <Label Content="仓库" HorizontalAlignment="Left" Margin="364,12,0,0" VerticalAlignment="Top" FontSize="20" RenderTransformOrigin="0.026,0.272"/>
        <tu:CurveControl HorizontalAlignment="Left" Margin="198,181,0,0" VerticalAlignment="Top" x:Name="wdCurveCtr"/>
        <tu:CurveControl HorizontalAlignment="Left" Margin="365,181,0,0" VerticalAlignment="Top" x:Name="sdCurveCtr"/>
        <tu:CurveControl HorizontalAlignment="Left" Margin="535,182,0,0" VerticalAlignment="Top" x:Name="CurveCtr"/>
        <Label Content="温度" HorizontalAlignment="Left" Margin="250,385,0,0" VerticalAlignment="Top"/>
        <Label Content="湿度" HorizontalAlignment="Left" Margin="418,384,0,0" VerticalAlignment="Top"/>
        <Label Content="光感度" HorizontalAlignment="Left" Margin="598,383,0,0" VerticalAlignment="Top"/>
    </Grid>
</Window>

main.xaml.cs

using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace goodsdb.view
{
    /// <summary>
    /// main.xaml 的交互逻辑
    /// </summary>
    public partial class main : Window
    {
        public main()
        {
            InitializeComponent();
        }
        Thread timer;
        private void Window_Closing_1(object sender, System.ComponentModel.CancelEventArgs e)
        {
            //timer.Abort();
            //timer = null;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            MainWindow user = new MainWindow();
            user.Show();
            this.Close();
        }

        private void Button_Click_11(object sender, RoutedEventArgs e)
        {
            commodity.goodsmanagement user = new commodity.goodsmanagement();
            user.Show();
            this.Close();
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            view.usermanagement user = new view.usermanagement();
            user.Show();
            this.Close();
        }
        private void Window_Loaded_1(object sender, RoutedEventArgs e)
        {
            string[] ports = SerialPort.GetPortNames();
            foreach (string port in ports)
            {
                cb_port.Items.Add(port);
            }
        }
        SerialPort port;
        byte[] ip = new byte[2];
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            port = new SerialPort(cb_port.SelectedValue.ToString(), 38400);
            port.Open();
            port.DataReceived += datareceived;
            CurveCtr.DrawBackground();
        }

        private void datareceived(object sender, SerialDataReceivedEventArgs e)
        {
            Thread.Sleep(20);
            int n = port.BytesToRead;
            if (n > 10)
            {
                byte[] data = new byte[n];
                port.Read(data, 0, n);
                ip[0] = data[4];
                ip[1] = data[5];
                string content = Encoding.Default.GetString(data, 9, n - 11);
                string[] datas = content.Split(',');
                if (datas.Length == 1)
                {
                    int LED = int.Parse(datas[0].Remove(0, 3));
                    Dispatcher.Invoke(() =>
                    {
                        if ((LED & 128) == 128)
                        {
                            lb_led1.Content = "亮";
                            bt_led1.Content = "关";
                        }
                        else
                        {
                            lb_led1.Content = "灭";
                            bt_led1.Content = "开";
                        }
                        if ((LED & 64) == 64)
                        {
                            lb_led2.Content = "亮";
                            bt_led2.Content = "关";
                        }
                        else
                        {
                            lb_led2.Content = "灭";
                            bt_led2.Content = "开";
                        }
                    });
                }
                else
                {
                    int LED = int.Parse(datas[7].Remove(0, 3));
                    Dispatcher.Invoke(() =>
                    {
                        lb_message.Items.Add(content);
                        lb_wd.Content = datas[0].Remove(0, 3);
                        lb_sd.Content = datas[1].Remove(0, 3);
                        lb_gzd.Content = datas[2].Remove(0, 3);

                        Dispatcher.Invoke(new Action(() =>
                        {
                            double wd = Convert.ToDouble(datas[0].Remove(0, 3));
                            double sd = Convert.ToDouble(datas[1].Remove(0, 3));
                            double gzd = Convert.ToDouble(datas[2].Remove(0, 3));
                            
                            wdCurveCtr.DrawLine(wd);
                            sdCurveCtr.DrawLine(sd);
                            CurveCtr.DrawLine(gzd);
                        }));


                        if ((LED & 128) == 128)
                        {
                            lb_led1.Content = "亮";
                            bt_led1.Content = "关";
                        }
                        else
                        {
                            lb_led1.Content = "灭";
                            bt_led1.Content = "开";
                        }
                        if ((LED & 64) == 64)
                        {
                            lb_led2.Content = "亮";
                            bt_led2.Content = "关";
                        }
                        else
                        {
                            lb_led2.Content = "灭";
                            bt_led2.Content = "开";
                        }
                    });
                }
            }
            else
            {
                port.DiscardInBuffer();
            }
        }
        private void bt_led1_Click(object sender, RoutedEventArgs e)
        {
            string cmd;
            if (bt_led1.Content.ToString() == "开")
            {
                cmd = "OD1=128";
                control(cmd);
            }
            else
            {
                cmd = "CD1=128";
                control(cmd);
            }
        }
        private void bt_led2_Click(object sender, RoutedEventArgs e)
        {
            string cmd;
            if (bt_led2.Content.ToString() == "开")
            {
                cmd = "OD1=64";
                control(cmd);
            }
            else
            {
                cmd = "CD1=64";
                control(cmd);
            }
        }
        private void control(string cmd)
        {
            string control = "{" + cmd + ",D1=?}";
            int lenght = control.Length + 10;
            byte[] data = new byte[lenght];
            data[0] = 0xFE;
            data[1] = byte.Parse((control.Length + 5).ToString());
            data[2] = 0x29;
            data[3] = 0x00;
            data[4] = 0x02;
            ip.CopyTo(data, 5);
            data[7] = 0x00;
            data[8] = 0x00;
            byte[] controls = Encoding.Default.GetBytes(control);
            controls.CopyTo(data, 9);
            byte jiaoyan = 0;
            for (int i = 1; i < lenght - 1; i++)
            {
                jiaoyan ^= data[i];
            }
            data[lenght - 1] = jiaoyan;
            port.Write(data, 0, lenght);

        }

        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            port.Close();
        }

        private void Button_Click_4(object sender, RoutedEventArgs e)
        {
            record.delivermanagement deli = new record.delivermanagement();
            deli.Show();
            this.Close();
        }
        private void Button_Click_7(object sender, RoutedEventArgs e)
        {
            record.housingmanagement deli = new record.housingmanagement();
            deli.Show();
            this.Close();
        }
    }
}

regist.xaml

<Window x:Class="goodsdb.view.regist"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:goodsdb.view"
        mc:Ignorable="d"
        Title="注册页面" Height="300" Width="360">
    <Grid>
        <TextBox x:Name="username" HorizontalAlignment="Left" Margin="136,50,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
        <PasswordBox x:Name="password" HorizontalAlignment="Left"  Margin="136,89,0,0" VerticalAlignment="Top" Width="120"/>
        <PasswordBox x:Name="passwordtest" HorizontalAlignment="Left"  Margin="136,120,0,0" VerticalAlignment="Top" Width="120"/>
        <TextBlock HorizontalAlignment="Left" Margin="69,51,0,0" TextWrapping="Wrap" VerticalAlignment="Top" RenderTransformOrigin="0.075,0.706"><Run Language="zh-cn" Text="用户名:"/></TextBlock>
        <TextBlock HorizontalAlignment="Left" Margin="68,88,0,0" TextWrapping="Wrap" VerticalAlignment="Top"><Run Language="zh-cn" Text="密码:"/></TextBlock>
        <TextBlock HorizontalAlignment="Left" Margin="70,120,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Text="确认密码:"/>
        <Button Content="注册" HorizontalAlignment="Left" Margin="99,177,0,0" VerticalAlignment="Top" Click="Button_Click" Height="20" Width="40"/>
        <Button Content="取消" HorizontalAlignment="Left" Margin="185,176,0,0" VerticalAlignment="Top" Click="Button_Click_1" Height="20" Width="40"/>
    </Grid>
</Window>

regist.xaml.cs

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace goodsdb.view
{
    /// <summary>
    /// regist.xaml 的交互逻辑
    /// </summary>
    public partial class regist : Window
    {
        public regist()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (username.Text != "" | password.Password != "" | passwordtest.Password != "")
            {
                if (password.Password == passwordtest.Password)
                {
                    string user = username.Text;
                    string pwd = password.Password;
                    string sql1 = "select * from user_t where username='" + user + "'";
                    string sql2 = "insert into user_t(username,password) values('" + user + "','" + pwd + "')";
                    string sql = "Address=localhost;Database=commoditydb;integrated security=SSPI";
                    SqlConnection connection = new SqlConnection();
                    try
                    {
                        connection.ConnectionString = sql;
                        connection.Open();
                        //MessageBox.Show("连接到数据库!");
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("错误信息:" + ex.Message, "无法连接到数据库!");
                    }
                    SqlCommand command = new SqlCommand(sql1, connection);
                    command.ExecuteNonQuery();
                    //object Result = command.ExecuteScalar();
                    //string result = command.ExecuteScalar().ToString();
                    if (command.ExecuteScalar() == null)
                    {
                        SqlCommand command1 = new SqlCommand(sql2, connection);
                        command1.ExecuteNonQuery();
                        MessageBox.Show(user + "  : 注册成功!");
                        connection.Close();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("用户已存在!");
                    }
                }
                else
                {
                    MessageBox.Show("密码不一致,请重新输入!");
                }
            }
            else
            {
                MessageBox.Show("输入不能为空!");
            }
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}

updatauser.xaml

<Window x:Class="goodsdb.view.updatauser"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:goodsdb.view"
        mc:Ignorable="d"
        Title="修改用户" Height="300" Width="360">
    <Grid>
        <TextBox x:Name="id" HorizontalAlignment="Left" Margin="147,62,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" IsReadOnly="True"/>
        <TextBox x:Name="username" HorizontalAlignment="Left" Margin="147,87,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
        <PasswordBox x:Name="password" HorizontalAlignment="Left"  Margin="147,116,0,0" VerticalAlignment="Top" Width="120"/>
        <TextBlock HorizontalAlignment="Left" Margin="80,88,0,0" TextWrapping="Wrap" VerticalAlignment="Top" RenderTransformOrigin="0.075,0.706"><Run Language="zh-cn" Text="用户名:"/></TextBlock>
        <TextBlock HorizontalAlignment="Left" Margin="79,115,0,0" TextWrapping="Wrap" VerticalAlignment="Top"><Run Language="zh-cn" Text="密码:"/></TextBlock>
        <TextBlock HorizontalAlignment="Left" Margin="80,63,0,0" TextWrapping="Wrap" VerticalAlignment="Top" RenderTransformOrigin="0.075,0.706"><Run Language="zh-cn" Text="序号:"/></TextBlock>
        <Button Content="提交修改" HorizontalAlignment="Left" Margin="152,193,0,0" VerticalAlignment="Top" Click="Button_Click"/>

    </Grid>
</Window>

updatauser.xaml.cs

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace goodsdb.view
{
    /// <summary>
    /// updatauser.xaml 的交互逻辑
    /// </summary>
    public partial class updatauser : Window
    {
        public updatauser(string id, string username, string password)
        {
            InitializeComponent();
            this.id.Text = id;
            this.username.Text = username;
            this.password.Password = password;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            SqlConnection connection = new SqlConnection("Address=localhost; Database=commoditydb;integrated security=SSPI");
            connection.Open();
            string sqlstr = "update user_t set username='" + username.Text + "',password='" + password.Password + "' where id='" + id.Text + "'";
            SqlCommand command = new SqlCommand(sqlstr, connection);
            command.ExecuteNonQuery();
            MessageBox.Show("修改成功!");
            view.usermanagement user = new view.usermanagement();
            user.Show();
            this.Close();
        }
    }
}

usermanagement.xaml

<Window x:Class="goodsdb.view.usermanagement"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:goodsdb.view"
        mc:Ignorable="d"
        Title="用户管理" Height="450" Width="800">
    <Grid>
        <DataGrid x:Name="dg" Margin="144,65,143,66" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" >
            <DataGrid.Columns>
                <DataGridTextColumn Header="序号:" Width="100" Binding="{Binding id}"/>
                <DataGridTextColumn Header="用户名:" Width="100" Binding="{Binding username}"/>
                <DataGridTextColumn Header="密码:" Width="100" Binding="{Binding password}"/>
            </DataGrid.Columns>
        </DataGrid>
        <Button Content="返回" HorizontalAlignment="Left" Margin="642,387,0,0" VerticalAlignment="Top" Click="Button_Click" Width="56" Height="26"/>
        <Button Content="修改" HorizontalAlignment="Left" Margin="115,384,0,0" VerticalAlignment="Top" Click="Button_Click_2" Width="56" Height="26"/>
        <Button Content="删除" HorizontalAlignment="Left" Margin="374,389,0,0" VerticalAlignment="Top" Click="Button_Click_3" Width="56" Height="26"/>
        <Label Content="用户管理" HorizontalAlignment="Left" Margin="335,20,0,0" VerticalAlignment="Top" FontSize="20" RenderTransformOrigin="0.026,0.272"/>
    </Grid>
</Window>

usermanagement.xaml.cs

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace goodsdb.view
{
    /// <summary>
    /// goods.xaml 的交互逻辑
    /// </summary>
    public partial class usermanagement : Window
    {
        public usermanagement()
        {
            InitializeComponent();
            SqlDataAdapter da = new SqlDataAdapter("select *  from user_t", "Server=localhost;Database=commoditydb;integrated security=SSPI");
            DataTable dt = new DataTable();
            da.Fill(dt);
            //DataRow dr = dt.NewRow();
            //dr["id"] = 9;
            //dr[1] = 9;
            //dr[2] = 9;
            //dr[3] = 9;
            //dt.Rows.Add(dr);
            dg.ItemsSource = dt.DefaultView;        //表单显示
            //da.Update(dt);
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            view.main main = new view.main();
            main.Show();
            this.Close();
        }

        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            if (dg.SelectedItem != null)
            {
                DataRowView dr = (DataRowView)dg.SelectedItem;
                string username = dr[1].ToString();
                SqlConnection connection = new SqlConnection("Address=localhost; Database=commoditydb;integrated security=SSPI");
                connection.Open();
                string sqlstr = "delete user_t where username='" + username + "'";
                SqlCommand command = new SqlCommand(sqlstr, connection);
                command.ExecuteNonQuery();
                MessageBox.Show("删除成功!");

                SqlDataAdapter da = new SqlDataAdapter("select *  from user_t", "Server=localhost;Database=commoditydb;integrated security=SSPI");
                DataTable dt = new DataTable();
                da.Fill(dt);
                dg.ItemsSource = dt.DefaultView;        //表单显示
            }
            else
            {
                MessageBox.Show("删除数据未选中!");
            }
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            if (dg.SelectedItem != null)
            {
                DataRowView dr = (DataRowView)dg.SelectedItem;
                string id = dr[0].ToString();
                string username = dr[1].ToString();
                string password = dr[2].ToString();
                view.updatauser win4 = new view.updatauser(id, username, password);
                win4.Show();
                this.Close();
            }
            else
            {
                MessageBox.Show("修改数据未选中!");
            }
        }
    }
}

CurveControl.xaml

<UserControl x:Class="goodsdb.tu.CurveControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:goodsdb.tu"
             mc:Ignorable="d" 
             d:DesignHeight="220" d:DesignWidth="150"  Loaded="UserControl_Loaded_1">
    <Grid>
        <Canvas x:Name="grdBackground" Height="200" Width="150" HorizontalAlignment="Center" VerticalAlignment="Center" Background="#012F59">
        </Canvas>
        <Grid x:Name="grdMain" Height="200" Width="150" HorizontalAlignment="Center" VerticalAlignment="Center" Background="Transparent">
        </Grid>
    </Grid>
</UserControl>

CurveControl.xaml.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace goodsdb.tu
{
    /// <summary>
    /// CurveControl.xaml 的交互逻辑
    /// </summary>
    public partial class CurveControl : UserControl
    {
        public CurveControl()
        {
            InitializeComponent();
        }
        #region 绘制折线
        /// <summary>
        /// X轴步长(两个顶点点X轴的距离)
        /// </summary>
        public int StepLength = 20;
        /// <summary>
        /// 顶点最多个数
        /// </summary>
        public int MaxCount = 8;
        /// <summary>
        /// 最大量程
        /// </summary>
        public int MaxReg = 150;
        /// <summary>
        /// 最小量程
        /// </summary>
        public int MinReg = 0;
        //底部数字列表
        List<TextBlock> listBottom = new List<TextBlock>();
        //折线图
        Polyline pline = new Polyline();
        /// <summary>
        /// 画线
        /// </summary>
        /// <param name="Y2">线段终点Y轴坐标</param>
        public void DrawLine(double Y2)
        {
            //将值转换为图上坐标
            Y2 = grdMain.Height - (grdMain.Height / (MaxReg - MinReg)) * (Y2 - MinReg);
            //判断折线图顶点集合个数是否大于0
            if (pline.Points.Count > 0)
            {
                //向折线图顶点集合添加新线段终点坐标
                pline.Points.Add(new Point((pline.Points[pline.Points.Count - 1].X + StepLength), Y2));
                //判断顶点集合个数是否超过最大个数
                if (MaxCount + 1 < pline.Points.Count)
                {
                    //将曲线及下方数字往左移动

                    //删除第一个点
                    pline.Points.Remove(pline.Points[0]);
                    int ForLen = (pline.Points.Count > listBottom.Count) ? pline.Points.Count : listBottom.Count;
                    //将点击数字往左移动一位
                    for (int i = 0; i < ForLen; i++)
                    {
                        if (i < pline.Points.Count)
                        {
                            //将顶点的X轴坐标减去步长
                            pline.Points[i] = new Point(pline.Points[i].X - StepLength, pline.Points[i].Y);
                        }
                        if (i < listBottom.Count)
                        {
                            listBottom[i].Text = (int.Parse(listBottom[i].Text) + 1).ToString();
                        }
                    }
                }
            }
            else
            {//第一次添加顶点

                //设置线条颜色
                pline.Stroke = new SolidColorBrush(Colors.White);
                //设置线条宽度
                pline.StrokeThickness = 1;

                //添加第一个点
                pline.Points.Add(new Point(0, Y2));
                //将折线控件作为子控件添加到界面
                this.grdMain.Children.Add(pline);
            }
        }
        /// <summary>
        /// 绘制背景
        /// </summary>
        public void DrawBackground()
        {
            //清空
            grdBackground.Children.Clear();
            listBottom.Clear();
            ClearLines();
            //==============绘制底部数字及绘制Y轴方向直线
            //计算顶点最大个数
            MaxCount = (int)(grdBackground.Width / StepLength);
            for (int i = 1; i <= MaxCount; i++)
            {
                //绘制Y轴直线
                Line line = new Line();
                //设置开始坐标及终点坐标
                line.X1 = StepLength * i;
                line.X2 = StepLength * i;
                line.Y1 = 0;
                line.Y2 = grdBackground.Height;

                Color color = new Color();
                color.R = 20;
                color.G = 80;
                color.B = 136;
                color.A = 100;
                //设置线条颜色
                line.Stroke = new SolidColorBrush(color);
                //设置线条宽度
                line.StrokeThickness = 2;

                //绘制下方数字
                TextBlock tb = new TextBlock();
                //设置字体颜色
                tb.Foreground = new SolidColorBrush(Colors.Red);
                //数字
                tb.Text = "" + i;
                //显示界面
                grdBackground.Children.Add(tb);
                grdBackground.Children.Add(line);
                //添加到全局变量
                listBottom.Add(tb);
                //设置坐标
                Canvas.SetBottom(tb, 0);
                Canvas.SetLeft(tb, StepLength * i);
            }

            //==============绘制左侧数字及绘制X轴方向直线(大概原理同上)
            for (int i = MinReg; i <= MaxReg; i+=15)
            {
                Line line = new Line();
                line.X1 = 0;
                line.X2 = grdBackground.Width;
                //grdMain.Height - (grdMain.Height / (MaxReg-MinReg)) * Y2
                line.Y1 = grdMain.Height - (grdMain.Height / (MaxReg - MinReg)) * (i - MinReg);
                line.Y2 = grdMain.Height - (grdMain.Height / (MaxReg - MinReg)) * (i - MinReg);
                Color color = new Color();
                color.R = 20;
                color.G = 80;
                color.B = 136;
                color.A = 100;
                line.Stroke = new SolidColorBrush(color);
                line.StrokeThickness = 2;

                TextBlock tb = new TextBlock();
                tb.Foreground = new SolidColorBrush(Colors.Red);
                tb.Text = "" + i;
                grdBackground.Children.Add(tb);
                grdBackground.Children.Add(line);
                //  listBottom.Add(tb);
                Canvas.SetTop(tb, grdMain.Height - (grdMain.Height / (MaxReg - MinReg)) * (i - MinReg));
                Canvas.SetLeft(tb, 0);
            }
            //设置线条颜色
            pline.Stroke = new SolidColorBrush(Colors.Red);
            //设置线条宽度
            pline.StrokeThickness = 1;

            //添加第一个点
            pline.Points.Add(new Point(0, this.grdMain.Height));
            //将折线控件作为子控件添加到界面
            this.grdMain.Children.Add(pline);
        }
        /// <summary>
        /// 清空折线
        /// </summary>
        public void ClearLines()
        {
            //清空柱状集合
            pline.Points.Clear();
            //清空界面
            this.grdMain.Children.Clear();
        }
        #endregion

        private void UserControl_Loaded_1(object sender, RoutedEventArgs e)
        {
            DrawBackground();
        }
    }
}

CurveWindow.xaml

<Window x:Class="goodsdb.tu.CurveWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:goodsdb.tu"
        mc:Ignorable="d"
        Title="曲线图" Height="240" Width="440" Loaded="Window_Loaded_1" Closing="Window_Closing_1">
    <Grid>
        <Canvas x:Name="grdBackground" Height="220" Width="440" HorizontalAlignment="Center" VerticalAlignment="Center" Background="#012F59">
        </Canvas>
        <Grid x:Name="grdMain" Height="220" Width="440" HorizontalAlignment="Center" VerticalAlignment="Center" Background="Transparent">
        </Grid>
    </Grid>
</Window>

CurveWindow.xaml.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace goodsdb.tu
{
    /// <summary>
    /// CurveWindow.xaml 的交互逻辑
    /// </summary>
    public partial class CurveWindow : Window
    {
        public CurveWindow()
        {
            InitializeComponent();
        }
        Thread timer;
        private void Window_Loaded_1(object sender, RoutedEventArgs e)
        {
            DrawBackground();

            timer = new Thread(new ThreadStart(() =>
            {
                Random rd = new Random();
                while (true)
                {
                    try
                    {

                        Dispatcher.Invoke(new Action(() =>
                        {
                            double d = rd.Next(MinReg, MaxReg);
                            DrawLine(d);
                            Console.WriteLine(d + "");
                        }));

                    }
                    catch (Exception)
                    {
                    }
                    Thread.Sleep(700);
                }
            }));
            timer.Start();
        }
        private void Window_Closing_1(object sender, System.ComponentModel.CancelEventArgs e)
        {
            timer.Abort();
            timer = null;
        }
        #region 绘制折线
        int StepLength = 20;//X轴步长(两个顶点点X轴的距离)
        int MaxCount = 8;//顶点最多个数
        int MaxReg = 30;//最大量程‘
        int MinReg = 20;//最大量程
        //底部数字列表
        List<TextBlock> listBottom = new List<TextBlock>();
        //折线图
        Polyline pline = new Polyline();
        /// <summary>
        /// 画线
        /// </summary>
        /// <param name="Y2">线段终点Y轴坐标</param>
        private void DrawLine(double Y2)
        {
            //将值转换为图上坐标
            Y2 = grdMain.Height - (grdMain.Height / (MaxReg - MinReg)) * (Y2 - MinReg);
            //判断折线图顶点集合个数是否大于0
            if (pline.Points.Count > 0)
            {
                //向折线图顶点集合添加新线段终点坐标
                pline.Points.Add(new Point((pline.Points[pline.Points.Count - 1].X + StepLength), Y2));
                //判断顶点集合个数是否超过最大个数
                if (MaxCount + 1 < pline.Points.Count)
                {
                    //将曲线及下方数字往左移动

                    //删除第一个点
                    pline.Points.Remove(pline.Points[0]);
                    int ForLen = (pline.Points.Count > listBottom.Count) ? pline.Points.Count : listBottom.Count;
                    //将点击数字往左移动一位
                    for (int i = 0; i < ForLen; i++)
                    {
                        if (i < pline.Points.Count)
                        {
                            //将顶点的X轴坐标减去步长
                            pline.Points[i] = new Point(pline.Points[i].X - StepLength, pline.Points[i].Y);
                        }
                        if (i < listBottom.Count)
                        {
                            listBottom[i].Text = (int.Parse(listBottom[i].Text) + 1).ToString();
                        }
                    }
                }
            }
            else
            {//第一次添加顶点

                //设置线条颜色
                pline.Stroke = new SolidColorBrush(Colors.Red);
                //设置线条宽度
                pline.StrokeThickness = 1;

                //添加第一个点
                pline.Points.Add(new Point(0, Y2));
                //将折线控件作为子控件添加到界面
                this.grdMain.Children.Add(pline);
            }

            return;
            //=====================第二种写法===================
            Line line = new Line();
            double X1 = 0;
            double Y1 = grdMain.Height;
            if (grdMain.Children.Count > 0)
            {
                Line uPLine = (Line)grdMain.Children[grdMain.Children.Count - 1];
                X1 = uPLine.X2; Y1 = uPLine.Y2;
                if (X1 + StepLength > grdMain.Width)
                {
                    grdMain.Children.Remove(grdMain.Children[0]);
                    int ForLen = (grdMain.Children.Count > listBottom.Count) ? grdMain.Children.Count : listBottom.Count;
                    for (int i = 0; i < ForLen; i++)
                    {
                        if (i < grdMain.Children.Count)
                        {
                            ((Line)grdMain.Children[i]).X1 = ((Line)grdMain.Children[i]).X1 - StepLength;
                            ((Line)grdMain.Children[i]).X2 = ((Line)grdMain.Children[i]).X2 - StepLength;
                        }
                        if (i < listBottom.Count)
                        {
                            listBottom[i].Text = (int.Parse(listBottom[i].Text) + 1).ToString();
                        }
                    }
                    X1 = X1 - StepLength;
                }
            }



            line.X1 = X1;
            line.Y1 = Y1;

            X1 += StepLength;
            line.X2 = X1;
            line.Y2 = (grdMain.Height - (grdMain.Height / MaxReg) * Y2);
            Y1 = line.Y2;
            X1 = line.X2;

            line.Stroke = new SolidColorBrush(Colors.Red);
            line.StrokeThickness = 1;



            this.grdMain.Children.Add(line);
        }
        /// <summary>
        /// 绘制背景
        /// </summary>
        private void DrawBackground()
        {
            //==============绘制底部数字及绘制Y轴方向直线
            //计算顶点最大个数
            MaxCount = (int)(grdBackground.Width / StepLength);
            for (int i = 1; i <= MaxCount; i++)
            {
                //绘制Y轴直线
                Line line = new Line();
                //设置开始坐标及终点坐标
                line.X1 = StepLength * i;
                line.X2 = StepLength * i;
                line.Y1 = 0;
                line.Y2 = grdBackground.Height;

                Color color = new Color();
                color.R = 20;
                color.G = 80;
                color.B = 136;
                color.A = 100;
                //设置线条颜色
                line.Stroke = new SolidColorBrush(color);
                //设置线条宽度
                line.StrokeThickness = 2;

                //绘制下方数字
                TextBlock tb = new TextBlock();
                //设置字体颜色
                tb.Foreground = new SolidColorBrush(Colors.Red);
                //数字
                tb.Text = "" + i;
                //显示界面
                grdBackground.Children.Add(tb);
                grdBackground.Children.Add(line);
                //添加到全局变量
                listBottom.Add(tb);
                //设置坐标
                Canvas.SetBottom(tb, 0);
                Canvas.SetLeft(tb, StepLength * i);
            }

            //==============绘制左侧数字及绘制X轴方向直线(大概原理同上)
            for (int i = MinReg; i <= MaxReg; i++)
            {
                Line line = new Line();
                line.X1 = 0;
                line.X2 = grdBackground.Width;
                //grdMain.Height - (grdMain.Height / (MaxReg-MinReg)) * Y2
                line.Y1 = grdMain.Height - (grdMain.Height / (MaxReg - MinReg)) * (i - MinReg);
                line.Y2 = grdMain.Height - (grdMain.Height / (MaxReg - MinReg)) * (i - MinReg);
                Color color = new Color();
                color.R = 20;
                color.G = 80;
                color.B = 136;
                color.A = 100;
                line.Stroke = new SolidColorBrush(color);
                line.StrokeThickness = 2;

                TextBlock tb = new TextBlock();
                tb.Foreground = new SolidColorBrush(Colors.Red);
                tb.Text = "" + i;
                grdBackground.Children.Add(tb);
                grdBackground.Children.Add(line);
                //  listBottom.Add(tb);
                Canvas.SetTop(tb, grdMain.Height - (grdMain.Height / (MaxReg - MinReg)) * (i - MinReg));
                Canvas.SetLeft(tb, 0);
            }
            //设置线条颜色
            pline.Stroke = new SolidColorBrush(Colors.Red);
            //设置线条宽度
            pline.StrokeThickness = 1;

            //添加第一个点
            pline.Points.Add(new Point(0, this.grdMain.Height));
            //将折线控件作为子控件添加到界面
            this.grdMain.Children.Add(pline);
        }
        #endregion
    }
}

delivermanagement.xaml

<Window x:Class="goodsdb.record.delivermanagement"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:goodsdb.record"
        mc:Ignorable="d"
        Title="入库管理" Height="450" Width="800">
    <Grid>
        <DataGrid x:Name="dg" Margin="116,105,116,70" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" >
            <DataGrid.Columns>
                <DataGridTextColumn Header="序号:" Width="60" Binding="{Binding id}"/>
                <DataGridTextColumn Header="商品名:" Width="100" Binding="{Binding commoditysn}"/>
                <DataGridTextColumn Header="入库数量:" Width="80" Binding="{Binding deliverynumber}"/>
                <DataGridTextColumn Header="入库时间:" Width="200" Binding="{Binding deliverytime}"/>
            </DataGrid.Columns>
        </DataGrid>
        <Button Content="返回" HorizontalAlignment="Left" Margin="588,386,0,0" VerticalAlignment="Top" Click="Button_Click" Width="56" Height="26"/>
        <Button Content="删除" HorizontalAlignment="Left" Margin="141,387,0,0" VerticalAlignment="Top" Click="Button_Click_3" Width="56" Height="26"/>
        <Label Content="入库记录表" HorizontalAlignment="Left" Margin="343,18,0,0" VerticalAlignment="Top" FontSize="20" RenderTransformOrigin="0.026,0.272"/>
        <Button Content="入库" HorizontalAlignment="Left" Margin="529,66,0,0" VerticalAlignment="Top" Width="50" Height="25" Click="Button_Click_1"/>
        <ComboBox x:Name="tradenamecomboBox" HorizontalAlignment="Left" Margin="173,69,0,0" VerticalAlignment="Top" Width="120" Loaded="name_Loaded"/>
        <TextBox x:Name="number" HorizontalAlignment="Left"  Margin="371,71,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
        <TextBlock HorizontalAlignment="Left" Margin="115,70,0,0" TextWrapping="Wrap" VerticalAlignment="Top" RenderTransformOrigin="0.075,0.706"><Run Language="zh-cn" Text="商品名:"/></TextBlock>
        <TextBlock HorizontalAlignment="Left" Margin="328,70,0,0" TextWrapping="Wrap" VerticalAlignment="Top"><Run Language="zh-cn" Text="数量:"/></TextBlock>
    </Grid>
</Window>

delivermanagement.xaml.cs

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace goodsdb.record
{
    /// <summary>
    /// delivermanagement.xaml 的交互逻辑
    /// </summary>
    public partial class delivermanagement : Window
    {
        public delivermanagement()
        {
            InitializeComponent();
            SqlDataAdapter da = new SqlDataAdapter("select *  from [delivery_record_t]", "Server=localhost;Database=commoditydb;integrated security=SSPI");
            DataTable dt = new DataTable();
            da.Fill(dt);
            dg.ItemsSource = dt.DefaultView;        //表单显示
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            view.main main = new view.main();
            main.Show();
            this.Close();
        }

        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            if (dg.SelectedItem != null)
            {
                DataRowView dr = (DataRowView)dg.SelectedItem;
                string id = dr[0].ToString();
                SqlConnection connection = new SqlConnection("Address=localhost; Database=commoditydb;integrated security=SSPI");
                connection.Open();
                string sqlstr = "delete [delivery_record_t] where id='" + id + "'";
                SqlCommand command = new SqlCommand(sqlstr, connection);
                command.ExecuteNonQuery();
                MessageBox.Show("删除成功!");
                SqlDataAdapter da = new SqlDataAdapter("select *  from delivery_record_t", "Server=localhost;Database=commoditydb;integrated security=SSPI");
                DataTable dt = new DataTable();
                da.Fill(dt);
                dg.ItemsSource = dt.DefaultView;        //表单显示
            }
            else
            {
                MessageBox.Show("删除数据未选中!");
            }
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            if (number.Text != "" | tradenamecomboBox.Text != "")
            {
                string sql3 = "update commodity_information_t set stocknumber=stocknumber + '" + number.Text + "'where tradename = '" + tradenamecomboBox.Text + "'";
                string sql2 = "insert into [delivery_record_t] (commoditysn,deliverynumber) values('" + tradenamecomboBox.Text + "','" + number.Text + "')";
                string sql = "Address=localhost;Database=commoditydb;integrated security=SSPI";
                SqlConnection connection = new SqlConnection();
                try
                {
                    connection.ConnectionString = sql;
                    connection.Open();
                    //MessageBox.Show("连接到数据库!");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("错误信息:" + ex.Message, "无法连接到数据库!");
                }
                SqlCommand command = new SqlCommand(sql3, connection);
                command.ExecuteNonQuery();
                SqlCommand command1 = new SqlCommand(sql2, connection);
                command1.ExecuteNonQuery();
                MessageBox.Show(tradenamecomboBox.Text + "  : 入库成功!");
                SqlDataAdapter da = new SqlDataAdapter("select *  from delivery_record_t", "Server=localhost;Database=commoditydb;integrated security=SSPI");
                DataTable dt = new DataTable();
                da.Fill(dt);
                dg.ItemsSource = dt.DefaultView;        //表单显示
                connection.Close();
            }
            else
            {
                MessageBox.Show("数量不能为空!");
            }
        }

        private void name_Loaded(object sender, RoutedEventArgs e)
        {
            SqlConnection connection = new SqlConnection("Address=localhost; Database=commoditydb;integrated security=SSPI");
            connection.Open();
            string sqlstr = "select tradename from [commodity_information_t]";
            SqlCommand com = new SqlCommand(sqlstr, connection);
            SqlDataReader dr = com.ExecuteReader();
            while (dr.Read())
            {
                tradenamecomboBox.Items.Add(dr["tradename".ToString()]);
            }
            dr.Close();
            connection.Close();
        }
    }
}

housingmanagement.xaml

<Window x:Class="goodsdb.record.housingmanagement"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:goodsdb.record"
        mc:Ignorable="d"
        Title="出库管理" Height="450" Width="800">
    <Grid>
        <DataGrid x:Name="dg" Margin="116,105,116,70" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" >
            <DataGrid.Columns>
                <DataGridTextColumn Header="序号:" Width="60" Binding="{Binding id}"/>
                <DataGridTextColumn Header="商品名:" Width="100" Binding="{Binding commoditysn}"/>
                <DataGridTextColumn Header="出库数量:" Width="80" Binding="{Binding warehousingnumber}"/>
                <DataGridTextColumn Header="出库时间:" Width="200" Binding="{Binding warehousingtime}"/>
            </DataGrid.Columns>
        </DataGrid>
        <Button Content="返回" HorizontalAlignment="Left" Margin="588,386,0,0" VerticalAlignment="Top" Click="Button_Click" Width="56" Height="26"/>
        <Button Content="删除" HorizontalAlignment="Left" Margin="141,387,0,0" VerticalAlignment="Top" Click="Button_Click_3" Width="56" Height="26"/>
        <Label Content="出库记录表" HorizontalAlignment="Left" Margin="343,18,0,0" VerticalAlignment="Top" FontSize="20" RenderTransformOrigin="0.026,0.272"/>
        <Button Content="出库" HorizontalAlignment="Left" Margin="529,66,0,0" VerticalAlignment="Top" Width="50" Height="25" Click="Button_Click_1"/>
        <ComboBox x:Name="tradenamecomboBox" HorizontalAlignment="Left" Margin="173,69,0,0" VerticalAlignment="Top" Width="120" Loaded="name_Loaded"/>
        <TextBox x:Name="number" HorizontalAlignment="Left"  Margin="371,71,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
        <TextBlock HorizontalAlignment="Left" Margin="115,70,0,0" TextWrapping="Wrap" VerticalAlignment="Top" RenderTransformOrigin="0.075,0.706"><Run Language="zh-cn" Text="商品名:"/></TextBlock>
        <TextBlock HorizontalAlignment="Left" Margin="328,70,0,0" TextWrapping="Wrap" VerticalAlignment="Top"><Run Language="zh-cn" Text="数量:"/></TextBlock>
    </Grid>
</Window>

housingmanagement.xaml.cs

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace goodsdb.record
{
    /// <summary>
    /// housingmanagement.xaml 的交互逻辑
    /// </summary>
    public partial class housingmanagement : Window
    {
        public housingmanagement()
        {
            InitializeComponent();
            SqlDataAdapter da = new SqlDataAdapter("select *  from [warehousing_record_t]", "Server=localhost;Database=commoditydb;integrated security=SSPI");
            DataTable dt = new DataTable();
            da.Fill(dt);
            dg.ItemsSource = dt.DefaultView;        //表单显示
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            view.main main = new view.main();
            main.Show();
            this.Close();
        }

        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            if (dg.SelectedItem != null)
            {
                DataRowView dr = (DataRowView)dg.SelectedItem;
                string id = dr[0].ToString();
                SqlConnection connection = new SqlConnection("Address=localhost; Database=commoditydb;integrated security=SSPI");
                connection.Open();
                string sqlstr = "delete [warehousing_record_t] where id='" + id + "'";
                SqlCommand command = new SqlCommand(sqlstr, connection);
                command.ExecuteNonQuery();
                MessageBox.Show("删除成功!");
                SqlDataAdapter da = new SqlDataAdapter("select *  from [warehousing_record_t]", "Server=localhost;Database=commoditydb;integrated security=SSPI");
                DataTable dt = new DataTable();
                da.Fill(dt);
                dg.ItemsSource = dt.DefaultView;        //表单显示
            }
            else
            {
                MessageBox.Show("删除数据未选中!");
            }
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            if (number.Text != "" | tradenamecomboBox.Text != "")
            {
                string sql3 = "update commodity_information_t set stocknumber=stocknumber - '" + number.Text + "'where tradename = '" + tradenamecomboBox.Text + "'";
                string sql2 = "insert into [warehousing_record_t] (commoditysn,warehousingnumber) values('" + tradenamecomboBox.Text + "','" + number.Text + "')";
                string sql = "Address=localhost;Database=commoditydb;integrated security=SSPI";
                SqlConnection connection = new SqlConnection();
                try
                {
                    connection.ConnectionString = sql;
                    connection.Open();
                    //MessageBox.Show("连接到数据库!");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("错误信息:" + ex.Message, "无法连接到数据库!");
                }
                string sql4 = "select tradename from commodity_information_t where stocknumber>='" + number.Text + "' and tradename='"+tradenamecomboBox.Text+"'";
                SqlCommand command3 = new SqlCommand(sql4, connection);
                command3.ExecuteNonQuery();
                if (command3.ExecuteScalar() != null) {
                    SqlCommand command = new SqlCommand(sql3, connection);
                    command.ExecuteNonQuery();
                    SqlCommand command1 = new SqlCommand(sql2, connection);
                    command1.ExecuteNonQuery();
                    MessageBox.Show(tradenamecomboBox.Text + "  : 出库成功!");
                    SqlDataAdapter da = new SqlDataAdapter("select *  from [warehousing_record_t]", "Server=localhost;Database=commoditydb;integrated security=SSPI");
                    DataTable dt = new DataTable();
                    da.Fill(dt);
                    dg.ItemsSource = dt.DefaultView;        //表单显示
                    connection.Close();
                }
                else {
                    MessageBox.Show(tradenamecomboBox.Text+"库存不足!请查看库存!");
                }
            }
            else
            {
                MessageBox.Show("数量不能为空!");
            }
        }

        private void name_Loaded(object sender, RoutedEventArgs e)
        {
            SqlConnection connection = new SqlConnection("Address=localhost; Database=commoditydb;integrated security=SSPI");
            connection.Open();
            string sqlstr = "select tradename from [commodity_information_t]";
            SqlCommand com = new SqlCommand(sqlstr, connection);
            SqlDataReader dr = com.ExecuteReader();
            while (dr.Read())
            {
                tradenamecomboBox.Items.Add(dr["tradename".ToString()]);
            }
            dr.Close();
            connection.Close();
        }
    }
}

addgood.xaml

<Window x:Class="goodsdb.commodity.addgood"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:goodsdb.commodity"
        mc:Ignorable="d"
        Title="添加商品" Height="450" Width="800">
    <Grid>
        <TextBox x:Name="tradename" HorizontalAlignment="Left" Margin="385,101,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
        <TextBox x:Name="brand" HorizontalAlignment="Left"  Margin="385,130,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
        <TextBlock HorizontalAlignment="Left" Margin="318,102,0,0" TextWrapping="Wrap" VerticalAlignment="Top" RenderTransformOrigin="0.075,0.706"><Run Language="zh-cn" Text="商品名:"/></TextBlock>
        <TextBlock HorizontalAlignment="Left" Margin="318,129,0,0" TextWrapping="Wrap" VerticalAlignment="Top"><Run Language="zh-cn" Text="品牌:"/></TextBlock>
        <Button Content="添加" HorizontalAlignment="Left" Margin="330,318,0,0" VerticalAlignment="Top" Click="Button_Click_1" Height="22" Width="51"/>
        <TextBox x:Name="productspecifications" HorizontalAlignment="Left" Margin="384,161,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
        <TextBox x:Name="supplier" HorizontalAlignment="Left" Margin="384,194,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
        <TextBox x:Name="stocknumber" HorizontalAlignment="Left" Margin="384,226,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
        <TextBox x:Name="earlywarningnumber" HorizontalAlignment="Left" Margin="384,252,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
        <TextBlock HorizontalAlignment="Left" Margin="318,162,0,0" TextWrapping="Wrap" VerticalAlignment="Top" RenderTransformOrigin="0.075,0.706"><Run Language="zh-cn" Text="商品规格:"/></TextBlock>
        <TextBlock HorizontalAlignment="Left" Margin="318,194,0,0" TextWrapping="Wrap" VerticalAlignment="Top" RenderTransformOrigin="0.075,0.706"><Run Language="zh-cn" Text="供货商:"/></TextBlock>
        <TextBlock HorizontalAlignment="Left" Margin="318,227,0,0" TextWrapping="Wrap" VerticalAlignment="Top" RenderTransformOrigin="0.075,0.706"><Run Language="zh-cn" Text="库存数量:"/></TextBlock>
        <TextBlock HorizontalAlignment="Left" Margin="318,254,0,0" TextWrapping="Wrap" VerticalAlignment="Top" RenderTransformOrigin="0.075,0.706"><Run Language="zh-cn" Text="预警数量:"/></TextBlock>
        <Button Content="取消" HorizontalAlignment="Left" Margin="439,318,0,0" VerticalAlignment="Top"  Height="22" Width="51" Click="Button_Click"/>

    </Grid>
</Window>

addgood.xaml.cs

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace goodsdb.commodity
{
    /// <summary>
    /// addgood.xaml 的交互逻辑
    /// </summary>
    public partial class addgood : Window
    {
        public addgood()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            commodity.goodsmanagement goods = new commodity.goodsmanagement();
            goods.Show();
            this.Close();
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            if (tradename.Text != "" | brand.Text != "" | productspecifications.Text != "" | supplier.Text != "" | stocknumber.Text != "" | earlywarningnumber.Text != "")
            {
                string sql2 = "insert into commodity_information_t(tradename,brand,productspecifications,supplier,stocknumber,earlywarningnumber) values('" + tradename.Text + "','" + brand.Text + "','" + productspecifications.Text + "','" + supplier.Text + "','" + stocknumber.Text + "','" + earlywarningnumber.Text + "')";
                string sql = "Address=localhost;Database=commoditydb;integrated security=SSPI";
                SqlConnection connection = new SqlConnection();
                try
                {
                    connection.ConnectionString = sql;
                    connection.Open();
                    //MessageBox.Show("连接到数据库!");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("错误信息:" + ex.Message, "无法连接到数据库!");
                }
                SqlCommand command1 = new SqlCommand(sql2, connection);
                command1.ExecuteNonQuery();
                MessageBox.Show(tradename.Text + "  : 添加成功!");
                commodity.goodsmanagement goods = new commodity.goodsmanagement();
                goods.Show();
                this.Close();
            }
            else
            {
                MessageBox.Show("输入不能为空!");
            }
        }
    }
}

goodsmanagement.xaml

<Window x:Class="goodsdb.commodity.goodsmanagement"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:goodsdb.commodity"
        mc:Ignorable="d"
        Title="商品管理" Height="450" Width="800">
    <Grid>
        <DataGrid x:Name="dg" Margin="38,62,44,70" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" >
            <DataGrid.Columns>
                <DataGridTextColumn Header="序号:" Width="60" Binding="{Binding id}"/>
                <DataGridTextColumn Header="商品名:" Width="100" Binding="{Binding tradename}"/>
                <DataGridTextColumn Header="品牌:" Width="100" Binding="{Binding brand}"/>
                <DataGridTextColumn Header="商品规格:" Width="100" Binding="{Binding productspecifications}"/>
                <DataGridTextColumn Header="供货商:" Width="100" Binding="{Binding supplier}"/>
                <DataGridTextColumn Header="库存数量:" Width="80" Binding="{Binding stocknumber}"/>
            </DataGrid.Columns>
        </DataGrid>
        <Button Content="返回" HorizontalAlignment="Left" Margin="642,387,0,0" VerticalAlignment="Top" Click="Button_Click" Width="56" Height="26"/>
        <Button Content="修改" HorizontalAlignment="Left" Margin="276,390,0,0" VerticalAlignment="Top" Click="Button_Click_2" Width="56" Height="26"/>
        <Button Content="删除" HorizontalAlignment="Left" Margin="467,389,0,0" VerticalAlignment="Top" Click="Button_Click_3" Width="56" Height="26"/>
        <Label Content="商品管理" HorizontalAlignment="Left" Margin="343,18,0,0" VerticalAlignment="Top" FontSize="20" RenderTransformOrigin="0.026,0.272"/>
        <Button Content="添加" HorizontalAlignment="Left" Margin="106,390,0,0" VerticalAlignment="Top" Click="Button_Click_1" Width="56" Height="26"/>
    </Grid>
</Window>

goodsmanagement.xaml.cs

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace goodsdb.commodity
{
    /// <summary>
    /// goodsmanagement.xaml 的交互逻辑
    /// </summary>
    public partial class goodsmanagement : Window
    {
        public goodsmanagement()
        {
            InitializeComponent();
            SqlDataAdapter da = new SqlDataAdapter("select *  from commodity_information_t", "Server=localhost;Database=commoditydb;integrated security=SSPI");
            DataTable dt = new DataTable();
            da.Fill(dt);
            dg.ItemsSource = dt.DefaultView;        //表单显示
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            view.main main = new view.main();
            main.Show();
            this.Close();
        }

        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            if (dg.SelectedItem != null)
            {

                DataRowView dr = (DataRowView)dg.SelectedItem;
                string tradename = dr[1].ToString();
                string stocknumber = dr[5].ToString();
                if (stocknumber == "0")
                {
                    SqlConnection connection = new SqlConnection("Address=localhost; Database=commoditydb;integrated security=SSPI");
                    connection.Open();
                    string sqlstr = "delete [commodity_information_t] where tradename='" + tradename + "'";
                    SqlCommand command = new SqlCommand(sqlstr, connection);
                    command.ExecuteNonQuery();
                    MessageBox.Show("删除成功!");

                    SqlDataAdapter da = new SqlDataAdapter("select *  from commodity_information_t", "Server=localhost;Database=commoditydb;integrated security=SSPI");
                    DataTable dt = new DataTable();
                    da.Fill(dt);
                    dg.ItemsSource = dt.DefaultView;        //表单显示
                }
                else
                {
                    MessageBox.Show("库存大于0,不可操作!");
                }
            }
            else
            {
                MessageBox.Show("删除数据未选中!");
            }
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            if (dg.SelectedItem != null)
            {
                DataRowView dr = (DataRowView)dg.SelectedItem;
                string id = dr[0].ToString();
                string stock = dr[5].ToString();
                if (stock == "0")
                {
                    string tradename = dr[1].ToString();
                    string brand = dr[2].ToString();
                    string productspecifications = dr[3].ToString();
                    string supplier = dr[4].ToString();
                    string stocknumber = dr[5].ToString();
                    string earlywarningnumber = dr[6].ToString();
                    commodity.updatagoods good = new updatagoods(id, tradename, brand, productspecifications, supplier, stocknumber, earlywarningnumber);
                    good.Show();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("库存大于0,不可操作!");
                }
            }
            else
            {
                MessageBox.Show("修改数据未选中!");
            }
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            commodity.addgood good = new commodity.addgood();
            good.Show();
            this.Close();
        }
    }
}

updatagoods.xaml

<Window x:Class="goodsdb.commodity.updatagoods"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:goodsdb.commodity"
        mc:Ignorable="d"
        Title="修改商品" Height="400" Width="360">
    <Grid>
        <TextBox x:Name="id" HorizontalAlignment="Left" Margin="147,62,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" IsReadOnly="True"/>
        <TextBox x:Name="tradename" HorizontalAlignment="Left" Margin="147,87,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
        <TextBox x:Name="brand" HorizontalAlignment="Left"  Margin="147,116,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
        <TextBlock HorizontalAlignment="Left" Margin="80,88,0,0" TextWrapping="Wrap" VerticalAlignment="Top" RenderTransformOrigin="0.075,0.706"><Run Language="zh-cn" Text="商品名:"/></TextBlock>
        <TextBlock HorizontalAlignment="Left" Margin="80,115,0,0" TextWrapping="Wrap" VerticalAlignment="Top"><Run Language="zh-cn" Text="品牌:"/></TextBlock>
        <TextBlock HorizontalAlignment="Left" Margin="80,63,0,0" TextWrapping="Wrap" VerticalAlignment="Top" RenderTransformOrigin="0.075,0.706"><Run Language="zh-cn" Text="序号:"/></TextBlock>
        <Button Content="提交修改" HorizontalAlignment="Left" Margin="103,298,0,0" VerticalAlignment="Top" Click="Button_Click" Height="21" Width="54"/>
        <TextBox x:Name="productspecifications" HorizontalAlignment="Left" Margin="146,147,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
        <TextBox x:Name="supplier" HorizontalAlignment="Left" Margin="146,180,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
        <TextBox x:Name="stocknumber" HorizontalAlignment="Left" Margin="146,212,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
        <TextBox x:Name="earlywarningnumber" HorizontalAlignment="Left" Margin="146,238,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
        <TextBlock HorizontalAlignment="Left" Margin="80,148,0,0" TextWrapping="Wrap" VerticalAlignment="Top" RenderTransformOrigin="0.075,0.706"><Run Language="zh-cn" Text="商品规格:"/></TextBlock>
        <TextBlock HorizontalAlignment="Left" Margin="80,180,0,0" TextWrapping="Wrap" VerticalAlignment="Top" RenderTransformOrigin="0.075,0.706"><Run Language="zh-cn" Text="供货商:"/></TextBlock>
        <TextBlock HorizontalAlignment="Left" Margin="80,213,0,0" TextWrapping="Wrap" VerticalAlignment="Top" RenderTransformOrigin="0.075,0.706"><Run Language="zh-cn" Text="库存数量:"/></TextBlock>
        <TextBlock HorizontalAlignment="Left" Margin="80,240,0,0" TextWrapping="Wrap" VerticalAlignment="Top" RenderTransformOrigin="0.075,0.706"><Run Language="zh-cn" Text="预警数量:"/></TextBlock>
        <Button Content="取消" HorizontalAlignment="Left" Margin="206,297,0,0" VerticalAlignment="Top"  Height="21" Width="54" Click="Button_Click_1"/>

    </Grid>
</Window>

updatagoods.xaml.cs

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace goodsdb.commodity
{
    /// <summary>
    /// updatagoods.xaml 的交互逻辑
    /// </summary>
    public partial class updatagoods : Window
    {
        public updatagoods(string id, string tradename, string brand, string productspecifications, string supplier, string stocknumber, string earlywarningnumber)
        {
            InitializeComponent();
            this.id.Text = id;
            this.tradename.Text = tradename;
            this.brand.Text = brand;
            this.productspecifications.Text = productspecifications;
            this.supplier.Text = supplier;
            this.stocknumber.Text = stocknumber;
            this.earlywarningnumber.Text = earlywarningnumber;
        }


        private void Button_Click(object sender, RoutedEventArgs e)
        {
            SqlConnection connection = new SqlConnection("Address=localhost; Database=commoditydb;integrated security=SSPI");
            connection.Open();
            string sqlstr = "update commodity_information_t set tradename='" + tradename.Text + "',brand='" + brand.Text + "',productspecifications='" + productspecifications.Text + "'," +
                "supplier='" + supplier.Text + "',stocknumber='" + stocknumber.Text + "',earlywarningnumber='" + earlywarningnumber.Text + "' where id='" + id.Text + "'";
            SqlCommand command = new SqlCommand(sqlstr, connection);
            command.ExecuteNonQuery();
            MessageBox.Show("修改成功!");
            commodity.goodsmanagement goods = new commodity.goodsmanagement();
            goods.Show();
            this.Close();
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            commodity.goodsmanagement goods = new commodity.goodsmanagement();
            goods.Show();
            this.Close();
        }
    }
}