protected void btnAddConstant_Click(object sender, EventArgs e) { int index = KPI_ConstantDal.ConstantIDCounts(); string sID = PageControl.GetGuid(); ConstantEntity ote = new ConstantEntity(); ote.ConstantID = sID; ote.ConstantCode = "InputCode"; ote.ConstantName = "Input Name"; ote.ConstantDesc = ""; ote.ConstantValue = "Input Value"; ote.ConstantNote = ""; ote.ConstantCreateTime = DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss"); ote.ConstantModifyTime = ote.ConstantCreateTime; if (KPI_ConstantDal.Insert(ote)) { //MessageBox.popupClientMessage(this.Page, "添加成功!", "call();"); gvConstant.EditIndex = index; BindConstant(); } else { MessageBox.popupClientMessage(this.Page, "添加错误!", "call();"); } }
protected void gvConstant_RowUpdating(object sender, GridViewUpdateEventArgs e) { HtmlInputHidden key = (HtmlInputHidden)gvConstant.Rows[e.RowIndex].Cells[0].FindControl("constantid"); string sID = key.Value; string sCode = ((TextBox)(gvConstant.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim(); string sName = ((TextBox)(gvConstant.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim(); string sDesc = ((TextBox)(gvConstant.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim(); string sValue = ((TextBox)(gvConstant.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim(); string sNote = ((TextBox)(gvConstant.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim(); string msg = ""; if (sCode == "") { msg += "类型不能为空!\r\n"; } if (sName == "") { msg += "名称不能为空!\r\n"; } if (!Regex.IsMatch(sCode, "^[A-Za-z]+$")) { msg += "类型只能为字母!\r\n"; } if (msg != "") { MessageBox.popupClientMessage(this.Page, msg); return; } //代码是否重复 if (KPI_ConstantDal.ConstantNameExists(sName,sCode )) { MessageBox.popupClientMessage(this.Page, "相同的类型下已存在该名称!"); return; } //更新 ConstantEntity ote = new ConstantEntity(); ote.ConstantID = sID; ote.ConstantCode = sCode; ote.ConstantName = sName; ote.ConstantDesc = sDesc; ote.ConstantValue = sValue; ote.ConstantNote = sNote; ote.ConstantModifyTime = DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss"); if (KPI_ConstantDal.Update(ote)) { MessageBox.popupClientMessage(this.Page, "编辑成功!", "call();"); } else { MessageBox.popupClientMessage(this.Page, "编辑错误!", "call();"); } gvConstant.EditIndex = -1; BindConstant(); }