📄 ininfoform.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Elysian
{
public partial class inInfoForm : Form
{
SqlConnection sqlconn;
SqlDataAdapter adapter;
DataSet ds = new DataSet();
public inInfoForm()
{
InitializeComponent();
}
private static string GetConnectionString()
{
return "data source=.;initial catalog=ElysianDB;integrated security=true";
}
private void button1_Click(object sender, EventArgs e)
{
string selectStr = string.Empty;
selectStr = "select * from 商品入库信息";
if (textBox1.Text != null)
{
selectStr = selectStr + " " + "where 商品编号='" + textBox1.Text + "'";
if (textBox2.Text != null)
{
selectStr = selectStr + " " + "and 商品名称='" + textBox2.Text + "'";
}
}
else
{
if (textBox2.Text != null)
{
selectStr = selectStr + "where 商品名称='" + textBox2.Text + "'";
}
MessageBox.Show("请您输入要查询的信息");
}
sqlconn = new SqlConnection(GetConnectionString());
SqlCommand sqlcomm = new SqlCommand();
sqlcomm.CommandText = selectStr;
sqlcomm.Connection = sqlconn;
sqlconn.Open();
ds.Clear();
adapter = new SqlDataAdapter(sqlcomm);
adapter.Fill(ds, "商品入库信息");
dataGridView1.DataSource = ds.Tables[0];
sqlconn.Close();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void button4_Click(object sender, EventArgs e)
{
this.Close();
}
private void button3_Click(object sender, EventArgs e)
{
string insertStr = string.Format("insert into 商品入库信息 values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}')",
textBox3.Text,textBox4.Text,textBox5.Text,textBox6.Text,textBox7.Text,textBox8.Text,textBox9.Text,textBox10.Text,textBox11.Text,textBox12.Text,textBox13.Text);
sqlconn = new SqlConnection(GetConnectionString());
SqlCommand sqlcomm = new SqlCommand();
sqlcomm.CommandText = insertStr;
sqlcomm.Connection = sqlconn;
sqlconn.Open();
int i = sqlcomm.ExecuteNonQuery();
if (i > 0)
{
DateTime get_time1 = Convert.ToDateTime(textBox11.Text.ToString());
DateTime get_time2 = Convert.ToDateTime(textBox8.Text.ToString());
TimeSpan ts = TimeSpan.FromDays(int.Parse(textBox9.Text));
if ((get_time1 - get_time2) < ts)
{
MessageBox.Show("商品入库成功");
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
textBox6.Text = "";
textBox7.Text = "";
textBox8.Text = "";
textBox9.Text = "";
textBox10.Text = "";
textBox11.Text = "";
textBox12.Text = "";
textBox13.Text = "";
}
else
{
MessageBox.Show("该入库商品过期");
}
}
sqlconn.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -