Beispiel #1
0
        private void sbtnOk_Click(object sender, EventArgs e)
        {
            sbtnOk.Enabled = false;

            #region  输入 判断

            string strToolId   = tbToolID.Text.Trim();//strToolId
            string strRFID     = tbRFID.Text.Trim();
            string strToolType = cbbToolType.Text.Trim();
            string strToolName = cbbToolName.Text.Trim();
            string strPlace    = tbPlace.Text.Trim();
            string strPeople   = cbbOverPeople.Text.Trim();
            string strTime     = dtpTime.Text;

            if (string.IsNullOrEmpty(strToolId))
            {
                MessageUtil.ShowTips("工具ID不可为空");
                return;
            }
            if (string.IsNullOrEmpty(strPlace))
            {
                MessageUtil.ShowTips("工具存放位置不可为空");
                return;
            }
            if (this.Tag != null)
            {
                string strSql = "";
                if (this.Tag.ToString() == TagType.修改.ToString())
                {
                    strSql = "Select ID From tb_Tools where ToolID='" + strToolId + "' and ID<>'" + sId + "'";
                }
                else if (this.Tag.ToString() == TagType.添加.ToString())
                {
                    strSql = "Select ID From tb_Tools where ToolID='" + strToolId + "' ";
                }
                if (!string.IsNullOrEmpty(strSql))
                {
                    if (operatedata.blCheckHas(strSql))
                    {
                        MessageUtil.ShowTips("工具ID重复,请重新输入");
                        return;
                    }
                }
            }

            if (cboxRfid.Checked)
            {
                if (string.IsNullOrEmpty(strRFID))
                {
                    MessageUtil.ShowTips("RFID编号不可为空");
                    return;
                }
                else
                {
                    if (strRFID.Length != 12)
                    {
                        MessageUtil.ShowTips("RFID编号格式错误,请重新输入");
                        return;
                    }
                    else
                    {
                        if (this.Tag != null)
                        {
                            string strSql = "";
                            if (this.Tag.ToString() == TagType.修改.ToString())
                            {
                                strSql = "Select ID From tb_Tools where RFIDCoding='" + strRFID + "' and ID<>'" + sId + "'";
                            }
                            else if (this.Tag.ToString() == TagType.添加.ToString())
                            {
                                strSql = "Select ID From tb_Tools where RFIDCoding='" + strRFID + "' ";
                            }
                            if (!string.IsNullOrEmpty(strSql))
                            {
                                if (operatedata.blCheckHas(strSql))
                                {
                                    MessageUtil.ShowTips("RFID编号重复,请重新输入");
                                    return;
                                }
                            }
                        }
                    }
                }
            }


            #endregion

            #region 入库记录 及 写RFID

            if (this.Tag != null)
            {
                if (this.Tag.ToString() == TagType.修改.ToString())
                {
                    string strSql = "update tb_Tools set tvParent='" + strTreeSeleParent + "',ToolType='" + strToolType + "',ToolName='" + strToolName + "'" +
                                    ",ToolID='" + strToolId + "',RFIDCoding='" + strRFID + "',StoragePlace='" + strPlace + "' ,TestCycle='" + tbCycle.Text + "'" +
                                    "where ID='" + sId + "' ";
                    datalogic.SqlComNonQuery(strSql);
                    this.Close();
                }
                else if (this.Tag.ToString() == TagType.添加.ToString())
                {
                    try
                    {
                        int    WriteEPCResult = 1;
                        string strWriteEPC    = tbRFID.Text;
                        if (cboxRfid.Checked)
                        {
                            //strWriteEPC = MainControl.strServerAddr + strWriteEPC;
                            byte   WriteEPClen = Convert.ToByte(strWriteEPC.Length / 4); //WriteEPC的字节长度   ////byte WriteEPClen = Convert.ToByte(strWriteEPC.Length / 4);//WriteEPC的字节长度   //20151109 8616
                            byte[] WriteEPC    = new byte[WriteEPClen];                  //访问密码数组形式
                            //WriteEPC = HexStringToByteArray(strWriteEPC);
                            WriteEPC = SerialPortUtil.HexStrToByte(strWriteEPC);
                            byte[] PassWord = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00 };                                                              //byte[] PassWord = new byte[] { 0x00, 0x00, 0x00, 0x00 }; //  20151109 8616
                            for (int i = 0; i < 50; i++)                                                                                                //最多写50次
                            {
                                WriteEPCResult = StaticClassReaderB.WriteEPC_G2(ref ComAdr, PassWord, WriteEPC, WriteEPClen, ref errorcode, frmHandle); //fCmdRet = StaticClassReaderB.WriteEPC_G2(ref fComAdr, fPassWord, EPC, ENum, ref ferrorcode, frmcomportindex);
                                if (WriteEPCResult == 0)
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            WriteEPCResult = 0;
                            strWriteEPC    = "";
                        }

                        if (WriteEPCResult == 0)//写RFID成功
                        {
                            #region 更新 显示树

                            TreeNode node = new TreeNode();
                            //获取ChildId
                            string strChild = operatedata.GetChildId("tb_Tools", "tvChildId");
                            node.Name = strChild;// node.Name 为本节点的编号
                            string strParent = treeView1.SelectedNode.Name.ToString();
                            node.Tag                = strParent;
                            node.Text               = strToolId;
                            node.ImageIndex         = 3;
                            node.SelectedImageIndex = 3;
                            treeView1.SelectedNode.Nodes.Add(node);
                            //treeView1.CollapseAll();

                            #endregion


                            string strTimeBorrRet = DateTime.Now.AddMinutes(-1).ToString("yyyy-MM-dd HH:mm:ss");
                            string strSql         = "insert into tb_Tools (tvParent,tvChildId,IsArea,ToolType,ToolName,ToolID,RFIDCoding,StoragePlace,InPeople,InTime,IsInStore," +
                                                    "TestCycle,TestState,BorrowReturnTime)" +
                                                    "values ('" + strParent + "','" + strChild + "','" + ToolAreaType.工具.ToString() + "','" + strToolType + "','" + strToolName + "'," +
                                                    "'" + strToolId + "','" + strWriteEPC + "','" + strPlace + "','" + strPeople + "','" + strTime + "'," +
                                                    "'" + ToolsState.在库.ToString() + "','" + tbCycle.Text + "','未录入试验记录','" + strTime + "')";
                            datalogic.SqlComNonQuery(strSql);

                            strSql = "insert into tb_RecordInRoom (ToolType,ToolName,ToolID,RFIDCoding,StoragePlace,InPeople,InTime) values ('" + strToolType + "'," +
                                     "'" + strToolName + "','" + strToolId + "','" + strWriteEPC + "','" + strPlace + "','" + strPeople + "','" + strTime + "')";
                            datalogic.SqlComNonQuery(strSql);

                            #region  自动生成工具ID

                            string strName = cbbToolName.Text;
                            strSql = "select top 1 ToolID from tb_Tools where IsArea='" + ToolAreaType.工具.ToString() + "' " +
                                     "and ToolName='" + strName + "' order by id desc ";// select top 1 * from table order by id desc
                            object ob = datalogic.SqlComScalar(strSql);

                            int iNo = 0;
                            if (ob != null)
                            {
                                int iLength = strName.Length;
                                strToolId = ob.ToString();
                                string strNameOfId = strToolId.Substring(0, iLength);//strToolId中的工具名称 绝缘手套007 绝缘手套
                                if (strName == strNameOfId)
                                {
                                    if ((strToolId.Length - iLength) == 3)//数字部分的长度
                                    {
                                        string strNo = strToolId.Substring(iLength, 3);
                                        try
                                        {
                                            iNo = Convert.ToInt32(strNo);
                                        }
                                        catch (Exception ex)
                                        {
                                            //iNo = 0;
                                            if (frmMain.blDebug)
                                            {
                                                MessageUtil.ShowTips(ex.Message);
                                            }
                                        }
                                    }
                                }
                            }

                            iNo++;
                            string striNo = iNo.ToString();
                            int    iLen   = 3 - striNo.Length;
                            striNo           = clsCommon.FormatString(iLen) + striNo;
                            tbToolIdAdd.Text = striNo;
                            tbToolID.Text    = strName + striNo;

                            #endregion

                            #region  自动生成 RFID

                            if (cboxRfid.Checked)
                            {
                                //工具名称编码 tbRfidName
                                strSql = "select ToolsNameCoding from tb_TypeAndName where ToolName='" + cbbToolName.Text + "' ";
                                ob     = datalogic.SqlComScalar(strSql);
                                if (ob != null)
                                {
                                    string strServerAddrRfid = infoOfSystem.strServerAddr;
                                    if (strServerAddrRfid.Length == 1)
                                    {
                                        strServerAddrRfid = "000" + strServerAddrRfid;
                                    }
                                    else if (strServerAddrRfid.Length == 2)
                                    {
                                        strServerAddrRfid = "00" + strServerAddrRfid;
                                    }
                                    if (strServerAddrRfid.Length > 4)
                                    {
                                        strServerAddrRfid = strServerAddrRfid.Substring(0, 4);
                                    }
                                    tbRfidName.Text = strServerAddrRfid + ob.ToString();
                                }

                                //RFID 编码
                                strSql = "select top 1 RFIDCoding from tb_Tools where IsArea='" + ToolAreaType.工具.ToString() + "' and " +
                                         "ToolName='" + strName + "' order by id desc ";// select top 1 * from table order by id desc
                                ob  = datalogic.SqlComScalar(strSql);
                                iNo = 0;
                                if (ob != null)
                                {
                                    string strLastCoding = ob.ToString();
                                    if (strLastCoding.Length == 12)
                                    {
                                        string strLastNo = strLastCoding.Substring(8, 4);
                                        iNo = Convert.ToInt32(strLastNo);
                                    }
                                }

                                iNo++;
                                striNo        = iNo.ToString();
                                iLen          = 4 - striNo.Length;
                                striNo        = clsCommon.FormatString(iLen) + striNo;
                                tbRfidNo.Text = striNo;
                                tbRFID.Text   = tbRfidName.Text + tbRfidNo.Text;
                            }



                            #endregion
                        }
                        else
                        {
                            MessageUtil.ShowError("工具入库失败,请检查RFID标签是否正确放置或重新录");
                        }
                    }
                    catch (Exception ex)
                    {
                        if (frmMain.blDebug)
                        {
                            MessageUtil.ShowError(ex.ToString());
                        }
                        //MessageUtil.ShowError("工具入库失败,请检查RFID标签是否正确放置、RFID读卡器是否正确连接或重新录入");
                    }
                }
            }

            #endregion

            //sbtnOk.Enabled = true;

            treeView1.SelectedNode = null;
        }
Beispiel #2
0
        private void sbtnTypeOk_Click(object sender, EventArgs e)
        {
            #region 输入 判断
            string strType = tbType.Text.Trim();
            if (string.IsNullOrEmpty(strType))
            {
                MessageUtil.ShowTips("工具种类不可为空");
                return;
            }
            if (strType.Length > 50)
            {
                strType = strType.Substring(0, 50);
            }

            string strSame = "";
            if (EditType == TagType.添加)
            {
                strSame = "Select ID From tb_TypeAndName where ToolType='" + strType + "' ";
            }
            else if (EditType == TagType.修改)
            {
                strSame = "Select ID From tb_TypeAndName where ToolType='" + strType + "' and tvChildId<>'" + strAlterChildId + "' ";
            }
            if (!string.IsNullOrEmpty(strSame))
            {
                if (operatedata.blCheckHas(strSame))
                {
                    MessageUtil.ShowTips("工具种类重复,请重新输入");
                    return;
                }
            }

            #endregion

            string strParent = "";
            string strChild  = "";
            if (EditType == TagType.添加)
            {
                TreeNode node = new TreeNode();
                //获取ChildId
                strChild                = operatedata.GetChildId("tb_TypeAndName", "tvChildId");
                node.Name               = strChild;// node.Name 为本节点的编号
                strParent               = "0";
                node.Tag                = strParent;
                node.Text               = strType;
                node.ImageIndex         = 0;
                node.SelectedImageIndex = 0;
                treeView1.Nodes.Add(node);
                string strSql = "insert into tb_TypeAndName (tvParent,tvChildId,ToolType) values ('" + strParent + "'," +
                                "'" + strChild + "','" + strType + "')";
                datalogic.SqlComNonQuery(strSql);
                treeView1.ExpandAll();
            }
            else if (EditType == TagType.修改)
            {
                treeView1.SelectedNode.Text = strType;
                string strSql = "update tb_TypeAndName set ToolType='" + strType + "' where tvChildId='" + strAlterChildId + "' ";
                datalogic.SqlComNonQuery(strSql);
                strSql = "update tb_Tools set ToolType='" + strType + "' where ToolType='" + strNoAlterType + "' ";
                datalogic.SqlComNonQuery(strSql);
                ShowNew();
            }
        }
Beispiel #3
0
        private void sbtnAreaOk_Click(object sender, EventArgs e)
        {
            #region 输入 判断
            string strAreaName = tbAreaName.Text.Trim();
            if (string.IsNullOrEmpty(strAreaName))
            {
                MessageUtil.ShowTips("区域名称不可为空");
                return;
            }
            if (strAreaName.Length > 50)
            {
                strAreaName = strAreaName.Substring(0, 50);
            }

            string strSame = "";
            if (EditType == TagType.添加)
            {
                strSame = "Select ID From tb_Tools where AreaName='" + strAreaName + "' and IsArea='" + ToolAreaType.区域.ToString() + "'";
            }
            else if (EditType == TagType.修改)
            {
                strSame = "Select ID From tb_Tools where AreaName='" + strAreaName + "' and IsArea='" + ToolAreaType.区域.ToString() + "' and tvChildId<>'" + strAlterChildId + "' ";
            }
            if (!string.IsNullOrEmpty(strSame))
            {
                if (operatedata.blCheckHas(strSame))
                {
                    MessageUtil.ShowTips("区域名称重复,请重新输入");
                    return;
                }
            }

            #endregion

            string strParent = "";
            string strChild  = "";
            if (EditType == TagType.添加)
            {
                TreeNode node = new TreeNode();
                if (treeView1.SelectedNode == null)
                {
                    //获取ChildId
                    strChild                = operatedata.GetChildId("tb_Tools", "tvChildId");
                    node.Name               = strChild;// node.Name 为本节点的编号
                    strParent               = "0";
                    node.Tag                = strParent;
                    node.Text               = strAreaName;
                    node.ImageIndex         = 0;
                    node.SelectedImageIndex = 0;
                    treeView1.Nodes.Add(node);
                }
                else
                {
                    //获取ChildId
                    strChild                = operatedata.GetChildId("tb_Tools", "tvChildId");
                    node.Name               = strChild;// node.Name 为本节点的编号
                    strParent               = treeView1.SelectedNode.Name.ToString();
                    node.Tag                = strParent;
                    node.Text               = strAreaName;
                    node.ImageIndex         = 1;
                    node.SelectedImageIndex = 1;
                    treeView1.SelectedNode.Nodes.Add(node);
                }
                string strSql = "insert into tb_Tools (tvParent,tvChildId,IsArea,AreaName) values ('" + strParent + "'," +
                                "'" + strChild + "','" + ToolAreaType.区域.ToString() + "','" + strAreaName + "')";
                datalogic.SqlComNonQuery(strSql);
                treeView1.ExpandAll();
            }
            else if (EditType == TagType.修改)
            {
                treeView1.SelectedNode.Text = strAreaName;
                string strSql = "update tb_Tools set AreaName='" + strAreaName + "' where tvChildId='" + strAlterChildId + "' ";
                datalogic.SqlComNonQuery(strSql);
                if (treeView1.SelectedNode.FirstNode != null)
                {
                    if (treeView1.SelectedNode.FirstNode.ImageIndex == 2 || treeView1.SelectedNode.FirstNode.ImageIndex == 4)
                    {
                        strSql = "update tb_Tools set AreaName='" + strAreaName + "' where tvParent='" + strAlterChildId + "' ";
                        datalogic.SqlComNonQuery(strSql);
                    }
                }
                ShowNew();
            }
        }