Example #1
0
    protected void btn_manImport_Click(object sender, EventArgs e)
    {
        lbl_error.Text = "";
        HRAAdminBill hobj = new HRAAdminBill();
        string       _qy  = ddlQY.SelectedItem.Text;
        HRAImportDAL iObj = new HRAImportDAL();

        if (Page.IsValid)
        {
            if (txtPrevQY.Visible)
            {
                lbl_error.Text = "Enter Quarter-Year in format 'Qd-yyyy'";
                return;
            }

            string strFilePath1 = "";

            if (FileUpload1.GotFile)
            {
                try
                {
                    string fn = System.IO.Path.GetFileName(FileUpload1.FilePost.FileName);
                    strFilePath1 = Server.MapPath("~/uploads/") + fn;
                    if (File.Exists(strFilePath1))
                    {
                        File.Delete(strFilePath1);
                    }
                    FileUpload1.FilePost.SaveAs(strFilePath1);
                    _counter          = hobj.ImportHRAAUDITR(strFilePath1, source, _qy);
                    Session["taskId"] = Convert.ToInt32(Session["taskId"]) + 1;
                    Audit.auditUserTaskI(Session.SessionID, Session["mid"].ToString(), Session["taskId"].ToString(), "HRA", "Administrative Bill Validation", "hra_AUDITR", "HRAAUDITR Import", _qy, _counter);
                    MultiView1.SetActiveView(view_result);
                    lbl_result.Text = "Import completed successfully -- " + _counter + " records imported";
                }
                catch (Exception ex)
                {
                    iObj.Rollback(source, _qy);
                    lbl_error.Text     = "Error - " + ex.Message;
                    lbl_notice.Visible = false;
                }
                finally
                {
                    if (File.Exists(strFilePath1))
                    {
                        File.Delete(strFilePath1);
                    }
                    FileUpload1.FilePost.InputStream.Flush();
                    FileUpload1.FilePost.InputStream.Close();
                    FileUpload1.FilePost.InputStream.Dispose();
                }
            }
        }
    }