📄 company_add.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
using LoginCheckClass; //(类)验证用户是否登录
/// <summary>
/// 公司信息添加页面
/// 2008年7月18日 9点 谈鸿如 编码
/// 2008年7月19日 测试
/// 2008年7月21日 添加登录验证功能
/// 2008年7月21日 测试登录验证功能
/// </summary>
public partial class _Default : System.Web.UI.Page
{
/*点击重置按钮事件
功能清空各Textbox值,将公司类型置为供应商*/
protected void btnCancel_Click(object sender, EventArgs e)
{
CompanyName.Text = "";
CompanyShort.Text = "";
CompanyAddress.Text = "";
Postalcode.Text = "";
Tel.Text = "";
Fax.Text = "";
Linkman.Text = "";
Email.Text = "";
Bank.Text = "";
BankAccount.Text = "";
CompanyType.SelectedIndex = 0;
CompanyType.Text = CompanyType.SelectedItem.Value;
}
//点击添加按钮事件,实现公司信息添加功能
protected void btnAdd_Click(object sender, EventArgs e)
{
try
{
using (SqlConnection connection = new SqlConnection(_connectString)) //建立连接
{
connection.Open(); //打开连接
using (SqlCommand command = new SqlCommand())
{
command.Connection = connection;
command.CommandType = CommandType.Text;
//从页面中读取各项需要的值,并赋予变量中
command.Parameters.Add("@CompanyName", SqlDbType.VarChar, 50).Value = CompanyName.Text; //公司名称
command.Parameters.Add("@CompanyShort", SqlDbType.VarChar, 50).Value = CompanyShort.Text; //公司简称
command.Parameters.Add("@CompanyAddress", SqlDbType.VarChar, 50).Value = CompanyAddress.Text; //公司地址
command.Parameters.Add("@Postalcode", SqlDbType.VarChar, 50).Value = Postalcode.Text; //邮政编码
command.Parameters.Add("@Tel", SqlDbType.VarChar, 50).Value = Tel.Text; //联系电话
command.Parameters.Add("@Fax", SqlDbType.VarChar, 50).Value = Fax.Text; //传真号码
command.Parameters.Add("@Linkman", SqlDbType.VarChar, 50).Value = Linkman.Text; //联系人
command.Parameters.Add("@Email", SqlDbType.VarChar, 50).Value = Email.Text; //电子邮箱地址
command.Parameters.Add("@Bank", SqlDbType.VarChar, 50).Value = Bank.Text; //开户银行
command.Parameters.Add("@BankAccount", SqlDbType.VarChar, 50).Value = BankAccount.Text; //银行帐号
command.Parameters.Add("@CompanyType", SqlDbType.VarChar, 50).Value = CompanyType.SelectedItem.Value; //公司类型,分为供应商和用户两种
command.Parameters.Add("@UserName", SqlDbType.VarChar, 50).Value = Session["UserName"]; //读取当前登陆用户的用户名
command.Parameters.Add("AddTime", SqlDbType.VarChar, 50).Value = DateTime.Now; //获取当前时间
//向tb_Company表中添加以上公司信息
command.CommandText = "Insert into tb_Company(CompanyName,CompanyShort,CompanyAddress,Postalcode,Tel,Fax,Linkman,Email,Bank,BankAccounts,CompanyType,UserName,AddTime) Values(@CompanyName,@CompanyShort,@CompanyAddress,@Postalcode,@Tel,@Fax,@Linkman,@Email,@Bank,@BankAccount,@CompanyType,@UserName,@AddTime)";
command.ExecuteNonQuery();
Response.Write(@"<script>alert('添加成功');</script>");
//添加完成后,清空页面上各项信息
CompanyName.Text="";
CompanyShort.Text="";
CompanyAddress.Text="";
Postalcode.Text="";
Tel.Text="";
Fax.Text="";
Linkman.Text="";
Email.Text="";
Bank.Text="";
BankAccount.Text="";
}
}
}
//若插入失败,则抛出异常信息
catch (Exception ex)
{
Response.Write(@"<script>alert('系统错误');</script>");
}
}
//使用db_sellConnectionString连接字符串
private static readonly string _connectString = System.Configuration.ConfigurationManager.ConnectionStrings["db_sellConnectionString"].ConnectionString;
//页面加载时运行
protected void Page_Load(object sender, EventArgs e)
{
//调用LoginCheck类的check方法来判断用户是否登录
LoginCheck a = new LoginCheck();
a.check();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -