Royal Free Flash Case Study 3â€“Pleuritic Chest Pa is showing ''Royal Free Flash Case Study 3 – Pleuritic Chest Pa'' at the time of excel export : When I am tring to download Project Name, i m getting different character for Special charter at the time excel export.      
 

 protected void lnkExportToExcel_Click(object sender, EventArgs e)
        {
            //INS1-219
            DataTable dt1 = DataHelper.ExecuteQuery(Session["strForExcelReport"].ToString());
            DataTable dt3 = new DataTable();
            dt3.Columns.Add("Project Code");
            dt3.Columns.Add("Project Name");
            dt3.Columns.Add("Client");
            dt3.Columns.Add("Status");
            dt3.Columns.Add("Sale Date");
            dt3.Columns.Add("Project Type");
            dt3.Columns.Add("Sales Agent");
            dt3.Columns.Add("Project Incharge");
            dt3.Columns.Add("Project Cost");
            dt3.Columns.Add("Planned Cost");
            dt3.Columns.Add("Additional Cost");
            dt3.Columns.Add("Payment Raised");
            dt3.Columns.Add("Payment Received");
            dt3.Columns.Add("Planned Start Date");
            dt3.Columns.Add("Revised Start Date");
            dt3.Columns.Add("Actual Start Date");
            dt3.Columns.Add("Planned End Date");
            dt3.Columns.Add("Revised End Date");
            dt3.Columns.Add("Actual End Date");
            dt3.Columns.Add("Planned Efforts(Hrs.)");
            dt3.Columns.Add("Revised Efforts(Hrs.)");
            dt3.Columns.Add("Actual Efforts(Hrs.)");
            dt3.Columns.Add("% TimeLine");
            dt3.Columns.Add("% Effort Plan");
            dt3.Columns.Add("% Revised");
            dt3.Columns.Add("% Overall");
            dt3.Columns.Add("Profitibility Number");

            foreach (DataRow dr in dt1.Rows)
            {
                DateTime dtNullDate = new DateTime(2008, 1, 1);
                DateTime dtPlannedStart, dtPlannedEnd, dtActualStart, dtActualEnd;
                double dblPlanedDays = 0, dblActualDays = 0;
                double dblPlannedEffort = 0, dblCalculatedEffort = 0, dblPercentCompleteEffort = 0, dblPercentCompleteTimeLine = 0, dblPercentCompleteOverAll = 0, dblRevisedEffort = 0;
                DataRow drnew = dt3.NewRow();
                TimeSpan oPlannedSpan = TimeSpan.Zero;
                TimeSpan oActualSpan = TimeSpan.Zero;
                string[] strArr = null;             
                drnew["Project Code"] = dr["ProjectCode"].ToString();
                drnew["Project Name"] = dr["ProjectName"].ToString();
                drnew["Client"] = dr["OrganizationName"].ToString();              
                string  PercentOverallComplete = dr["PercentageComplete_Overall"].ToString();               
                drnew["Status"] = dr["ProjectStatus"].ToString();
                DateTime SaleDate = Convert.ToDateTime(dr["CreatedOn"]);
                drnew["Sale Date"] = SaleDate.ToString("dd-MMM-yyyy");
                      drnew["Project Type"] = dr["CustomProjectTypeName"].ToString();
                drnew["Sales Agent"] = dr["SalesAgentFullName"].ToString();
                drnew["Project Incharge"] = dr["UserFullName"].ToString();
                drnew["Project Cost"] = TypeConvert.IsNullDecimal(dr["ProjectCost"], 0).ToString("N", en); 
                drnew["Planned Cost"] = dr["ProjectCost"].ToString(); 
                string sql = "EXEC SPGetProjectCostClassification " + dr["ProjectID"].ToString();
                DataTable dtProjCost = DataHelper.ExecuteQuery(sql);
                if (dtProjCost != null)
                {
                    drnew["Planned Cost"] = TypeConvert.IsNullDecimal(dtProjCost.Rows[0]["ProjectCostInitial"], 0).ToString("N", en);
                    drnew["Additional Cost"] = TypeConvert.IsNullDecimal(dtProjCost.Rows[0]["AdditionalCost"], 0).ToString("N", en);
                }
                  string RaisedAmt = dr["InvoiceRasiedAmount"].ToString();
                  drnew["Payment Raised"] = RaisedAmt;
                  string receivedAmt = dr["PaymentReceived"].ToString();
                  strArr = TypeConvert.IsNullString(RaisedAmt, string.Empty).Split(' ');
                    if (strArr.Length > 1)
                    {
                        drnew["Payment Received"] = strArr[0] + ' ' + receivedAmt;
                    }
                    else
                    {
                        drnew["Payment Received"] = receivedAmt;
                    }                           
                DateTime PlannedStartDate = Convert.ToDateTime(dr["PlannedStartDate"]);
                drnew["Planned Start Date"] = PlannedStartDate.ToString("dd-MMM-yyyy");
                if (drnew["Planned Start Date"].ToString() == "01-Jan-2008")
                {
                    drnew["Planned Start Date"] = "";
                }                
                DateTime RevisedStartDate = Convert.ToDateTime(dr["AllocatedStartDate"]);
                drnew["Revised Start Date"] = RevisedStartDate.ToString("dd-MMM-yyyy");
                if (drnew["Revised Start Date"].ToString() == "01-Jan-2008")
                {
                    drnew["Revised Start Date"] = "";
                }
                DateTime ActualStartDate = Convert.ToDateTime(dr["ActualStartDate"]);
                drnew["Actual Start Date"] = ActualStartDate.ToString("dd-MMM-yyyy");
                if (drnew["Actual Start Date"].ToString() == "01-Jan-2008")
                {
                    drnew["Actual Start Date"] = "";
                }
                DateTime PlannedEndDate = Convert.ToDateTime(dr["PlannedEndDate"]);
                drnew["Planned End Date"] = PlannedEndDate.ToString("dd-MMM-yyyy");
                if (drnew["Planned End Date"].ToString() == "01-Jan-2008")
                {
                    drnew["Planned End Date"] = "";
                }
                DateTime RevisedEndDate = Convert.ToDateTime(dr["AllocatedEndDate"]);
                drnew["Revised End Date"] = RevisedEndDate.ToString("dd-MMM-yyyy");
                if (drnew["Revised End Date"].ToString() == "01-Jan-2008")
                {
                    drnew["Revised End Date"] = "";
                }
                DateTime ActualEndDate = Convert.ToDateTime(dr["ActualEndDate"]);
                drnew["Actual End Date"] = ActualEndDate.ToString("dd-MMM-yyyy");
                if (drnew["Actual End Date"].ToString() == "01-Jan-2008")
                {
                    drnew["Actual End Date"] = "";
                }
                drnew["Planned Efforts(Hrs.)"] = dr["PlannedEfforts"].ToString();
                drnew["Revised Efforts(Hrs.)"] = dr["AllocatedEfforts"].ToString();
                string ActualEfforts = dr["ActualTime"].ToString();
                if (ActualEfforts != "" && ActualEfforts != "0")
                {
                    string[] tokens = ActualEfforts.Split(':');
                    if (tokens.Length == 2)
                    {
                        int HourValue = Convert.ToInt32(tokens[0]);
                        int MinuteValue = Convert.ToInt32(tokens[1]);
                        double MinutesInDecimalFormat = Convert.ToDouble(MinuteValue)/60;
                        if (MinutesInDecimalFormat != 0)
                        {
                            string Minute = String.Format("{0:0.00}", MinutesInDecimalFormat);
                            string[] tokensExcel = Minute.ToString().Split('.');
                            drnew["Actual Efforts(Hrs.)"] = HourValue + "." + tokensExcel[1]; 
                        }
                        else
                        {

                            drnew["Actual Efforts(Hrs.)"] = HourValue + "." + MinutesInDecimalFormat;
                           
                        }
                    }
                }             
                dblPlanedDays = Convert.ToDateTime(dr["PlannedEndDate"]).Subtract(Convert.ToDateTime(dr["PlannedStartDate"])).TotalDays;
                oPlannedSpan = Convert.ToDateTime(dr["PlannedEndDate"]).Subtract(Convert.ToDateTime(dr["PlannedStartDate"]));
                dtActualStart = (dr["ActualStartDate"] is DBNull) ? DateTime.Now : Convert.ToDateTime(dr["ActualStartDate"]);
                if (dr["ActualEndDate"] is DBNull || (!(dr["ActualEndDate"] is DBNull) && Convert.ToDateTime(dr["ActualEndDate"]) == MiscConstants.DEFAULT_DATE))
                    dtActualEnd = DateTime.Now;
                else
                    dtActualEnd = Convert.ToDateTime(dr["ActualEndDate"]);                
                if (dtActualStart != dtNullDate)
                {
                   oActualSpan = dtActualEnd.Subtract(dtActualStart);
                    if (oPlannedSpan.Ticks != 0)
                    {
                        if (oActualSpan.Ticks >= oPlannedSpan.Ticks)
                            dblPercentCompleteTimeLine = (100 +
                                                          (((oActualSpan.Ticks - oPlannedSpan.Ticks)*100)/
                                                           oPlannedSpan.Ticks));
                        else
                            dblPercentCompleteTimeLine = ((oActualSpan.Ticks*100)/oPlannedSpan.Ticks);
                    }
                }
                else
                {
                    dblPercentCompleteTimeLine = 0;
                }
                drnew["% TimeLine"] = dblPercentCompleteTimeLine.ToString("F");
                dblPlannedEffort = Convert.ToDouble(dr["PlannedEfforts"]);
                dblRevisedEffort = Convert.ToDouble(dr["AllocatedEfforts"]);              
                dblCalculatedEffort = Convert.ToDouble(dr["ActualTime"].ToString().Replace(':', '.'));// Convert.ToDouble(actualTime);
                double dblPercentCompleteEffortRevised = 0;
                if (dblPlannedEffort > 0)
                {
                    if (dblCalculatedEffort > dblPlannedEffort)
                        dblPercentCompleteEffort = (100 + (((dblCalculatedEffort - dblPlannedEffort) * 100) / dblPlannedEffort));
                    else
                        dblPercentCompleteEffort = ((dblCalculatedEffort * 100) / dblPlannedEffort);
                }
                else
                {
                    dblPercentCompleteEffort = 100;
                }
                drnew["% Effort Plan"] = dblPercentCompleteEffort.ToString("F");


                if (dblRevisedEffort > 0)
                {
                    if (dblCalculatedEffort > dblRevisedEffort)
                        dblPercentCompleteEffortRevised = (100 + (((dblCalculatedEffort - dblRevisedEffort) * 100) / dblRevisedEffort));
                    else
                        dblPercentCompleteEffortRevised = ((dblCalculatedEffort * 100) / dblRevisedEffort);
                }
                else
                {
                    dblPercentCompleteEffortRevised = 100;
                }
                drnew["% Revised"] = dblPercentCompleteEffortRevised.ToString("F");
                drnew["% Overall"] = PercentOverallComplete;
                decimal totResourceCost = TypeConvert.IsNullDecimal(dr["ResourceCostOffshore"].ToString(), 0) + TypeConvert.IsNullDecimal(dr["ResourceCostOnSite"].ToString(), 0);
                decimal vmsCost = TypeConvert.IsNullDecimal(dr["OutSourcingCost"].ToString(), 0) + TypeConvert.IsNullDecimal(dr["DirectCost"].ToString(), 0);
                decimal grandTotalCogs = totResourceCost + vmsCost;
                if ((TypeConvert.IsNullDecimal(dr["ProjectCost"].ToString(), 0)).ToString("0.00") == "0.00")
                {
                    drnew["Profitibility Number"] = "0.00%";
                }
                else
                {

                    decimal currentCOGS = (((grandTotalCogs) / (TypeConvert.IsNullDecimal(dr["ProjectCost"].ToString(), 0))) * 100);
                    decimal percentComplete = TypeConvert.IsNullDecimal(PercentOverallComplete, 0);
                    drnew["Profitibility Number"] = ((percentComplete > 0) ? currentCOGS * ((Convert.ToDecimal(100)) - percentComplete) / percentComplete + currentCOGS : 0).ToString("0.00") + "%";
                }                
                dt3.Rows.Add(drnew);
            }
            string attachment = "attachment; filename=ProjectInHandDetailsList_" + DateTime.Now.ToString("dd MMM yyyy") + ".xls";
            Response.ClearContent();
            Response.AddHeader("content-disposition", attachment);
            Response.ContentType = "application/vnd.ms-excel";
            string tab = "";
            foreach (DataColumn dc in dt3.Columns)
            {
                Response.Write(tab + dc.ColumnName);
                tab = "\t";
            }
            Response.Write("\n");
            int i;

            foreach (DataRow dr in dt3.Rows)
            {
                tab = "";
                for (i = 0; i < dt3.Columns.Count; i++)
                {
                    Response.Write(tab + dr[i].ToString());
                    tab = "\t";
                }
                Response.Write("\n");
            }

            Response.End();
            //END INS1-219
        }