コード例 #1
0
        protected void btnImport_Click(object sender, EventArgs e)
        {
            try
            {
                string Err = string.Empty;
                if (!FileUpload1.HasFile)
                {
                    Err                = "               Please select file";
                    lblerror.Text      = Err;
                    lblerror.ForeColor = Color.Red;
                    lblerror.Visible   = true;
                    grdErrors.Visible  = false;
                    grdExcel.Visible   = false;
                    btnUpload.Visible  = false;
                    return;
                }
                if (!(Path.GetExtension(FileUpload1.FileName).Equals(".xlsx")))

                {
                    Err                = "               Please Select Excel file (.xlsx) only ";
                    lblerror.Text      = Err;
                    lblerror.ForeColor = Color.Red;
                    lblerror.Visible   = true;
                    grdErrors.Visible  = false;
                    grdExcel.Visible   = false;
                    btnUpload.Visible  = false;
                    return;
                }



                path = Server.MapPath(@"~/writedata/") + FileUpload1.FileName;


                try
                {
                    System.IO.File.Delete(path);
                }
                catch (Exception ex)
                {
                }
                try
                {
                    FileUpload1.SaveAs(path);
                }
                catch (FileNotFoundException ex)
                {
                    lblerror.Text = "Error creating file";
                }
                catch (Exception ex)
                {
                    throw ex;
                }


                clsExcelInterface       objExcel    = new clsExcelInterface();
                DataTable               dtExcelData = objExcel.getExcelDataTable(path);
                List <ProjectionDataWB> ListRows    = new List <ProjectionDataWB>();
                List <ProjectionDataWB> ListRowserr = new List <ProjectionDataWB>();
                List <ErrorMessage>     ListError   = new List <ErrorMessage>();
                int     rowIndex = 0;
                decimal ddd      = 0;
                bool    chk      = true;
                bool    chk1     = true;
                bool    chk2     = true;
                bool    chk3     = true;

                foreach (DataRow dr in dtExcelData.Rows)
                {
                    if (rowIndex >= Convert.ToInt32(drpRows.SelectedValue.ToString()) && dr[11].ToString() != "")
                    {
                        int selectedindex = Convert.ToInt32(drpColumn.SelectedValue.ToString());

                        chk  = dr[selectedindex + 9].ToString() != "" ? dr[selectedindex + 9].ToString().IsNumericText() : true;
                        chk1 = dr[selectedindex + 10].ToString() != "" ? dr[selectedindex + 10].ToString().IsNumericText() : true;
                        chk2 = dr[selectedindex + 11].ToString() != "" ? dr[selectedindex + 11].ToString().IsNumericText() : true;
                        chk3 = dr[selectedindex + 12].ToString() != "" ? dr[selectedindex + 12].ToString().IsNumericText() : true;

                        //if (!dr[selectedindex + 9].ToString().IsNumericText())
                        //{
                        //	ListError.Add(new ErrorMessage() { row = rowIndex.ToString(), ColumnIndex = 2, LoanNum = "Bank Financing", column = "Bank Financing", Message = "Please enter Numeric value" });
                        //}
                        //else if (!dr[selectedindex + 10].ToString().IsNumericText())
                        //{
                        //	ListError.Add(new ErrorMessage() { row = rowIndex.ToString(), ColumnIndex = 2, LoanNum = "Current Disbursement", column = "Current Disbursement", Message = "Please enter Numeric value" });
                        //}
                        //else if (!dr[selectedindex + 11].ToString().IsNumericText())
                        //{
                        //	ListError.Add(new ErrorMessage() { row = rowIndex.ToString(), ColumnIndex = 2, LoanNum = "Current Disbursement", column = "Current Disbursement", Message = "Please enter Numeric value" });
                        //}

                        ProjectionDataWB row1 = new ProjectionDataWB()
                        {
                            rowIndex    = rowIndex.ToString(),
                            ProjectNo   = dr[selectedindex].ToString(),
                            ProjectName = dr[selectedindex + 1].ToString(),

                            ApprovalDate  = dr[selectedindex + 2].ToString(),
                            EffectiveDate = dr[selectedindex + 3].ToString(),
                            closingdate   = dr[selectedindex + 4].ToString(),
                            Reclosingdate = dr[selectedindex + 5].ToString(),
                            DO            = dr[selectedindex + 6].ToString(),
                            IP            = dr[selectedindex + 7].ToString(),
                            //Agency = dr[selectedindex+8].ToString(),
                            QuarterYear = dr[selectedindex + 8].ToString(),
                            Amt         = dr[selectedindex + 9].ToString().Contains("E") || dr[selectedindex + 9].ToString().Contains("e") ? decimal.TryParse(dr[selectedindex + 9].ToString(), out ddd).ToString() : dr[selectedindex + 9].ToString(),
                            TotalDis    = dr[selectedindex + 10].ToString().Contains("E") || dr[selectedindex + 10].ToString().Contains("e") ? decimal.TryParse(dr[selectedindex + 10].ToString(), out ddd).ToString() : dr[selectedindex + 10].ToString(),
                            OriginalDis = dr[selectedindex + 11].ToString().Contains("E") || dr[selectedindex + 11].ToString().Contains("e") ? decimal.TryParse(dr[selectedindex + 11].ToString(), out ddd).ToString() : dr[selectedindex + 11].ToString(),
                            FrevDis     = dr[selectedindex + 12].ToString().Contains("E") || dr[selectedindex + 12].ToString().Contains("e") ? decimal.TryParse(dr[selectedindex + 12].ToString(), out ddd).ToString() : dr[selectedindex + 12].ToString()
                        };

                        ListRowserr.Add(row1);

                        if (chk == false || chk1 == false || chk2 == false || chk3 == false)
                        {
                            grdExcel.DataSource = ListRowserr;
                            grdExcel.DataBind();
                            grdExcel.Visible  = true;
                            btnUpload.Visible = false;
                            Alert.show("Please select valid range or correct this error");
                            lblerror.Text    = "Please select valid range or correct this error";
                            lblerror.Visible = true;
                            return;
                        }
                        ProjectionDataWB row = new ProjectionDataWB()
                        {
                            rowIndex    = rowIndex.ToString(),
                            ProjectNo   = dr[selectedindex].ToString(),
                            ProjectName = dr[selectedindex + 1].ToString(),

                            ApprovalDate  = dr[selectedindex + 2].ToString(),
                            EffectiveDate = dr[selectedindex + 3].ToString(),
                            closingdate   = dr[selectedindex + 4].ToString(),
                            Reclosingdate = dr[selectedindex + 5].ToString(),
                            DO            = dr[selectedindex + 6].ToString(),
                            IP            = dr[selectedindex + 7].ToString(),
                            //Agency = dr[selectedindex+8].ToString(),
                            QuarterYear = dr[selectedindex + 8].ToString(),
                            Amt         = dr[selectedindex + 9].ToString().Contains("E") || dr[selectedindex + 9].ToString().Contains("e") ? Decimal.Parse(dr[selectedindex + 9].ToString(), System.Globalization.NumberStyles.Float).ToString() : dr[selectedindex + 9].ToString(),
                            TotalDis    = dr[selectedindex + 10].ToString().Contains("E") || dr[selectedindex + 10].ToString().Contains("e") ? Decimal.Parse(dr[selectedindex + 10].ToString(), System.Globalization.NumberStyles.Float).ToString() : dr[selectedindex + 10].ToString(),
                            OriginalDis = dr[selectedindex + 11].ToString().Contains("E") || dr[selectedindex + 11].ToString().Contains("e") ? Decimal.Parse(dr[selectedindex + 11].ToString(), System.Globalization.NumberStyles.Float).ToString() : dr[selectedindex + 11].ToString(),
                            FrevDis     = dr[selectedindex + 12].ToString().Contains("E") || dr[selectedindex + 12].ToString().Contains("e") ? Decimal.Parse(dr[selectedindex + 12].ToString(), System.Globalization.NumberStyles.Float).ToString() : dr[selectedindex + 12].ToString()
                        };

                        ListRows.Add(row);
                    }


                    rowIndex++;
                }



                grdExcel.DataSource = ListRows;
                grdExcel.DataBind();
                grdExcel.Visible = true;

                Session["ExcelRows"] = ListRows;
                grdErrors.DataSource = ListError;
                grdErrors.DataBind();
                foreach (ErrorMessage er in ListError)
                {
                    grdExcel.Rows[Convert.ToInt32(er.row)].BackColor = Color.FromArgb(255, 220, 220);
                    grdExcel.Rows[Convert.ToInt32(er.row)].Cells[er.ColumnIndex + 1].BackColor = Color.FromArgb(255, 140, 140);
                }


                if (grdErrors.Rows.Count == 0)
                {
                    grdErrors.Visible = false;
                    btnUpload.Visible = true;
                    lblerr.Visible    = false;
                }
                else
                {
                    lblerr.Visible    = true;
                    grdErrors.Visible = true;
                    btnUpload.Visible = false;
                }
                //}
            }
            catch (Exception ex)
            {
                grdExcel.Visible  = false;
                grdErrors.Visible = false;
                btnUpload.Visible = false;

                string Error = ex.ToString();
                lblerror.Text      = Error;
                lblerror.ForeColor = Color.Red;
                lblerror.Visible   = true;
            }
            finally
            {
                try
                {
                    System.IO.File.Delete(path);
                }
                catch (Exception ex)
                {
                }
            }
        }
