private void ButRepair_Click(object sender, EventArgs e) { try { // 1.验证输入内容是否有效 if (TextAddress.Text.Trim().Equals("")) { MessageBox.Show("报修地点不能为空", "提示"); TextAddress.Focus(); return; } else if (TextContent.Text.Trim().Equals("")) { MessageBox.Show("报修内容不能为空", "提示"); TextContent.Focus(); return; } else if (ComType.SelectedIndex == -1) { MessageBox.Show("请选择报修类型", "提示"); ComType.Focus(); return; } // 验证数据库中是否已经有相同的报修 string id = "select userId from user_info where userName = '******'"; DataSet user = DBconn.getData(id); string sqlStr = "select repairId,repairCount from repairtable where userId = '" + user.Tables[0].Rows[0][0] + "'"; DataSet ds = DBconn.getData(sqlStr); //如果ds里面不存在数据,说明这个用户第一次报修,直接插入新的记录 if (ds.Tables[0].Rows.Count == 0) { string sqlInsert = "insert into repairtable(userId,repairContent,repairDate," + "repairStatus,repairAddress,repairType,repairCount)values('" + user.Tables[0].Rows[0][0] + "','" + TextContent.Text + "','" + DateRepair.Value + "','" + "待维修" + "','" + TextAddress.Text + "','" + ComType.Text + "','" + 1 + "')"; DBconn.upData(sqlInsert); MessageBox.Show("报修成功!"); ClearAll(); } else { //否则的话就是repairtable表里已经有了LanUser里的这个用户。目的就是更新这个用户的报修次数,并插入新的记录 int count = ds.Tables[0].Rows.Count; string sqlInsert = "insert into repairtable(userId,repairContent,repairDate," + "repairStatus,repairAddress,repairType,repairCount)values('" + user.Tables[0].Rows[0][0] + "','" + TextContent.Text + "','" + DateRepair.Value + "','" + "待维修" + "','" + TextAddress.Text + "','" + ComType.Text + "','" + (count + 1) + "')"; DBconn.upData(sqlInsert); MessageBox.Show("报修成功!"); ClearAll(); } } catch (Exception ex) { MessageBox.Show("报修出错:" + ex.Message); TextContent.Focus(); } finally { // 最后关闭数据库 DBconn.conn.Close(); } }
private bool IsCheckInput() { if (string.IsNullOrEmpty(this.TextCrowName.Text)) { MessageBox.Show("众筹名称不能为空!", "提示"); TextCrowName.Focus(); return(false); } if (string.IsNullOrEmpty(this.TextBeginDate.Text)) { MessageBox.Show("开始时间不能为空!", "提示"); TextBeginDate.Focus(); return(false); } if (string.IsNullOrEmpty(this.TextEndDate.Text)) { MessageBox.Show("结束时间不能为空!", "提示"); TextEndDate.Focus(); return(false); } if (TextBeginDate.Value <= DateTime.Now) { MessageBox.Show("开始时间必须晚于今天!", "提示"); TextBeginDate.Focus(); return(false); } if (TextBeginDate.Value >= TextEndDate.Value) { MessageBox.Show("开始时间必须早于结束时间!", "提示"); TextEndDate.Focus(); return(false); } if (this.CityControl.GetCity() == null) { MessageBox.Show("城市不能为空!", "提示"); CityControl.Focus(); return(false); } if (string.IsNullOrEmpty(this.TextAddress.Text.Trim())) { MessageBox.Show("服务地点详细地址不能为空!", "提示"); TextAddress.Focus(); return(false); } if (string.IsNullOrEmpty(this.TextServiceDuration.Text)) { MessageBox.Show("服务时长不能为空!", "提示"); TextServiceDuration.Focus(); return(false); } if (this.TextActor.SelectActor == null) { MessageBox.Show("服务艺人不能为空!", "提示"); TextActor.Focus(); return(false); } if (string.IsNullOrEmpty(this.TextServiceCost.Text.Trim())) { MessageBox.Show("服务费用不能为空!", "提示"); TextServiceCost.Focus(); return(false); } if (string.IsNullOrEmpty(this.TextNote.HtmlContent.Trim())) { MessageBox.Show("注意事项不能为空!", "提示"); TextNote.Focus(); return(false); } if (string.IsNullOrEmpty(this.TextFrontImg.GetUrl().Trim())) { MessageBox.Show("封面图不能为空!", "提示"); TextFrontImg.Focus(); return(false); } if (string.IsNullOrEmpty(this.TextServiceIntro.HtmlContent.Trim())) { MessageBox.Show("封面图不能为空!", "提示"); TextServiceIntro.Focus(); return(false); } if (this.TextCrowDetail.CtTypes.Count == 0) { MessageBox.Show("众筹详情不能为空!", "提示"); TextCrowDetail.Focus(); return(false); } return(true); }