Ejemplo n.º 1
0
    private void ProcessFile(string strFolderPath, string strANReportId)
    {
        string strFileName          = string.Empty;
        string strFilePath          = string.Empty;
        string strFileExtension     = string.Empty;
        string strGeneratedFileName = string.Empty;

        try
        {
            strFileName          = ConfigurationManager.AppSettings["AwardNotificationFileName"];
            strFileExtension     = ConfigurationManager.AppSettings["AwardNotificationFileExtension"];
            strGeneratedFileName = DateTime.Now.Date.ToString("MMM-dd-yyyy") + "_" + strFileName + strFileExtension;
            strFilePath          = strFolderPath + strGeneratedFileName;
            DataSet dsANFinalCamperNotificationList = new DataSet();
            dsANFinalCamperNotificationList = _objCamperApplication.GetANFinalModeCampersOnReportID(Application["CampYear"].ToString(), strANReportId);

            if (dsANFinalCamperNotificationList.Tables.Count > 0)
            {
                if (dsANFinalCamperNotificationList.Tables[0].Rows.Count > 0)
                {
                    DataTable dtANFinalCamperNotificationList = dsANFinalCamperNotificationList.Tables[0];
                    //DataTable dtANFinalCamperNotificationList = UpdateDays(dsANFinalCamperNotificationList.Tables[0]);
                    //dtANFinalCamperNotificationList.Columns.Remove("StartDate");
                    //dtANFinalCamperNotificationList.Columns.Remove("EndDate");
                    //dtANFinalCamperNotificationList.Columns["Days"].ColumnName = "Number of days";
                    for (int i = 0; i < dtANFinalCamperNotificationList.Rows.Count; i++)
                    {
                        if (dtANFinalCamperNotificationList.Rows[i]["Federation ID"].ToString().Length == 1)
                        {
                            dtANFinalCamperNotificationList.Rows[i]["Federation ID"] = dtANFinalCamperNotificationList.Rows[i]["Federation ID"].ToString().Insert(0, "00");
                        }
                        else if (dtANFinalCamperNotificationList.Rows[i]["Federation ID"].ToString().Length == 2)
                        {
                            dtANFinalCamperNotificationList.Rows[i]["Federation ID"] = dtANFinalCamperNotificationList.Rows[i]["Federation ID"].ToString().Insert(0, "0");
                        }
                    }

                    if (File.Exists(strFilePath))
                    {
                        File.Delete(strFilePath);
                    }

                    StreamWriter strmWriterFile = new StreamWriter(strFilePath, false); //true defines append to the file if exists
                    //if file does not exists creates new and header (true) if file exists writeheader to be set as false
                    _objGen.ProduceTabDelimitedFile(dtANFinalCamperNotificationList, strmWriterFile, true, 0);
                }
            }
            string localpath = Request.ApplicationPath + "/" + ConfigurationManager.AppSettings["AwardNotificationFolderPath"].Replace('\\', '/');
            string url       = Request.ServerVariables["HTTP_HOST"] + localpath + HttpUtility.UrlEncode(strGeneratedFileName);
            lblMessage.Text    = "Note: Award notification final mode was successful and txt file generated with camper details, please <a href='http://" + url + "' target='_blank'>click here</a> to download it";
            lblMessage.Visible = true;
            Session["url"]     = url;
        }
        catch (FileNotFoundException ex)
        {
            throw ex;
        }
    }