Exemplo n.º 1
0
        public int GetSerialsFromPartDest(string operatorCode, string destination, string part, decimal quantity)
        {
            var dt     = new ObjectParameter("TranDT", typeof(DateTime));
            var result = new ObjectParameter("Result", typeof(int));

            try
            {
                using (var context = new MONITOREntities())
                {
                    context.usp_CreateRma_GetSerialsFromPartDest(operatorCode, destination, part, quantity, dt, result);

                    var query = from s in context.SerialsQuantitiesToAutoRMA_RTV
                                select s;

                    foreach (var item in query)
                    {
                        _serialQuantityDataModel = new SerialQuantityDataModel
                        {
                            Serial   = item.Serial,
                            Quantity = Math.Round(item.Quantity, 2)
                        };
                        SerialsList.Add(_serialQuantityDataModel);
                    }
                }
            }
            catch (Exception ex)
            {
                string error = (ex.InnerException == null) ? ex.Message : ex.InnerException.Message;
                _messages.Message = String.Format("Failed to create serials for part {0}.  Error: {1}", part, error);
                _messages.ShowDialog();
                return(0);
            }
            return(1);
        }
        public void GetSerialsFromPartDest(string operatorCode, string destination, string part, decimal quantity, out string error)
        {
            var dt     = new ObjectParameter("TranDT", typeof(DateTime));
            var result = new ObjectParameter("Result", typeof(int));

            error = "";
            try
            {
                using (var context = new MONITOREntities())
                {
                    context.usp_CreateRma_GetSerialsFromPartDest(operatorCode, destination, part, quantity, dt, result);

                    var query = from s in context.SerialsQuantitiesToAutoRMA_RTV
                                where s.OperatorCode == operatorCode
                                select s;

                    foreach (var item in query)
                    {
                        _serialQuantityDataModel = new SerialQuantityDataModel
                        {
                            Serial   = item.Serial,
                            Quantity = Math.Round(item.Quantity, 2)
                        };

                        // Querying the SerialsQuantitiesToAutoRMA_RTV table every time will duplicate List items,
                        //   so only add an item if it isn't already in the List.
                        if (!SerialsList.Any(x => x.Serial == item.Serial))
                        {
                            SerialsList.Add(_serialQuantityDataModel);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string errorMsg = (ex.InnerException == null) ? ex.Message : ex.InnerException.Message;
                error = String.Format("Failed to create serials for part {0}.  Error: {1}", part, errorMsg);
            }
        }