Example #1
0
 // 修改按钮
 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     try {
         if (dataGridView1.Columns[e.ColumnIndex].Name == "ColumnRe" && e.ColumnIndex >= 0)
         {
             //说明点击的列是DataGridViewButtonColumn列
             DataGridViewColumn column = dataGridView1.Columns[e.ColumnIndex];
             // MessageBox.Show(dataGridView1.CurrentRow.Cells[0].Value.ToString());
             // 获取需要修改的状态
             string strStatus = Convert.ToString(dataGridView1.CurrentRow.Cells[6].Value);
             if (strStatus.Equals("待维修"))
             {
                 // 弹出消息框,并获取消息框的返回值
                 DialogResult dr = MessageBox.Show("是否已经维修?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                 if (dr == DialogResult.Yes)
                 {
                     // 修改状态数据库语句
                     string sql = "update repairtable set repairStatus = '" + "已维修" + "' where repairId = '" + int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString()) + "'";
                     DBconn.upData(sql);
                     // 修改窗体状态语句
                     dataGridView1.CurrentRow.Cells[6].Value = "已维修";
                     dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[6].Style.BackColor = Color.Aqua;
                 }
             }
             else
             {
                 // 弹出消息框,并获取消息框的返回值
                 DialogResult dr = MessageBox.Show("是否未维修?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                 if (dr == DialogResult.Yes)
                 {
                     // 修改状态数据库语句
                     string sql = "update repairtable set repairStatus = '" + "待维修" + "'where repairId = '" + int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString()) + "'";
                     DBconn.upData(sql);
                     // 修改窗体状态语句
                     dataGridView1.CurrentRow.Cells[6].Value = "待维修";
                     dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[6].Style.BackColor = Color.Pink;
                 }
             }
         }
     }catch (Exception ex)
     {
         MessageBox.Show("修改失败" + ex.Message);
     }
     finally
     {
         // 最后关闭数据库
         DBconn.conn.Close();
     }
 }
Example #2
0
        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();
            }
        }