public string GetCarName(Image image) { var client = new RestClient("http://api.openfpt.vn/anpr"); var request = new RestRequest(Method.POST); request.AddHeader("content-type", "multipart/form-data"); request.AddHeader("api_key", "3fa389a41e084709a9f2eecfcfd764b4"); MemoryStream ms = new MemoryStream(); image.Save(ms, System.Drawing.Imaging.ImageFormat.Png); byte[] imageBytes = ms.ToArray(); request.AddFileBytes("image", imageBytes, "image"); IRestResponse response = client.Execute(request); string content = response.Content; if (content != null) { string[] pl = content.Split('"', '{', '}', ',', ':'); //for (int i = 0; i < pl.Length; i++) //{ // if (pl[i] != "") MessageBox.Show("Test " + i + " is " + pl[i]); //} if (pl.Length > 5) { string result = pl[5]; if (cam != null && cam.IsRunning) { cam.Stop(); } tblCarDAO camc = new tblCarDAO(); string carname = camc.checkCarReturnName(result); if (carname != null) { return(carname); } } else { MessageBox.Show("please take photo again"); } } else { MessageBox.Show("please take photo again"); } return(null); }
private void btnTakePicture_Click(object sender, EventArgs e) { if (checkKeyCode == false) { if (pictureBox1.Image != null) { Image image = (Image)pictureBox1.Image.Clone(); string carname = GetCarName(image); if (carname != null) { pictureBox1.Image = image; tblParkDAO parkDao = new tblParkDAO(); bool checkPark = parkDao.CheckBooked(carname); if (checkPark == true) { welcomeForm w = new welcomeForm("Welcome " + carname, this); w.Show(); tblHistoryDAO camc = new tblHistoryDAO(); camc.CreateHistory(carname); } else { MessageBox.Show("You do not have booked place, we will fill you in the random place"); bool haveBlankPalce = parkDao.CreateRamdomPlace(carname); if (haveBlankPalce == true) { parkDao.CheckBooked(carname); welcomeForm w = new welcomeForm("Welcome " + carname, this); w.Show(); tblHistoryDAO camc = new tblHistoryDAO(); camc.CreateHistory(carname); } else { MessageBox.Show("We don't have blank slot, sorrry guy!"); } } } else { MessageBox.Show("You car is invaliable"); } } else { MessageBox.Show("start first!!!!!"); } } else { if (pictureBox1.Image != null) { Image image = (Image)pictureBox1.Image.Clone(); string carname = GetCarName(image); tblCarDAO carDao = new tblCarDAO(); if (carname != null && carDao.getCarIdByCarName(carname) == shareHis.carID) { pictureBox1.Image = image; tblParkDAO parkDao = new tblParkDAO(); parkDao.UpdateParkingSlot(carname); tblHistoryDAO hisDao = new tblHistoryDAO(); hisDao.UpdateFullHistory(carname); welcomeForm w = new welcomeForm("GoodBye " + carname, this); w.Show(); } else { MessageBox.Show("the code not for this car!"); } } else { MessageBox.Show("start first!!!!!"); } } }