/*
         * ----------------------------------------------------------------------------------------------------
         * Synopsis		:	Used to get the Filter Details
         * Input			:
         * Output			:
         * -----------------------------------------------------------------------------------------------------
         */
        private void GetFilterDetails()
        {
            NTrust.K2.BO.ExportManager ObjExpMan = null;
            ObjExpMan = (NTrust.K2.BO.ExportManager)NTrustSession.CreateBusinessObject("ExportManager", 1);
            string    strFilter      = "varname ='" + FIELDSETTINGS + "'";
            string    strSort        = "";
            DataTable dtExportResult = ObjExpMan.GetExportNamedFilter(strFilter, strSort);

            DataRow drNewRow = null;

            drNewRow = dtExportResult.NewRow();
            drNewRow[SELECT_VARNAME] = "";
            drNewRow[SELECT_FKEY]    = strDEFAULT_SELECTION_VALUE;
            drNewRow["FILTERNAME"]   = strDEFAULT_SELECTION_TEXT;
            dtExportResult.Rows.Add(drNewRow);
            dtExportResult.DefaultView.Sort = SELECT_FKEY;
            FillCombo(this.ddlNamedFilter, dtExportResult, SELECT_FKEY, "FILTERNAME");
        }
        /*
         * ----------------------------------------------------------------------------------------------------
         * Synopsis		:	This function will Set the Default value to respectively controls
         * Input			:   udgFieldList as object E
         * Output			:
         * -----------------------------------------------------------------------------------------------------
         */
        private void SetDefaultValue()
        {
            NTrust.K2.BO.ExportManager ObjExpMan = null;
            ObjExpMan = (NTrust.K2.BO.ExportManager)NTrustSession.CreateBusinessObject("ExportManager", 1);
            strFilter = "varname ='" + EXPORTDIRECTORY + "'";
            strSort   = "";
            DataTable dtExportResult = ObjExpMan.GetExportVariable(strFilter, strSort);

            if (dtExportResult.Rows.Count > 0)
            {
                string mon = DateTime.Today.Month.ToString();
                string day = DateTime.Today.Day.ToString();
                txtSelectedFile.Text = file_name;
            }
            strFilter      = "varname ='" + DELIMITCHAR + "'";
            dtExportResult = ObjExpMan.GetExportVariable(strFilter, strSort);
            if (dtExportResult.Rows.Count > 0)
            {
                setDefault(this.ddlDelimiter, dtExportResult.Rows[0][SELECT_FIELDNAME].ToString());
            }
        }
        /*
         * ----------------------------------------------------------------------------------------------------
         * Synopsis		:	This Method will EXPORT the Data  to a TEXT FILE
         * Input			:
         * Output			:
         * -----------------------------------------------------------------------------------------------------
         */
        protected void btnExport_Click(object sender, System.EventArgs e)
        {
            bool blnWriteFlag = false;

            string[] strSQLScript = new string[4];
            try
            {
                NTrust.K2.BO.Export objExport = (NTrust.K2.BO.Export)NTrustSession.CreateBusinessObject("AEXPORT", 1);
                NTrust.K2.BO.Export.ExportFieldStruct ExpFldStruct = new  NTrust.K2.BO.Export.ExportFieldStruct();

                string strPKEY      = ddlNamedFilter.SelectedValue;
                string strDelimiter = this.ddlDelimiter.SelectedValue;
                string strFilePath  = this.txtSelectedFile.Text;

                bool blnOpenOrOverWrite = (this.chkAppend.Checked == true)?true:false;

                string strFilter = "";

                /*
                 *      if (this.chkSave.Checked )
                 *      {
                 *              // Here Deleting the Demlimiter Record
                 *              strFilter		= "varname='" + DELIMITCHAR + "'";
                 *              strSQLScript[0] = "DELETE FROM Y_VARIABLES WHERE " + strFilter ;
                 *              // Here Deleting the Export File Directory Record
                 *              strFilter		= "varname='" + EXPORTDIRECTORY + "'";
                 *              strSQLScript[1] = "DELETE FROM Y_VARIABLES WHERE " + strFilter ;
                 *              // Here Forming the Insert Script for the Demlimiter Record
                 *              ExpFldStruct.strTemplateName	= "";
                 *              ExpFldStruct.strValue1		= strDelimiter;
                 *              ExpFldStruct.strValue2		= "";
                 *              ExpFldStruct.strValue3		= "";
                 *              ExpFldStruct.strVarName		= DELIMITCHAR;
                 *              ExpFldStruct.strValueDate	= "";
                 *              ExpFldStruct.strSeqence		= "0";
                 *              strSQLScript[2] = objExport.GenInsExportFieldsSetting(ExpFldStruct);
                 *
                 *      // Here Forming the Insert Script for the  Export File Directory Record
                 *              ExpFldStruct.strTemplateName	= "";
                 *              ExpFldStruct.strValue1		= strFilePath;
                 *              ExpFldStruct.strValue2		= "";
                 *              ExpFldStruct.strValue3		= "";
                 *              ExpFldStruct.strVarName		= EXPORTDIRECTORY;
                 *              ExpFldStruct.strValueDate	= "";
                 *              ExpFldStruct.strSeqence		= "0";
                 *              strSQLScript[3] = objExport.GenInsExportFieldsSetting(ExpFldStruct);
                 *              // Here Execution the Script  Both Deleting and Inserting in a Single Transaction
                 *              objExport.AddExportFieldsSetting(strSQLScript);
                 *
                 *      }
                 *
                 *      // Here Getting the Template details
                 *      NTrust.K2.BO.ExportManager   ObjExpMan = null;
                 *      ObjExpMan		= (NTrust.K2.BO.ExportManager) NTrustSession.CreateBusinessObject("ExportManager", 1);
                 *      strFilter		= "varname ='"+ FIELDSETTINGS +"' and VALUE_FKEY='"+strPKEY +"'";
                 *      strSort			= SELECT_FIELDVALUE;
                 *      DataTable dtExportResult = ObjExpMan.GetExportVariable(strFilter,strSort);
                 *
                 */
                NTrust.K2.BO.ExportManager ObjExpMan = null;
                ObjExpMan = (NTrust.K2.BO.ExportManager)NTrustSession.CreateBusinessObject("ExportManager", 1);
                // Here forming the Select Statement Based on the Template Selected
                int [] intSize = new int[50];
                intSize[0] = 8;
                intSize[1] = 20;
                intSize[2] = 8;
                intSize[3] = 11;
                intSize[4] = 8;
                intSize[5] = 8;
                intSize[6] = 30;

                string strQuery = "SELECT * FROM V_K2_EXPORTJOURNALFIELDSCOCOS";
                strQuery += " ORDER BY PARENT_ID,GLCODE,VENDOR_NUMBER,DUE_DATE,CHECK_KEY";

                if (strFilePath != "")
                {
                    //Cocos Result data to Text File
                    strDelimiter = ",";                   // For CSV file.

                    string strpath      = System.Configuration.ConfigurationSettings.AppSettings[SAVE_FILE_PATH] + ADD_FILE_PATH;
                    bool   folderExists = Directory.Exists(strpath);
                    if (!folderExists)
                    {
                        Directory.CreateDirectory(strpath);
                    }
                    strFilePath  = strpath + strFilePath;
                    blnWriteFlag = ObjExpMan.ExportToCOCOSFile(strQuery, strDelimiter, strFilePath, blnOpenOrOverWrite, intSize);
                    if (blnWriteFlag)
                    {
                        string url = "";//changes made for CR - Journal Accrual Export for not to update Accrual Records. by Biru
                        if (chkExportLocal.Checked)
                        {
                            url = "JounralExportMessage.aspx?ParentName=" + strSettings + "&DisplayName=" + strDisplayName + "&MenuKey=" + strMenuKey + "&ExportType=" + strExportType + "&FileName=" + txtSelectedFile.Text + "";
                        }
                        else
                        {
                            url = "JounralExportMessage.aspx?ParentName=" + strSettings + "&DisplayName=" + strDisplayName + "&MenuKey=" + strMenuKey + "&ExportType=" + strExportType + "&FileName=";
                        }
                        string strScript = "<script language=JavaScript>window.showModalDialog('" + url + "',window,'status:no;dialogWidth:465px;dialogHeight:175px;');</script>";
                        this.RegisterStartupScript("Winclose", strScript);
                    }
                    else
                    {
                        NTrustSessionPage.InitializeResources("K2Web.CommonResource");
                        this.CreateMessageAlert(this, GetString("NoRectoExportExcel"));
                    }
                }
            }


            catch (NTrust.Util.NTrustException nex)
            {
                if (nex.ErrorCode == 500000)
                {
                    ErrExist = "Y";
                    lblErrorMessage.Visible = true;
                    NTrustSessionPage.InitializeResources("K2Web.Utility.Integration");
                    CreateMessageAlert(this, GetString("FileAccess"));
                    //lblErrorMessage.Text    = "File is accessed by Another Process. Close the file and export again";
                }
                else
                {
                    ErrExist = "Y";
                    lblErrorMessage.Visible = true;
                    NTrustSessionPage.InitializeResources("K2Web.Utility.Integration");
                    SetErrorMessage(lblErrorMessage, nex.ErrorCode, nex.Message, GetString("Export File"));
                }
            }
            catch (System.IO.FileNotFoundException Ferr)
            {
                ErrExist = "Y";
                lblErrorMessage.Visible = true;
                SetErrorMessage(lblErrorMessage, 0, Ferr.Message.ToString(), "");
            }
            catch (Exception ex)
            {
                ErrExist = "Y";
                ShowCustomError(0, ex.Message.ToString());
            }
        }