コード例 #2
0
    protected void btnImport_Click(object sender, EventArgs e)
    {
        string path = string.Empty;

        try
        {
            string Err = string.Empty;
            if (!FileUpload1.HasFile)
            {
                Err           = "               Please select file";
                lblerror.Text = Err;

                return;
            }
            if (!(Path.GetExtension(FileUpload1.FileName).Equals(".xlsx")) && !(Path.GetExtension(FileUpload1.FileName).Equals(".xls")))

            {
                Err           = "               Please Select Excel file (.xlsx) only/(.xls) only ";
                lblerror.Text = Err;


                return;
            }



            path = Server.MapPath(@"~/writedata/") + FileUpload1.FileName;


            try
            {
                System.IO.File.Delete(path);
            }
            catch (Exception ex)
            {
            }
            try
            {
                FileUpload1.SaveAs(path);
            }
            catch (FileNotFoundException ex)
            {
                lblerror.Text = "Error creating file";
            }
            catch (Exception ex)
            {
                throw ex;
            }


            clsExcelInterface       objExcel    = new clsExcelInterface();
            DataTable               dtExcelData = objExcel.getExcelDataTable(path);
            List <ProjectionDataWB> ListRows    = new List <ProjectionDataWB>();
            List <ErrorList>        errolist    = new List <ErrorList>();
            float         a        = 0;
            StringBuilder error    = new StringBuilder();
            int           rowIndex = 0;
            foreach (DataRow dr in dtExcelData.Rows)
            {
                if (rowIndex >= Convert.ToInt32(drpRows.SelectedValue.ToString()) && dr[0].ToString().Trim() != "")
                {
                    int selectedindex = Convert.ToInt32(drpColumn.SelectedValue.ToString());

                    if (float.TryParse(dr[selectedindex + 2].ToString(), out a))
                    {
                        if (float.TryParse(dr[selectedindex + 3].ToString(), out a))
                        {
                            ProjectionDataWB row = new ProjectionDataWB()
                            {
                                rowIndex                  = rowIndex.ToString(),
                                ProjectName               = dr[selectedindex + 1].ToString(),
                                PosedLoanAmt              = dr[selectedindex + 2].ToString(),
                                RevisedLoanAmt            = dr[selectedindex + 3].ToString(),
                                Sector                    = dr[selectedindex + 4].ToString(),
                                DateofPosing              = dr[selectedindex + 5].ToString(),
                                ExpectedApprovalDateofMDB = dr[selectedindex + 6].ToString(),
                                ProjectDescription        = dr[selectedindex + 7].ToString(),
                            };
                            ListRows.Add(row);
                        }
                        else
                        {
                            ErrorList row = new ErrorList()
                            {
                                rowIndex                  = rowIndex.ToString(),
                                ProjectName               = dr[selectedindex + 1].ToString(),
                                PosedLoanAmt              = dr[selectedindex + 2].ToString(),
                                RevisedLoanAmt            = "<span style='color:red'>" + dr[selectedindex + 3].ToString() + "</span>",
                                Sector                    = dr[selectedindex + 4].ToString(),
                                DateofPosing              = dr[selectedindex + 5].ToString(),
                                ExpectedApprovalDateofMDB = dr[selectedindex + 6].ToString(),
                                ProjectDescription        = dr[selectedindex + 7].ToString(),
                            };
                            errolist.Add(row);
                        }
                    }
                    else
                    {
                        ErrorList row = new ErrorList()
                        {
                            rowIndex                  = rowIndex.ToString(),
                            ProjectName               = dr[selectedindex + 1].ToString(),
                            PosedLoanAmt              = "<span style='color:red'>" + dr[selectedindex + 2].ToString() + "</span>",
                            RevisedLoanAmt            = dr[selectedindex + 3].ToString(),
                            Sector                    = dr[selectedindex + 4].ToString(),
                            DateofPosing              = dr[selectedindex + 5].ToString(),
                            ExpectedApprovalDateofMDB = dr[selectedindex + 6].ToString(),
                            ProjectDescription        = dr[selectedindex + 7].ToString(),
                        };
                        errolist.Add(row);
                    }
                }


                rowIndex++;
            }



            grdExcel.DataSource = ListRows;
            grdExcel.DataBind();
            grdExcel.Visible = true;
            if (errolist.Count > 0)
            {
                grdErrorlist.DataSource = errolist;
                grdErrorlist.DataBind();
                grdErrorlist.Visible = true;
                btnSubmit.Visible    = false;
                grdErrorlist.Caption = HttpUtility.HtmlDecode("<span style='color:red; font-weight:bold'>Error List Please correct Amout is only numeric</span>");
            }
            else
            {
                btnSubmit.Visible    = true;
                grdErrorlist.Visible = false;
                Session["ExcelRows"] = ListRows;
            }



            //}
        }
        catch (Exception ex)
        {
            grdExcel.Visible = false;

            string Error = ex.ToString();
            lblerror.Text = Error;

            lblerror.Visible = true;
        }
        finally
        {
            try
            {
                System.IO.File.Delete(path);
            }
            catch (Exception ex)
            {
            }
        }
    }
