public void SaveReplacementOrder(ReplacementOrder argReplacementOrder, ReplacementOrderDetailCol argReplacementOrderDetailCol, ReplacementOrderSerialDetailCol argReplacementOrderSerialDetailCol, DataAccess da, List <ErrorHandler> lstErr)
        {
            try
            {
                string strRetValue = "";
                if (blnIsReplacementOrderExists(argReplacementOrder.RepOrderCode, argReplacementOrder.ClientCode, da) == false)
                {
                    strRetValue = InsertReplacementOrder(argReplacementOrder, da, lstErr);
                }
                else
                {
                    strRetValue = UpdateReplacementOrder(argReplacementOrder, da, lstErr);
                }

                if (strRetValue != "")
                {
                    if (argReplacementOrderDetailCol.colReplacementOrderDetail.Count > 0)
                    {
                        foreach (ReplacementOrderDetail objReplacementOrderDetail in argReplacementOrderDetailCol.colReplacementOrderDetail)
                        {
                            objReplacementOrderDetail.RepOrderCode = strRetValue;

                            if (objReplacementOrderDetail.IsDeleted == 0)
                            {
                                objReplacementOrderDetailMan.SaveReplacementOrderDetail(objReplacementOrderDetail, da, lstErr);
                            }
                            else
                            {
                                /*******************/
                                /** Call Delete Function **/
                            }

                            if (argReplacementOrderSerialDetailCol.colReplacementOrderSerialDetail.Count > 0)
                            {
                                foreach (ReplacementOrderSerialDetail objReplacementOrderSerialDetail in argReplacementOrderSerialDetailCol.colReplacementOrderSerialDetail)
                                {
                                    if (objReplacementOrderSerialDetail.RepOrderItemNo == objReplacementOrderDetail.RepOrderItemNo)
                                    {
                                        objReplacementOrderSerialDetail.RepOrderCode = strRetValue;
                                        if (objReplacementOrderSerialDetail.IsDeleted == 0)
                                        {
                                            objReplacementOrderSerialDetailManager.SaveReplacementOrderSerialDetail(objReplacementOrderSerialDetail, da, lstErr);
                                        }
                                        else
                                        {
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                objErrorHandler.Type       = ErrorConstant.strAboartType;
                objErrorHandler.MsgId      = 0;
                objErrorHandler.Module     = ErrorConstant.strInsertModule;
                objErrorHandler.ModulePart = ErrorConstant.strMasterModule;
                objErrorHandler.Message    = ex.Message.ToString();
                objErrorHandler.RowNo      = 0;
                objErrorHandler.FieldName  = "";
                objErrorHandler.LogCode    = "";
                lstErr.Add(objErrorHandler);
            }
        }
        public PartnerErrorResult SavePartnerGoodsMovement(PartnerGoodsMovement argPartnerGoodsMovement, PartnerGoodsMovementDetailCol argPartnerGNDetail, PartnerGoodsMovSerialDetailCol argPartnerGMSerialDetail)
        {
            List <ErrorHandler> lstErr   = new List <ErrorHandler>();
            PartnerErrorResult  errorcol = new PartnerErrorResult();
            PartnerGoodsMovementDetailManager  objPartnerGMDetailManager       = new PartnerGoodsMovementDetailManager();
            PartnerGoodsMovSerialDetailManager objPartnerGNSerialDetailManager = new PartnerGoodsMovSerialDetailManager();
            DataAccess da          = new DataAccess();
            string     strRetValue = "";

            try
            {
                da.Open_Connection();
                da.BEGIN_TRANSACTION();

                if (blnIsPartnerGoodsMovementExists(argPartnerGoodsMovement.PGoodsMovementCode, argPartnerGoodsMovement.ClientCode, da) == false)
                {
                    strRetValue = InsertPartnerGoodsMovement(argPartnerGoodsMovement, da, lstErr);
                }
                else
                {
                    strRetValue = UpdatePartnerGoodsMovement(argPartnerGoodsMovement, da, lstErr);
                }

                foreach (ErrorHandler objerr in lstErr)
                {
                    if (objerr.Type == "E")
                    {
                        errorcol.colErrorHandler.Add(objerr);
                        da.ROLLBACK_TRANSACTION();
                        return(errorcol);
                    }

                    if (objerr.Type == "A")
                    {
                        errorcol.colErrorHandler.Add(objerr);
                        da.ROLLBACK_TRANSACTION();
                        return(errorcol);
                    }
                }

                if (strRetValue != "")
                {
                    if (argPartnerGNDetail.colPartnerGMDetail.Count > 0)
                    {
                        foreach (PartnerGoodsMovementDetail objPartnerGMDetail in argPartnerGNDetail.colPartnerGMDetail)
                        {
                            objPartnerGMDetail.PGoodsMovementCode = strRetValue;

                            if (objPartnerGMDetail.IsDeleted == 0)
                            {
                                objPartnerGMDetailManager.SavePartnerGoodsMovementDetail(objPartnerGMDetail, da, lstErr);
                            }
                            else
                            {
                                /*Delete Function Call*/
                            }
                        }

                        foreach (ErrorHandler objerr in lstErr)
                        {
                            if (objerr.Type == "E")
                            {
                                errorcol.colErrorHandler.Add(objerr);
                                da.ROLLBACK_TRANSACTION();
                                return(errorcol);
                            }

                            if (objerr.Type == "A")
                            {
                                errorcol.colErrorHandler.Add(objerr);
                                da.ROLLBACK_TRANSACTION();
                                return(errorcol);
                            }
                        }
                    }

                    if (argPartnerGMSerialDetail.colPartnerGMSerialDetail.Count > 0)
                    {
                        foreach (PartnerGoodsMovSerialDetail objPartnerGMSerialDetail in argPartnerGMSerialDetail.colPartnerGMSerialDetail)
                        {
                            objPartnerGMSerialDetail.PGoodsMovementCode = strRetValue;

                            if (objPartnerGMSerialDetail.IsDeleted == 0)
                            {
                                objPartnerGNSerialDetailManager.SavePartnerGoodsMovSerialDetail(objPartnerGMSerialDetail, da, lstErr);
                            }
                            else
                            {
                                /*Call delete function*/
                            }
                        }

                        foreach (ErrorHandler objerr in lstErr)
                        {
                            if (objerr.Type == "E")
                            {
                                errorcol.colErrorHandler.Add(objerr);
                                da.ROLLBACK_TRANSACTION();
                                return(errorcol);
                            }

                            if (objerr.Type == "A")
                            {
                                errorcol.colErrorHandler.Add(objerr);
                                da.ROLLBACK_TRANSACTION();
                                return(errorcol);
                            }
                        }
                    }

                    /******************************/

                    int IsCreateRepOrder = 0;
                    PartnerGMDocTypeManager objPartnerGMDocTypeMan = new PartnerGMDocTypeManager();
                    DataSet ds = objPartnerGMDocTypeMan.GetPartnerGMDocType(Convert.ToString(argPartnerGoodsMovement.PartnerGMDocTypeCode), Convert.ToString(argPartnerGoodsMovement.ClientCode), da);

                    if (ds != null)
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            if (Convert.ToString(ds.Tables[0].Rows[0]["CreateRepOrder"]) != "")
                            {
                                IsCreateRepOrder = Convert.ToInt32(ds.Tables[0].Rows[0]["CreateRepOrder"]);
                            }
                        }
                    }


                    if (IsCreateRepOrder == 1)
                    {
                        ///* Call Replace Order Save Function */
                        ReplacementOrder objRepalcementOrder = new ReplacementOrder();
                        string           strNewRepOrderCode  = objReplaceOrderManager.GenerateRepOrderCode("NEW", "RO01", argPartnerGoodsMovement.PartnerCode, argPartnerGoodsMovement.ClientCode);

                        objRepalcementOrder.RepOrderCode        = strNewRepOrderCode;
                        objRepalcementOrder.RepOrderDocTypeCode = Convert.ToString("RO01");
                        objRepalcementOrder.RepOrderDate        = Convert.ToDateTime(argPartnerGoodsMovement.GoodsMovDate).ToString("yyyy-MM-dd");
                        objRepalcementOrder.TotalQuantity       = 0;
                        objRepalcementOrder.RepOrderStatus      = "OPEN";
                        objRepalcementOrder.OrderType           = Convert.ToString(argPartnerGoodsMovement.AssignType);
                        objRepalcementOrder.IssueDocCode        = Convert.ToString(argPartnerGoodsMovement.PGoodsMovementCode);
                        objRepalcementOrder.PartnerCode         = Convert.ToString(argPartnerGoodsMovement.PartnerCode);
                        objRepalcementOrder.ToPartnerCode       = Convert.ToString(argPartnerGoodsMovement.ToPartnerCode);
                        objRepalcementOrder.ClientCode          = Convert.ToString(argPartnerGoodsMovement.ClientCode);
                        objRepalcementOrder.CreatedBy           = Convert.ToString(argPartnerGoodsMovement.CreatedBy);
                        objRepalcementOrder.ModifiedBy          = Convert.ToString(argPartnerGoodsMovement.ModifiedBy);

                        ReplacementOrderDetailCol argReplacementOrderDetailCol = new ReplacementOrderDetailCol();
                        ReplacementOrderDetail    objReplacementOrderDetail    = null;

                        ReplacementOrderSerialDetailCol argReplacementOrderSerialDetailCol = new ReplacementOrderSerialDetailCol();
                        ReplacementOrderSerialDetail    objReplacementOrderSerialDetail    = null;

                        int ictr = 0;

                        foreach (PartnerGoodsMovementDetail objPartnerGMDetail in argPartnerGNDetail.colPartnerGMDetail)
                        {
                            ictr = ictr + 1;
                            objReplacementOrderDetail = new ReplacementOrderDetail();
                            objReplacementOrderDetail.RepOrderCode        = strNewRepOrderCode;
                            objReplacementOrderDetail.RepOrderItemNo      = ictr;
                            objReplacementOrderDetail.MaterialCode        = objPartnerGMDetail.MaterialCode;
                            objReplacementOrderDetail.MatGroup1Code       = objPartnerGMDetail.MatGroup1Code;
                            objReplacementOrderDetail.PartnerCode         = objPartnerGMDetail.PartnerCode;
                            objReplacementOrderDetail.PartnerEmployeeCode = objPartnerGMDetail.FromPartnerEmployeeCode;
                            objReplacementOrderDetail.OrderQty            = objPartnerGMDetail.Quantity;
                            objReplacementOrderDetail.UOMCode             = objPartnerGMDetail.UOMCode;
                            objReplacementOrderDetail.ReceivedQty         = 0;
                            objReplacementOrderDetail.RepOrderStatus      = "OPEN";
                            objReplacementOrderDetail.IssueDocCode        = objPartnerGMDetail.PGoodsMovementCode;
                            objReplacementOrderDetail.IssueDocItemNo      = objPartnerGMDetail.ItemNo;
                            objReplacementOrderDetail.ToPartnerCode       = objPartnerGMDetail.ToPartnerCode;
                            objReplacementOrderDetail.ClientCode          = argPartnerGoodsMovement.ClientCode;
                            objReplacementOrderDetail.CreatedBy           = argPartnerGoodsMovement.CreatedBy;
                            objReplacementOrderDetail.ModifiedBy          = argPartnerGoodsMovement.ModifiedBy;
                            objReplacementOrderDetail.IsDeleted           = 0;

                            argReplacementOrderDetailCol.colReplacementOrderDetail.Add(objReplacementOrderDetail);

                            foreach (PartnerGoodsMovSerialDetail objPartnerGMSerialDetail in argPartnerGMSerialDetail.colPartnerGMSerialDetail)
                            {
                                if (objPartnerGMSerialDetail.ItemNo == objPartnerGMDetail.ItemNo)
                                {
                                    objReplacementOrderSerialDetail = new ReplacementOrderSerialDetail();
                                    objReplacementOrderSerialDetail.RepOrderCode        = strNewRepOrderCode;
                                    objReplacementOrderSerialDetail.RepOrderItemNo      = ictr;
                                    objReplacementOrderSerialDetail.SerialNo1           = objPartnerGMSerialDetail.SerialNo1;
                                    objReplacementOrderSerialDetail.SerialNo2           = objPartnerGMSerialDetail.SerialNo2;
                                    objReplacementOrderSerialDetail.MaterialCode        = objPartnerGMSerialDetail.MaterialCode;
                                    objReplacementOrderSerialDetail.MatGroup1Code       = objPartnerGMSerialDetail.MatGroup1Code;
                                    objReplacementOrderSerialDetail.PartnerCode         = objPartnerGMSerialDetail.PartnerCode;
                                    objReplacementOrderSerialDetail.PartnerEmployeeCode = objPartnerGMSerialDetail.PartnerEmployeeCode;
                                    objReplacementOrderSerialDetail.OrderQty            = 1;
                                    objReplacementOrderSerialDetail.UOMCode             = objPartnerGMDetail.UOMCode;
                                    objReplacementOrderSerialDetail.ReceivedQty         = 0;
                                    objReplacementOrderSerialDetail.RepOrderStatus      = "OPEN";
                                    objReplacementOrderSerialDetail.IssueDocCode        = objPartnerGMSerialDetail.PGoodsMovementCode;
                                    objReplacementOrderSerialDetail.IssueDocItemNo      = objPartnerGMSerialDetail.ItemNo;
                                    objReplacementOrderSerialDetail.ToPartnerCode       = objPartnerGMSerialDetail.ToPartnerCode;
                                    objReplacementOrderSerialDetail.ClientCode          = argPartnerGoodsMovement.ClientCode;
                                    objReplacementOrderSerialDetail.CreatedBy           = argPartnerGoodsMovement.CreatedBy;
                                    objReplacementOrderSerialDetail.ModifiedBy          = argPartnerGoodsMovement.ModifiedBy;
                                    objReplacementOrderSerialDetail.IsDeleted           = 0;

                                    argReplacementOrderSerialDetailCol.colReplacementOrderSerialDetail.Add(objReplacementOrderSerialDetail);
                                }
                            }
                        }

                        if (argReplacementOrderDetailCol.colReplacementOrderDetail.Count > 0)
                        {
                            objReplaceOrderManager.SaveReplacementOrder(objRepalcementOrder, argReplacementOrderDetailCol, argReplacementOrderSerialDetailCol, da, lstErr);

                            foreach (ErrorHandler objerr in lstErr)
                            {
                                if (objerr.Type == "E")
                                {
                                    errorcol.colErrorHandler.Add(objerr);
                                    da.ROLLBACK_TRANSACTION();
                                    return(errorcol);
                                }

                                if (objerr.Type == "A")
                                {
                                    errorcol.colErrorHandler.Add(objerr);
                                    da.ROLLBACK_TRANSACTION();
                                    return(errorcol);
                                }
                            }
                        }
                    }

                    /******************************/
                }
                da.COMMIT_TRANSACTION();
            }
            catch (Exception ex)
            {
                if (da != null)
                {
                    da.ROLLBACK_TRANSACTION();
                }
                objErrorHandler.Type       = ErrorConstant.strAboartType;
                objErrorHandler.MsgId      = 0;
                objErrorHandler.Module     = ErrorConstant.strInsertModule;
                objErrorHandler.ModulePart = ErrorConstant.strMasterModule;
                objErrorHandler.Message    = ex.Message.ToString();
                objErrorHandler.RowNo      = 0;
                objErrorHandler.FieldName  = "";
                objErrorHandler.LogCode    = "";
                lstErr.Add(objErrorHandler);
                errorcol.colErrorHandler.Add(objErrorHandler);
            }
            finally
            {
                if (da != null)
                {
                    da.Close_Connection();
                    da = null;
                }
            }
            return(errorcol);
        }