📄 company_open.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 LoginCheckClass; //(类)验证用户是否登录
/// <summary>
/// 2008年7月19日 谈鸿如 编码
/// 2008年7月19日 测试
/// 2008年7月21日 添加登录验证功能
/// 2008年7月21日 测试登录验证功能
/// </summary>
public partial class _Default : System.Web.UI.Page
{
//页面加载时运行
protected void Page_Load(object sender, EventArgs e)
{
//调用LoginCheck类的check方法来判断用户是否登录
LoginCheck a = new LoginCheck();
a.check();
try
{
using (SqlConnection connection = new SqlConnection(_connectString)) //建立连接
{
if (!IsPostBack) //判断是否为页面回传
{
connection.Open(); //打开连接
using (SqlCommand command = new SqlCommand())
{
command.Connection = connection;
//读取在Company_manage页面中建立的Session【“ID”】的值,用来确定页面读出tb_company表中的哪条信息
command.Parameters.Add("@id", SqlDbType.Int).Value = (int)Session["ID"];
//查询出所选公司的详细信息
command.CommandText = "SELECT CompanyName,CompanyShort,CompanyAddress,Postalcode,Tel,Fax,Linkman,Email,Bank,BankAccounts,CompanyType FROM tb_Company WHERE id=@id";
command.ExecuteNonQuery();
SqlDataReader reader = command.ExecuteReader();
//将取出的信息付给页面中各控件
while (reader.Read())
{
CompanyName.Text = reader.GetString(0); //公司名称
CompanyShort.Text = reader.GetString(1); //公司简称
CompanyAddress.Text = reader.GetString(2); //公司地址
Postalcode.Text = reader.GetString(3); //邮政编码
Tel.Text = reader.GetString(4); //联系电话
Fax.Text = reader.GetString(5); //传真号码
Linkman.Text = reader.GetString(6); //联系人
Email.Text = reader.GetString(7); //电子邮箱地址
Bank.Text = reader.GetString(8); //开户银行
BankAccounts.Text = reader.GetString(9); //银行帐号
/*判断tb_company表中companytype字段的值是否为“用户”
若 是 则DropDownList1值置为用户
若 否 则置为供应商
DropDownList1中的值为页面绑定的,仅有供应商、客户可以用*/
if (reader.GetString(10) == "用户")
DropDownList1.SelectedIndex = 1;
else
DropDownList1.SelectedIndex = 0;
DropDownList1.Text = DropDownList1.SelectedItem.Text;
}
}
}
}
}
//若查询失败,则抛出异常信息
catch (Exception ex)
{
Response.Write(@"<script>alert('系统错误');</script>");
}
}
//当点击取消按钮时,返回主页面
protected void btnCancel_Click(object sender, EventArgs e)
{
Response.Redirect("Default.aspx");
}
//当点击关闭按钮时,关闭当前弹出窗口
protected void btnClose_Click(object sender, EventArgs e)
{
Response.Write("<script>window.close();</script>");
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void SqlDataSource1_Selecting1(object sender, SqlDataSourceSelectingEventArgs e)
{
}
//点击修改按钮时触发下面事件
protected void btnAlert_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("@id", SqlDbType.Int).Value = (int)Session["ID"]; //Session["ID"]
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 = BankAccounts.Text; //银行帐号
command.Parameters.Add("@CompanyType", SqlDbType.VarChar, 50).Value = DropDownList1.SelectedItem.Value; //公司类型,分为供应商和用户两种
command.Parameters.Add("@UserName", SqlDbType.VarChar, 50).Value = Session["UserName"]; //读取当前登陆用户的用户名
command.Parameters.Add("@AddTime", SqlDbType.VarChar, 50).Value = Convert.ToString(DateTime.Now); //获取当前时间
//更新数据库tb_company表中id等于Session["ID"]的数据的相应值
command.CommandText = "UPDATE tb_Company SET CompanyName=@CompanyName,CompanyShort=@CompanyShort,CompanyAddress=@CompanyAddress,Postalcode=@Postalcode,Tel=@Tel,Fax=@Fax,Linkman=@Linkman,Email=@Email,Bank=@Bank,BankAccounts=@BankAccount,CompanyType=@CompanyType,UserName=@UserName,AddTime=@AddTime WHERE id=@id";
command.ExecuteNonQuery();
//更新成功后,以弹出对话框的形式给用户提示成功信息
Response.Write(@"<script>alert('修改成功');opener.location.reload();window.close();</script>");
}
}
}
//若更新失败,则抛出异常信息
catch (Exception ex)
{
Response.Write(@"<script>alert('系统错误');</script>");
}
}
//使用db_sellConnectionString连接字符串
private static readonly string _connectString = System.Configuration.ConfigurationManager.ConnectionStrings["db_sellConnectionString"].ConnectionString;
//点击重置按钮时调用以下内容
protected void btnCancel_Click1(object sender, EventArgs e)
{
using (SqlConnection connection = new SqlConnection(_connectString)) //建立连接
{
connection.Open(); //打开连接
using (SqlCommand command = new SqlCommand())
{
command.Connection = connection;
//读取在Company_manage页面中建立的Session【“ID”】的值,用来确定页面读出tb_company表中的哪条信息
command.Parameters.Add("@id", SqlDbType.Int).Value = (int)Session["ID"];
//查询出所选公司的详细信息
command.CommandText = "SELECT CompanyName,CompanyShort,CompanyAddress,Postalcode,Tel,Fax,Linkman,Email,Bank,BankAccounts,CompanyType FROM tb_Company WHERE id=@id";
command.ExecuteNonQuery();
SqlDataReader reader = command.ExecuteReader();
//将取出的信息付给页面中各控件
while (reader.Read())
{
CompanyName.Text = reader.GetString(0); //公司名称
CompanyShort.Text = reader.GetString(1); //公司简称
CompanyAddress.Text = reader.GetString(2); //公司地址
Postalcode.Text = reader.GetString(3); //邮政编码
Tel.Text = reader.GetString(4); //联系电话
Fax.Text = reader.GetString(5); //传真号码
Linkman.Text = reader.GetString(6); //联系人
Email.Text = reader.GetString(7); //电子邮箱地址
Bank.Text = reader.GetString(8); //开户银行
BankAccounts.Text = reader.GetString(9); //银行帐号
/*判断tb_company表中companytype字段的值是否为“用户”
若 是 则DropDownList1值置为用户
若 否 则置为供应商
DropDownList1中的值为页面绑定的,仅有供应商、客户可以用*/
if (reader.GetString(10) == "用户")
DropDownList1.SelectedIndex = 1;
else
DropDownList1.SelectedIndex = 0;
DropDownList1.Text = DropDownList1.SelectedItem.Text;
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -