Beispiel #1
0
 public string Read(CSVHandler csvHandler, string webpath, DoctorIncomeDataList doctorIncomeDataList)
 {
     throw new NotImplementedException();
 }
Beispiel #2
0
        public string Write(string fileName, string webpath, DoctorIncomeDataList displayResult)
        {
            // create a writer and open the file
            if (!fileName.EndsWith(".csv"))
            {
                fileName += ".csv";
            }

            //string webpath = HttpContext.Current.Request.Url.AbsoluteUri;
            string webFolderPath       = webpath.Substring(0, webpath.LastIndexOf("/"));
            string fileWebPath         = webFolderPath + "/" + dataFolderName + "/" + fileName;
            string fileStorageFilePath = resultStorageFolder + dataFolderName + "/" + fileName;

            try
            {
                if (File.Exists(fileStorageFilePath))
                {
                    File.Delete(fileStorageFilePath);
                }
            }
            catch (Exception ex)
            {
                YelpTrace.Write(ex);
            }
            string header  = string.Empty;
            string rowText = string.Empty;

            if (displayResult.LstDoctorIncomeDataList.Count > 0)
            {
                if (textWriter == null)
                {
                    textWriter = new StreamWriter(fileStorageFilePath);
                }

                string reportHeader = string.Empty;
                if (fileName.StartsWith("Conversion_Report"))
                {
                    reportHeader = "Conversion Report as of " + DateTime.Today.ToShortDateString();
                }
                else
                {
                    reportHeader = "Potential Profit/Loss Value Report as of " + DateTime.Today.ToShortDateString();
                }

                header = "Name, Email, Phone, First Consult, Treatment, Source, Status Group, Status, Treatment Cost, Aging";
                header = reportHeader + Environment.NewLine + Environment.NewLine + Environment.NewLine + header;

                if (!string.IsNullOrEmpty(header))
                {
                    textWriter.WriteLine(header);

                    foreach (DoctorIncomeData doctorIncomeData in displayResult.LstDoctorIncomeDataList)
                    {
                        string joinedStr = doctorIncomeData.Name.Replace(",", " ") + ", ";
                        joinedStr += doctorIncomeData.Email.Replace(",", ";") + ", ";
                        joinedStr += doctorIncomeData.Phone.Replace(",", ";") + ", ";
                        string firstConsultDate = (doctorIncomeData.FirstConsultDate == null) ? string.Empty : doctorIncomeData.FirstConsultDate.ToShortDateString();
                        joinedStr += ((firstConsultDate.Equals("01/01/0001")) || (firstConsultDate.Equals("1/1/0001")) == true) ? string.Empty : firstConsultDate + ", ";
                        joinedStr += doctorIncomeData.Treatment.Replace(",", ";") + ", ";
                        joinedStr += doctorIncomeData.Source.Replace(",", ";") + ", ";
                        joinedStr += doctorIncomeData.StatusGroup.Replace(",", ";") + ", ";
                        joinedStr += doctorIncomeData.StatusName + ", ";
                        joinedStr += (doctorIncomeData.TxCost == 0) ? string.Empty : doctorIncomeData.TxCost.ToString("C2").Replace(",", "") + ", ";
                        joinedStr += (doctorIncomeData.Ageing == 0) ? string.Empty : doctorIncomeData.Ageing + ", ";
                        textWriter.WriteLine(joinedStr);
                    }
                }
            }
            return(fileWebPath);
        }