/// <summary> /// 通过物料代码查找 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void txtMaterielCode_TextChanged(object sender, EventArgs e) { if (!string.IsNullOrEmpty(txtMaterielCode.Text)) { string sql = " exec GetdataByTaskNo '','" + txtMaterielCode.Text + "'"; using (SqlConnection conn = new SqlConnection(MyDataLib.ConnString())) { conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) //判断有数据 { txtMaterielCode.Text = reader["fnumber"].ToString(); //物料单号 txtCustomer.Text = reader["f_102"].ToString(); //客户 txtSpec.Text = reader["fmodel"].ToString(); //规格 txtProTotal.Text = reader["FAuxQty"].ToString(); //数量 txtProNum.Text = reader["mtsl"].ToString(); //每托数量 txtProDirection.Text = reader["direction"].ToString(); //方向 } else { return;//返回 } } } }
/// <summary> /// 删除产品 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDeleteProduct_Click(object sender, EventArgs e) { if (dgvProductSetting.Rows.Count == 0) { MessageBox.Show("没有产品信息可以删除!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else if (dgvProductSetting.CurrentRow.Selected == false) { MessageBox.Show("请选择要删除的产品信息条目!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else { ProductInfo objProduct; //通过夺取查找 objProduct = productMethod.GetProductByZone(int.Parse(dgvProductSetting.CurrentRow.Cells[5].Value.ToString()), GLB.objListProduct); string info = "您确定要删除信息【任务单号:" + dgvProductSetting.CurrentRow.Cells[2].Value.ToString() + "垛区:" + dgvProductSetting.CurrentRow.Cells[5].Value.ToString() + "】信息吗?"; DialogResult result = MessageBox.Show(info, "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { try { //执行删除动作 productMethod.DeleteProduct(objProduct, GLB.objListProduct); //待加数据库删除 string sql = "delete from dbo.StowMissionn_list where StowNo='" + objProduct.RobotID + "'and TaskNo='" + objProduct.MissionID + "'and area='" + objProduct.Zone + "' and yxbz='Y'"; int i = MyDataLib.ExecNoneQueryBySql(sql); //提示删除成功 MessageBox.Show("删除成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); btnCancel_Click(null, null); //更新界面数据 } catch (Exception ex) { MessageBox.Show("删除失败,具体原因:" + ex.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { return; } } }
/// <summary> /// 保存到数据库 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtRobotID.Text)) { MessageBox.Show("机器人ID不能为空", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (string.IsNullOrEmpty(txtcompleteStowCode.Text)) { MessageBox.Show("完成堆垛托号不能为空", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (string.IsNullOrEmpty(txtMaterielCode.Text)) { MessageBox.Show("物料代码不能为空", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (string.IsNullOrEmpty(txtCustomer.Text)) { MessageBox.Show("客户名称不能为空,不为零", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (string.IsNullOrEmpty(txtProTotal.Text) || int.Parse(txtProTotal.Text) == 0) { MessageBox.Show("产品总量不能为空", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (string.IsNullOrEmpty(txtComepleteNum.Text)) { MessageBox.Show("完成数量不能为空", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (string.IsNullOrEmpty(txtProNum.Text)) { MessageBox.Show("每垛可堆产品数量不能为空", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (string.IsNullOrEmpty(txtProZone.Text)) { MessageBox.Show("产品所属垛区不能为空", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (string.IsNullOrEmpty(txtProDirection.Text)) { MessageBox.Show("产品码垛方向不能为空", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (string.IsNullOrEmpty(txtCurrentCounts.Text)) { MessageBox.Show("产品已经码垛数量不能为空", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!string.IsNullOrEmpty(txtProZone.Text) && GLB.zoneCheckStatus[int.Parse(txtProZone.Text)] == false) { MessageBox.Show("该托盘没有识别位置成功!", "系统消息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } ProductInfo product = new ProductInfo { RobotID = txtRobotID.Text.Trim().ToString(), //机器人编号 completeStowCode = txtcompleteStowCode.Text.Trim(), //完成堆垛托号 MissionID = txtMissionID.Text.Trim().ToString(), //任务单号 Customer = txtCustomer.Text.Trim().ToString(), //客户 Zone = int.Parse(txtProZone.Text.Trim()), //垛区 Total = (int)double.Parse(txtProTotal.Text.Trim()), //总数 ComepleteNum = int.Parse(txtComepleteNum.Text.Trim()), //完成数量 CurrentCounts = int.Parse(txtCurrentCounts.Text.Trim()), //已码数量 PerZoneNumbers = int.Parse(txtProNum.Text.Trim()), //每垛数量 Direction = int.Parse(txtProDirection.Text.Trim()), //方向 MaterielCode = txtMaterielCode.Text.Trim().ToString(), //物料代码 Spec = txtSpec.Text.Trim().ToString(), //规格 }; DialogResult result = MessageBox.Show("是否覆盖第" + txtProZone.Text.Trim() + "垛区订单?", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.No) { return; } if (product.Zone == 0) { if (product.CurrentCounts == 0) { //删除不良品记录 string sql = "delete from StowNgStatus "; MyDataLib.ExecNoneQueryBySql(sql); MessageBox.Show("确保不良区已经清空?", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else if (int.Parse(txtCurrentCounts.Text) > int.Parse(txtProNum.Text)) { MessageBox.Show("垛区当前产品数量大于每垛产品总数量", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } switch (actionFlag) { case 1: //Add try { productMethod.AddProduct(product, GLB.objListProduct); gpbProductSet.Enabled = false; MessageBox.Show("新增产品信息成功", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); btnCancel_Click(null, null); //更新界面数据 productMethod.updateMyDataLib(product); //添加新产品---更新数据库 } catch (Exception ex) { MessageBox.Show("添加失败,具体原因:" + ex.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } break; case 2: //Modify try { productMethod.ChangeProduct(product, GLB.objListProduct); gpbProductSet.Enabled = false; MessageBox.Show("修改产品信息成功", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); btnCancel_Click(null, null); //更新界面数据 productMethod.changeProInfo(product); //修改产品--更新数据库 } catch (Exception ex) { MessageBox.Show("修改失败,具体原因:" + ex.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } break; default: break; } }
FileOperation fileOperation = new FileOperation();//实例化处理文本的类 /// <summary> /// 获取各区块的轮廓 /// </summary> public void getContours(TextBox txtTypeName, PictureBox ptb) //找最近的轮廓 { GLB.Match_success = false; //重新检测赋值 Image <Gray, byte> dnc = new Image <Gray, byte>(GLB.BUFW, GLB.BUFH); Image <Gray, byte> threshImage = new Image <Gray, byte>(GLB.BUFW, GLB.BUFH); CvInvoke.CvtColor(GLB.frame, threshImage, ColorConversion.Bgra2Gray);//灰度化 //CvInvoke.BilateralFilter(threshImage, threshImage, 10, 10, 4);//双边滤波 //CvInvoke.GaussianBlur(threshImage, threshImage, new Size(3, 3), 4);//高斯滤波 CvInvoke.BoxFilter(threshImage, threshImage, Emgu.CV.CvEnum.DepthType.Cv8U, new Size(3, 3), new Point(-1, -1));//方框滤波 #region //var kernal1 = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(3, 3), new Point(-1, -1)); //CvInvoke.Dilate(threshImage, threshImage, kernal1, new Point(-1, -1), 2, BorderType.Default, new MCvScalar());//膨胀 //var kernal1 = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(3, 3), new Point(-1, -1)); //CvInvoke.Erode(threshImage, threshImage, kernal1, new Point(-1, -1), 2, BorderType.Default, new MCvScalar());//腐蚀 //方式1 //CvInvoke.Threshold(threshImage, threshImage, 100, 255, ThresholdType.BinaryInv | ThresholdType.Otsu);//二值化 //if (Mainform.runMode == 6)//匹配托盘 //{ // var kernal1 = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(9, 9), new Point(-1, -1)); // CvInvoke.Erode(threshImage, threshImage, kernal1, new Point(-1, -1), 1, BorderType.Default, new MCvScalar());//腐蚀 //} //else//匹配箱子 //{ // var kernal1 = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(3, 3), new Point(-1, -1)); // CvInvoke.Erode(threshImage, threshImage, kernal1, new Point(-1, -1), 2, BorderType.Default, new MCvScalar());//腐蚀 //} //方式2 //if (Mainform.runMode == 6)//匹配托盘 //{ // var kernal1 = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(9, 9), new Point(-1, -1)); // CvInvoke.Dilate(threshImage, threshImage, kernal1, new Point(-1, -1), 1, BorderType.Default, new MCvScalar());//膨胀 //} //else //加了膨胀跳动更大 //{ // var kernal1 = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(5, 5), new Point(-1, -1)); // CvInvoke.Dilate(threshImage, threshImage, kernal1, new Point(-1, -1), 1, BorderType.Default, new MCvScalar());//膨胀 //} //ptb.Image = threshImage.ToBitmap(); #endregion //检测连通域,每一个连通域以一系列的点表示,FindContours方法只能得到第一个域: try { VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint(2000); //区块集合 CvInvoke.FindContours(threshImage, contours, dnc, RetrType.Ccomp, ChainApproxMethod.ChainApproxSimple); //轮廓集合 GLB.block_num = 0; Dictionary <int, VectorOfPoint> mycontours = new Dictionary <int, VectorOfPoint>(100);//序号,轮廓 mycontours.Clear(); for (int k = 0; k < contours.Size; k++) { double area = CvInvoke.ContourArea(contours[k]); //获取各连通域的面积 if (area > 100000 && area < 800000) //根据面积作筛选(指定最小面积,最大面积): { if (!mycontours.ContainsKey(k)) { mycontours.Add(k, contours[k]); } } } float my_depth_temp = GLB.myp3d[(GLB.BUFH / 2 * GLB.BUFW + GLB.BUFW / 2) * 3 + 2]; if (mycontours.Count == 0 && Mainform.ProduceArrive == true && Mainform.CarryMode == 0 && Mainform.runMode == 1 && (my_depth_temp > 1400 || double.IsNaN(my_depth_temp)))//空车来,小车自动离开 { Mainform.ProduceArrive = false; Mainform.SetCarryArrive(0); //修改产品没送到 ArrayList array = new ArrayList(); //多条SQL语句数组 string sql = "update Agv_list set isworking =0,stowerid ='',pronum =0 where agvid in(select agvid from Agvmission_list where fstatus =7 and messionType =1 and stowerid='" + GLB.RobotId + "')"; //修改小车状态 string sql1 = "update Agvmission_list set fstatus =6 ,actionenddate=getdate() where fstatus =7 and messionType =1 and stowerid='" + GLB.RobotId + "'"; //修改任务 等待状态为完成状态 array.Add(sql); array.Add(sql1); bool isok = MyDataLib.transactionOp_list(array); Mainform.SetRobotStatus(2, "等待送货");//修改码垛机器人状态 } //按面积最大排序 生成新的字典 Dictionary <int, VectorOfPoint> mycontours_SortedByKey = new Dictionary <int, VectorOfPoint>(100);//序号,轮廓; mycontours_SortedByKey.Clear(); mycontours_SortedByKey = mycontours.OrderByDescending(o => CvInvoke.ContourArea(o.Value)).ToDictionary(p => p.Key, o => o.Value); GLB.obj.Clear(); foreach (int k in mycontours_SortedByKey.Keys) { OBJ obj = new OBJ(); { if (!GLB.obj.ContainsKey(GLB.block_num)) { GLB.obj.Add(GLB.block_num, obj); //不含这个,就添加 } GLB.obj[GLB.block_num].typName = txtTypeName.Text.Replace(" ", ""); // 对象名称 if (getMinAreaRect(mycontours_SortedByKey[k], GLB.block_num) == true) //获取最小外接矩形并处理相关参数 { if (GLB.img_mode == 0) //匹配模式 { if (Device_Macth(GLB.block_num) == true) //与库对比,生成工件位置,法向量,旋转角 { Thread.Sleep(400); break; } } } GLB.TitleStr += "block_num=" + GLB.block_num; GLB.block_num++;//区块计数器 } } } catch (Exception ex) { Console.WriteLine("发生错误: " + ex.Message); throw; } }