Ejemplo n.º 1
0
 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         if (e.ColumnIndex == dataGridView1.Columns["btnsave"].Index)
         {
             int index = e.RowIndex;
             if (dataGridView1.Rows[index].Cells[1].Value.ToString() == "admin")
             {
                 MessageBox.Show("禁止修改管理员用户", "系统提示");
                 return;
             }
             qzj_vehicle model = new qzj_vehicle();
             model.VEHICLENAME      = dataGridView1.Rows[index].Cells[0].Value.ToString();
             model.LEFTTURNLEFT     = double.Parse(dataGridView1.Rows[index].Cells[1].Value.ToString());
             model.LEFTTURNRIGHT    = double.Parse(dataGridView1.Rows[index].Cells[2].Value.ToString());
             model.RIGHTTURNLEFT    = double.Parse(dataGridView1.Rows[index].Cells[3].Value.ToString());
             model.RIGHTTURNRIGHT   = double.Parse(dataGridView1.Rows[index].Cells[4].Value.ToString());
             model.LEFTTURNLEFTWC   = double.Parse(dataGridView1.Rows[index].Cells[5].Value.ToString());
             model.LEFTTURNRIGHTWC  = double.Parse(dataGridView1.Rows[index].Cells[6].Value.ToString());
             model.RIGHTTURNLEFTWC  = double.Parse(dataGridView1.Rows[index].Cells[7].Value.ToString());
             model.RIGHTTURNRIGHTWC = double.Parse(dataGridView1.Rows[index].Cells[8].Value.ToString());
             if (SqlControl.updateVehicle(model))
             {
                 MessageBox.Show("更改成功", "系统提示");
             }
             else
             {
                 MessageBox.Show("未知原因导致信息更改失败", "系统提示");
             }
         }
         else if (e.ColumnIndex == dataGridView1.Columns["btndelete"].Index)
         {
             int index = e.RowIndex;
             if (dataGridView1.Rows[index].Cells[0].Value.ToString() == "DEFAULT")
             {
                 MessageBox.Show("禁止删除DEFAULT车型信息", "系统提示");
             }
             else
             {
                 SqlControl.deleteVehicle(dataGridView1.Rows[index].Cells[0].Value.ToString());
                 MessageBox.Show("删除成功", "系统提示");
                 ref_Staff();
             }
         }
     }
     catch (Exception er)
     {
         MessageBox.Show("操作失败:" + er.Message, "系统提示");
     }
 }
Ejemplo n.º 2
0
        public static bool getVehicleXz(string vehiclename, out qzj_vehicle model)
        {
            model = new qzj_vehicle();
            bool result = false;

            try
            {
                OleDbConnection adoConn = new OleDbConnection();
                adoConn.ConnectionString = strConn;
                adoConn.Open();
                OleDbCommand     cmd   = adoConn.CreateCommand();
                OleDbTransaction Trans = adoConn.BeginTransaction();
                cmd.Transaction = Trans;
                Trans.Rollback();
                try
                {
                    logControl.saveLogInf("连接数据库成功");
                    string          checksql  = "select * from QZJ_VEHICLE where VEHICLENAME='" + vehiclename + "'";
                    OleDbCommand    datacheck = new OleDbCommand(checksql, adoConn);
                    OleDbDataReader reader    = datacheck.ExecuteReader();
                    if (reader.HasRows)
                    {
                        reader.Read();
                        model.VEHICLENAME      = reader["VEHICLENAME"].ToString();
                        model.LEFTTURNLEFT     = double.Parse(reader["LEFTTURNLEFT"].ToString());
                        model.LEFTTURNRIGHT    = double.Parse(reader["LEFTTURNRIGHT"].ToString());
                        model.RIGHTTURNLEFT    = double.Parse(reader["RIGHTTURNLEFT"].ToString());
                        model.RIGHTTURNRIGHT   = double.Parse(reader["RIGHTTURNRIGHT"].ToString());
                        model.LEFTTURNLEFTWC   = double.Parse(reader["LEFTTURNLEFTWC"].ToString());
                        model.LEFTTURNRIGHTWC  = double.Parse(reader["LEFTTURNRIGHTWC"].ToString());
                        model.RIGHTTURNLEFTWC  = double.Parse(reader["RIGHTTURNLEFTWC"].ToString());
                        model.RIGHTTURNRIGHTWC = double.Parse(reader["RIGHTTURNRIGHTWC"].ToString());
                        result = true;
                        //return dt;
                    }
                }
                catch (Exception er)
                {
                    logControl.saveLogInf("查询数据发生异常:" + er.Message);
                    Trans.Rollback();
                }
                adoConn.Close();
            }
            catch (Exception er)
            {
                logControl.saveLogInf("链接到驰达数据库失败:" + er.Message);
            }
            return(result);
        }
