protected override GenericStateMachineEngine.ActionResult Create()
 {
     try
     {
         List <string> _errors = new List <string>();
         double?       _nq     = Parent.m_InvoiceQuantityTextBox.TextBox2Double(_errors);
         if (_errors.Count > 0)
         {
             return(ActionResult.NotValidated(_errors[0]));
         }
         if (_nq.HasValue && _nq.Value < 0)
         {
             return(ActionResult.NotValidated
                        (String.Format(Resources.NegativeValueNotAllowed.GetLocalizedString(), Parent.m_InvoiceQuantityLabel.Text)));
         }
         Batch      _batch = Parent.m_ControlState.Batch;
         InvoiceLib _invc  = Parent.m_ControlState.Invoice;
         if (!_batch.Available(_nq.Value))
         {
             string _tmplt = Resources.QuantityIsUnavailable.GetLocalizedString();
             return(ActionResult.NotValidated(String.Format(CultureInfo.CurrentCulture, _tmplt, _batch.AvailableQuantity())));
         }
         InvoiceContent _nic = new InvoiceContent()
         {
             InvoiceContent2BatchIndex = _batch,
             InvoiceIndex         = _invc,
             SKUDescription       = _batch.SKUIndex.Title,
             ProductType          = _batch.ProductType,
             Quantity             = _nq.Value,
             InvoiceContentStatus = InvoiceContentStatus.OK,
             Title = _batch.SKUIndex.Title,
             Units = _batch.ProductType.Value.Units()
         };
         Parent.m_DataContextManagement.DataContext.InvoiceContent.InsertOnSubmit(_nic);
         Parent.m_DataContextManagement.DataContext.SubmitChanges();
         _nic.CreateTitle();
         Parent.m_DataContextManagement.DataContext.SubmitChanges();
     }
     catch (Exception ex)
     {
         return(GenericStateMachineEngine.ActionResult.Exception(ex, "Create"));
     }
     return(GenericStateMachineEngine.ActionResult.Success);
 }
예제 #2
0
        private static bool GetXmlContent(InvoiceItemXml[] invoiceEntries, Entities edc, InvoiceLib parent)
        {
            List <InvoiceContent> _invcs    = new List <InvoiceContent>();
            ErrorsList            _warnings = new ErrorsList();
            bool _result = true;

            foreach (InvoiceItemXml item in invoiceEntries)
            {
                try
                {
                    InvoiceContent _ic = CreateInvoiceContent(edc, parent, item, _warnings);
                    if (_ic == null)
                    {
                        continue;
                    }
                    _invcs.Add(_ic);
                    _result &= _ic.InvoiceContentStatus.Value == InvoiceContentStatus.OK;
                    if (parent.BillDoc.IsNullOrEmpty())
                    {
                        parent.BillDoc             = item.Bill_doc.ToString();
                        parent.InvoiceCreationDate = item.Created_on;
                    }
                }
                catch (Exception ex)
                {
                    string _msg = "Cannot create new entry for the invoice No={0}/{1}, SKU={2}, because of error: {3}";
                    _warnings.Add(new Warnning(String.Format(_msg, item.Bill_doc, item.Item, item.Description, ex.Message), true));
                }
            }
            if (_warnings.Count > 0)
            {
                throw new InputDataValidationException("there are fatal errors in the XML message.", "GetBatchLookup", _warnings);
            }
            edc.InvoiceContent.InsertAllOnSubmit(_invcs);
            edc.SubmitChanges();
            foreach (InvoiceContent _ic in _invcs)
            {
                _ic.CreateTitle();
            }
            edc.SubmitChanges();
            return(_result);
        }
 protected override GenericStateMachineEngine.ActionResult Update()
 {
     try
     {
         List <string> _errors = new List <string>();
         double?       _nq     = Parent.m_InvoiceQuantityTextBox.TextBox2Double(_errors);
         if (_errors.Count > 0)
         {
             return(ActionResult.NotValidated(_errors[0]));
         }
         if (_nq.HasValue && _nq.Value < 0)
         {
             return(ActionResult.NotValidated(String.Format(Resources.NegativeValueNotAllowed.GetLocalizedString(), Parent.m_InvoiceQuantityLabel.Text)));
         }
         Batch _batch = Parent.Batch;
         if (!_batch.Available(_nq.Value))
         {
             string _tmplt = Resources.NeBatchQuantityIsUnavailable.GetLocalizedString();
             return(ActionResult.NotValidated(String.Format(CultureInfo.CurrentCulture, _tmplt, _batch.AvailableQuantity())));
         }
         InvoiceContent _ic = Parent.m_ControlState.InvoiceContent;
         _ic.Quantity             = _nq;
         _ic.InvoiceContentStatus = InvoiceContentStatus.OK;
         if (_ic.InvoiceContent2BatchIndex != _batch)
         {
             _ic.InvoiceContent2BatchIndex = _batch;
             _ic.ProductType = _ic.InvoiceContent2BatchIndex.ProductType;
             _ic.Units       = _ic.InvoiceContent2BatchIndex.ProductType.Value.Units();
             _ic.Quantity    = _nq;
             _ic.CreateTitle();
         }
         Parent.m_DataContextManagement.DataContext.SubmitChanges();
     }
     catch (Exception ex)
     {
         return(GenericStateMachineEngine.ActionResult.Exception(ex, "Update"));
     }
     return(GenericStateMachineEngine.ActionResult.Success);
 }