Exemplo n.º 1
0
        public bool ProcessLog(string logNo, int LocationID, int userID, List <CO> lstCo, ref String ErrorCode)
        {
            try
            {
                bool   isSuccess    = false;
                bool   isValid      = true;
                string errorMessage = string.Empty;
                //Check Batch Qty Not Available for all Items of orders
                //isValid = CI.CheckBatchForLog(logNo, LocationID, ref errorMessage);
                //if (isValid)
                {
                    List <CI> CIList = new List <CI>();
                    errorMessage = string.Empty;
                    if (lstCo != null && lstCo.Count > 0)
                    {
                        DataTaskManager dtManager = null;
                        try
                        {
                            using (dtManager = new DataTaskManager())
                            {
                                //dtManager.BeginTransaction();
                                try
                                {
                                    foreach (CO o in lstCo)
                                    {
                                        dtManager.BeginTransaction();
                                        CO COrder = new CO();
                                        COrder.GetCOAllDetails(o.CustomerOrderNo, -1);
                                        errorMessage = string.Empty;
                                        List <CIBatchDetail> ListBatch = CIBatchDetail.GetDefaultBatch(COrder.CustomerOrderNo, LocationID, ref errorMessage);
                                        CI invoice = CreateInvoiceObject(COrder, ListBatch, userID);
                                        if (invoice != null)
                                        {
                                            string ValidationCode = string.Empty;
                                            isValid      = invoice.ValidateInvoice(COrder.CODetailList, ListBatch, ref ValidationCode);
                                            errorMessage = errorMessage + ValidationCode;
                                            if (isValid)
                                            {
                                                bool isSaved = invoice.Save(ref ValidationCode);
                                                if (!isSaved)
                                                {
                                                    isSuccess = false;
                                                    ErrorCode = ValidationCode;
                                                    dtManager.RollbackTransaction();
                                                    //return isSuccess;
                                                }
                                                else
                                                {
                                                    dtManager.CommitTransaction();
                                                    ErrorCode = string.Empty;
                                                    isSuccess = true;
                                                }
                                            }
                                            else
                                            {
                                                if (ValidationCode == "40007")
                                                {
                                                    // Not sufficent Batch Qty present
                                                    ErrorCode = "40008";
                                                }
                                                else
                                                {
                                                    ErrorCode = ValidationCode;
                                                }
                                                isSuccess = false;
                                                dtManager.RollbackTransaction();
                                                //break;
                                            }
                                        }
                                        else
                                        {
                                            ErrorCode = "40029," + COrder.CustomerOrderNo;
                                            isSuccess = false;
                                            dtManager.RollbackTransaction();
                                            break;
                                        }
                                    }

                                    //dtManager.CommitTransaction();
                                    //ErrorCode = string.Empty;
                                    //isSuccess = true;
                                    //return isSuccess;
                                }

                                catch (Exception ex)
                                {
                                    throw ex;
                                }
                            }

                            //return isSuccess;
                        }
                        catch (Exception ex)
                        {
                            Common.LogException(ex);
                        }
                    }
                    else
                    {
                        //No Order found in confirmed status
                        ErrorCode = "40011";
                    }
                }
                // Error in batch qty check
                ////else if (!errorMessage.Trim().Equals(string.Empty))
                //{
                //    if (errorMessage.Trim().IndexOf("30001:") >= 0)
                //    {
                //        throw new Exception(errorMessage.Trim());
                //    }
                //    else
                //    {
                //        ErrorCode = errorMessage.Trim();
                //    }
                //}
                if (!errorMessage.Equals(""))
                {
                    MessageBox.Show(errorMessage, Common.GetMessage("10004"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                return(isSuccess);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
 public bool ProcessLog(string logNo, int LocationID, int userID, ref String ErrorCode, ref DataTable dtItems)
 {
     try
     {
         bool   isSuccess    = false;
         bool   isValid      = true;
         string errorMessage = string.Empty;
         //Check Batch Qty Not Available for all Items of orders
         isValid = CI.CheckBatchForLog(logNo, LocationID, ref errorMessage, ref dtItems);
         if (isValid)
         {
             List <CI> CIList = new List <CI>();
             CO        order  = new CO();
             order.LogNo  = logNo;
             order.Status = (int)Common.OrderStatus.Confirmed;
             errorMessage = string.Empty;
             List <CO> lstCo = order.Search(ref errorMessage);
             if (errorMessage.Equals(string.Empty) && lstCo != null && lstCo.Count > 0)
             {
                 DataTaskManager dtManager = null;
                 try
                 {
                     using (dtManager = new DataTaskManager())
                     {
                         dtManager.BeginTransaction();
                         try
                         {
                             foreach (CO o in lstCo)
                             {
                                 CO m_Order = new CO();
                                 m_Order.GetCOAllDetails(o.CustomerOrderNo, -1);
                                 errorMessage = string.Empty;
                                 List <CIBatchDetail> ListBatch = CIBatchDetail.GetDefaultBatch(m_Order.CustomerOrderNo, LocationID, ref errorMessage);
                                 CI invoice = CreateInvoiceObject(m_Order, ListBatch, userID);
                                 if (invoice != null)
                                 {
                                     string ValidationCode = string.Empty;
                                     isValid = invoice.ValidateInvoice(m_Order.CODetailList, ListBatch, ref ValidationCode);
                                     if (isValid)
                                     {
                                         bool isSaved = invoice.Save(ref ValidationCode);
                                         if (!isSaved)
                                         {
                                             isSuccess = false;
                                             dtManager.RollbackTransaction();
                                         }
                                     }
                                     else
                                     {
                                         if (ValidationCode == "40007")
                                         {
                                             // Not sufficent Batch Qty present
                                             ErrorCode = "40008";
                                         }
                                         else
                                         {
                                             ErrorCode = ValidationCode;
                                         }
                                         isSuccess = false;
                                         dtManager.RollbackTransaction();
                                         break;
                                     }
                                 }
                                 else
                                 {
                                     ErrorCode = "40029," + m_Order.CustomerOrderNo;
                                     isSuccess = false;
                                     dtManager.RollbackTransaction();
                                     break;
                                 }
                             }
                             dtManager.CommitTransaction();
                             ErrorCode = string.Empty;
                             isSuccess = true;
                         }
                         catch (Exception ex)
                         {
                             throw ex;
                         }
                     }
                 }
                 catch (Exception ex)
                 {
                     Common.LogException(ex);
                 }
             }
             else
             {
                 //No Order found in confirmed status
                 ErrorCode = "40011";
             }
         }
         // Error in batch qty check
         else if (!errorMessage.Trim().Equals(string.Empty))
         {
             if (errorMessage.Trim().IndexOf("30001:") >= 0)
             {
                 throw new Exception(errorMessage.Trim());
             }
             else
             {
                 ErrorCode = errorMessage.Trim();
             }
         }
         return(isSuccess);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }