예제 #1
0
        //them object xe
        public bool insertVehicle(vehicleDTO vel)
        {
            try
            {
                this.openConnection();

                SqlCommand cmd = new SqlCommand("INSERT INTO VEHICLE(id,type, img1, img2, park, fix, wash)" +
                                                "VALUES (@id,@type, @img1,@img2, @park, @fix, @wash)", this.getConnection);
                cmd.Parameters.Add("@id", SqlDbType.NChar).Value   = vel.id;
                cmd.Parameters.Add("@type", SqlDbType.Int).Value   = vel.type;
                cmd.Parameters.Add("@img1", SqlDbType.Image).Value = vel.Img1.ToArray();
                cmd.Parameters.Add("@img2", SqlDbType.Image).Value = vel.Img2.ToArray();
                cmd.Parameters.Add("@park", SqlDbType.Int).Value   = vel.park;
                cmd.Parameters.Add("@fix", SqlDbType.Int).Value    = vel.fix;
                cmd.Parameters.Add("@wash", SqlDbType.Int).Value   = vel.wash;
                if (cmd.ExecuteNonQuery() == 1)
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: ", ex.Message);
            }
            finally
            {
                this.closeConnection();
            }
            return(false);
        }
        private void btnSuaXe_Click(object sender, EventArgs e)
        {
            if (this.vehBUS.CheckID_Exited(this.txtID.Text.Trim()))
            {
                MessageBox.Show("ID xe đã tồn tại trong bãi xe", "Gửi Xe", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Warning);
                this.txtID.Text = "";
            }
            else
            {
                if (this.picBox1.Image == null || this.picBox2.Image == null)
                {
                    MessageBox.Show("Can't insert new vehicle if you don't upload your image", "Insert object", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (this.txtID.Text.Trim() == "")
                {
                    MessageBox.Show("Can't insert new vehicle if you don't have id", "Insert object", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    int type = this.cbLoaiXe.SelectedIndex;

                    MemoryStream pic1 = new MemoryStream();
                    this.picBox1.Image.Save(pic1, this.picBox1.Image.RawFormat);

                    MemoryStream pic2 = new MemoryStream();
                    this.picBox2.Image.Save(pic2, this.picBox2.Image.RawFormat);

                    vehicleDTO vehDTO = new vehicleDTO(this.txtID.Text.Trim(), type, pic1, pic2, 0, 0, 0);

                    if (this.vehBUS.insertVehicle(vehDTO))
                    {
                        MessageBox.Show("Successfully~~");

                        //thu phi
                        this.openForm_Sua(vehDTO, type);
                        //end
                    }
                    else
                    {
                        MessageBox.Show("Unsuccessfully~~");
                    }
                }
            }
        }
 //open child form sửa
 public void openForm_Sua(vehicleDTO vel, int type)
 {
     this.formQuanLyXeGui.openChildForm(new fphiSuaXe(vel.id, formQuanLyXeGui, type, 0));
 }
 //open child form gửi
 public void openForm_Gui(vehicleDTO vel)
 {
     this.formQuanLyXeGui.openChildForm(new fphiGuiXe(vel.id, formQuanLyXeGui, 0));
 }