📄 addnewspaper.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using 报刊管理.类; //添加引用
using System.Data.SqlClient;
namespace 报刊管理.报刊处理
{
public partial class AddNewspaper : Form
{
public AddNewspaper()
{
InitializeComponent();
}
SqlBaseClass SqlClass = new SqlBaseClass();
private void ListInfo(string SQL)
{
try
{
this.listView1.Items.Clear();
SqlDataAdapter da = new SqlDataAdapter(SQL, SqlClass.GetCon());
DataTable dt = new DataTable();
da.Fill(dt);
foreach (DataRow dr in dt.Rows)
{
ListViewItem lv;
lv = new ListViewItem(dr[0].ToString());
lv.SubItems.Add(dr[1].ToString());
lv.SubItems.Add(dr[2].ToString());
lv.SubItems.Add(dr[3].ToString());
lv.SubItems.Add(dr[4].ToString());
this.listView1.Items.Add(lv);
}
}
catch { }
}
private void button1_Click(object sender, EventArgs e)
{
string Str_select = "SELECT NewspaperID FROM N_Newspaper WHERE NewspaperID = '" + this.textBox10.Text + "' ";
SqlDataReader dr = SqlClass.GetReader(Str_select);
dr.Read();
if (dr.HasRows)
{
MessageBox.Show("该报刊已存在!", "提示对话框", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
dr.Close();
if (this.textBox9.Text == "")
{
MessageBox.Show("报刊名不能为空!", "提示对话框", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
else if (this.textBox10.Text == "")
{
MessageBox.Show("报刊号不能为空!", "提示对话框", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
else if (this.textBox8.Text == "")
{
MessageBox.Show("报刊价格不能为空!", "提示对话框", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
else if (this.textBox7.Text == "")
{
MessageBox.Show("出版社不能为空!", "提示对话框", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
else if (this.textBox2.Text == "")
{
MessageBox.Show("出版周期不能为空!", "提示对话框", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
string Str_sqlcmd = "INSERT INTO N_Newspaper VALUES( '" + this.textBox10.Text + "','" + this.textBox9.Text + "','" + this.textBox8.Text + "','" + this.textBox2.Text + "'";
Str_sqlcmd += ",'" + this.textBox7.Text + "')";
if (SqlClass.GetExecute(Str_sqlcmd))
{
MessageBox.Show("插入成功!", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("插入失败,请重新插入!", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void button4_Click(object sender, EventArgs e)
{
string Str_select = "SELECT NewspaperID,NewspaperName,NewspaperCompany,NewspaperTime,NewspaperPrice FROM N_Newspaper";
ListInfo(Str_select.ToString());
this.textBox10.Text = "";
this.textBox9.Text = "";
this.textBox8.Text = "";
this.textBox7.Text = "";
this.textBox2.Text = "";
}
private void AddNewspaper_Load(object sender, EventArgs e)
{
this.textBox10.ReadOnly = !this.textBox10.ReadOnly;
this.textBox9.ReadOnly = !this.textBox9.ReadOnly;
this.textBox8.ReadOnly = !this.textBox8.ReadOnly;
this.textBox7.ReadOnly = !this.textBox7.ReadOnly;
this.textBox2.ReadOnly = !this.textBox2.ReadOnly;
string Str_select = "SELECT NewspaperID,NewspaperName,NewspaperCompany,NewspaperTime,NewspaperPrice FROM N_Newspaper";
ListInfo(Str_select.ToString());
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -