コード例 #1
0
        public bool GetPreviousSequenceMachinesByProcessId(int processId, out List <ProductSequenceItem> machines)
        {
            machines = new List <ProductSequenceItem>(0);
            var check = CheckIfInitialized();

            if (!check)
            {
                return(false);
            }


            var result = new SqlParameter("@result", SqlDbType.Int)
            {
                Direction = ParameterDirection.Output
            };
            var parameters = new[]
            {
                new SqlParameter("@processId", SqlDbType.NVarChar, 30)
                {
                    SqlValue = processId
                },
                result
            };

            try
            {
                var dataset = SqlHelper.ExecuteDataset(_dbConnection, CommandType.StoredProcedure, "GetPreviousSequenceMachinesByProcessId", parameters);
                if (dataset.Tables.Count <= 0)
                {
                    return(false);
                }
                var tables   = dataset.Tables[0];
                var rowCount = tables.Rows.Count;
                if (rowCount <= 0)
                {
                    return(false);
                }
                machines = new List <ProductSequenceItem>(rowCount);

                foreach (DataRow row in tables.Rows)
                {
                    var machine = new ProductSequenceItem
                    {
                        Id                = row.Field <int>("Id"),
                        Level             = row.Field <int>("Level"),
                        MachineFamilyId   = row.Field <int>("MachineFamilyId"),
                        ProductSequenceId = row.Field <int>("ProductSequenceId"),
                        MachineFamilyname = row.Field <string>("MachineFamilyname")
                    };
                    machines.Add(machine);
                }
                return(true);
            }
            catch (Exception exception)
            {
                MachineHookException?.Invoke(@"Get Sequence Machine : " + exception.Message);
                return(false);
            }
        }