Ejemplo n.º 3
0
        public static bool updateVehicle(qzj_vehicle model)
        {
            bool result;

            try
            {
                OleDbConnection adoConn = new OleDbConnection();
                adoConn.ConnectionString = strConn;
                adoConn.Open();
                OleDbCommand     cmd   = adoConn.CreateCommand();
                OleDbTransaction Trans = adoConn.BeginTransaction();
                cmd.Transaction = Trans;
                Trans.Rollback();
                try
                {
                    logControl.saveLogInf("连接数据库成功");
                    string           updatesql   = SqlBuilderHelper.UpdateSql <qzj_vehicle>(model, "QZJ_VEHICLE", "VEHICLENAME='" + model.VEHICLENAME + "'");
                    OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
                    dataAdapter.InsertCommand             = new OleDbCommand(updatesql, adoConn);
                    dataAdapter.InsertCommand.CommandText = updatesql;
                    if (dataAdapter.InsertCommand.ExecuteNonQuery() > 0)
                    {
                        result = true;
                        logControl.saveLogInf("插入数据成功");
                    }
                    else
                    {
                        result = false;
                        logControl.saveLogInf("插入数据失败");
                    }
                    dataAdapter.Dispose();
                }
                catch (Exception er)
                {
                    result = false;
                    logControl.saveLogInf("更新数据发生异常:" + er.Message);
                    Trans.Rollback();
                }
                adoConn.Close();
            }
            catch (Exception er)
            {
                result = false;
                logControl.saveLogInf("链接到数据库失败:" + er.Message);
            }
            return(result);
        }
Ejemplo n.º 4
0
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         qzj_vehicle model = new qzj_vehicle();
         model.VEHICLENAME      = textBoxVehicleName.Text;
         model.LEFTTURNLEFT     = double.Parse(textBoxll.Text);
         model.LEFTTURNRIGHT    = double.Parse(textBoxlr.Text);
         model.RIGHTTURNLEFT    = double.Parse(textBoxrl.Text);
         model.RIGHTTURNRIGHT   = double.Parse(textBoxrr.Text);
         model.LEFTTURNLEFTWC   = double.Parse(textBoxllwc.Text);
         model.LEFTTURNRIGHTWC  = double.Parse(textBoxlrwc.Text);
         model.RIGHTTURNLEFTWC  = double.Parse(textBoxrlwc.Text);
         model.RIGHTTURNRIGHTWC = double.Parse(textBoxrrwc.Text);
         if (model.VEHICLENAME.Trim() == "")
         {
             MessageBox.Show("请先填写车型名称", "系统提示");
             return;
         }
         if (SqlControl.checkVehicleIsAlive(model.VEHICLENAME))
         {
             MessageBox.Show("此车型信息已存在,请勿重复添加", "系统提示");
         }
         else if (SqlControl.insertVehicle(model))
         {
             MessageBox.Show("添加成功", "系统提示");
         }
         else
         {
             MessageBox.Show("添加失败", "系统提示");
         }
         ref_Staff();
     }
     catch
     {
         MessageBox.Show("数据格式有误", "系统提示");
     }
 }