protected void btnAdd_Click(object sender, EventArgs e) { string groupname = tbx_GroupName.Text.Trim(); string groupdesc = tbx_GroupDesc.Text.Trim(); string groupisvalid = ddl_GroupIsValid.Value; string groupnote = tbx_GroupNote.Text.Trim(); // string groupid = Guid.NewGuid().ToString(); string groupcode = GroupDal.GetNextCode(); string msg = ""; if (groupname == "") { msg += "名称不能为空!\r\n"; } if (groupisvalid == "") { msg += "有效性不能为空!\r\n"; } else { try { int.Parse(groupisvalid); } catch { msg += "有效性格式错误!\r\n"; } } if (msg != "") { MessageBox.popupClientMessage(this.Page, msg, "call();"); return; } if (GroupDal.GroupExist(groupname, groupid)) { MessageBox.popupClientMessage(this.Page, "该组名称已存在!", "call();"); return; } GroupEntity mEntity = new GroupEntity(); mEntity.GroupID = groupid; mEntity.GroupCode = groupcode; mEntity.GroupName = groupname; mEntity.GroupDesc = groupdesc; mEntity.GroupIsValid = int.Parse(groupisvalid); mEntity.GroupNote = groupnote; mEntity.GroupCreateTime = DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss"); mEntity.GroupModifyTime = mEntity.GroupCreateTime; if (!GroupDal.Insert(mEntity)) { MessageBox.popupClientMessage(this.Page, "修改错误!", "call();"); } else { MessageBox.popupClientMessage(this.Page, "修改成功!", "call();"); tbx_GroupName.Text = ""; tbx_GroupDesc.Text = ""; tbx_GroupNote.Text = ""; gvGroup.EditIndex = -1; BindGrid(); } }
protected void gvGroup_RowUpdating(object sender, GridViewUpdateEventArgs e) { string groupname = ((TextBox)(gvGroup.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim(); string groupdesc = ((TextBox)(gvGroup.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim(); string groupisvalid = ((TextBox)(gvGroup.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim(); string groupnote = ((TextBox)(gvGroup.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim(); string groupid = ((HtmlInputHidden)(gvGroup.Rows[e.RowIndex].Cells[0].FindControl("groupid"))).Value; string msg = ""; if (groupname == "") { msg += "名称不能为空!\r\n"; } if (groupisvalid == "") { msg += "有效性不能为空!\r\n"; } else { try { int.Parse(groupisvalid); } catch { msg += "有效性格式错误!\r\n"; } } if (GroupDal.GroupExist(groupname, groupid)) { MessageBox.popupClientMessage(this.Page, "该组名称已存在!", "call();"); return; } GroupEntity mEntity = new GroupEntity(); mEntity.GroupID = groupid; mEntity.GroupName = groupname; mEntity.GroupDesc = groupdesc; mEntity.GroupIsValid = int.Parse(groupisvalid); mEntity.GroupNote = groupnote; //mEntity.GroupCreateTime = DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss"); mEntity.GroupModifyTime = DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss"); if (!GroupDal.Update(mEntity)) { MessageBox.popupClientMessage(this.Page, "修改错误!", "call();"); } else { MessageBox.popupClientMessage(this.Page, "修改成功!", "call();"); gvGroup.EditIndex = -1; BindGrid(); } }