Comm o_Comm = new Comm();
o_Comm.PagerButtonClick(grvQuery, "Frist", this.Master);
两个一维数组处理要删除的资料:可以扩展为一个二维数组。
string[] ms_CheckDataPK_Group = ms_CheckDataPK.Split(';');
if (ms_CheckDataPK_Group.Length != 0)
{
for (int i = 0; i < ms_CheckDataPK_Group.Length; i++)
{
string[] mo_PM048TB_Data = ms_CheckDataPK_Group[i].Split(',');
mo_PM048TB.TASK_CODE = mo_PM048TB_Data[0].Trim().ToString();
if (!mo_PM048TB_Data[1].Trim().ToString().Equals(""))
mo_PM048TB.LOG_DATE = Convert.ToDateTime(mo_PM048TB_Data[1].Trim().ToString());
mo_PM048TB.USER_CODE = mo_PM048TB_Data[2].Trim().ToString();
mo_PM048TB.TASK_KIND = mo_PM048TB_Data[3].Trim().ToString();
mo_BLLPM048TB.Delete(mo_PM048TB);
}
}
AJAX的使用函数:
private void Query(string s_aUserCode)
{
PMUC01 o_PMUC01 = new PMUC01();
DataSet o_ds = new DataSet();
string s_UserName = string.Empty;
try
{
o_ds = o_PMUC01.Query(Request["UserCode"].ToString());
if (o_ds != null && o_ds.Tables[0].Rows.Count > 0)
{
s_UserName = o_ds.Tables[0].Rows[0]["USER_CHNAME"].ToString();
}
else
{
s_UserName = "";
}
Response.Clear();
Response.Write(s_UserName);
Response.Flush();
Response.Close();
}
catch (Exception ex)
{
ex.Message.ToString();
}
}
//Ajax的JS:
function GetNameById(obj)
{
LeachInputChinese();
var userCode=obj.value;
if(userCode=="")
{
return true;
}
else
{
var reqURL = 'PMTM02Q.aspx?UserCode=' + userCode;
var oHttpReq = GetXmlHttpRequest();
oHttpReq.open("POST",reqURL,false);
oHttpReq.send("");
var result = oHttpReq.responseText;
document.getElementById("ctl00_cphPage_txtUSER_CHNAME").value=result;
}
}
导出Excel的代码:
private bool ExportExcel()
{
try
{
Response.ClearContent();
Response.Charset = "UTF8";
Response.AddHeader("content-disposition", "attachment; filename=PMTM02.xls");
Response.ContentType = "application/excel";
Response.ContentEncoding = System.Text.Encoding.UTF7;
StringWriter o_sw = new StringWriter();
HtmlTextWriter o_htw = new HtmlTextWriter(o_sw);
GridView o_GridView = new GridView();
o_GridView = this.grvQuery;
o_GridView.RowDataBound += new GridViewRowEventHandler(o_GridView_RowDataBound);
o_GridView.DataSource = (DataTable)ViewState["DT"];
o_GridView.AllowPaging = false;
o_GridView.DataBind();
o_GridView.RenderControl(o_htw);
Response.Write(o_sw.ToString());
Response.End();
return true;
}
catch (Exception ex)
{
ex.Message.ToString();
return false;
}
}
override一个事件,导出Excel所需的:
#region VerifyRenderingInServerForm
/// <summary>
/// VerifyRenderingInServerForm
/// </summary>
/// <param name="control"></param>
public override void VerifyRenderingInServerForm(Control control)
{
//
}
#endregion
加入EnableEventValidation="false" :
例:<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
CodeFile="PMTM02Q.aspx.cs" EnableEventValidation="false"
设置Grv的某列显示为隐藏:
protected void o_GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[0].Visible = false;
e.Row.Cells[1].Visible = false;
}
ArrayList的使用:
ArrayList a_Authority = ((Auth)Session["AUTH"]).chkAuthority("PMTM02Q");
for (int i = 0; i < a_Authority.Count; i++)
{
if (a_Authority[i].ToString().Equals(Authority.SELECT.ToString()))
this.ibtQuery.Visible = false;
}
Server,Context:
this.Context.Items.Add("FromPage", "PMTM02Q");
Server.Transfer("PMTM02M.aspx");
查找CheckBox的控件:
CheckBox o_CheckData = new CheckBox();
o_CheckData = (CheckBox)grvQuery.Rows[i_Check].FindControl("chkHit");
删除事件:并接要删除的资料,删除动作,删除后再查询
for (int i_Check = 0; i_Check < grvQuery.Rows.Count; i_Check++)
{
CheckBox o_CheckData = new CheckBox();
o_CheckData = (CheckBox)grvQuery.Rows[i_Check].FindControl("chkHit");
if (o_CheckData.Checked)
{
ms_CheckDataPK += ((Label)grvQuery.Rows[i_Check].Cells[4].FindControl("lblTASK_CODE")).Text.Trim() + ","
+ ((Label)grvQuery.Rows[i_Check].Cells[10].FindControl("lblLOG_DATE")).Text.Trim() + ","
+ ((Label)grvQuery.Rows[i_Check].Cells[15].FindControl("lblUSER_CODE")).Text.Trim() + ","
+ ((Label)grvQuery.Rows[i_Check].Cells[16].FindControl("lblTASK_KIND")).Text.Trim() + ";";//TxRefNo 2 3 4 15
}
}
ms_CheckDataPK = ms_CheckDataPK.Substring(0, ms_CheckDataPK.Length - 1);
if (isDelete(ms_CheckDataPK))
{
AlertMessage1.AddOkMsg(Resources.WebResource.S018);
}
else
{
AlertMessage1.AddOkMsg(Resources.WebResource.S019);
}
//
Query(false);
grvQuery_RowCommand的事件:
if (e.CommandName == "imgbtn")
{
ImageButton imgIndex = (ImageButton)(e.CommandSource);
mo_PM048TB.TASK_CODE = ((Label)imgIndex.FindControl("lblTASK_CODE")).Text.Trim();
this.Context.Items.Add("Action", "UPD");
this.Server.Transfer("PMTM02M.aspx");
}
PMTM02M:
更新事件:
private Boolean isUpdate(Model.PM048TB mo_PM048TB)
{
try
{
mo_BLLPM048TB.Update(mo_PM048TB);
return true;
}
catch
{
return false;
}
}
遍历rdiobuttonlist内的Items:
if (ViewState["Action"].ToString().Equals("UPD") && (!ViewState["RadioPROGR_CODE"].Equals("")))
{
for (int i = 0; i < rdolstPROGR_CODE.Items.Count; i++)
{
if (rdolstPROGR_CODE.Items[i].Text.Trim().ToUpper().Equals(ViewState["RadioPROGR_CODE"].ToString().Trim().ToUpper()))
rdolstPROGR_CODE.Items[i].Selected = true;
}
}
保存事件:
简介:
局部对象的声明:
Model.PM048TB mo_PM048TBViewState = new com.thoughtchina.pms.Model.PM048TB();
//初始化新增或修改对象:
if (ViewState["Action"].ToString().Trim().Equals("ADD"))//GetModel
{
mo_PM048TB = new mo_BLLPM048TB();//初始化新增对象
}
else if(ViewState["Action"].ToString().Trim().Equals("UPD"))
{
mo_PM048TB = mo_BLLPM048TB.GetModel(mo_PM048TBViewState);//初始化修改对象
}
//对象的更改 放值进去:这里可以根据程式的复杂程度细分,作用用于分解复杂的程式,以方便维护。
if (ViewState["Action"].ToString().Trim().Equals("ADD"))//GetModel
{
mo_PM045TB.PAGE_NUMS = Convert.ToInt32(this.txtCODE_NUMS.Text.Trim());
}
else if(ViewState["Action"].ToString().Trim().Equals("UPD"))
{
mo_PM045TB.PAGE_NUMS = Convert.ToInt32(this.txtCODE_NUMS.Text.Trim());
}
if (ViewState["Action"].ToString().Trim().Equals("ADD"))
{
if(IsExists(mo_PM048TB))
{
isAdd(mo_PM048TB);
}
}
else if(ViewState["Action"].ToString().Trim().Equals("ADD"))
{
if(IsExists(mo_PM048TB))
{
CheckExecStart(mo_PM045TB_PRE);
IsUpdatePM045TB_EXECEnd_Hour(mo_PM045TB, d_AddExecHour);
isUPD(mo_PM048TB);
}
}
函数原型:
function IsAdd(Model.PM045TB mo_PM048TB)
{
if (mo_BLLPM048TB.Add(mo_PM048TB))//注意Add这个方法在BLL中进行定义。
{
AlertMessage1.AddOkMsg(Resources.WebResource.X010);
}
else
{
AlertMessage1.AddOkMsg(Resources.WebResource.X011);
}
}
详细的原型:
protected void ibtnSave_Click(object sender, ImageClickEventArgs e)
{
BLL.PM048TB mo_BLLPM048TB =new com.thoughtchina.pms.BLL.PM048TB();
#region MO update
string IsChange = "N";
Model.PM048TB mo_PM048TBViewState = new com.thoughtchina.pms.Model.PM048TB();
if (ViewState["Action"].ToString().Trim().Equals("UPD"))
{
mo_PM048TBViewState = (Model.PM048TB)ViewState["Context_mo_PM048TB"];
mo_PM048TB = mo_BLLPM048TB.GetModel(mo_PM048TBViewState);
this.ViewState.Add("mo_PM048TB_DB_EXECHOUR", mo_PM048TB.EXEC_HOUR);
mo_PM048TB.LOG_DATE_PRE = mo_PM048TBViewState.LOG_DATE;
mo_PM048TB.TASK_CODE_PRE = mo_PM048TBViewState.TASK_CODE;
mo_PM048TB.TASK_KIND_PRE = mo_PM048TBViewState.TASK_KIND;
if (!this.drpENTRY_VALUE.SelectedValue.ToString().Equals("4"))
{
if (!mo_PM048TB.TASK_KIND_PRE.Equals(this.drpENTRY_VALUE.SelectedValue.ToString().Trim()) ||
!mo_PM048TB.TASK_CODE_PRE.Equals(this.rdolstPROGR_CODE.SelectedItem.Text.ToString().Trim()) ||
!mo_PM048TB.LOG_DATE_PRE.Equals(Convert.ToDateTime(this.txtLOG_DATE.Text.Trim())))
IsChange = "Y";
}
else
{
if (!mo_PM048TB.TASK_KIND_PRE.Equals(this.drpENTRY_VALUE.SelectedValue.ToString().Trim()) ||
!mo_PM048TB.LOG_DATE_PRE.Equals(Convert.ToDateTime(this.txtLOG_DATE.Text.Trim())))
IsChange = "Y";
}
mo_PM048TB.MDF_USER = this.mo_CurrentUser.UserCode.ToString();
mo_PM048TB.MDF_DATE = DateTime.Now;
}
else
{
mo_PM048TB.PROJ_CODE = this.ms_ProjectCode.ToString().Trim();
if (!this.drpENTRY_VALUE.SelectedValue.ToString().Equals("4"))
mo_PM048TB.TASK_CODE = this.rdolstPROGR_CODE.SelectedItem.Text.ToString().Trim();
else
mo_PM048TB.TASK_CODE = "VACATION";
mo_PM048TB.CRT_USER = this.mo_CurrentUser.UserCode.ToString();
mo_PM048TB.CRT_DATE = DateTime.Now;
}
#endregion
#region
Model.PM045TB mo_PM045TB_PRE = new Model.PM045TB();
if (!this.drpENTRY_VALUE.SelectedValue.ToString().Equals("4"))
{
mo_PM045TB = mo_BLLPM045TB.GetModel(mo_PM048TB.PROJ_CODE, mo_PM048TB.TASK_CODE);
mo_PM045TB_PRE = mo_PM045TB;
#region
if (this.drpPROGR_STATE_OK.Text.Trim().Equals("1"))
{
mo_PM048TB.CODE_NUMS = Convert.ToInt32(this.txtCODE_NUMS.Text.Trim());
if (this.drpENTRY_VALUE.SelectedValue.ToString().Equals("2"))
{
mo_PM045TB.CODE_NUMS = Convert.ToInt32(this.txtCODE_NUMS.Text.Trim());
}
if (this.drpENTRY_VALUE.SelectedValue.ToString().Equals("3"))
{
mo_PM045TB.PAGE_NUMS = Convert.ToInt32(this.txtCODE_NUMS.Text.Trim());
}
}
else
{
mo_PM048TB.CODE_NUMS = 0;
if (this.drpENTRY_VALUE.SelectedValue.ToString().Equals("2"))
{
mo_PM045TB.CODE_NUMS = 0;
}
if (this.drpENTRY_VALUE.SelectedValue.ToString().Equals("3"))
{]
mo_PM045TB.PAGE_NUMS = 0;
}
}
#endregion
if (!this.drpPROGR_STATE.Text.Trim().Equals("2"))
{
if (!this.txtEXEC_HOUR.Text.Trim().Equals(""))
mo_PM048TB.EXEC_HOUR = Convert.ToDecimal(this.txtEXEC_HOUR.Text.Trim());
if (!this.txtPROGR_FINISH.Text.Trim().Equals(""))
mo_PM048TB.PGOGR_FINISH = Convert.ToInt32(this.txtPROGR_FINISH.Text.Trim());
if (this.drpPROGR_STATE_OK.Text.Trim().Equals("1"))
mo_PM048TB.PGOGR_FINISH = Convert.ToInt32("100");
}
mo_PM048TB.MEMO = this.txtMEMO.Text.Trim();
mo_PM048TB.PROGR_STATE = this.drpPROGR_STATE_OK.Text.Trim();
}
else
{
mo_PM048TB.CODE_NUMS = 0;
mo_PM048TB.EXEC_HOUR = 0;
mo_PM048TB.PGOGR_FINISH = 0;
mo_PM048TB.MEMO = "";
mo_PM048TB.PROGR_STATE = "";
}
mo_PM048TB.USER_CODE = this.mo_CurrentUser.UserCode.ToString();
if (!this.txtLOG_DATE.Text.Trim().Equals(""))
mo_PM048TB.LOG_DATE = Convert.ToDateTime(this.txtLOG_DATE.Text.Trim());
mo_PM048TB.TASK_KIND = this.drpENTRY_VALUE.Text.Trim();
if (this.drpENTRY_VALUE.SelectedValue.ToString().Equals("4"))
mo_PM048TB.TASK_CODE = "VACATION";
else
mo_PM048TB.TASK_CODE = this.rdolstPROGR_CODE.SelectedItem.Text.ToString().Trim();
mo_PM048TB.PROJ_CODE = this.ms_ProjectCode.ToString();
#endregion
if (!ViewState["Action"].ToString().Trim().Equals("UPD"))
{
#region
if (drpENTRY_VALUE.SelectedValue.Trim().Equals("0") || drpENTRY_VALUE.SelectedValue.Trim().Equals("5")
|| drpENTRY_VALUE.SelectedValue.Trim().Equals("6") || drpENTRY_VALUE.SelectedValue.Trim().Equals("7"))
{
if (!IsExists(mo_PM048TB))
{
if (isAdd(mo_PM048TB))
{
AlertMessage1.AddOkMsg(Resources.WebResource.X010);
}
else
{
AlertMessage1.AddOkMsg(Resources.WebResource.X011);
}
}
else
{
this.AlertMessage1.AddOkMsg(Resources.WebResource.G016);
}
}
else
{
if (!IsExists(mo_PM048TB))
{
if (CheckExecStart(mo_PM045TB_PRE))
{
IsUpdatePM045TB_EXECStart(mo_PM045TB);
}
if (this.drpPROGR_STATE_OK.Text.Trim().Equals("1"))
{
decimal d_AddExecHour = Convert.ToDecimal(this.txtEXEC_HOUR.Text.ToString().Trim());
IsUpdatePM045TB_EXECEnd_Hour(mo_PM045TB, d_AddExecHour);
}
if (isAdd(mo_PM048TB))
{
AlertMessage1.AddOkMsg(Resources.WebResource.X010);
}
else
{
AlertMessage1.AddOkMsg(Resources.WebResource.X011);
}
}
else
{
AlertMessage1.AddOkMsg(Resources.WebResource.G016);
}
}
#endregion
}
else
{
#region
if (drpENTRY_VALUE.SelectedValue.Trim().Equals("0") || drpENTRY_VALUE.SelectedValue.Trim().Equals("5")
|| drpENTRY_VALUE.SelectedValue.Trim().Equals("6") || drpENTRY_VALUE.SelectedValue.Trim().Equals("7"))
{
if ((!IsExists(mo_PM048TB) && IsChange == "Y") || IsChange == "N")
{
if (isUpdate(mo_PM048TB))
{
AlertMessage1.AddOkMsg(Resources.WebResource.X012);
}
else
{
AlertMessage1.AddOkMsg(Resources.WebResource.X013);
}
}
else
{
AlertMessage1.AddOkMsg(Resources.WebResource.G016);
}
}
else
{
if ((!IsExists(mo_PM048TB) && IsChange == "Y") || IsChange == "N")
{
if (CheckExecStart(mo_PM045TB_PRE))
{
IsUpdatePM045TB_EXECStart(mo_PM045TB);
}
if (this.drpPROGR_STATE_OK.Text.Trim().Equals("1"))
{
decimal d_AddExecHour = Convert.ToDecimal(this.txtEXEC_HOUR.Text.ToString().Trim()) - Convert.ToDecimal(ViewState["mo_PM048TB_DB_EXECHOUR"].ToString().Trim());
IsUpdatePM045TB_EXECEnd_Hour(mo_PM045TB, d_AddExecHour);
}
if (isUpdate(mo_PM048TB))
{
AlertMessage1.AddOkMsg(Resources.WebResource.X012);
}
else
{
AlertMessage1.AddOkMsg(Resources.WebResource.X013);
}
}
else
{
AlertMessage1.AddOkMsg(Resources.WebResource.G016);
}
}
#endregion
mo_PM048TBViewState.LOG_DATE = mo_PM048TB.LOG_DATE; mo_PM048TBViewState.TASK_CODE = mo_PM048TB.TASK_CODE;
mo_PM048TBViewState.TASK_KIND = mo_PM048TB.TASK_KIND;
ViewState["Context_mo_PM048TB"] = mo_PM048TBViewState;
}
}