📄 enter_record.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.IO;
public partial class _Default : System.Web.UI.Page
{
static string path;
//static int cur_no=0; //定义当前的报告单元的卡片为0
Int32 teststr=0;
//String teststr="";
SqlConnection con = new SqlConnection("server=42.1.47.11;user id=szy;pwd=123456;DataBase=AssetsDB");
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
con.Open();
if (!IsPostBack)
{
dpl_year.SelectedValue = DateTime.Now.Year.ToString();
}
int year = Convert.ToInt32(dpl_year.SelectedValue);
String get_max_y_no = "select max(y_no) as y_no from asset where year(a_date)='"+year+"'";
SqlCommand com = new SqlCommand(get_max_y_no, con);
SqlDataReader read = com.ExecuteReader();
read.Read();
try
{
String y_no = read.GetString(0).ToString();
//String year = y_no.Substring(0, 5);
String seq = y_no.Substring(5, y_no.Length - 5);
int temp = (Convert.ToInt32(seq) + 1);
seq = temp.ToString();
txt_y_no.Text = year.ToString() + "-" + seq;
}
catch
{
txt_y_no.Text = year.ToString() + "-1";
}
read.Close();
con.Close();
}
protected void Button4_Click(object sender, EventArgs e)
{
string str = this.FileUpload1.PostedFile.FileName;
if (str == "")
{
Response.Write("<script language=javascript>alert('请选择上传的图片!')</script>");
return;
}
string ss=str.Substring(str.LastIndexOf("\\")+1);
string s=Server.MapPath(".\\Images\\picture\\"+ss);
path = "~/Images/picture/" + ss;
/*
if(File.exists(s))
{
Response.Write("<script languge=javascript>alert('图片已经存在!')</script>");
return;
}
*/
this.FileUpload1.PostedFile.SaveAs(s);
//String teststr = "str="+str+"\n"+"ss="+ss + "\n" +"s="+ s + "\n"+"path=" + path;
//this.txt_as_equiment.Text = teststr;
img_photo.ImageUrl = path;
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
con.Open();
/*
String get_m_reason_id ="select m_reason_id from m_reason where m_reason_detail='"+dpl_m_reason.SelectedValue+"'"; //此部分在减少变动报告单用到
SqlCommand com=new SqlCommand(get_m_reason_id,con);
SqlDataReader read =com.ExecuteReader();
read.Read();
Int32 m_id = read.GetInt32(0);
read.Close();
//teststr = m_id;
* */
String get_a_reason_id = "select a_reason_id from a_reason where a_reason_detail='" + dpl_a_reason.SelectedValue + "'";
SqlCommand com = new SqlCommand(get_a_reason_id, con);
SqlDataReader read = com.ExecuteReader();
read.Read();
Int32 a_id = read.GetInt32(0);
read.Close();
//teststr = a_id;
String get_u_branch_id = "select u_branch_no from u_branch where u_branch_name='" + dpl_u_branch.SelectedValue + "'";
com = new SqlCommand(get_u_branch_id, con);
read = com.ExecuteReader();
read.Read();
String u_branch_id = read.GetString(0).ToString();
read.Close();
Application["u_branch_no"] = u_branch_id; //在CardReg.aspx.cs的插入Card表中用到此变量
//teststr = u_branch_id;
String get_source_id = "select source_id from source where source_name='" + dpl_source.SelectedValue + "'";
com = new SqlCommand(get_source_id, con);
read = com.ExecuteReader();
read.Read();
Int32 s_id = read.GetInt32(0);
read.Close();
teststr = s_id;
String get_purchase_way_id = "select purchase_way_id from purchase_way where purchase_way='" + dpl_purchase_way.SelectedValue + "'";
com = new SqlCommand(get_purchase_way_id, con);
read = com.ExecuteReader();
read.Read();
Int32 p_id = read.GetInt32(0);
read.Close();
//teststr = p_id;
string InsertAssetSql = "Insert Into asset(y_no,f_no,name,brain,type,number,old_value,source_id,purchase_way_id,";
InsertAssetSql += "as_equiment,u_branch_no,u_bra_detail,receive_name,a_date,a_reason_id,";
InsertAssetSql += "deal_name,check_name,photo)"; //m_date,m_reason_id, refer字段没有添加
InsertAssetSql += "values('" + this.txt_y_no.Text + "','" + this.txt_f_no.Text + "','" + this.txt_name.Text + "','" + this.txt_brain.Text + "','" + this.txt_type.Text + "',";
InsertAssetSql += " '" + this.txt_number.Text + "','" + this.txt_old_value.Text + "','" + s_id + "','" + p_id + "','" + this.txt_as_equiment.Text + "',";
InsertAssetSql += "'" + u_branch_id + "','" + txt_u_bra_detail.Text + "','" + txt_receive_name.Text + "','" + txt_a_date.Text + "','" + a_id + "',";
InsertAssetSql += "'" + txt_deal_name.Text + "','" + txt_check_name.Text + "','"+img_photo.ImageUrl+"')";
//txt_as_equiment.Text = InsertAssetSql;
com = new SqlCommand(InsertAssetSql, con);
com.ExecuteNonQuery();
con.Close();
Application["name"] = txt_name.Text;
Application["brain"] = txt_brain.Text;
Application["type"] = txt_type.Text;
Application["number"] = txt_number.Text;
Application["y_no"] = txt_y_no.Text;
Application["old_value"] = txt_old_value.Text;
Application["f_no"] = txt_f_no.Text;
Application["u_bra_detail"] = txt_u_bra_detail.Text;
Application["a_reason"] = dpl_a_reason.SelectedValue;
Application["deal_name"] = txt_deal_name.Text;
Application["check_name"] = txt_check_name.Text;
Application["u_branch"] = dpl_u_branch.SelectedValue;
Application["receive_name"] = txt_receive_name.Text;
Application["as_equiment"] = txt_as_equiment.Text;
Application["source"] = dpl_source.SelectedValue;
Application["purchase_way"] = dpl_purchase_way.SelectedValue;
Application["imgurl"] = img_photo.ImageUrl;
Button6.Attributes.Add("onclick", "javasrcipt:window.open('ReportSheet.aspx');"); //Button6是"预览报告单"按钮
Button3.Enabled = true;
Button3.Attributes.Add("onclick", "javasrcipt:window.open('CardReg.aspx');"); //Button3是"预览卡片"按钮
Response.Write("<script language=javascript>alert('添加数据成功')</script>");
}
catch
{
Button3.Enabled = false;
Response.Write("<script language=javascript>alert('添加数据失败')</script>");
}
}
protected void SqlDataSource_u_branch_detail_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
}
protected void btn_a_date_Click1(object sender, EventArgs e)
{
btn_m_date.Visible = !btn_m_date.Visible; //交错置btn_m_date这个按钮为不可见或可见,否则会盖住cld_a_date 这个日历控件
cld_a_date.Visible = !cld_a_date.Visible;
dpl_source.Visible= txt_deal_name.Visible = dpl_u_branch.Visible = !cld_a_date.Visible; //置下面相应控件的可见性与日历控件的相反,否则会盖住它
dpl_m_reason.Enabled = false;
dpl_m_reason.SelectedValue = null;
dpl_a_reason.Enabled = true;
}
protected void btn_m_date_Click1(object sender, EventArgs e)
{
cld_m_date.Visible = !cld_m_date.Visible;
dpl_source.Visible = txt_deal_name.Visible = dpl_u_branch.Visible = !cld_m_date.Visible; //置下面两个下拉列表的可见性与日历控件的相反,否则会盖住它
dpl_m_reason.Enabled = true;
dpl_a_reason.Enabled = false;
dpl_a_reason.SelectedValue = null;
}
protected void cld_a_date_SelectionChanged1(object sender, EventArgs e)
{
txt_a_date.Text = cld_a_date.SelectedDate.Date.ToString().Substring(0,10);
cld_a_date.Visible = false;
btn_m_date.Visible = true;
dpl_source.Visible = txt_deal_name.Visible = dpl_u_branch.Visible = true; //恢复下拉列表的可见性
Application["a_date"] = txt_a_date.Text;
Application["m_date"] = txt_m_date.Text = "";
}
protected void cld_m_date_SelectionChanged1(object sender, EventArgs e)
{
txt_m_date.Text = cld_m_date.SelectedDate.Hour.ToString().Substring(0, 10);
cld_m_date.Visible = false;
dpl_source.Visible = txt_deal_name.Visible = dpl_u_branch.Visible = true;
Application["m_date"] = txt_m_date.Text;
Application["a_date"] = txt_a_date.Text = "";
}
protected void Button6_ServerClick(object sender, EventArgs e)
{
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -