public ReplacementOrder objGetReplacementOrder(string argRepOrderCode, string argClientCode)
        {
            ReplacementOrder argReplacementOrder = new ReplacementOrder();
            DataSet          DataSetToFill       = new DataSet();

            if (argRepOrderCode.Trim() == "")
            {
                goto ErrorHandlers;
            }

            if (argClientCode.Trim() == "")
            {
                goto ErrorHandlers;
            }

            DataSetToFill = this.GetReplacementOrder(argRepOrderCode, argClientCode);

            if (DataSetToFill.Tables[0].Rows.Count <= 0)
            {
                goto Finish;
            }

            argReplacementOrder = this.objCreateReplacementOrder((DataRow)DataSetToFill.Tables[0].Rows[0]);

            goto Finish;

ErrorHandlers:

Finish:
            DataSetToFill = null;


            return(argReplacementOrder);
        }
        private ReplacementOrder objCreateReplacementOrder(DataRow dr)
        {
            ReplacementOrder tReplacementOrder = new ReplacementOrder();

            tReplacementOrder.SetObjectInfo(dr);

            return(tReplacementOrder);
        }
        public string UpdateReplacementOrder(ReplacementOrder argReplacementOrder, DataAccess da, List <ErrorHandler> lstErr)
        {
            SqlParameter[] param = new SqlParameter[15];
            param[0]  = new SqlParameter("@RepOrderCode", argReplacementOrder.RepOrderCode);
            param[1]  = new SqlParameter("@RepOrderDocTypeCode", argReplacementOrder.RepOrderDocTypeCode);
            param[2]  = new SqlParameter("@RepOrderDate", argReplacementOrder.RepOrderDate);
            param[3]  = new SqlParameter("@TotalQuantity", argReplacementOrder.TotalQuantity);
            param[4]  = new SqlParameter("@RepOrderStatus", argReplacementOrder.RepOrderStatus);
            param[5]  = new SqlParameter("@IssueDocCode", argReplacementOrder.IssueDocCode);
            param[6]  = new SqlParameter("@PartnerCode", argReplacementOrder.PartnerCode);
            param[7]  = new SqlParameter("@ToPartnerCode", argReplacementOrder.ToPartnerCode);
            param[8]  = new SqlParameter("@OrderType", argReplacementOrder.OrderType);
            param[9]  = new SqlParameter("@ClientCode", argReplacementOrder.ClientCode);
            param[10] = new SqlParameter("@CreatedBy", argReplacementOrder.CreatedBy);
            param[11] = new SqlParameter("@ModifiedBy", argReplacementOrder.ModifiedBy);

            param[12]           = new SqlParameter("@Type", SqlDbType.Char);
            param[12].Size      = 1;
            param[12].Direction = ParameterDirection.Output;

            param[13]           = new SqlParameter("@Message", SqlDbType.VarChar);
            param[13].Size      = 255;
            param[13].Direction = ParameterDirection.Output;

            param[14]           = new SqlParameter("@returnvalue", SqlDbType.VarChar);
            param[14].Size      = 20;
            param[14].Direction = ParameterDirection.Output;

            int i = da.NExecuteNonQuery("Proc_UpdateReplacementOrder", param);


            string strMessage  = Convert.ToString(param[13].Value);
            string strType     = Convert.ToString(param[12].Value);
            string strRetValue = Convert.ToString(param[14].Value);


            objErrorHandler.Type       = strType;
            objErrorHandler.MsgId      = 0;
            objErrorHandler.Module     = ErrorConstant.strInsertModule;
            objErrorHandler.ModulePart = ErrorConstant.strMasterModule;
            objErrorHandler.Message    = strMessage.ToString();
            objErrorHandler.RowNo      = 0;
            objErrorHandler.FieldName  = "";
            objErrorHandler.LogCode    = "";
            lstErr.Add(objErrorHandler);

            return(strRetValue);
        }
        public ICollection <ReplacementOrder> colGetReplacementOrder(string argClientCode)
        {
            List <ReplacementOrder> lst        = new List <ReplacementOrder>();
            DataSet          DataSetToFill     = new DataSet();
            ReplacementOrder tReplacementOrder = new ReplacementOrder();

            DataSetToFill = this.GetReplacementOrder(argClientCode);

            if (DataSetToFill != null)
            {
                foreach (DataRow dr in DataSetToFill.Tables[0].Rows)
                {
                    lst.Add(objCreateReplacementOrder(dr));
                }
            }
            goto Finish;

Finish:
            DataSetToFill = null;


            return(lst);
        }
        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 ICollection <ErrorHandler> SaveReplacementOrder(ReplacementOrder argReplacementOrder)
        {
            List <ErrorHandler> lstErr = new List <ErrorHandler>();
            DataAccess          da     = new DataAccess();

            try
            {
                if (blnIsReplacementOrderExists(argReplacementOrder.RepOrderCode, argReplacementOrder.ClientCode) == false)
                {
                    da.Open_Connection();
                    da.BEGIN_TRANSACTION();
                    InsertReplacementOrder(argReplacementOrder, da, lstErr);
                    foreach (ErrorHandler objerr in lstErr)
                    {
                        if (objerr.Type == "E")
                        {
                            da.ROLLBACK_TRANSACTION();
                            return(lstErr);
                        }
                    }
                }
                else
                {
                    da.Open_Connection();
                    da.BEGIN_TRANSACTION();
                    UpdateReplacementOrder(argReplacementOrder, da, lstErr);
                    foreach (ErrorHandler objerr in lstErr)
                    {
                        if (objerr.Type == "E")
                        {
                            da.ROLLBACK_TRANSACTION();
                            return(lstErr);
                        }
                    }
                }

                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);
            }
            finally
            {
                if (da != null)
                {
                    da.Close_Connection();
                    da = null;
                }
            }
            return(lstErr);
        }
        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);
        }