コード例 #1
0
        protected void btnProceed_Click(object sender, EventArgs e)
        {
            string folderPath = this.Server.MapPath(@"..\Eligibility\TempDirectory");

            try
            {
                if (fileUploadExcel.HasFile)
                {
                    //checking extension
                    if (!(fileUploadExcel.FileName.EndsWith(".xls", StringComparison.OrdinalIgnoreCase) || fileUploadExcel.FileName.EndsWith(".xlsx", StringComparison.OrdinalIgnoreCase)))
                    {
                        lblFileError.Text = "Invalid File Extension.";
                        return;
                    }
                    //code to upload file.
                    CreateFileInServer(folderPath);
                    //checking if data and columns of Excel are valid
                    string proceed = CheckExcelForValidData(folderPath + "\\" + fileUploadExcel.FileName);
                    if (proceed.Equals(string.Empty))
                    {
                        clsEligibilityRights oImportFromExcel = new clsEligibilityRights();
                        //string IsExists = string.Empty;
                        string result = string.Empty;
                        //IsExists = oImportFromExcel.CheckTableExists("Prov_Src_" + hidUniID.Value + hidFacID.Value + hidCrID.Value + hidMoLrnID.Value + hidPtrnID.Value + hidBrnID.Value + hidCrPrDetailsID.Value + hidCrPrChID.Value);
                        //if (IsExists.Equals("Successful"))
                        //{
                        string tablename = string.Empty;
                        tablename = "Prov_Src_" + hidUniID.Value + "_" + hidFacID.Value + "_" + hidCrID.Value + "_" + hidMoLrnID.Value + "_" + hidPtrnID.Value + "_" + hidBrnID.Value + "_" + hidCrPrDetailsID.Value + "_" + hidCrPrChID.Value + "_" + DateTime.Now.ToString("ddMMyyyyHHmmss");

                        string message = oImportFromExcel.CreateTable(folderPath + "\\" + fileUploadExcel.FileName, tablename.Trim());
                        if (message.Equals("0"))
                        {
                            result = oImportFromExcel.ConfirmProvisionalANDNonProvisionalEligibilityfromExcel(tablename.Trim(), hidFacID.Value, hidCrID.Value, hidMoLrnID.Value, hidPtrnID.Value, hidBrnID.Value, hidCrPrDetailsID.Value, hidCrPrChID.Value, user.User_ID, hid_fk_AcademicYr_ID.Value, rbtCriteria.SelectedValue);
                            if (result.Equals("Successful"))
                            {
                                lblFileError.Text     = "Data updated successfully.";
                                lblFileError.CssClass = "saveNote";
                            }
                        }
                        else
                        {
                            lblFileError.Text     = message;
                            lblFileError.CssClass = "errorNote";
                        }
                        //}

                        oImportFromExcel = null;
                    }
                    else
                    {
                        FileInfo fi = new FileInfo(folderPath + "\\" + fileUploadExcel.FileName);
                        if (fi.Exists)
                        {
                            fi.Delete();
                        }
                        lblFileError.Text = proceed;
                        return;
                    }
                }
                else
                {
                    string script = "<script language='javascript'>alert('Please select proper file for Importing data.')</script>";
                    ClientScript.RegisterStartupScript(GetType(), "PopUp", script);
                }
            }
            catch (Exception ex)
            {
                lblFileError.Text = "Error in " + ex.Message;
            }
            finally
            {
            }
        }