コード例 #2
0
        public bool LoadReferenceCheck(string reference, out int productId)
        {
            productId             = -1;
            _thisMachineReference = new Product();
            reference             = reference.Trim();
            var check = CheckIfInitialized();

            if (!check)
            {
                return(false);
            }
            var result = new SqlParameter("@result", SqlDbType.Int)
            {
                Direction = ParameterDirection.Output,
            };

            var parameters = new[]
            {
                new SqlParameter("@reference", SqlDbType.NVarChar, 30)
                {
                    SqlValue = reference
                },
                result
            };

            try
            {
                var product = SqlHelper.ExecuteDataset(_dbConnection, CommandType.StoredProcedure, "usp_LoadReference",
                                                       parameters);

                var code = Convert.ToInt32(result.SqlValue.ToString());
                if (code > 0)
                {
                    if (product?.Tables.Count > 0)
                    {
                        if (product.Tables[0].Rows.Count > 0)
                        {
                            var row = product.Tables[0].Rows[0];
                            _thisMachineReference = new Product()
                            {
                                Id            = row.Field <int>("Id"),
                                ArticleNumber = row.Field <string>("ArticleNumber"),
                                Reference     = row.Field <string>("Reference"),
                                SequenceId    = row.Field <int?>("SequenceId"),
                                SequenceName  = row.Field <string>("SequenceName")
                            };
                            productId = _thisMachineReference.Id;
                            return(true);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                MachineHookException?.Invoke(exception.Message);
                return(false);
            }
            return(false);
        }
コード例 #3
0
        public bool ProductRename(string currentDataMatrix, string newDataMatrix)
        {
            var status = -1;
            var check  = CheckIfInitialized();

            if (!check)
            {
                return(false);
            }

            //Check if the product are same reference
            ReferenceParsed parsedCurrentDataMatrix;
            ReferenceParsed parsedNewDataMatrix;

            ParseProductFullName(currentDataMatrix, out parsedCurrentDataMatrix);
            ParseProductFullName(newDataMatrix, out parsedNewDataMatrix);
            if (!(parsedNewDataMatrix.ArticlePart == parsedCurrentDataMatrix.ArticlePart && parsedNewDataMatrix.ReferencePart == parsedCurrentDataMatrix.ReferencePart))
            {
                return(false);
            }


            var result = new SqlParameter("@result", SqlDbType.Int)
            {
                Direction = ParameterDirection.Output
            };
            var parameters = new[]
            {
                new SqlParameter("@currentDataMatrix", SqlDbType.NVarChar, 40)
                {
                    SqlValue = currentDataMatrix
                },
                new SqlParameter("@newDataMatrix", SqlDbType.NVarChar, 40)
                {
                    SqlValue = newDataMatrix
                },
                result
            };

            try
            {
                var i = SqlHelper.ExecuteNonQuery(_dbConnection, CommandType.StoredProcedure, "usp_ProductRename", parameters);
            }
            catch (Exception exception)
            {
                MachineHookException?.Invoke(exception.Message);
                return(false);
            }

            status = Convert.ToInt32(result.SqlValue.ToString());

            if (status > 0)
            {
                return(true);
            }

            return(false);
        }
コード例 #4
0
        public bool GetProductLastProcessWithDetails(string productFullName, out ProductProcessWithDetails lastProcessedInMachine)
        {
            lastProcessedInMachine = new ProductProcessWithDetails();
            var check = CheckIfInitialized();

            if (!check)
            {
                return(false);
            }
            var parameters = new[]
            {
                new SqlParameter("@productFullName", SqlDbType.NVarChar, 50)
                {
                    SqlValue = productFullName
                }
            };

            try
            {
                var dbMachine = SqlHelper.ExecuteDataset(_dbConnection, CommandType.StoredProcedure,
                                                         "usp_GetProductLastMachineProcessDetails",
                                                         parameters);

                if (dbMachine?.Tables.Count > 0)
                {
                    if (dbMachine.Tables[0].Rows.Count > 0)
                    {
                        var row = dbMachine.Tables[0].Rows[0];
                        lastProcessedInMachine = new ProductProcessWithDetails()
                        {
                            Id              = row.Field <int>("Id"),
                            DateTime        = row.Field <DateTime>("DateTime"),
                            DataMatrix      = row.Field <string>("FullName"),
                            MachineName     = row.Field <string>("MachineName"),
                            Reference       = row.Field <string>("Reference"),
                            Remarks         = row.Field <string>("Remarks"),
                            Result          = row.Field <ProcessResult>("Result"),
                            WorkOrderNumber = row.Field <string>("WorkOrderNumber")
                        };
                        if (lastProcessedInMachine.Id > 0)
                        {
                            return(true);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                MachineHookException?.Invoke(exception.Message);
            }
            return(false);
        }
コード例 #5
0
        public bool ProductDismantle(string productFullName, string remarks, out int status)
        {
            status = -1;
            var check = CheckIfInitialized();

            if (!check)
            {
                return(false);
            }


            var result = new SqlParameter("@result", SqlDbType.Int)
            {
                Direction = ParameterDirection.Output
            };
            var parameters = new[]
            {
                new SqlParameter("@ProductFullName", SqlDbType.NVarChar, 50)
                {
                    SqlValue = productFullName
                },
                new SqlParameter("@Remarks", SqlDbType.NVarChar, 20)
                {
                    SqlValue = remarks
                },
                new SqlParameter("@machineId", SqlDbType.Int)
                {
                    SqlValue = _thisMachine.Id
                },
                result
            };

            try
            {
                var i = SqlHelper.ExecuteNonQuery(_dbConnection, CommandType.StoredProcedure, "usp_ProductDismantle", parameters);
            }
            catch (Exception exception)
            {
                MachineHookException?.Invoke(exception.Message);
                return(false);
            }

            status = Convert.ToInt32(result.SqlValue.ToString());

            if (status > 0)
            {
                return(true);
            }

            return(false);
        }
コード例 #6
0
        public bool ProductProcessJumpBack(int processId, int jumpBackToMachineFamily)
        {
            var status = -1;
            var check  = CheckIfInitialized();

            if (!check)
            {
                return(false);
            }


            var result = new SqlParameter("@result", SqlDbType.Int)
            {
                Direction = ParameterDirection.Output
            };
            var parameters = new[]
            {
                new SqlParameter("@processId", SqlDbType.NVarChar, 40)
                {
                    SqlValue = processId
                },
                new SqlParameter("@jumpBackToMachineFamily", SqlDbType.Int)
                {
                    SqlValue = jumpBackToMachineFamily
                },
                result
            };

            try
            {
                var i = SqlHelper.ExecuteNonQuery(_dbConnection, CommandType.StoredProcedure, "usp_ProductProcessJumpBack", parameters);
            }
            catch (Exception exception)
            {
                MachineHookException?.Invoke(exception.Message);
                return(false);
            }

            status = Convert.ToInt32(result.SqlValue.ToString());

            if (status > 0)
            {
                return(true);
            }

            return(false);
        }
コード例 #7
0
        public bool GetMachineBySerialNumber(string serialNumber, string connection, out Machine resultMachine)
        {
            resultMachine = new Machine();
            var parameters = new[]
            {
                new SqlParameter("@SerialNumber", SqlDbType.NVarChar, 20)
                {
                    SqlValue = serialNumber
                }
            };

            try
            {
                var dbMachine = SqlHelper.ExecuteDataset(connection, CommandType.StoredProcedure,
                                                         "usp_GetMachineBySerialNumber",
                                                         parameters);

                if (dbMachine?.Tables.Count > 0)
                {
                    if (dbMachine.Tables[0].Rows.Count > 0)
                    {
                        var row = dbMachine.Tables[0].Rows[0];
                        resultMachine = new Machine()
                        {
                            Id                = row.Field <int>("Id"),
                            Name              = row.Field <string>("Name"),
                            SerialNumber      = row.Field <string>("SerialNumber"),
                            MachineFamilyId   = row.Field <int?>("MachineFamilyId"),
                            ProductionLineId  = row.Field <int?>("ProductionLineId"),
                            MachineFamilyName = row.Field <string>("MachineFamilyName"),
                        };
                        return(true);
                    }
                }
            }
            catch (Exception exception)
            {
                MachineHookException?.Invoke(exception.Message);
            }

            return(false);
        }
コード例 #8
0
        public bool Initialize()
        {
            _setting = new SettingHook();
            try
            {
                _dbConnection          = _setting.GetDatabaseConnectionString();
                _traceabilityIsEnabled = _setting.GetEnableTraceability();
                _machineSerialNumber   = _setting.MachineSerialNumber();
                _uniqueIdLength        = _setting.GetUniqueIdLength();
                _allowCrossWorkOrder   = _setting.GetAllowCrossWorkOrder();
            }
            catch (Exception exception)
            {
                MachineHookException?.Invoke(exception.Message);
                return(false);
            }
            var result = GetMachineBySerialNumber(_machineSerialNumber, _dbConnection, out _thisMachine);

            return(CheckIfInitialized());
        }
コード例 #9
0
        public bool GetProductByReference(string reference, out int productId)
        {
            productId = -1;
            var check = CheckIfInitialized();

            if (!check)
            {
                return(false);
            }
            var result = new SqlParameter("@result", SqlDbType.Int)
            {
                Direction = ParameterDirection.Output,
            };
            var parameters = new[]
            {
                new SqlParameter("@reference", SqlDbType.NVarChar, 20)
                {
                    SqlValue = reference
                },
                result
            };

            try
            {
                var i = SqlHelper.ExecuteNonQuery(_dbConnection, CommandType.StoredProcedure, "usp_GetProductByReference",
                                                  parameters);
            }
            catch (Exception exception)
            {
                MachineHookException?.Invoke(exception.Message);
                return(false);
            }
            productId = Convert.ToInt32(result.SqlValue.ToString());
            if (productId > 0)
            {
                return(true);
            }
            return(false);
        }
コード例 #10
0
        public bool GetMachineSequenceItem()
        {
            _thisMachineSequenceItem = new ProductSequenceItem();
            var check = CheckIfInitialized();

            if (!check)
            {
                return(false);
            }
            var result = new SqlParameter("@result", SqlDbType.Int)
            {
                Direction = ParameterDirection.Output,
            };

            var parameters = new[]
            {
                new SqlParameter("@SequenceId", SqlDbType.Int)
                {
                    SqlValue = _thisMachineReference.SequenceId
                },
                new SqlParameter("@MachineFamilyId", SqlDbType.Int)
                {
                    SqlValue = _thisMachine.MachineFamilyId
                },
                result
            };

            try
            {
                var prev = SqlHelper.ExecuteDataset(_dbConnection, CommandType.StoredProcedure,
                                                    "usp_GetMachineSequenceItem",
                                                    parameters);
                var code = Convert.ToInt32(result.SqlValue.ToString());
                if (code < 1)
                {
                    return(false);
                }

                if (prev?.Tables.Count > 0)
                {
                    if (prev.Tables[0].Rows.Count > 0)
                    {
                        var row = prev.Tables[0].Rows[0];
                        _thisMachineSequenceItem = new ProductSequenceItem()
                        {
                            Id                = row.Field <int>("Id"),
                            Level             = row.Field <int>("Level"),
                            MachineFamilyId   = row.Field <int>("MachineFamilyId"),
                            ProductSequenceId = row.Field <int>("ProductSequenceId"),
                            MachineFamilyname = row.Field <string>("MachineFamilyname")
                        };
                        return(true);
                    }
                }
            }
            catch (Exception exception)
            {
                MachineHookException?.Invoke(exception.Message);
            }
            return(false);
        }
コード例 #11
0
        public bool CreateWorkOrderIfNotExisted(string workOrderNumber, int productId, int target, out int workorderId)
        {
            workorderId = -1;
            var check = CheckIfInitialized();

            if (!check)
            {
                return(false);
            }
            var result = new SqlParameter("@result", SqlDbType.Int)
            {
                Direction = ParameterDirection.Output,
            };

            var parameters = new[]
            {
                new SqlParameter("@WorkOderNumber", SqlDbType.NVarChar, 20)
                {
                    SqlValue = workOrderNumber
                },
                new SqlParameter("@productId", SqlDbType.Int)
                {
                    SqlValue = productId
                },
                new SqlParameter("@Target", SqlDbType.Int)
                {
                    SqlValue = target
                },
                new SqlParameter("@EntryThroughMachineId", SqlDbType.Int)
                {
                    SqlValue = _thisMachine.Id
                },
                result
            };

            try
            {
                var workorder = SqlHelper.ExecuteDataset(_dbConnection, CommandType.StoredProcedure,
                                                         "usp_CreateWorkOrderIfNotExisted",
                                                         parameters);
                workorderId = Convert.ToInt32(result.SqlValue.ToString());
                if (workorderId <= 0)
                {
                    return(false);
                }
                if (workorder?.Tables.Count > 0)
                {
                    if (workorder.Tables[0].Rows.Count > 0)
                    {
                        var row = workorder.Tables[0].Rows[0];
                        _thisMachineWorkorder = new Workorder()
                        {
                            Id     = row.Field <int>("Id"),
                            Number = row.Field <string>("Number"),
                            EntryThroughMachineId = row.Field <int>("EntryThroughMachineId"),
                            DateTime    = row.Field <DateTime>("DateTime"),
                            Quantity    = row.Field <int>("Quantity"),
                            ReferenceId = row.Field <int>("ReferenceId")
                        };
                        return(true);
                    }
                }
            }
            catch (Exception exception)
            {
                MachineHookException?.Invoke(exception.Message);
            }
            return(false);
        }
コード例 #12
0
        public bool StartProductTraceability(string productFullName, string remarks, out int status)
        {
            status = -1;
            var check = CheckIfInitialized();

            if (!check)
            {
                return(false);
            }

            ReferenceParsed parsed;
            var             checkName = ParseProductFullName(productFullName, out parsed);

            if (!checkName)
            {
                return(false);
            }
            if (_thisMachinePreviousSequenceMachineFamily.Id > 0)
            {
                MachineHookErrorOccured?.Invoke("Machine is not an Id Generator");
                return(false);
            }

            var result = new SqlParameter("@result", SqlDbType.Int)
            {
                Direction = ParameterDirection.Output,
            };
            var parameters = new[]
            {
                new SqlParameter("@productFullName", SqlDbType.NVarChar, 50)
                {
                    SqlValue = productFullName
                },
                new SqlParameter("@reference", SqlDbType.NVarChar, 30)
                {
                    SqlValue = parsed.ReferencePart
                },
                new SqlParameter("@machineId", SqlDbType.Int)
                {
                    SqlValue = _thisMachine.Id
                },
                new SqlParameter("@workOrderId", SqlDbType.Int)
                {
                    SqlValue = _thisMachineWorkorder.Id
                },
                new SqlParameter("@Remarks", SqlDbType.NVarChar, 50)
                {
                    SqlValue = remarks
                },
                new SqlParameter("@SequenceItemId", SqlDbType.Int)
                {
                    SqlValue = _thisMachineSequenceItem.Id
                },
                new SqlParameter("@ProcessResult", SqlDbType.Int)
                {
                    SqlValue = ProcessResult.Generated
                },
                result
            };

            try
            {
                var i = SqlHelper.ExecuteNonQuery(_dbConnection, CommandType.StoredProcedure,
                                                  "usp_StartProductTraceability",
                                                  parameters);
            }
            catch (Exception exception)
            {
                MachineHookException?.Invoke(exception.Message);
                return(false);
            }
            status = result.Value != null?Convert.ToInt32(result.SqlValue.ToString()) : -1;

            if (status > 0)
            {
                return(true);
            }
            return(false);
        }
コード例 #13
0
        public bool UpdateProductStatusNOk(string productFullName, string remarks, out int status)
        {
            status = -1;
            var check = CheckIfInitialized();

            if (!check)
            {
                return(false);
            }

            ReferenceParsed parsed;

            ParseProductFullName(productFullName, out parsed);
            if (parsed.ReferencePart != _thisMachineReference.Reference)
            {
                MachineHookErrorOccured?.Invoke("Reference Not Matched");
                return(false);
            }
            var result = new SqlParameter("@result", SqlDbType.Int)
            {
                Direction = ParameterDirection.Output
            };
            var parameters = new[]
            {
                new SqlParameter("@ProductFullName", SqlDbType.NVarChar, 50)
                {
                    SqlValue = productFullName
                },
                new SqlParameter("@Reference", SqlDbType.NVarChar, 20)
                {
                    SqlValue = parsed.ReferencePart
                },
                new SqlParameter("@Remarks", SqlDbType.NVarChar, 20)
                {
                    SqlValue = remarks
                },
                new SqlParameter("@machineId", SqlDbType.Int)
                {
                    SqlValue = _thisMachine.Id
                },
                new SqlParameter("@SequenceId", SqlDbType.Int)
                {
                    SqlValue = _thisMachineReference.SequenceId
                },
                new SqlParameter("@ProductId", SqlDbType.Int)
                {
                    SqlValue = _thisMachineReference.Id
                },
                new SqlParameter("@MachineFamilyId", SqlDbType.Int)
                {
                    SqlValue = _thisMachine.MachineFamilyId
                },
                result
            };

            try
            {
                var i = SqlHelper.ExecuteNonQuery(_dbConnection, CommandType.StoredProcedure, "usp_UpdateProductStatusNOk", parameters);
            }
            catch (Exception exception)
            {
                MachineHookException?.Invoke(exception.Message);
                return(false);
            }
            status = Convert.ToInt32(result.SqlValue.ToString());

            if (status > 0)
            {
                return(true);
            }

            return(false);
        }