62,243
社区成员




protected void BtnBookTypeAdd_Click(object sender, EventArgs e)
{
//遍历所有控件
decimal max_score =0;
decimal pf_score = 0;
decimal ckbox_score = 0;
decimal txtbox_score = 0;
decimal zf = 0;
foreach (RepeaterItem c in RpBookType.Items)
{
CheckBox check = (CheckBox)c.FindControl("chk_active");
TextBox txtbox = (TextBox)c.FindControl("txt_active");
Label lbl_PFXL_SCORE = (Label)c.FindControl("lbl_PFXL_SCORE");
Label lbl_PFDL_NAME = (Label)c.FindControl("lbl_PFDL_NAME");
Label lbl_PFXL_NAME = (Label)c.FindControl("lbl_PFXL_NAME");
Label lbl_PFDL_ID = (Label)c.FindControl("lbl_PFDL_ID");
Label lbl_PFXL_ID = (Label)c.FindControl("lbl_PFXL_ID");
max_score = Convert.ToDecimal(lbl_PFXL_SCORE.Text.ToString());
//先做一些输入合法性的判断
if (DAL.DataOperWj.IsNumric_wj(txtbox.Text.ToString()) == false) //是否是合法的格式
{
Common.ShowMessage.Show(Page, "error", "二级分类 " + lbl_PFXL_NAME.Text.ToString() + " 输入的格式错误,请检查! ");
return;
}
if (txtbox.Text.ToString().Trim().IndexOf('-') > -1)
{
Common.ShowMessage.Show(Page, "error", "二级分类 " + lbl_PFXL_NAME.Text.ToString() + " 有非法字符,请检查! ");
return;
}
pf_score = Convert.ToDecimal(txtbox.Text.ToString()); //合法的格式再转换
if (pf_score > max_score && txtbox.Visible==true ) //是否大于最高分
{
Common.ShowMessage.Show(Page, "error", "二级分类 " + lbl_PFXL_NAME.Text.ToString() + " 列,大于最高分,请检查! " );
return;
}
//合法检查结束,算个总分
txtbox_score = txtbox_score + Convert.ToDecimal(txtbox.Text.ToString().Trim());
if (check.Checked == true)
{
ckbox_score = ckbox_score + Convert.ToDecimal(lbl_PFXL_SCORE.Text.ToString().Trim());
}
}
//总分
zf = txtbox_score + ckbox_score;
//前面是一系列的判断,遍历repeater 取数
//取完后,算出个总分,确认是否提交
this.BtnBookTypeAdd.Attributes.Add("onclick", "return confirm('总分为: "+zf+" 确定提交吗? ');");
//选择是就提交,否就什么都不做,上面那句好像不行
//todo 写库。
}
protected void BtnBookTypeAdd_Click(object sender, EventArgs e)
{
//遍历所有控件
decimal max_score =0;
decimal pf_score = 0;
decimal ckbox_score = 0;
decimal txtbox_score = 0;
decimal zf = 0;
foreach (RepeaterItem c in RpBookType.Items)
{
CheckBox check = (CheckBox)c.FindControl("chk_active");
TextBox txtbox = (TextBox)c.FindControl("txt_active");
Label lbl_PFXL_SCORE = (Label)c.FindControl("lbl_PFXL_SCORE");
Label lbl_PFDL_NAME = (Label)c.FindControl("lbl_PFDL_NAME");
Label lbl_PFXL_NAME = (Label)c.FindControl("lbl_PFXL_NAME");
Label lbl_PFDL_ID = (Label)c.FindControl("lbl_PFDL_ID");
Label lbl_PFXL_ID = (Label)c.FindControl("lbl_PFXL_ID");
max_score = Convert.ToDecimal(lbl_PFXL_SCORE.Text.ToString());
//先做一些输入合法性的判断
if (DAL.DataOperWj.IsNumric_wj(txtbox.Text.ToString()) == false) //是否是合法的格式
{
Common.ShowMessage.Show(Page, "error", "二级分类 " + lbl_PFXL_NAME.Text.ToString() + " 输入的格式错误,请检查! ");
return;
}
if (txtbox.Text.ToString().Trim().IndexOf('-') > -1)
{
Common.ShowMessage.Show(Page, "error", "二级分类 " + lbl_PFXL_NAME.Text.ToString() + " 有非法字符,请检查! ");
return;
}
pf_score = Convert.ToDecimal(txtbox.Text.ToString()); //合法的格式再转换
if (pf_score > max_score && txtbox.Visible==true ) //是否大于最高分
{
Common.ShowMessage.Show(Page, "error", "二级分类 " + lbl_PFXL_NAME.Text.ToString() + " 列,大于最高分,请检查! " );
return;
}
//合法检查结束,算个总分
txtbox_score = txtbox_score + Convert.ToDecimal(txtbox.Text.ToString().Trim());
if (check.Checked == true)
{
ckbox_score = ckbox_score + Convert.ToDecimal(lbl_PFXL_SCORE.Text.ToString().Trim());
}
}
//总分
zf = txtbox_score + ckbox_score;
ClientScript.RegisterStartupScript(GetType(), "confirm", "CallServerMethod(confirm('总分为: "+zf.ToString()+" 是否提交?'),null);", true);
}
private string Confirm()
{
//这里是提交
//遍历所有控件
decimal pf_score = 0;
//decimal ckbox_score = 0;
//decimal txtbox_score = 0;
decimal zf = 0;
foreach (RepeaterItem c in RpBookType.Items)
{
CheckBox check = (CheckBox)c.FindControl("chk_active");
TextBox txtbox = (TextBox)c.FindControl("txt_active");
Label lbl_PFXL_SCORE = (Label)c.FindControl("lbl_PFXL_SCORE");
Label lbl_PFDL_NAME = (Label)c.FindControl("lbl_PFDL_NAME");
Label lbl_PFXL_NAME = (Label)c.FindControl("lbl_PFXL_NAME");
Label lbl_PFDL_ID = (Label)c.FindControl("lbl_PFDL_ID");
Label lbl_PFXL_ID = (Label)c.FindControl("lbl_PFXL_ID");
if (txtbox.Visible == true)
{
pf_score = Convert.ToDecimal(txtbox.Text.ToString());
}
if (check.Visible == true)
{
if (check.Checked == true)
{
pf_score = Convert.ToDecimal(lbl_PFXL_SCORE.Text.ToString().Trim());
}
else
{
pf_score = 0;
}
}
//开始插入数据
int KHXM_ID = Convert.ToInt16(DrpBiz.SelectedValue.ToString()); //考核项目
int PFDL_ID = Convert.ToInt16(lbl_PFDL_ID.Text.ToString()); //评分一级分类
int PFXL_ID = Convert.ToInt16(lbl_PFXL_ID.Text.ToString()); //评分二级分类
string KHXM_NAME = DrpBiz.SelectedItem.Text.ToString().Trim();
string PFDL_NAME = lbl_PFDL_NAME.Text.ToString();
string PFXL_NAME = lbl_PFXL_NAME.Text.ToString();
string PFSD = drp_PFSD.SelectedItem.Text.ToString().Trim(); //评分时点
string RYID = drp_PFR.SelectedValue.ToString().Trim(); //被考核人员ID
string RYNAME = drp_PFR.SelectedItem.Text.ToString().Trim(); //被考核人员姓名
string PFRY = "admin"; //评分人员
string sql =" INSERT into SCORE "
+ "( SCORE_PFSD,SCORE_RYID, SCORE_NAME,SCORE_KHXM_ID,SCORE_KHXM_NAME, "
+ " SCORE_PFDL_ID,SCORE_PFDL_NAME,SCORE_PFXL_ID,SCORE_PFXL_NAME,SCORE_CRKHXM, "
+ " SCORE_PFSCORE,SCORE_DATE,SCORE_PFRY) "
+ " values('"+PFSD+"','"+RYID+"', '"+RYNAME +"','"+KHXM_ID+"','"+KHXM_NAME+"','"+PFDL_ID+"',"
+ " '"+PFDL_NAME+"','"+PFXL_ID+"','"+PFXL_NAME+"','"+PFSD+"', '"+ pf_score+"','"+DateTime.Now.Date+"','"+PFRY+"')";
if (DAL.DataBaseWj.Exe_cmd(sql))
{
//Common.ShowMessage.Show(Page, "success", "信息添加成功!");
}
else
{
//Common.ShowMessage.Show(Page, "seuss", "信息删除失败!请重试或联系管理人员...", "");
}
}
//写下日志库,目的是评过分的人员不再显示在list中
string sql_log = " INSERT into PFLOG "
+ " (PFLOG_KHXMBH,PFLOG_RYID,PFLOG_NAME,PFLOG_DATE,PFLOG_PFR) "
+ " values('" + drp_PFSD.SelectedItem.Text.ToString().Trim() + "','" + drp_PFR.SelectedValue.ToString().Trim() + "',"
+ " '"+ drp_PFR.SelectedItem.Text.ToString().Trim() + "','" + DateTime.Now.Date + "','admin')";
if (DAL.DataBaseWj.Exe_cmd(sql_log))
{
//ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "click", "alert('信息添加成功!');", true)
}
else
{
//ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "click", "alert('日志信息添加失败!');", true);
}
//再绑下数据
BindData1("");
return "Confirm";
}
ClientScript.RegisterStartupScript(GetType(), "confirm", "CallServerMethod(confirm('总分为: "+zf.ToString()+" 是否提交?'),null);", true);
private string Confirm()
{
//这里有一些写库操作
binddata();
//这个是绑定 repeater 的操作,但发现repeater上的数据并没有刷新。
}
this.BtnBookTypeAdd.Attributes.Add("onclick", "return confirm('总分为: "+zf+" 确定提交吗? ')
这里你只是给前端标签一个行为定义,但是你并没有让页面本次刷新时立刻就执行 confirm,而且你注册的 confirm 代码执行之后也没有将用户提交的信息回发给 asp.net 代码中的精确指定的控件(页面或者页面中某个组件、控件)来捕获事件,实际上这里你的 asp.net 知识是“倒置”的,编程技术方向理解是错的。