コード例 #3
0
        protected void btnImport_Click(object sender, EventArgs e)
        {
            try
            {
                string Err = string.Empty;
                if (!FileUpload1.HasFile)
                {
                    Err                = "Please select file";
                    lblerror.Text      = Err;
                    lblerror.ForeColor = Color.Red;
                    lblerror.Visible   = true;
                    return;
                }
                if (!(Path.GetExtension(FileUpload1.FileName).Equals(".xlsx") || Path.GetExtension(FileUpload1.FileName).Equals(".xls")))
                {
                    Err                = "Please Select Excel file (.xls or .xlsx) only ";
                    lblerror.Text      = Err;
                    lblerror.ForeColor = Color.Red;
                    lblerror.Visible   = true;
                    return;
                }
                if (drpYear.SelectedIndex == 0)
                {
                    Err                 = "Please Select Year";
                    lblYerror.Text      = Err;
                    lblYerror.ForeColor = Color.Red;
                    lblYerror.Visible   = true;
                    return;
                }
                if (drpMonth.SelectedIndex == 0)
                {
                    Err                 = "Please Select Month";
                    lblMerror.Text      = Err;
                    lblMerror.ForeColor = Color.Red;
                    lblMerror.Visible   = true;
                    return;
                }
                if (drpCumCA.SelectedIndex == 0)
                {
                    Err = "Please Select Column Number For Cum. Contract Award Actual From Excel";
                    lblCumCAerr.Text      = Err;
                    lblCumCAerr.ForeColor = Color.Red;
                    lblCumCAerr.Visible   = true;
                    return;
                }
                if (drpCumDisb.SelectedIndex == 0)
                {
                    Err                  = "Please Select Column Number For Cum. Disbursement Actual From Excel";
                    lblCumDisb.Text      = Err;
                    lblCumDisb.ForeColor = Color.Red;
                    lblCumDisb.Visible   = true;
                    return;
                }
                if (drpCAct.SelectedIndex == 0)
                {
                    Err                  = "Please Select Column Number For Contract Award Actual From Excel";
                    lblCTarErr.Text      = Err;
                    lblCTarErr.ForeColor = Color.Red;
                    lblCTarErr.Visible   = true;
                    return;
                }
                if (drpDAct.SelectedIndex == 0)
                {
                    Err                  = "Please Select Column Number For Disbursement Award Actual From Excel";
                    lblDTarErr.Text      = Err;
                    lblDTarErr.ForeColor = Color.Red;
                    lblDTarErr.Visible   = true;
                    return;
                }
                if (drpRowNum.SelectedIndex == 0)
                {
                    Err                 = "Please Select Starting Row From Excel";
                    lblRerror.Text      = Err;
                    lblRerror.ForeColor = Color.Red;
                    lblRerror.Visible   = true;
                    return;
                }
                string path = Server.MapPath(@"~/writereaddata/") + FileUpload1.FileName;
                try
                {
                    System.IO.File.Delete(path);
                }
                catch (Exception ex)
                {
                }

                FileUpload1.SaveAs(path);

                clsExcelInterface     objExcel    = new clsExcelInterface();
                DataTable             dtExcelData = objExcel.getExcelDataTable(path);
                List <ProjectionData> ListRows    = new List <ProjectionData>();
                List <ErrorMessage>   ListError   = new List <ErrorMessage>();
                int rowIndex = 0;
                int skiprows = 0;

                foreach (DataRow dr in dtExcelData.Rows)
                {
                    if (skiprows < int.Parse(drpRowNum.SelectedValue) - 1)
                    {
                        skiprows++;
                        continue;
                    }

                    string loanno = dr[0].ToString();
                    if (!string.IsNullOrWhiteSpace(loanno) && loanno.IsNumericText())
                    {
                        if ((dr[drpCumCA.SelectedValue].ToString() != "-") && (!dr[drpCumCA.SelectedValue].ToString().IsNumericText()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 2, LoanNum = loanno, column = "Cum. Contract Award ", Message = "Please enter Numeric value"
                            });
                        }

                        if ((dr[drpCumDisb.SelectedValue].ToString() != "-") && (!dr[drpCumDisb.SelectedValue].ToString().IsNumericText()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 3, LoanNum = loanno, column = "Cum. Disbursement ", Message = "Please enter Numeric value"
                            });
                        }

                        if ((dr[drpCAct.SelectedValue].ToString() != "-") && (!dr[drpCAct.SelectedValue].ToString().IsNumericText()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 4, LoanNum = loanno, column = "Contract Award Monthly", Message = "Please enter Numeric value"
                            });
                        }

                        if ((dr[drpDAct.SelectedValue].ToString() != "-") && (!dr[drpDAct.SelectedValue].ToString().IsNumericText()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 5, LoanNum = loanno, column = "Disbursement Monthly", Message = "Please enter Numeric value"
                            });
                        }

                        if (dr[drpCAct.SelectedValue].ToString() == "-")
                        {
                            camact = "0";
                        }
                        else
                        {
                            if (dr[drpCAct.SelectedValue].ToString().IsNumericText())
                            {
                                camact = String.Format("{0:0.000}", (Math.Round(decimal.Parse(dr[drpCAct.SelectedValue].ToString()), 3)));
                            }
                        }

                        if (dr[drpCumCA.SelectedValue].ToString() == "-")
                        {
                            cumca = "0";
                        }
                        else
                        {
                            if (dr[drpCumCA.SelectedValue].ToString().IsNumericText())
                            {
                                cumca = String.Format("{0:0.000}", (Math.Round(decimal.Parse(dr[drpCumCA.SelectedValue].ToString()), 3)));
                            }
                        }

                        if (dr[drpCumDisb.SelectedValue].ToString() == "-")
                        {
                            cumdisb = "0";
                        }
                        else
                        {
                            if (dr[drpCumDisb.SelectedValue].ToString().IsNumericText())
                            {
                                cumdisb = String.Format("{0:0.000}", (Math.Round(decimal.Parse(dr[drpCumDisb.SelectedValue].ToString()), 3)));
                            }
                        }

                        if (camact.IsNumericText())
                        {
                            ctotal = ctotal + decimal.Parse(camact);
                        }

                        if (dr[drpDAct.SelectedValue].ToString() == "-")
                        {
                            dmact = "0";
                        }
                        else
                        {
                            if (dr[drpDAct.SelectedValue].ToString().IsNumericText())
                            {
                                dmact = String.Format("{0:0.000}", (Math.Round(decimal.Parse(dr[drpDAct.SelectedValue].ToString()), 3)));
                            }
                        }
                        if (dmact.IsNumericText())
                        {
                            dtotal = dtotal + decimal.Parse(dmact);
                        }
                        ProjectionData row = new ProjectionData()
                        {
                            rowIndex = rowIndex.ToString(),
                            LoanNo   = dr[0].ToString(),
                            LoanName = dr[1].ToString(),
                            CAMAct   = camact,
                            DMAct    = dmact,
                            CumCA    = cumca,
                            CumDisb  = cumdisb
                        };
                        ListRows.Add(row);
                        rowIndex++;
                    }
                    camact = string.Empty;
                    dmact  = string.Empty;
                    if (loanno.Contains("Sub-Total"))
                    {
                        ProjectionData row = new ProjectionData()
                        {
                            LoanName = dr[0].ToString(),
                            CAMAct   = String.Format("{0:0.000}", ctotal),
                            DMAct    = String.Format("{0:0.000}", dtotal)
                        };
                        if (!(String.Format("{0:0.000}", (decimal.Parse(dr[drpCAct.SelectedValue].ToString()))) == ctotal.ToString()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 2, LoanNum = loanno, column = "Contract Award", Message = "Total For Contract Award Actual Does Not Match"
                            });
                        }


                        if (!(String.Format("{0:0.000}", (decimal.Parse(dr[drpDAct.SelectedValue].ToString()))) == dtotal.ToString()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 3, LoanNum = loanno, column = "Disbursement", Message = "Total For Disbursement Actual Does Not Match"
                            });
                        }
                        ListRows.Add(row);
                        rowIndex++;
                        ctotal = 0;
                        dtotal = 0;
                    }
                }

                grdExcel.DataSource = ListRows;
                grdExcel.DataBind();
                Session["ExcelRows"] = ListRows;
                grdErrors.DataSource = ListError;
                grdErrors.DataBind();


                foreach (ErrorMessage er in ListError)
                {
                    grdExcel.Rows[Convert.ToInt32(er.row)].BackColor = Color.FromArgb(255, 165, 165);
                    grdExcel.Rows[Convert.ToInt32(er.row)].Cells[er.ColumnIndex + 1].BackColor = Color.FromArgb(255, 140, 140);
                }
                if (grdErrors.Rows.Count == 0)
                {
                    grdErrors.Visible = false;
                    btnUpload.Visible = true;
                    lblerr.Visible    = false;
                }
                else
                {
                    lblerr.Visible    = true;
                    grdErrors.Visible = true;
                    btnUpload.Visible = false;
                }
                //}
            }
            catch (Exception ex)
            {
            }
        }
