Exemple #1
0
        void WorkClientAdd(object sender, Socket e)
        {
            string       strIp = (e.RemoteEndPoint as IPEndPoint).Address.ToString();
            YBDTWorkInfo yw    = GetWorkInfoFromLst(YbdtWorkInfoLst, strIp);

            if (yw != null)
            {
                YBDTWork ybdtwork = new YBDTWork(e, yw);
                if (ybdtwork.YbtdDevice.Status == Constant.DeviceConnected)
                {
                    YBDTWorkChanged(Constant.AddWork, ybdtwork);
                }
                else
                {
                    ybdtwork.Dispose();
                }
            }
        }
Exemple #2
0
        public void YBDTWorkChanged(int op, YBDTWork ybdtwork)
        {
            switch (op)
            {
            case Constant.AddWork:
            {
                if (YbdtWorkLst != null)
                {
                    //按照正产逻辑 消息 是一层一层往上报的
                    ybdtwork.YbtdDevice.SocManager.WorkManger = this;
                    ybdtwork.InitControl();
                    ybdtwork.ShiftPage(0);
                    YbdtWorkLst.Add(ybdtwork);
                    if (ydtdWorkChangedEvent != null)
                    {
                        ydtdWorkChangedEvent(this, ybdtwork);
                    }
                }

                break;
            }

            case Constant.DelWork:
            {
                if (YbdtWorkLst != null)
                {
                    YbdtWorkLst.Remove(ybdtwork);
                    if (ydtdWorkChangedEvent != null)
                    {
                        ydtdWorkChangedEvent(this, ybdtwork);
                    }
                }
                break;
            }
            }
        }
Exemple #3
0
 public void SetYbtdWork(YBDTWork yw)
 {
     YbdtWork = yw;
     dataGridView1.DataSource = YbdtWork.YbtdDevice.DataFormLst[0];
 }
Exemple #4
0
        public void GetDataFromSql(DataGridView dg1)
        {
            //DataRow[] dr = showDataTable.Select("设备编号='ybtj0056'");
            if (ybdtWorkLst != null && ybdtWorkLst.Count > 0)
            {
                for (int j = 0; j < ybdtWorkLst.Count; j++)
                // foreach (YBDTWork ywork in ybdtWorkLst)
                {
                    YBDTWork ywork = ybdtWorkLst[j];
                    if (ywork == null)
                    {
                        break;
                    }
                    DataRow[] dr = showDataTable.Select("设备编号=" + "'" + ywork.YbdtWorkInfo.DeviceId + "'");
                    Dictionary <string, string> dic = ywork.PackAllData();
                    if (dic != null && dic.Count > 0)
                    {
                    }
                    else
                    {
                        return;
                    }

                    List <string> value = new List <string>();

                    for (int i = 0; i < ShowDataTable.Columns.Count; i++)
                    {
                        value.Add(dic[ShowDataTable.Columns[i].ColumnName]);
                    }

                    if (dr.Length == 0)
                    {
                        DataRow dr0 = showDataTable.NewRow();

                        if (value.Count > 0)
                        {
                            dr0.ItemArray = value.ToArray();
                        }
                        showDataTable.Rows.Add(dr0);
                    }
                    else
                    {
                        dr[0].ItemArray = value.ToArray();
                    }
                }
            }

            if (showDataTable.Rows.Count != ybdtWorkLst.Count)
            {
                for (int i = showDataTable.Rows.Count - 1; i > -1; i--)
                {
                    string decviceId = showDataTable.Rows[i]["设备编号"].ToString();
                    bool   isDelete  = true;
                    for (int j = 0; j < ybdtWorkLst.Count; j++)
                    {
                        if (ybdtWorkLst[j].YbdtWorkInfo.DeviceId.Equals(decviceId))
                        {
                            isDelete = false;
                        }
                    }
                    if (isDelete)
                    {
                        showDataTable.Rows.RemoveAt(i);
                    }
                }
            }


            /****
             * string sqlStr = "SELECT * FROM deviceinfo" + " WHERE ";
             *
             * if (ybdtWorkLst.Count == 0)
             * {
             *  dg1.DataSource = null;
             *  if(SqlShowDataTable !=null)
             *  SqlShowDataTable.Rows.Clear();
             *  return;
             * }
             *
             * for(int i=0;i<YbdtWorkLst.Count;i++)
             * {
             *
             *  if (i == YbdtWorkLst.Count - 1)
             *  {
             *      sqlStr += "设备地址=" + "'" + YbdtWorkLst[i].YbdtWorkInfo.DeviceIP + "'";
             *  }
             *  else
             *  {
             *      sqlStr += "设备地址=" + "'" + YbdtWorkLst[i].YbdtWorkInfo.DeviceIP + "'" + " or ";
             *  }
             *
             * }
             *
             * DataTable dt0 = SqlHelper.ExecuteDataTable(sqlStr);
             *
             *
             * if (SqlShowDataTable == null || dt0.Rows.Count != SqlShowDataTable.Rows.Count || SqlShowDataTable.Rows.Count ==0)
             * {
             *  SqlShowDataTable = dt0.Copy();
             *  DataTableShowItem(SqlShowDataTable, itemShowStr.ToArray());
             *  dg1.DataSource = SqlShowDataTable;
             * }
             * else
             * {
             *  for (int i = 0; i < dt0.Rows.Count; i++)
             *  {
             *      for (int j = 0; j < SqlShowDataTable.Columns.Count; j++)
             *      {
             *          if (j < dt0.Columns.Count)
             *          {
             *              SqlShowDataTable.Rows[i][j] = dt0.Rows[i][SqlShowDataTable.Columns[j].ColumnName];
             *          }
             *      }
             *  }
             * }
             ***/
        }