Esempio n. 1
0
        /// <summary>
        /// load file type combo
        /// </summary>
        private void LoadFileTypeCombo()
        {
            ImportSources imp = new ImportSources(SessionManager.GetSessionValueNoRedirect(this.Page, SessionStrings.CONNECTION_MANAGER));

            cmbFileType.DataSource     = imp.SelectApplicationTypes();
            cmbFileType.DataValueField = "IdCodeName";
            cmbFileType.DataTextField  = "SourceName";
            cmbFileType.DataBind();
        }
 protected override void PluginDispose()
 {
     ImportSources.Remove(import_source);
     import_source = null;
 }
 protected override void PluginInitialize()
 {
     import_source = new BeagleImportSource();
     ImportSources.Add(import_source);
 }
Esempio n. 4
0
        /// <summary>
        /// method for verify required fields
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private bool VerifyRequiredFields(string fileName)
        {
            if ((int)dtStartDate.GetValue() == ApplicationConstants.INT_NULL_VALUE)
            {
                errorMessages.Add(ApplicationMessages.IMPORT_SELECT_YEARMONTH);
                return(false);
            }

            if (cmbFileType.SelectedIndex == ApplicationConstants.INT_NULL_VALUE)
            {
                errorMessages.Add(ApplicationMessages.IMPORT_SELECT_FILETYPE);
                return(false);
            }


            try
            {
                string fileNameNoExtension      = filUpload.UploadedFiles[0].GetNameWithoutExtension();
                string countryName              = SessionManager.GetCurrentUser(this.Page).CountryName;
                string countryFirstThreeLetters = SessionManager.GetCurrentUser(this.Page).CountryCode;
                //check file type SAPFRA012007.csv
                if (fileNameNoExtension.Length != 12)
                {
                    errorMessages.Add(string.Format(ApplicationMessages.IMPORT_WRONG_FILE_FORMAT, fileName));
                    return(false);
                }
                //check YearMonth from file
                string month = fileNameNoExtension.Substring(6, 2);
                int    monthOut;
                if (!int.TryParse(month, out monthOut))
                {
                    errorMessages.Add(string.Format(ApplicationMessages.UPLOAD_WRONG_MONTH, month, fileName));
                    return(false);
                }
                if (int.Parse(month) < 1 || int.Parse(month) > 12)
                {
                    errorMessages.Add(string.Format(ApplicationMessages.UPLOAD_WRONG_MONTH, month, fileName));
                    return(false);
                }
                string year = fileNameNoExtension.Substring(8, 4);
                int    yearOut;
                if (!int.TryParse(year, out yearOut))
                {
                    errorMessages.Add(string.Format(ApplicationMessages.UPLOAD_WRONG_YEAR, month, fileName));
                    return(false);
                }
                if (int.Parse(year) < YearMonth.FirstYear)
                {
                    errorMessages.Add(string.Format(ApplicationMessages.UPLOAD_WRONG_YEAR, year, fileName));
                    return(false);
                }
                if (dtStartDate.Text != year + month)
                {
                    errorMessages.Add(string.Format(ApplicationMessages.IMPORT_WRONG_YEARMONTH, fileName, dtStartDate.Text));
                    return(false);
                }

                #region confront associate with selected file type
                string comboValue     = cmbFileType.SelectedValue;
                int    IdImportSource = GetIdFromCombo();

                ImportSources dbis = new ImportSources(SessionManager.GetSessionValueNoRedirect(
                                                           this.Page,
                                                           SessionStrings.CONNECTION_MANAGER));

                dbis.IdCurrentAssociate = currentUser.IdAssociate;
                dbis.IdImportSource     = IdImportSource;

                if (currentUser.UserRole.Id == ApplicationConstants.ROLE_FINANCIAL_TEAM)
                {
                    IsUserAllowedOnImportSource = dbis.IsUserAllowedOnImportSource();
                    if (!IsUserAllowedOnImportSource)
                    {
                        errorMessages.Add(string.Format(
                                              ApplicationMessages.IMPORT_COUNTRY_NOT_IN_IMPORTSOURCE,
                                              countryName,
                                              cmbFileType.SelectedItem.Text));
                        return(false);
                    }
                }
                #endregion

                #region confront application file with combo application type
                if (!comboValue.EndsWith(fileNameNoExtension.Substring(0, 3), StringComparison.CurrentCultureIgnoreCase))
                {
                    string fileType = comboValue.Substring(comboValue.IndexOf(ApplicationConstants.SEPARATOR_SQL) + 1);
                    errorMessages.Add(string.Format(
                                          ApplicationMessages.IMPORT_WRONG_APPLICATION,
                                          fileName, fileType));
                    return(false);
                }
                #endregion
            }
            catch (Exception ex)
            {
                errorMessages.Add(ex.Message);
                return(false);
            }
            return(true);
        }