Beispiel #1
0
        /// <summary>
        ///  Retruns doctor vist details as json.
        /// </summary>
        /// <param name="dsDoctorVisitData"></param>
        /// <param name="dsCPDoctors"></param>
        /// <returns></returns>
        private LargeJsonResult GetDoctorVisitJSON(DataSet dsDoctorVisitData, DataSet dsCPDoctors, string dcrActualDate)
        {
            DataTable dtDoctorVisitData = null;
            DataTable dtProductDetails  = null;
            DataTable dtChemistDetails  = null;
            DataTable dtRCPADetails     = null;
            DataTable dtProductAutoFill = null;
            string    saleProductCodes  = "";

            if (dsDoctorVisitData != null && dsDoctorVisitData.Tables.Count > 0 && dsDoctorVisitData.Tables[0] != null)
            {
                dtDoctorVisitData = dsDoctorVisitData.Tables[0];
            }
            if (dsDoctorVisitData != null && dsDoctorVisitData.Tables.Count > 0 && dsDoctorVisitData.Tables[1] != null)
            {
                dtProductDetails = dsDoctorVisitData.Tables[1];
            }
            if (dsDoctorVisitData != null && dsDoctorVisitData.Tables.Count > 0 && dsDoctorVisitData.Tables[2] != null)
            {
                dtChemistDetails = dsDoctorVisitData.Tables[2];
            }

            if (dsDoctorVisitData != null && dsDoctorVisitData.Tables.Count > 0 && dsDoctorVisitData.Tables[3] != null)
            {
                dtRCPADetails = dsDoctorVisitData.Tables[3];
            }
            if (dsDoctorVisitData != null && dsDoctorVisitData.Tables.Count > 0 && dsDoctorVisitData.Tables.Count == 5 && dsDoctorVisitData.Tables[4] != null)
            {
                dtProductAutoFill = dsDoctorVisitData.Tables[4];
            }

            int totalCount = 0;

            List <JsonResult> lstDoctorVisitData = new List <JsonResult>();

            // Convert the DataTable to list.
            List <DCRDoctorVisitModel> lstDoctorVisit = (from Doctor_Visit_Data in dtDoctorVisitData.AsEnumerable()
                                                         select new DCRDoctorVisitModel
            {
                Doctor_Visit_Code = Doctor_Visit_Data["DCR_Visit_Code"].ToString(),
                Doctor_Name = Doctor_Visit_Data["Doctor_Name"].ToString() + "_" + Doctor_Visit_Data["MDL"].ToString() + "_" + Doctor_Visit_Data["Speciality_Name"].ToString() + "_" + Doctor_Visit_Data["Region_Name"].ToString(),
                Doctor_Code = Doctor_Visit_Data["Doctor_Code"].ToString(),
                //Speciality_Code = Doctor_Visit_Data["Speciality_Code"].ToString(),
                Speciality_Name = Doctor_Visit_Data["Speciality_Name"].ToString(),
                POB_Amount = Doctor_Visit_Data["PO_Amount"].ToString(),
                Doctor_Visit_Time = Doctor_Visit_Data["Doctor_Visit_Time"].ToString(),
                Visit_Mode = Doctor_Visit_Data["Visit_Mode"].ToString(),
                Is_CPDoc = Doctor_Visit_Data["Is_CP_Doc"].ToString(),
                Remarks = Doctor_Visit_Data["Remarks_By_User"].ToString(),
                Doctor_Region_Code = Doctor_Visit_Data["Doctor_Region_Code"].ToString(),
                Unique_Doctor_Code = Doctor_Visit_Data["Doctor_Code"].ToString() + "_" + Doctor_Visit_Data["Doctor_Region_Code"].ToString()
            }).ToList <DCRDoctorVisitModel>();

            List <DCRDoctorVisitModel> lstCPDoctors = new List <DCRDoctorVisitModel>();

            if (dsCPDoctors.Tables != null && dsCPDoctors.Tables.Count > 0 && dsCPDoctors.Tables[0].Rows != null && dsCPDoctors.Tables[0].Rows.Count > 0)
            {
                DataTable dtCPDoctors = dsCPDoctors.Tables[0];

                // Convert the DataTable to list.
                lstCPDoctors = (from cp_doctors in dtCPDoctors.AsEnumerable()
                                select new DCRDoctorVisitModel
                {
                    Doctor_Name = cp_doctors["Doctor_Name"].ToString() + "_" + cp_doctors["MDL"].ToString() + "_" + cp_doctors["Speciality_Name"].ToString() + "_" + cp_doctors["Region_Name"].ToString(),
                    Doctor_Code = cp_doctors["Doctor_Code"].ToString(),
                    //Speciality_Code = Doctor_Visit_Data["Speciality_Code"].ToString(),
                    Is_CPDoc = "1",
                    Speciality_Name = cp_doctors["Speciality_Name"].ToString(),
                    Doctor_Region_Code = cp_doctors["Doctor_Region_Code"].ToString(),
                    Unique_Doctor_Code = cp_doctors["Doctor_Code"].ToString() + "_" + cp_doctors["Doctor_Region_Code"].ToString()
                }).ToList <DCRDoctorVisitModel>();
            }

            IEnumerable <DCRDoctorVisitModel> IlstDoctorVisit = lstDoctorVisit.Union(lstCPDoctors, new DoctorVisitDoctorCodeComparer());

            lstDoctorVisitData.Add(Json(IlstDoctorVisit));

            // Convert the DataTable to list.
            List <DCRProductDetailsModel> lstProductDetails = (from Product_Details in dtProductDetails.AsEnumerable()
                                                               select new DCRProductDetailsModel
            {
                DCR_Visit_Code = Product_Details["DCR_Visit_Code"].ToString(),
                DCR_Product_Code = Product_Details["DCR_Product_Code"].ToString(),
                Product_Name = Product_Details["Product_Name"].ToString(),
                Product_Code = Product_Details["Product_Code"].ToString(),
                //Speciality_Code = Product_Details["Speciality_Code"].ToString(),
                Quantity_Provided = Product_Details["Quantity_Provided"].ToString(),
                Is_Detailed = Product_Details["Is_Detailed"].ToString(),
                Doctor_Code = Product_Details["Doctor_Code"].ToString(),
                Doctor_Region_Code = Product_Details["Doctor_Region_Code"].ToString(),
                Unique_Doctor_Code = Product_Details["Doctor_Code"].ToString() + "_" + Product_Details["Doctor_Region_Code"].ToString(),
                Current_Stock = Product_Details["Current_Stock"].ToString()
            }).ToList <DCRProductDetailsModel>();
            List <DCRProductDetailsModel> lstTPProductDetails = new List <DCRProductDetailsModel>();

            if (dsCPDoctors.Tables.Count == 2)
            {
                DataTable dtTPProducts = dsCPDoctors.Tables[1];
                // Convert the DataTable to list.

                lstTPProductDetails = (from Product_Details in dtTPProducts.AsEnumerable()
                                       select new DCRProductDetailsModel
                {
                    Doctor_Code = Product_Details["Doctor_Code"].ToString(),
                    Product_Name = Product_Details["Product_Name"].ToString(),
                    Product_Code = Product_Details["Product_Code"].ToString(),
                    //Speciality_Code = Product_Details["Speciality_Code"].ToString(),
                    Quantity_Provided = Product_Details["Quantity_Provided"].ToString(),
                    Doctor_Region_Code = Product_Details["Doctor_Region_Code"].ToString(),
                    Unique_Doctor_Code = Product_Details["Doctor_Code"].ToString() + "_" + Product_Details["Doctor_Region_Code"].ToString(),
                    Current_Stock = Product_Details["Current_Stock"].ToString()
                }).ToList <DCRProductDetailsModel>();
            }

            IEnumerable <DCRProductDetailsModel> IlstDoctorProductDetails = lstProductDetails.Union(lstTPProductDetails);

            lstDoctorVisitData.Add(Json(IlstDoctorProductDetails));

            // Convert the DataTable to list.
            List <DCRChemistVisitModel> lstChemistVisit = (from Chemist_Visit_Data in dtChemistDetails.AsEnumerable()
                                                           select new DCRChemistVisitModel
            {
                DCR_Visit_Code = Chemist_Visit_Data["DCR_Visit_Code"].ToString(),
                DCR_Chemists_Code = Chemist_Visit_Data["DCR_Chemists_Code"].ToString(),
                Chemist_Name = Chemist_Visit_Data["Chemists_Name"].ToString(),
                Chemist_Code = Chemist_Visit_Data["Chemist_Code"].ToString(),
                POB_Amount = Chemist_Visit_Data["PO_Amount"].ToString()
            }).ToList <DCRChemistVisitModel>();

            // returns the list.
            lstDoctorVisitData.Add(Json(lstChemistVisit));
            totalCount += lstChemistVisit.Count;

            if (dtRCPADetails != null)
            {
                // Convert the DataTable to list.
                List <DCRRCPADetailsModel> lstRCPADetails = (from RCPA_Data in dtRCPADetails.AsEnumerable()
                                                             select new DCRRCPADetailsModel
                {
                    DCR_Visit_Code = RCPA_Data["DCR_Visit_Code"].ToString(),
                    DCR_Product_Code = RCPA_Data["DCR_Product_Code"].ToString(),
                    Product_Name = RCPA_Data["Product_Name"].ToString(),
                    Chemist_Visit_Code = RCPA_Data["Chemist_Visit_Code"].ToString(),
                    Product_Code = RCPA_Data["Product_Code"].ToString(),
                    Competitor_Product_Name = RCPA_Data["Competitor_Product_Name"].ToString(),
                    Suuport_Qty = RCPA_Data["Support_Qty"].ToString(),
                    DCR_RCPA_Code = RCPA_Data["DCR_RCPA_Code"].ToString(),
                    Competitor_Product_Code = RCPA_Data["Competitor_Product_Code"].ToString(),
                }).ToList <DCRRCPADetailsModel>();

                lstDoctorVisitData.Add(Json(lstRCPADetails));
                foreach (DCRRCPADetailsModel rcpa in lstRCPADetails)
                {
                    saleProductCodes += rcpa.Product_Code + "^";
                }

                totalCount += lstRCPADetails.Count;
            }

            //returns the list.
            //return Json(lstDoctorVisitData, JsonRequestBehavior.AllowGet);
            if (saleProductCodes.Length > 0)
            {
                string  companyCode = _objcurrentInfo.GetCompanyCode();
                string  Region_Code = _objcurrentInfo.GetRegionCode();
                DataSet ds          = _objSPData.GetCompetitors(companyCode, Region_Code, dcrActualDate, saleProductCodes);
                List <DCRProductDetailsModel> lstProducts = (from Products in dtProductAutoFill.AsEnumerable()
                                                             select new DCRProductDetailsModel
                {
                    label = Products["Product_Name"].ToString(),
                    value = Products["Product_Code"].ToString(),
                    Product_Code = Products["Sales_Product_Code"].ToString()
                }).ToList <DCRProductDetailsModel>();
                //JsonResult Comp = GetCompetitorsName(companyCode, Region_Code, dcrActualDate, saleProductCodes);
                lstDoctorVisitData.Add(Json(lstProducts));
            }
            else
            {
                JsonResult Comp = new JsonResult();
                lstDoctorVisitData.Add(Comp);
            }
            //returns the list.
            //return Json(lstDoctorVisitData, JsonRequestBehavior.AllowGet);

            // Convert the DataTable to list.
            if (dtProductAutoFill != null)
            {
                List <DCRProductDetailsModel> lstProducts = (from Products in dtProductAutoFill.AsEnumerable()
                                                             select new DCRProductDetailsModel
                {
                    label = Products["Product_Name"].ToString() + "(" + Products["Stock"].ToString() + ")",
                    value = Products["Product_Code"].ToString(),
                    Product_Code = Products["Product_Code"].ToString().Split('_')[0]
                }).ToList <DCRProductDetailsModel>();
                // returns the list.
                lstDoctorVisitData.Add(Json(lstProducts, JsonRequestBehavior.AllowGet));
                totalCount += lstProducts.Count;
            }

            return(new LargeJsonResult
            {
                MaxJsonLength = Int32.MaxValue,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                Data = new
                {
                    total = totalCount,
                    Data = lstDoctorVisitData
                }
            });
        }