public bool Save(string xmlDoc, string spName, ref Int32 promotionId, ref string errorMessage)
        {
            DBParameterList dbParam;
            bool            isSuccess = false;

            using (DataTaskManager dtManager = new DataTaskManager())
            {
                dtManager.BeginTransaction();
                {
                    dbParam = new DBParameterList();
                    dbParam.Add(new DBParameter(Common.PARAM_DATA, xmlDoc, DbType.String));
                    dbParam.Add(new DBParameter(Common.PARAM_OUTPUT, errorMessage, DbType.String, ParameterDirection.Output, Common.PARAM_OUTPUT_LENGTH));

                    DataTable dt = dtManager.ExecuteDataTable(spName, dbParam);
                    errorMessage = dbParam[Common.PARAM_OUTPUT].Value.ToString();
                    if (errorMessage.Length > 0)
                    {
                        isSuccess = false;
                        dtManager.RollbackTransaction();
                    }
                    else
                    {
                        isSuccess   = true;
                        promotionId = Convert.ToInt32(dt.Rows[0]["PromotionId"]);
                        dtManager.CommitTransaction();
                    }
                }
            }
            return(isSuccess);
        }
        public bool Save(ref string errorMessage)
        {
            DataTaskManager dtManager = null;

            try
            {
                DBParameterList dbParam;
                bool            isSuccess = false;
                using (dtManager = new DataTaskManager())
                {
                    try
                    {
                        dtManager.BeginTransaction();
                        {
                            string xmlDoc = Common.ToXml(this);

                            dbParam = new DBParameterList();
                            dbParam.Add(new DBParameter(Common.PARAM_DATA, xmlDoc, DbType.String));

                            dbParam.Add(new DBParameter(Common.PARAM_OUTPUT, errorMessage, DbType.String, ParameterDirection.Output, Common.PARAM_OUTPUT_LENGTH));

                            DataTable dt = dtManager.ExecuteDataTable(SP_CI_SAVE, dbParam);

                            errorMessage = dbParam[Common.PARAM_OUTPUT].Value.ToString();
                            {
                                if (errorMessage.Length > 0)
                                {
                                    isSuccess = false;
                                    dtManager.RollbackTransaction();
                                }
                                else
                                {
                                    isSuccess = true;
                                    dtManager.CommitTransaction();
                                    this.InvoiceNo = Convert.ToString(dt.Rows[0]["InvoiceNo"]);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (dtManager != null)
                        {
                            dtManager.RollbackTransaction();
                        }
                        throw ex;
                    }
                }
                return(isSuccess);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// save pack/unpack details
        /// </summary>
        /// <param name="xmlDoc"></param>
        /// <param name="spName"></param>
        /// <param name="errorMessage"></param>
        /// <returns></returns>
        public bool PUSave(string xmlDoc, string spName, ref string errorMessage)
        {
            bool isSuccess = false;

            try
            {
                using (DataTaskManager dtManager = new DataTaskManager())
                {
                    //Declare and initialize the parameter list object
                    DBParameterList dbParam = new DBParameterList();

                    //Add the relevant 2 parameters
                    dbParam.Add(new DBParameter(Common.PARAM_DATA, xmlDoc, DbType.String));
                    dbParam.Add(new DBParameter(Common.PARAM_OUTPUT, string.Empty, DbType.String,
                                                ParameterDirection.Output, Common.PARAM_OUTPUT_LENGTH));

                    try
                    {
                        //Begin the transaction and executing procedure to save the record(s)
                        dtManager.BeginTransaction();

                        // executing procedure to save the record

                        DataSet ds;

                        ds = dtManager.ExecuteDataSet(spName, dbParam);

                        //Update database message
                        errorMessage = dbParam[Common.PARAM_OUTPUT].Value.ToString();

                        //If an error returned from the database
                        if (errorMessage.Length > 0)
                        {
                            dtManager.RollbackTransaction();
                            isSuccess = false;
                        }
                        else
                        {
                            dtManager.CommitTransaction();
                            isSuccess = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        dtManager.RollbackTransaction();
                        throw ex;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(isSuccess);
        }
        public virtual bool RetVendorSave(string xmlDoc, string spName, ref string errorMessage)
        {
            bool isSuccess = false;

            try
            {
                DBParameterList dbParam;
                using (DataTaskManager dtManager = new DataTaskManager())
                {
                    try
                    {
                        // initialize the parameter list object
                        dbParam = new DBParameterList();

                        // add the relevant 2 parameters
                        dbParam.Add(new DBParameter(Common.PARAM_DATA, xmlDoc, DbType.String));
                        dbParam.Add(new DBParameter(Common.PARAM_OUTPUT, string.Empty, DbType.String, ParameterDirection.Output, Common.PARAM_OUTPUT_LENGTH));

                        // begin the transaction
                        dtManager.BeginTransaction();
                        // executing procedure to save the record
                        DataTable dt = dtManager.ExecuteDataTable(spName, dbParam);

                        // update database message
                        errorMessage = dbParam[Common.PARAM_OUTPUT].Value.ToString();

                        // if an error returned from the database
                        if (errorMessage != string.Empty)
                        {
                            isSuccess = false;
                            dtManager.RollbackTransaction();
                        }
                        else
                        {
                            this.ReturnNo     = dt.Rows[0]["ReturnNo"].ToString();
                            this.ModifiedDate = (dt.Rows[0]["ModifiedDate"]).ToString();
                            this.DebitNoteNo  = dt.Rows[0]["DebitNoteNumber"].ToString();
                            this.ShippingDate = dt.Rows[0]["ShippingDate"].ToString();
                            dtManager.CommitTransaction();
                            isSuccess = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        Common.LogException(ex);
                        dtManager.RollbackTransaction();
                    }
                }
            }
            catch (Exception ex)
            {
                Common.LogException(ex);
            }
            return(isSuccess);
        }
        public bool Save(ref string errorMessage, bool amend)
        {
            try
            {
                DBParameterList dbParam;
                using (DataTaskManager dtManager = new DataTaskManager())
                {
                    try
                    {
                        dtManager.BeginTransaction();
                        string xmlDoc = Common.ToXml(this);
                        dbParam = new DBParameterList();
                        dbParam.Add(new DBParameter(Common.PARAM_DATA, xmlDoc, DbType.String));
                        dbParam.Add(new DBParameter("@amend", amend, DbType.Boolean));
                        dbParam.Add(new DBParameter(Common.PARAM_OUTPUT, errorMessage, DbType.String, ParameterDirection.Output, Common.PARAM_OUTPUT_LENGTH));

                        DataTable dt = dtManager.ExecuteDataTable(SP_PO_SAVE, dbParam);

                        errorMessage = dbParam[Common.PARAM_OUTPUT].Value.ToString();
                        if (errorMessage.Length > 0)
                        {
                            dtManager.RollbackTransaction();
                            return(false);
                        }
                        else
                        {
                            this.PONumber = Convert.ToString(dt.Rows[0]["PoNo"]);
                            dtManager.CommitTransaction();
                            return(true);
                        }
                    }
                    catch (Exception ex)
                    {
                        dtManager.RollbackTransaction();
                        throw ex;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        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;
            }
        }
 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;
     }
 }