private void btnSave_Click(object sender, EventArgs e) { #region //验证 if (this.s_ReceTypeID.Text == "") { MessageBox.Show("模板编号不能为空!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (this.s_ReceName.Text.Trim() == "") { MessageBox.Show("模板名不能为空!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (this.n_DetailRows.Text.Trim() != "" && !Util.IsNumberic(this.n_DetailRows)) { MessageBox.Show("子表行数输入有误,请输入数值型数据!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } #endregion InitFuncs initFuncs = new InitFuncs(); DBUtil dbUtil = new DBUtil(); string strSql = ""; string strSql_ = ""; if (this.type == "add") { //插入之前的判断 bool isExistKey = dbUtil.Is_Exist_Data("T_ReceiptModal", "ReceTypeID", this.s_ReceTypeID.Text.Trim()); if (isExistKey) { MessageBox.Show("该单据模板已定义!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } strSql_ = "select * from T_ReceiptModal where Ltrim(Rtrim(ReceName))='{0}'"; strSql_ = string.Format(strSql_, this.s_ReceName.Text.Trim()); //插入 strSql = initFuncs.Build_Insert_Sql(this.panelReceiptModal, "T_ReceiptModal"); } else if (this.type == "edit") { //更新 strSql_ = "select * from T_ReceiptModal where Ltrim(Rtrim(ReceTypeID)) != '{0}' and Ltrim(Rtrim(ReceName))='{1}'"; strSql_ = string.Format(strSql_, this.s_ReceTypeID.Text.Trim(), this.s_ReceName.Text.Trim()); string strSqlWhere = "where ReceTypeID='" + this.s_ReceTypeID.Text.Trim() + "'"; strSql = initFuncs.Build_Update_Sql(this.panelReceiptModal, "T_ReceiptModal", strSqlWhere); } if (dbUtil.yn_exist_data(strSql_)) { MessageBox.Show("该模板名已存在!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } (new SqlDBConnect()).ExecuteNonQuery(strSql); MessageBox.Show("保存成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); receiptModalDefineChange(); //激活代理事件,在父窗体中处理 this.Close(); }
private void button1_Click(object sender, EventArgs e) { #region 输入验证 if (Util.ControlTextIsNUll(this.s_CustID )) { MessageBox.Show("客户编号不能为空!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (Util.ControlTextIsNUll(this.s_CustName )) { MessageBox.Show("客户名称不能为空!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (Util.ControlTextIsNUll(this.s_CustType)) { MessageBox.Show("请选择类别!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (Util.ControlTextIsNUll(this.s_whichTrade )) { MessageBox.Show("请选择所在行业!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (this.s_PostCode.Text != "" && Util.IsPhoneNumber(this.s_PostCode, 6) == false) { MessageBox.Show("邮编输入错误!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (this.s_Fax.Text.Trim() != "" && Util.IsNumberic(this.s_Fax) == false) { MessageBox.Show("传真输入错误!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } #endregion //数据处理 InitFuncs initFuncs = new InitFuncs(); DBUtil dbUtil = new DBUtil(); try { #region 添加 if (this.type == "add") { // 判断客户ID是否存在 string sql = "select * from T_CustomerInf where CustID='" + this.s_CustID.Text.Trim() + "'"; bool ynExistID = dbUtil.yn_exist_data(sql); if (ynExistID == true) { MessageBox.Show("该客户已存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); s_CustID.Focus(); return; } string strSqlInsert = initFuncs.Build_Insert_Sql(this.panelcustomer, "T_CustomerInf"); //插入之前首先判断是否存在该客户 bool isExist = dbUtil.Is_Exist_Data("T_CustomerInf", "CustName", this.s_CustName.Text.Trim()); if (isExist == false) //插入一条 { try { (new SqlDBConnect()).ExecuteNonQuery(strSqlInsert); MessageBox.Show("添加成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); //this.DialogResult = DialogResult.OK; this.custid = s_CustID.Text.Trim(); this.type = "edit"; tabControl1.Enabled = true; } catch { this.DialogResult = DialogResult.OK; } } else //该客名已存在 { MessageBox.Show("该客户已存在!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } customerInfoFormChange(); } #endregion #region 编辑 else if (this.type == "edit") { //插入之前首先判断是否存在该客户 string sql_ = "select CustName from T_CustomerInf where CustName='" + this.s_CustName.Text.Trim() + "' and CustID not like '" + custid + "'"; bool isExist = dbUtil.yn_exist_data(sql_); if (isExist) { MessageBox.Show("该客户名已存在,请重新输入!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string strSqlUpdate = initFuncs.Build_Update_Sql(this.panelcustomer, "T_CustomerInf", " where CustID='" + this.s_CustID.Text.Trim() + "'"); //执行 (new SqlDBConnect()).ExecuteNonQuery(strSqlUpdate); MessageBox.Show("更新成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); customerInfoFormChange(); //激活代理事件,在UserForm中处理 this.DialogResult = DialogResult.OK; } #endregion } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void button9_Click(object sender, EventArgs e) { #region 输入验证 if (((comboBoxUserName.SelectedIndex == 0) && (comboBoxArea.SelectedIndex == 0)) || ((comboBoxUserName.SelectedIndex != 0) && (comboBoxArea.SelectedIndex == 0)) || ((comboBoxUserName.SelectedIndex == 0) && (comboBoxArea.SelectedIndex != 0))) { MessageBox.Show("请输入完整的信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } #endregion try { bool isExist; String sql_ = "", sqle_ = ""; DBUtil dbUtil = new DBUtil(); isExist = dbUtil.Is_Exist_Data("T_User_Area", "UAid", this.T_UAid.Text.Trim()); if (T_UAid.ReadOnly) { string strSqlWhere = "where UAid='" + T_UAid.Text.Trim() + "'"; sql_ = String.Format("select * from T_User_Area where (Ltrim(Rtrim(userid)) like '{0}' and Ltrim(Rtrim(uAreaid)) like '{1}') and Ltrim(Rtrim(UAid)) not like '{2}'", s_userid.Text.Trim(), s_UAreaid.Text.Trim(), T_UAid.Text.Trim()); sqle_ = (new InitFuncs()).Build_Update_Sql(this.panelUserArea, "T_User_Area", strSqlWhere); } else { sql_ = String.Format("select * from T_User_Area where (Ltrim(Rtrim(userid)) like '{0}' and Ltrim(Rtrim(uAreaid)) like '{1}')", s_userid.Text.Trim(), s_UAreaid.Text.Trim()); sqle_ = (new InitFuncs()).Build_Insert_Sql(this.panelUserArea, "T_User_Area"); } isExist = dbUtil.yn_exist_data(sql_); if (isExist) { MessageBox.Show("该记录已经存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } (new SqlDBConnect()).ExecuteNonQuery(sqle_); InitDataGridView("T_User_Area"); } catch //(Exception ex) { MessageBox.Show("不能插入重复键!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void button51_Click(object sender, EventArgs e) { try { bool isExist; String sql_ = "", sqle_ = ""; DBUtil dbUtil = new DBUtil(); isExist = dbUtil.Is_Exist_Data("T_machproblem", "probcodeid", this.T_probcodeid.Text.Trim()); if (T_probcodeid.ReadOnly) { string strSqlWhere = "where probcodeid='" + T_probcodeid.Text.Trim() + "'"; sql_ = String.Format("select * from T_machproblem where Ltrim(Rtrim(probname)) like '{0}'and Ltrim(Rtrim(probcodeid)) not like '{1}'", s_probname.Text.Trim(), T_probcodeid.Text.Trim()); sqle_ = "update T_machproblem set probname='" + s_probname.Text.Trim() + "'," + "telcode ='" + s_Ptelcode.Text.Trim() + "' where probcodeid='" + T_probcodeid.Text.Trim() + "'"; } else { sql_ = String.Format("select * from T_machproblem where (Ltrim(Rtrim(probname)) like '{0}')", s_probname.Text.Trim()); sqle_ = "insert into T_machproblem(telcode,probname)values('" + s_Ptelcode.Text.Trim() + "','" + s_probname.Text.Trim() + "')"; } isExist = dbUtil.yn_exist_data(sql_); if (isExist) { MessageBox.Show("该记录已经存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } (new SqlDBConnect()).ExecuteNonQuery(sqle_); InitDataGridView("T_machproblem"); } catch //(Exception ex) { MessageBox.Show("不能插入重复键!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void btnOK_Click(object sender, EventArgs e) { #region //验证 if (Util.ControlTextIsNUll(this.s_RoleId)) { MessageBox.Show("角色编号不能为空!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (!Util.IsContainCharNumber(this.s_RoleId, 4)) { MessageBox.Show("角色编号不能大于4位!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (Util.ControlTextIsNUll(this.s_RoleName)) { MessageBox.Show("角色名不能为空!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } #endregion InitFuncs initFuncs = new InitFuncs(); string strSqlInsert = initFuncs.Build_Insert_Sql(this.panelRoles, "T_Roles"); //插入之前首先判断是否存在该角色 DBUtil dbUtil = new DBUtil(); bool isExist = false; if (this.s_RoleId.Text.Trim() != "") isExist = dbUtil.Is_Exist_Data("T_Roles", "RoleId", this.s_RoleId.Text.Trim()); SqlDBConnect db = new SqlDBConnect(); if (isExist == true) { if (this.s_RoleId.ReadOnly == false) { MessageBox.Show("已存在该角色!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //更新 List<string> sqls = new List<string>(); string strSqlWhere = "where RoleId='" + this.s_RoleId.Text.ToString().Trim() + "'"; string strSqlUpdate = initFuncs.Build_Update_Sql(this.panelRoles, "T_Roles", strSqlWhere); sqls.Add(strSqlUpdate); //更新权限 string strRoleId = this.s_RoleId.Text.Trim(); //先删除 string strSqlDelete = "delete from T_Role_Rights where RoleId='{0}'"; strSqlDelete = string.Format(strSqlDelete, strRoleId); sqls.Add(strSqlDelete); List<TreeNode> checkedNodes = new List<TreeNode>();//存储所有的选中的叶子菜单项 UserPermission(this.treeViewMenus, checkedNodes); foreach (TreeNode treeNode in checkedNodes) { string strSql = "insert into T_Role_Rights([RoleId],[Function]) values('{0}','{1}')"; strSql = string.Format(strSql, strRoleId, treeNode.Text.Trim()); sqls.Add(strSql); } db.Exec_Tansaction(sqls); MessageBox.Show("更新成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); InitDataGridView(this.curSelectRowIndex); //btnCancel_Click(null, null); } else { //插入 string strSql_ = "select * from T_Roles where Ltrim(Rtrim(RoleName))='{0}'"; strSql_ = string.Format(strSql_, this.s_RoleName.Text.Trim()); if (dbUtil.yn_exist_data(strSql_)) { MessageBox.Show("该角色名已存在!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } db.ExecuteNonQuery(strSqlInsert); //分配权限 string strRoleId = this.s_RoleId.Text.Trim(); if (strRoleId != "") { List<string> sqls = new List<string>(); List<TreeNode> checkedNodes = new List<TreeNode>();//存储所有的选中的叶子菜单项 UserPermission(this.treeViewMenus, checkedNodes); foreach (TreeNode treeNode in checkedNodes) { string strSql = "insert into T_Role_Rights([RoleId],[Function]) values('{0}','{1}')"; strSql = string.Format(strSql, strRoleId, treeNode.Text.Trim()); sqls.Add(strSql); } db.Exec_Tansaction(sqls); } MessageBox.Show("添加成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); InitDataGridView(0); btnCancel_Click(null, null); } }
private void btnOk_Click(object sender, EventArgs e) { #region 输入验证 if (Util.ControlTextIsNUll(this.s_UserId)) { MessageBox.Show("用户编码不能为空!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (!Util.IsContainCharNumber(this.s_UserId, 10)) { MessageBox.Show("用户编码不能为空!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (Util.ControlTextIsNUll(this.s_UserName)) { MessageBox.Show("用户名不能为空!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //if (Util.ControlTextIsNUll(this.s_SmsTel)) //{ // MessageBox.Show("接收短信电话号码不能为空!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); // return; //} //if (Util.IsPhoneNumber(this.s_SmsTel,11) == false) //{ // MessageBox.Show("接收短信电话号码输入错误!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); // return; //} if (this.s_OfficeTel.Text.Trim() != "" && Util.IsNumberic(this.s_OfficeTel) == false) { MessageBox.Show("办公电话输入错误!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); s_OfficeTel.Focus(); return; } if (this.s_MobileTel.Text.Trim() != "" && Util.IsNumberic(this.s_MobileTel) == false) { MessageBox.Show("移动电话输入错误!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); s_MobileTel.Focus(); return; } if (this.s_Email.Text.Trim() != "" && Util.IsEmail(this.s_Email.Text.Trim()) == false) { MessageBox.Show("Email输入错误!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); s_Email.Focus(); return; } if (this.s_PassWord.Text.Trim() != "" && this.s_PassWord.Text.Trim() != this.txtPasswordCheck.Text.Trim()) { MessageBox.Show("您两次输入的密码不一致,请重新输入!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); s_PassWord.Focus(); return; } #endregion //数据处理 SqlDBConnect db = new SqlDBConnect(); InitFuncs initFuncs = new InitFuncs(); DBUtil dbUtil = new DBUtil(); string strSql = ""; string strSql_ = ""; if (this.type == "add") { string strSqlInsert = initFuncs.Build_Insert_Sql(this.panelUser, "T_Users"); //插入之前首先判断是否存在该用户 bool isExist = dbUtil.Is_Exist_Data("T_Users", "UserId", this.s_UserId.Text.Trim()); if (isExist == true) //该用户名已存在 { MessageBox.Show("该用户已存在!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } strSql_ = "select * from T_Users where Ltrim(Rtrim(UserName))='{0}'"; strSql_ = string.Format(strSql_, this.s_UserName.Text.Trim()); //插入 strSql = initFuncs.Build_Insert_Sql(this.panelUser, "T_Users"); } else if (this.type == "edit") { //更新 strSql_ = "select * from T_Users where Ltrim(Rtrim(UserId)) != '{0}' and Ltrim(Rtrim(UserName))='{1}'"; strSql_ = string.Format(strSql_, this.s_UserId.Text.Trim(), this.s_UserName.Text.Trim()); string strSqlWhere = "where UserId='" + this.s_UserId.Text.Trim() + "'"; strSql = initFuncs.Build_Update_Sql(this.panelUser, "T_Users", strSqlWhere); } if (dbUtil.yn_exist_data(strSql_)) { MessageBox.Show("该用户已存在!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } db.ExecuteNonQuery(strSql); MessageBox.Show("保存成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); userInfoFormChange(); //激活代理事件,在UserForm中处理 this.Close(); }