コード例 #4
0
        protected void btnImport_Click(object sender, EventArgs e)
        {
            try
            {
                string Err = string.Empty;
                if (!FileUpload1.HasFile)
                {
                    Err                = "               Please select file";
                    lblerror.Text      = Err;
                    lblerror.ForeColor = Color.Red;
                    lblerror.Visible   = true;
                    grdErrors.Visible  = false;
                    grdExcel.Visible   = false;
                    btnUpload.Visible  = false;
                    return;
                }
                if (!(Path.GetExtension(FileUpload1.FileName).Equals(".xlsx")))

                {
                    Err                = "               Please Select Excel file (.xlsx) only ";
                    lblerror.Text      = Err;
                    lblerror.ForeColor = Color.Red;
                    lblerror.Visible   = true;
                    grdErrors.Visible  = false;
                    grdExcel.Visible   = false;
                    btnUpload.Visible  = false;
                    return;
                }

                if (drpYear.SelectedIndex == 0)
                {
                    Err                 = "Please Select Year";
                    lblYerror.Text      = Err;
                    lblYerror.ForeColor = Color.Red;
                    lblYerror.Visible   = true;
                    return;
                }


                path = Server.MapPath(@"~/writereaddata/") + FileUpload1.FileName;


                try
                {
                    System.IO.File.Delete(path);
                }
                catch (Exception ex)
                {
                }
                try
                {
                    FileUpload1.SaveAs(path);
                }
                catch (FileNotFoundException ex)
                {
                    lblerror.Text = "Error creating file";
                }
                catch (Exception ex)
                {
                    throw ex;
                }


                clsExcelInterface     objExcel    = new clsExcelInterface();
                DataTable             dtExcelData = objExcel.getExcelDataTable(path);
                List <ProjectionData> ListRows    = new List <ProjectionData>();
                List <ErrorMessage>   ListError   = new List <ErrorMessage>();
                int rowIndex = 0;
                foreach (DataRow dr in dtExcelData.Rows)
                {
                    string loanno = dr[0].ToString();
                    if (!string.IsNullOrWhiteSpace(loanno) && loanno.IsNumericText())
                    {
                        if ((dr[2].ToString() != "-") && (!dr[2].ToString().IsNumericText()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 2, LoanNum = loanno, column = "Target Q1(CA)", Message = "Please enter Numeric value"
                            });
                        }
                        if ((dr[3].ToString() != "-") && (!dr[3].ToString().IsNumericText()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 3, LoanNum = loanno, column = "Target Q2(CA)", Message = "Please enter Numeric value"
                            });
                        }
                        if ((dr[4].ToString() != "-") && (!dr[4].ToString().IsNumericText()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 4, LoanNum = loanno, column = "Target Q3(CA)", Message = "Please enter Numeric value"
                            });
                        }
                        if ((dr[5].ToString() != "-") && (!dr[5].ToString().IsNumericText()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 5, LoanNum = loanno, column = "Target Q4(CA)", Message = "Please enter Numeric value"
                            });
                        }
                        if ((dr[6].ToString() != "-") && (!dr[6].ToString().IsNumericText()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 6, LoanNum = loanno, column = "Total Target(CA)", Message = "Please enter Numeric value"
                            });
                        }
                        if ((dr[7].ToString() != "-") && (!dr[7].ToString().IsNumericText()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 7, LoanNum = loanno, column = "Target Q1(Dis.)", Message = "Please enter Numeric value"
                            });
                        }
                        if ((dr[8].ToString() != "-") && (!dr[8].ToString().IsNumericText()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 8, LoanNum = loanno, column = "Target Q2(Dis.)", Message = "Please enter Numeric value"
                            });
                        }
                        if ((dr[9].ToString() != "-") && (!dr[9].ToString().IsNumericText()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 9, LoanNum = loanno, column = "Target Q3(Dis.)", Message = "Please enter Numeric value"
                            });
                        }
                        if ((dr[10].ToString() != "-") && (!dr[10].ToString().IsNumericText()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 10, LoanNum = loanno, column = "Target Q4(Dis.)", Message = "Please enter Numeric value"
                            });
                        }
                        if ((dr[11].ToString() != "-") && (!dr[11].ToString().IsNumericText()))
                        {
                            ListError.Add(new ErrorMessage()
                            {
                                row = rowIndex.ToString(), ColumnIndex = 11, LoanNum = loanno, column = "Total Target(Dis.)", Message = "Please enter Numeric value"
                            });
                        }

                        ProjectionData row = new ProjectionData()
                        {
                            rowIndex = rowIndex.ToString(),
                            LoanNo   = dr[0].ToString(),
                            LoanName = dr[1].ToString(),

                            CTarQ1    = dr[2].ToString(),
                            CTarQ2    = dr[3].ToString(),
                            CTarQ3    = dr[4].ToString(),
                            CTarQ4    = dr[5].ToString(),
                            CTotalTar = dr[6].ToString(),

                            DTarQ1    = dr[7].ToString(),
                            DTarQ2    = dr[8].ToString(),
                            DTarQ3    = dr[9].ToString(),
                            DTarQ4    = dr[10].ToString(),
                            DTotalTar = dr[11].ToString()
                        };

                        ListRows.Add(row);
                        if (dr[2].ToString() == "-")
                        {
                            row.CTarQ1 = Convert.ToString(0);
                        }
                        else
                        {
                            if (dr[2].ToString().IsNumericText())
                            {
                                row.CTarQ1 = String.Format("{0:0.0}", (Math.Round(decimal.Parse(row.CTarQ1), 3)));
                            }
                        }

                        if (dr[3].ToString() == "-")
                        {
                            row.CTarQ2 = Convert.ToString(0);
                        }
                        else
                        {
                            if (dr[3].ToString().IsNumericText())
                            {
                                row.CTarQ2 = String.Format("{0:0.0}", (Math.Round(decimal.Parse(row.CTarQ2), 3)));
                            }
                        }

                        if (dr[4].ToString() == "-")
                        {
                            row.CTarQ3 = Convert.ToString(0);
                        }
                        else
                        {
                            if (dr[4].ToString().IsNumericText())
                            {
                                row.CTarQ3 = String.Format("{0:0.0}", (Math.Round(decimal.Parse(row.CTarQ3), 3)));
                            }
                        }

                        if (dr[5].ToString() == "-")
                        {
                            row.CTarQ4 = Convert.ToString(0);
                        }
                        else
                        {
                            if (dr[5].ToString().IsNumericText())
                            {
                                row.CTarQ4 = String.Format("{0:0.0}", (Math.Round(decimal.Parse(row.CTarQ4), 3)));
                            }
                        }

                        if (dr[6].ToString() == "-")
                        {
                            row.CTotalTar = Convert.ToString(0);
                        }
                        else
                        {
                            if (dr[6].ToString().IsNumericText())
                            {
                                row.CTotalTar = String.Format("{0:0.0}", (Math.Round(decimal.Parse(row.CTotalTar), 3)));
                            }
                        }

                        if (dr[7].ToString() == "-")
                        {
                            row.DTarQ1 = Convert.ToString(0);
                        }
                        else
                        {
                            if (dr[7].ToString().IsNumericText())
                            {
                                row.DTarQ1 = String.Format("{0:0.0}", (Math.Round(decimal.Parse(row.DTarQ1), 3)));
                            }
                        }

                        if (dr[8].ToString() == "-")
                        {
                            row.DTarQ2 = Convert.ToString(0);
                        }
                        else
                        {
                            if (dr[8].ToString().IsNumericText())
                            {
                                row.DTarQ2 = String.Format("{0:0.0}", (Math.Round(decimal.Parse(row.DTarQ2), 3)));
                            }
                        }

                        if (dr[9].ToString() == "-")
                        {
                            row.DTarQ3 = Convert.ToString(0);
                        }
                        else
                        {
                            if (dr[9].ToString().IsNumericText())
                            {
                                row.DTarQ3 = String.Format("{0:0.0}", (Math.Round(decimal.Parse(row.DTarQ3), 3)));
                            }
                        }

                        if (dr[10].ToString() == "-")
                        {
                            row.DTarQ4 = Convert.ToString(0);
                        }
                        else
                        {
                            if (dr[10].ToString().IsNumericText())
                            {
                                row.DTarQ4 = String.Format("{0:0.0}", (Math.Round(decimal.Parse(row.DTarQ4), 3)));
                            }
                        }

                        if (dr[11].ToString() == "-")
                        {
                            row.DTotalTar = Convert.ToString(0);
                        }
                        else
                        {
                            if (dr[11].ToString().IsNumericText())
                            {
                                row.DTotalTar = String.Format("{0:0.0}", (Math.Round(decimal.Parse(row.DTotalTar), 3)));
                            }
                        }

                        rowIndex++;
                    }
                }


                grdExcel.DataSource = ListRows;
                grdExcel.DataBind();
                grdExcel.Visible = true;

                Session["ExcelRows"] = ListRows;
                grdErrors.DataSource = ListError;
                grdErrors.DataBind();
                info.Titles[3] = "<b>Contract Award" + "  " + drpYear.SelectedItem.Text + "</b>";
                info.Titles[8] = "<b>Disbursement Award" + "  " + drpYear.SelectedItem.Text + "</b>";


                foreach (ErrorMessage er in ListError)
                {
                    grdExcel.Rows[Convert.ToInt32(er.row)].BackColor = Color.FromArgb(255, 220, 220);
                    grdExcel.Rows[Convert.ToInt32(er.row)].Cells[er.ColumnIndex + 1].BackColor = Color.FromArgb(255, 140, 140);
                }


                if (grdErrors.Rows.Count == 0)
                {
                    grdErrors.Visible = false;
                    btnUpload.Visible = true;
                    lblerr.Visible    = false;
                }
                else
                {
                    lblerr.Visible    = true;
                    grdErrors.Visible = true;
                    btnUpload.Visible = false;
                }
                //}
            }
            catch (Exception ex)
            {
                grdExcel.Visible  = false;
                grdErrors.Visible = false;
                btnUpload.Visible = false;

                string Error = ex.ToString();
                lblerror.Text      = Error;
                lblerror.ForeColor = Color.Red;
                lblerror.Visible   = true;
            }
            finally
            {
                try
                {
                    System.IO.File.Delete(path);
                }
                catch (Exception ex)
                {
                }
            }
        }