Esempio n. 1
0
        /// <summary>
        /// TODO: Replace this with the Data Validation Framework - once it supports user interaction as needed
        /// in this case (=asking the user to make a decision).
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnUnitDataColumnChanging(System.Object sender, DataColumnChangeEventArgs e)
        {
            TVerificationResult       VerificationResultReturned;
            TScreenVerificationResult VerificationResultEntry;
            Control BoundControl;

            // MessageBox.Show('Column ''' + e.Column.ToString + ''' is changing...');
            try
            {
                if (TPartnerVerification.VerifyUnitData(e, FMainDS, out VerificationResultReturned) == false)
                {
                    if (VerificationResultReturned.ResultCode != PetraErrorCodes.ERR_UNITNAMECHANGEUNDONE)
                    {
                        TMessages.MsgVerificationError(VerificationResultReturned, this.GetType());

                        BoundControl = TDataBinding.GetBoundControlForColumn(BindingContext[FMainDS.PUnit], e.Column);

                        // MessageBox.Show('Bound control: ' + BoundControl.ToString);
// TODO                        BoundControl.Focus();
                        VerificationResultEntry = new TScreenVerificationResult(this,
                                                                                e.Column,
                                                                                VerificationResultReturned.ResultText,
                                                                                VerificationResultReturned.ResultTextCaption,
                                                                                VerificationResultReturned.ResultCode,
                                                                                BoundControl,
                                                                                VerificationResultReturned.ResultSeverity);
                        FPetraUtilsObject.VerificationResultCollection.Add(VerificationResultEntry);

                        // MessageBox.Show('After setting the error: ' + e.ProposedValue.ToString);
                    }
                    else
                    {
                        // undo the change in the DataColumn
                        e.ProposedValue = e.Row[e.Column.ColumnName, DataRowVersion.Original];

                        // need to assign this to make the change actually visible...
                        txtUnitName.Text = e.ProposedValue.ToString();
// TODO                        BoundControl = TDataBinding.GetBoundControlForColumn(BindingContext[FMainDS.PUnit], e.Column);

                        // MessageBox.Show('Bound control: ' + BoundControl.ToString);
// TODO                        BoundControl.Focus();
                    }
                }
                else
                {
                    if (FPetraUtilsObject.VerificationResultCollection.Contains(e.Column))
                    {
                        FPetraUtilsObject.VerificationResultCollection.Remove(e.Column);
                    }
                }
            }
            catch (Exception Exp)
            {
                MessageBox.Show(Exp.ToString());
            }
        }
 public ContentBuilder(TextWriter textWriter, TLanguages languages, TSetupTypes setupTypes, TCustomMessages customMessages, TMessages messages, TComponents components, TTasks tasks, HashSet <InstallationMethod> methods)
 {
     _textWriter     = textWriter;
     _languages      = languages;
     _setupTypes     = setupTypes;
     _customMessages = customMessages;
     _messages       = messages;
     _components     = components;
     _methods        = methods;
     _tasks          = tasks;
 }
Esempio n. 3
0
        private static List <Message> Parse(TMessages messages)
        {
            var result = new List <Message>();

            foreach (var message in messages.Messages)
            {
                result.Add(MessageParser.Parse(message));
            }

            return(result);
        }
                            private IList <TEntry> AddEntries <TEntry, TBuilder>(
                                string sectionName,
                                Func <TBuilder> builderFactory,
                                Func <Func <TBuilder>, TLanguages, TSetupTypes, TCustomMessages, TMessages, TComponents, TTasks, IEnumerable <TEntry> > builder,
                                TLanguages languages,
                                TSetupTypes setupTypes,
                                TCustomMessages customMessages,
                                TMessages messages,
                                TComponents components,
                                TTasks tasks,
                                Action <TEntry> newEntryHandler = null) where TEntry : ICustomizable, IPredicated
                            {
                                var entries = builder(builderFactory, languages, setupTypes, customMessages, messages, components, tasks).ToList();

                                if (entries.Count > 0)
                                {
                                    var typeConverterFactory = new Func <System.ComponentModel.TypeConverterAttribute, System.ComponentModel.TypeConverter>(attr =>
                                    {
                                        var type          = typeof(DelegateExpressionToStringConverter <Func <string, bool> >);
                                        var converterType = Type.GetType(attr.ConverterTypeName);

                                        if (converterType == type)
                                        {
                                            return(new DelegateExpressionToStringConverter <Func <string, bool> >(methodInfo =>
                                            {
                                                if (!_methods.Any(im => im.MetadataToken == methodInfo.MetadataToken))
                                                {
                                                    _methods.Add(new InstallationMethod(methodInfo));
                                                }
                                            }));
                                        }

                                        return((System.ComponentModel.TypeConverter)Activator.CreateInstance(converterType));
                                    });

                                    using (new Section(_textWriter, sectionName))
                                    {
                                        foreach (var entry in entries)
                                        {
                                            newEntryHandler?.Invoke(entry);

                                            var converter = new PropertiesToNameValuePairsConverter(_propertyFormatter, typeConverterFactory);
                                            var pairs     = converter.ConvertTo(entry, typeof(NameValueCollection)) as NameValueCollection;

                                            _textWriter.WriteLine(pairs.Format());
                                        }
                                    }
                                }

                                return(entries);
                            }
        private void BtnOK_Click(System.Object sender, EventArgs e)
        {
            if (clbAddress.CheckedItemsCount == 0)
            {
                FUserAnswer = "CHANGE-NONE";
            }
            else if (clbAddress.CheckedItemsCount == FPartnerSharingLocationDV.Count)
            {
                FUserAnswer = "CHANGE-ALL";
            }
            else
            {
                FUserAnswer = "CHANGE-SOME" + ':';

                FUserAnswer = FUserAnswer + clbAddress.GetCheckedStringList();

                // return list separated by ';'
                FUserAnswer.Replace(',', ';');
            }

            //MessageBox.Show("FUserAnswer: " + FUserAnswer);

            if ((FUserAnswer == "CHANGE-NONE") || (FUserAnswer.StartsWith("CHANGE-SOME")))
            {
                /* Check whether user has CREATE right on p_location table */
                if (!UserInfo.GUserInfo.IsTableAccessOK(TTableAccessPermission.tapCREATE, PLocationTable.GetTableDBName()))
                {
                    TMessages.MsgSecurityException(new ESecurityDBTableAccessDeniedException("", "create",
                                                                                             PLocationTable.GetTableDBName()), this.GetType());
                    MessageBox.Show(Catalog.GetString("Due to the selection that you have made" + " a new Address would need" + "\r\n" +
                                                      "to be created. However, you do not have permission to do this." + "\r\n" + "\r\n" +
                                                      "Either select 'Change all' to change all addresses (if this is appropriate)," +
                                                      "\r\n" + "or choose 'Cancel' to abort the Save operation."),
                                    Catalog.GetString("Security Violation - Explanation"),
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
                    return;
                }
                else
                {
                    DialogResult = System.Windows.Forms.DialogResult.OK;
                }
            }
            else
            {
                DialogResult = System.Windows.Forms.DialogResult.OK;
            }

            Close();
        }
Esempio n. 6
0
        private static FileTreeNode CreateTreeNodeByMessage(TMessages msg)
        {
            FileTreeNode node = new FileTreeNode();
            TFile        file = msg.FileOject;

            node.CreateDate = (uint)msg.ProvideTime;
            node.FileID     = file.FileId;
            node.FileInfo   = file.FileInfo;
            node.FileKind   = (ContentKind)file.FileKind;
            node.FileSize   = (ulong)file.FileSize;
            node.FromApp    = msg.FromApp;
            node.NodeName   = msg.ProvideName;
            node.SubNodes   = null;
            return(node);
        }
Esempio n. 7
0
        public void AddMessage(TMessages mes)
        {
            //заносим сообщение в базу
            string query = @"
                        insert into dbo.TMessages
                        (contactID,messageText,topicID)
                        values 
                        (
                        '" + mes.contact + @"',
                        '" + mes.messageText + @"',
                        '" + mes.topic + @"'
                        )
                        ";

            DoSqlRequest(query);
        }
Esempio n. 8
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="e"></param>
        /// <param name="AVerificationResult"></param>
        public static void VerifyLocationType(DataColumnChangeEventArgs e, out TVerificationResult AVerificationResult)
        {
            AVerificationResult = null;
            PLocationTypeTable DataCache_ListTable;
            PLocationTypeRow   FoundRow;
            DialogResult       UseAlthoughUnassignable;

            DataCache_ListTable = (PLocationTypeTable)TDataCache.TMPartner.GetCacheablePartnerTable(TCacheablePartnerTablesEnum.LocationTypeList);
            FoundRow            = (PLocationTypeRow)DataCache_ListTable.Rows.Find(new Object[] { e.ProposedValue.ToString() });

            if (FoundRow != null)
            {
                if (!FoundRow.Assignable)
                {
                    UseAlthoughUnassignable = TMessages.MsgQuestion(
                        ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_VALUEUNASSIGNABLE, e.ProposedValue.ToString()),
                        new StackTrace(false).GetFrame(2).GetMethod().DeclaringType, false);

                    if (UseAlthoughUnassignable == System.Windows.Forms.DialogResult.No)
                    {
                        AVerificationResult = new TVerificationResult("",
                                                                      "",
                                                                      "",
                                                                      PetraErrorCodes.ERR_VALUEUNASSIGNABLE,
                                                                      TResultSeverity.Resv_Noncritical);
                    }
                }
                else
                {
                    if (e.ProposedValue.ToString().EndsWith(SharedConstants.SECURITY_CAN_LOCATIONTYPE) &&
                        (!UserInfo.GUserInfo.IsInGroup(SharedConstants.PETRAGROUP_ADDRESSCAN)))
                    {
                        TMessages.MsgGeneralError(
                            String.Format(StrErrorTheCodeIsNotAssignableSecurity, e.ProposedValue, SharedConstants.PETRAGROUP_ADDRESSCAN),
                            MCommonResourcestrings.StrValueUnassignable,
                            PetraErrorCodes.ERR_VALUEUNASSIGNABLE,
                            new StackTrace(false).GetFrame(2).GetMethod().DeclaringType);
                        AVerificationResult = new TVerificationResult("", "", "",
                                                                      PetraErrorCodes.ERR_VALUEUNASSIGNABLE,
                                                                      TResultSeverity.Resv_Noncritical);
                    }
                }
            }
        }
Esempio n. 9
0
        public JsonResult Post(TMessages mes)
        {
            string query = @"
                    select * from dbo.Contacts
                    where email = '" + mes.email + @"' and 
                          phoneNumber = '" + mes.phone + @"' 
                    ";

            DataTable table = new DataTable();

            table = DoSqlRequest(query);

            if (table.Rows.Count == 0) //если пользователя нет в бд заносим его
            {
                query = @"
                     insert into dbo.Contacts
                     (contactName,email,phoneNumber)
                     values 
                     (
                     '" + mes.contact + @"'
                     ,'" + mes.email + @"'
                     ,'" + mes.phone + @"'
                     )
                     ";
                DoSqlRequest(query);

                query = @"
                    select * from dbo.Contacts
                    where email = '" + mes.email + @"' 
                    ";
                table = DoSqlRequest(query);
            }
            // берём id контакта
            mes.contact = table.Rows[0][0].ToString();

            //заносим сообщение в бд
            AddMessage(mes);
            return(new JsonResult("Added"));
        }
        /// <summary>
        /// Performs checks to determine whether a deletion of the current row is permissable
        /// </summary>
        /// <param name="ARowToDelete">the currently selected row to be deleted</param>
        /// <param name="ADeletionQuestion">can be changed to a context-sensitive deletion confirmation question</param>
        /// <returns>true if user is permitted and able to delete the current row</returns>
        private bool PreDeleteManual(AAnalysisTypeRow ARowToDelete, ref string ADeletionQuestion)
        {
            /*Code to execute before the delete can take place*/
            DataView DependentRecordsDV = new DataView(FMainDS.AFreeformAnalysis);

            DependentRecordsDV.RowStateFilter = DataViewRowState.CurrentRows;
            DependentRecordsDV.RowFilter      = String.Format("{0} = '{1}'",
                                                              AFreeformAnalysisTable.GetAnalysisTypeCodeDBName(),
                                                              ARowToDelete.AnalysisTypeCode);

            if (DependentRecordsDV.Count > 0)
            {
                // Tell the user that we cannot allow deletion if any rows exist in the DataView
                TMessages.MsgRecordCannotBeDeletedDueToDependantRecordsError(
                    "Analysis Type", "an Analysis Type", "Analysis Types", "Analysis Value", "an Analysis Value",
                    "Analysis Values", ARowToDelete.AnalysisTypeCode, DependentRecordsDV.Count);

                return(false);
            }

            return(true);
        }
        private void SaveDataLabelUseChanges(TTypedDataTable ASubmitChanges)
        {
            // Submit changes to the PETRAServer for the DataLabelUse table
            // This code is basically lifted from a typical auto-generated equivalent
            // TODO: If the standard code changes because TODO's get done, we will need to change this manual code
            TSubmitChangesResult          SubmissionResult;
            TVerificationResultCollection VerificationResult;

            try
            {
                SubmissionResult = TDataCache.SaveChangedCacheableDataTableToPetraServer("DataLabelUseList",
                                                                                         ref ASubmitChanges,
                                                                                         out VerificationResult);
            }
            catch (ESecurityDBTableAccessDeniedException Exp)
            {
                FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataException);
                this.Cursor = Cursors.Default;

                TMessages.MsgSecurityException(Exp, this.GetType());

                return;
            }
            catch (EDBConcurrencyException Exp)
            {
                FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataException);
                this.Cursor = Cursors.Default;

                TMessages.MsgDBConcurrencyException(Exp, this.GetType());

                return;
            }
            catch (Exception exp)
            {
                TLogging.Log(
                    "An error occured while saving the 'used by' data" + Environment.NewLine + exp.ToString(),
                    TLoggingType.ToLogfile);
                MessageBox.Show(
                    Catalog.GetString("An error occured while saving the 'used by' data") + Environment.NewLine +
                    Catalog.GetString("For details see the log file: ") + TLogging.GetLogFileName(),
                    Catalog.GetString("Failed to Save 'Used By' Data"),
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning);

                return;
            }

            switch (SubmissionResult)
            {
            case TSubmitChangesResult.scrOK:

                // Call AcceptChanges to get rid now of any deleted columns before we Merge with the result from the Server
                FExtraDS.PDataLabelUse.AcceptChanges();

                // Merge back with data from the Server (eg. for getting Sequence values)
                ASubmitChanges.AcceptChanges();
                FExtraDS.PDataLabelUse.Merge(ASubmitChanges, false);

                // need to accept the new modification ID
                FExtraDS.PDataLabelUse.AcceptChanges();

                // need to refresh the cacheable DataTable 'DataLabelsForPartnerClassesList' (used by Partner Find's Maintain Menu)
                TDataCache.TMPartner.RefreshCacheablePartnerTable(TCacheablePartnerTablesEnum.DataLabelsForPartnerClassesList);

                return;

            case TSubmitChangesResult.scrNothingToBeSaved:

                return;

            case TSubmitChangesResult.scrError:

                MessageBox.Show(Catalog.GetString(
                                    "The 'UsedBy' part of the data could not be saved! There has been an error while making changes to the table."),
                                Catalog.GetString("Submit Changes to Table Error"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                break;

            case TSubmitChangesResult.scrInfoNeeded:

                MessageBox.Show(Catalog.GetString(
                                    "The 'UsedBy' part of the data could not be saved! Insufficient information was provided when making changes to the table."),
                                Catalog.GetString("Submit Changes to Table Error"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                break;
            }
        }
        /// <summary>
        /// Save the changes on the screen
        /// </summary>
        /// <returns></returns>
        public bool SaveChanges()
        {
            Boolean ReturnValue;

            // Be sure to fire the OnLeave event on the active control of any user control
            FPetraUtilsObject.ForceOnLeaveForActiveControl();

            FPetraUtilsObject.OnDataSavingStart(this, new System.EventArgs());

            // Don't allow saving if user is still editing a Detail of a List
            if (FPetraUtilsObject.InDetailEditMode())
            {
                ReturnValue = false;
                return(ReturnValue);
            }

            // Clear any validation errors so that the following call to ValidateAllData starts with a 'clean slate'.
            FPetraUtilsObject.VerificationResultCollection.Clear();

            if (ValidateAllData(false, TErrorProcessingMode.Epm_IgnoreNonCritical))
            {
                // Ask the user about non-critical warnings, if they are the only 'errors' in the collection
                if (FPetraUtilsObject.VerificationResultCollection.HasOnlyNonCriticalErrors &&
                    (TDataValidation.ProcessAnyDataValidationWarnings(FPetraUtilsObject.VerificationResultCollection,
                                                                      MCommonResourcestrings.StrFormSaveDataAnywayQuestion, this.GetType()) == false))
                {
                    return(false);
                }

                FMainDS.AApSupplier.Rows[0].BeginEdit();
                GetDataFromControls(FMainDS.AApSupplier[0]);

                if (FMainDS.AApSupplier[0].IsDefaultApAccountNull())
                {
                    MessageBox.Show(Catalog.GetString("Please select an AP account (eg. 9100)"));
                    FMainDS.AApSupplier.Rows[0].EndEdit();

                    ReturnValue = false;
                    return(ReturnValue);
                }

                // The account would usually be 9100-AP account.
                if (FMainDS.AApSupplier[0].DefaultApAccount != "9100")
                {
                    if (MessageBox.Show(Catalog.GetString("You are not using the standard AP account (9100) - is this OK?"),
                                        "Verification", MessageBoxButtons.YesNo)
                        != System.Windows.Forms.DialogResult.Yes)
                    {
                        FMainDS.AApSupplier.Rows[0].EndEdit();
                        return(false);
                    }
                }

                // Don't store with invalid currency value.
                //
                if (FMainDS.AApSupplier[0].CurrencyCode == "")
                {
                    FMainDS.AApSupplier[0].CurrencyCode = FLedgerRow.BaseCurrency;
                }

                // If this is a foreign currency supplier, it must be linked to accounts in that currency.
                // (And if it's not, it mustn't be!)
                if (!ValidateAccountCurrency(FMainDS.AApSupplier[0].DefaultBankAccount, "Bank"))
                {
                    return(false);
                }

                /*
                 * If we wanted to have only expense accounts in a single currency, we could have this,
                 * but that's probably not what we want...
                 *
                 *          if (!ValidateAccountCurrency(FMainDS.AApSupplier[0].DefaultExpAccount, "Expense"))
                 *          {
                 *              return false;
                 *          }
                 */
            }

            ReturnValue = TDataValidation.ProcessAnyDataValidationErrors(false, FPetraUtilsObject.VerificationResultCollection,
                                                                         this.GetType());

            if (ReturnValue)
            {
                // Fire the DataSavingValidated event, which is the last chance to cancel the save
                System.ComponentModel.CancelEventArgs eCancel = new System.ComponentModel.CancelEventArgs(false);
                FPetraUtilsObject.OnDataSavingValidated(this, eCancel);

                if (eCancel.Cancel == true)
                {
                    return(false);
                }

                foreach (DataTable InspectDT in FMainDS.Tables)
                {
                    foreach (DataRow InspectDR in InspectDT.Rows)
                    {
                        InspectDR.EndEdit();
                    }
                }

                if (FPetraUtilsObject.HasChanges)
                {
                    FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataInProgress);
                    this.Cursor = Cursors.WaitCursor;

                    AccountsPayableTDS SubmitDS = FMainDS.GetChangesTyped(true);

                    TSubmitChangesResult          SubmissionResult;
                    TVerificationResultCollection VerificationResult = new TVerificationResultCollection();

                    // Submit changes to the PETRAServer
                    try
                    {
                        SubmissionResult = FUIConnector.SubmitChanges(ref SubmitDS);
                    }
                    catch (ESecurityDBTableAccessDeniedException Exp)
                    {
                        FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataException);
                        this.Cursor = Cursors.Default;

                        TMessages.MsgSecurityException(Exp, this.GetType());

                        ReturnValue = false;
                        FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        return(ReturnValue);
                    }
                    catch (EDBConcurrencyException Exp)
                    {
                        FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataException);
                        this.Cursor = Cursors.Default;

                        TMessages.MsgDBConcurrencyException(Exp, this.GetType());

                        ReturnValue = false;
                        FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        return(ReturnValue);
                    }
                    catch (Exception)
                    {
                        FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataException);
                        this.Cursor = Cursors.Default;

                        FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        throw;
                    }

                    switch (SubmissionResult)
                    {
                    case TSubmitChangesResult.scrOK:

                        // Call AcceptChanges to get rid now of any deleted columns before we Merge with the result from the Server
                        FMainDS.AcceptChanges();

                        // Merge back with data from the Server (eg. for getting Sequence values)
                        if (SubmitDS != null)
                        {
                            FMainDS.Merge(SubmitDS, false);

                            // need to accept the new modification ID
                            FMainDS.AcceptChanges();
                        }

                        // Update UI
                        FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataSuccessful);
                        this.Cursor = Cursors.Default;

                        // We don't have unsaved changes anymore
                        FPetraUtilsObject.DisableSaveButton();
                        TFormsMessage broadcastMessage = new TFormsMessage(TFormsMessageClassEnum.mcAPSupplierChanged);
                        TFormsList.GFormsList.BroadcastFormMessage(broadcastMessage);

                        ReturnValue = true;
                        FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        break;

                    case TSubmitChangesResult.scrError:
                        this.Cursor = Cursors.Default;
                        FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataErrorOccured);

                        MessageBox.Show(Messages.BuildMessageFromVerificationResult(null, VerificationResult));

                        FPetraUtilsObject.SubmitChangesContinue = false;

                        ReturnValue = false;
                        FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        break;

                    case TSubmitChangesResult.scrNothingToBeSaved:
                        this.Cursor = Cursors.Default;
                        FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataNothingToSave);

                        // We don't have unsaved changes anymore
                        FPetraUtilsObject.DisableSaveButton();

                        ReturnValue = true;
                        FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        break;

                    case TSubmitChangesResult.scrInfoNeeded:

                        // TODO scrInfoNeeded
                        this.Cursor = Cursors.Default;
                        break;
                    }
                }
                else
                {
                    // Update UI
                    FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataNothingToSave);
                    this.Cursor = Cursors.Default;
                    FPetraUtilsObject.DisableSaveButton();

                    // We don't have unsaved changes anymore
                    FPetraUtilsObject.HasChanges = false;

                    ReturnValue = true;
                    FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                }
            }
            else
            {
                FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(false));
            }

            return(ReturnValue);
        }
Esempio n. 13
0
        /// <summary>
        /// save the changes on the screen (code is copied from auto-generated code)
        /// </summary>
        /// <returns></returns>
        public bool SaveChanges()
        {
            bool ReturnValue = false;

            FPetraUtilsObject.OnDataSavingStart(this, new System.EventArgs());

            if (FPetraUtilsObject.VerificationResultCollection.Count == 0)
            {
                foreach (DataRow InspectDR in FMainDS.MExtract.Rows)
                {
                    InspectDR.EndEdit();
                }

                if (!FPetraUtilsObject.HasChanges)
                {
                    return(true);
                }
                else
                {
                    FPetraUtilsObject.WriteToStatusBar("Saving data...");
                    this.Cursor = Cursors.WaitCursor;

                    TSubmitChangesResult SubmissionResult;

                    //Ict.Common.Data.TTypedDataTable SubmitDT = FMainDS.MExtract.GetChangesTyped();
                    MExtractTable           SubmitDT  = new MExtractTable();
                    ExtractTDSMExtractTable ChangesDT = FMainDS.MExtract.GetChangesTyped();

                    if (ChangesDT != null)
                    {
                        SubmitDT.Merge(ChangesDT);
                    }
                    else
                    {
                        SubmitDT = null;
                    }

                    if (SubmitDT == null)
                    {
                        // There is nothing to be saved.
                        // Update UI
                        FPetraUtilsObject.WriteToStatusBar(Catalog.GetString("There is nothing to be saved."));
                        this.Cursor = Cursors.Default;

                        // We don't have unsaved changes anymore
                        FPetraUtilsObject.DisableSaveButton();

                        return(true);
                    }

                    // Submit changes to the PETRAServer
                    try
                    {
                        SubmissionResult = TRemote.MPartner.Partner.WebConnectors.SaveExtract
                                               (FExtractId, ref SubmitDT);
                    }
                    catch (ESecurityDBTableAccessDeniedException Exp)
                    {
                        FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataException);
                        this.Cursor = Cursors.Default;

                        TMessages.MsgSecurityException(Exp, this.GetType());

                        ReturnValue = false;
                        FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        return(ReturnValue);
                    }
                    catch (EDBConcurrencyException Exp)
                    {
                        FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataException);
                        this.Cursor = Cursors.Default;

                        TMessages.MsgDBConcurrencyException(Exp, this.GetType());

                        ReturnValue = false;
                        FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        return(ReturnValue);
                    }
                    catch (Exception)
                    {
                        FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataException);
                        this.Cursor = Cursors.Default;

                        FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        throw;
                    }

                    switch (SubmissionResult)
                    {
                    case TSubmitChangesResult.scrOK:

                        // Call AcceptChanges to get rid now of any deleted columns before we Merge with the result from the Server
                        FMainDS.MExtract.AcceptChanges();

                        // Merge back with data from the Server (eg. for getting Sequence values)
                        FMainDS.MExtract.Merge(SubmitDT, false);

                        // need to accept the new modification ID
                        FMainDS.MExtract.AcceptChanges();

                        // Update UI
                        FPetraUtilsObject.WriteToStatusBar("Data successfully saved.");
                        this.Cursor = Cursors.Default;

                        // TODO EnableSave(false);

                        // We don't have unsaved changes anymore
                        FPetraUtilsObject.DisableSaveButton();

                        SetPrimaryKeyReadOnly(true);

                        // refresh extract master screen if it is open
                        TFormsMessage BroadcastMessage = new TFormsMessage(TFormsMessageClassEnum.mcExtractCreated);
                        BroadcastMessage.SetMessageDataName(ExtractName);
                        TFormsList.GFormsList.BroadcastFormMessage(BroadcastMessage);
                        this.Focus();     // keeps the focus on the current form

                        // TODO OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        return(true);

                    case TSubmitChangesResult.scrError:

                        // TODO scrError
                        this.Cursor = Cursors.Default;
                        break;

                    case TSubmitChangesResult.scrNothingToBeSaved:

                        // TODO scrNothingToBeSaved
                        this.Cursor = Cursors.Default;
                        return(true);

                    case TSubmitChangesResult.scrInfoNeeded:

                        // TODO scrInfoNeeded
                        this.Cursor = Cursors.Default;
                        break;
                    }
                }
            }

            return(false);
        }
Esempio n. 14
0
        /// <summary>
        /// save the changes on the screen
        /// </summary>
        /// <returns></returns>
        public bool SaveChanges()
        {
            Boolean ReturnValue;

            FPetraUtilsObject.OnDataSavingStart(this, new System.EventArgs());

            // Don't allow saving if user is still editing a Detail of a List
            if (FPetraUtilsObject.InDetailEditMode())
            {
                ReturnValue = false;
                return(ReturnValue);
            }

            // Clear any validation errors so that the following call to ValidateAllData starts with a 'clean slate'.
            FPetraUtilsObject.VerificationResultCollection.Clear();

            if (ValidateAllData(false, true))
            {
                FMainDS.AApSupplier.Rows[0].BeginEdit();
                GetDataFromControls(FMainDS.AApSupplier[0]);

                if (FMainDS.AApSupplier[0].IsDefaultApAccountNull())
                {
                    MessageBox.Show(Catalog.GetString("Please select an AP account (eg. 9100)"));
                    FMainDS.AApSupplier.Rows[0].EndEdit();

                    ReturnValue = false;
                    return(ReturnValue);
                }

                // The account would usually be 9100-AP account.
                if (FMainDS.AApSupplier[0].DefaultApAccount != "9100")
                {
                    if (MessageBox.Show(Catalog.GetString("You are not using the standard AP account (9100) - is this OK?"),
                                        "Verification", MessageBoxButtons.YesNo)
                        != System.Windows.Forms.DialogResult.Yes)
                    {
                        FMainDS.AApSupplier.Rows[0].EndEdit();
                        return(false);
                    }
                }

                // Don't store with invalid currency value.
                //
                if (FMainDS.AApSupplier[0].CurrencyCode == "")
                {
                    FMainDS.AApSupplier[0].CurrencyCode = FLedgerRow.BaseCurrency;
                }

                // If this is a foreign currency supplier, it must be linked to accounts in that currency.
                // (And if it's not, it mustn't be!)
                if (!ValidateAccountCurrency(FMainDS.AApSupplier[0].DefaultBankAccount, "Bank"))
                {
                    return(false);
                }

                /*
                 * If we wanted to have only expense accounts in a single currency, we could have this,
                 * but that's probably not what we want...
                 *
                 *          if (!ValidateAccountCurrency(FMainDS.AApSupplier[0].DefaultExpAccount, "Expense"))
                 *          {
                 *              return false;
                 *          }
                 */
            }

            ReturnValue = TDataValidation.ProcessAnyDataValidationErrors(false, FPetraUtilsObject.VerificationResultCollection,
                                                                         this.GetType());

            if (ReturnValue)
            {
                foreach (DataTable InspectDT in FMainDS.Tables)
                {
                    foreach (DataRow InspectDR in InspectDT.Rows)
                    {
                        InspectDR.EndEdit();
                    }
                }

                if (FPetraUtilsObject.HasChanges)
                {
                    FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataInProgress);
                    this.Cursor = Cursors.WaitCursor;

                    AccountsPayableTDS SubmitDS = FMainDS.GetChangesTyped(true);

                    TSubmitChangesResult          SubmissionResult;
                    TVerificationResultCollection VerificationResult = new TVerificationResultCollection();

                    // Submit changes to the PETRAServer
                    try
                    {
                        SubmissionResult = FUIConnector.SubmitChanges(ref SubmitDS);
                    }
                    catch (ESecurityDBTableAccessDeniedException Exp)
                    {
                        FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataException);
                        this.Cursor = Cursors.Default;
                        TMessages.MsgSecurityException(Exp, this.GetType());

                        ReturnValue = false;
                        FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        return(ReturnValue);
                    }
                    catch (EDBConcurrencyException Exp)
                    {
                        FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataException);
                        this.Cursor = Cursors.Default;
                        TMessages.MsgDBConcurrencyException(Exp, this.GetType());

                        ReturnValue = false;
                        FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        return(ReturnValue);
                    }
                    catch (Exception exp)
                    {
                        FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataException);
                        this.Cursor = Cursors.Default;
                        TLogging.Log(
                            Catalog.GetString(
                                "An error occurred while trying to connect to the OpenPetra Server!") + Environment.NewLine + exp.ToString(),
                            TLoggingType.ToLogfile);
                        MessageBox.Show(
                            Catalog.GetString("An error occurred while trying to connect to the OpenPetra Server!") + Environment.NewLine +
                            "For details see the log file: " + TLogging.GetLogFileName(),
                            "Server connection error",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Stop);

                        ReturnValue = false;
                        FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        return(ReturnValue);
                    }

                    switch (SubmissionResult)
                    {
                    case TSubmitChangesResult.scrOK:

                        // Call AcceptChanges to get rid now of any deleted columns before we Merge with the result from the Server
                        FMainDS.AcceptChanges();

                        // Merge back with data from the Server (eg. for getting Sequence values)
                        FMainDS.Merge(SubmitDS, false);

                        // need to accept the new modification ID
                        FMainDS.AcceptChanges();

                        // Update UI
                        FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataSuccessful);
                        this.Cursor = Cursors.Default;

                        // We don't have unsaved changes anymore
                        FPetraUtilsObject.DisableSaveButton();

                        ReturnValue = true;
                        FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        break;

                    case TSubmitChangesResult.scrError:
                        this.Cursor = Cursors.Default;
                        FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataErrorOccured);

                        MessageBox.Show(Messages.BuildMessageFromVerificationResult(null, VerificationResult));

                        FPetraUtilsObject.SubmitChangesContinue = false;

                        ReturnValue = false;
                        FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        break;

                    case TSubmitChangesResult.scrNothingToBeSaved:
                        this.Cursor = Cursors.Default;
                        FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataNothingToSave);

                        // We don't have unsaved changes anymore
                        FPetraUtilsObject.DisableSaveButton();

                        ReturnValue = true;
                        FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        break;

                    case TSubmitChangesResult.scrInfoNeeded:

                        // TODO scrInfoNeeded
                        this.Cursor = Cursors.Default;
                        break;
                    }
                }
                else
                {
                    // Update UI
                    FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataNothingToSave);
                    this.Cursor = Cursors.Default;
                    FPetraUtilsObject.DisableSaveButton();

                    // We don't have unsaved changes anymore
                    FPetraUtilsObject.HasChanges = false;

                    ReturnValue = true;
                    FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                }
            }
            else
            {
                FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(false));
            }

            return(ReturnValue);
        }
Esempio n. 15
0
        /// <summary>
        /// save the changes on the screen (code is copied from auto-generated code)
        /// </summary>
        /// <returns></returns>
        public bool SaveChanges()
        {
            bool ReturnValue = false;

            FPetraUtilsObject.OnDataSavingStart(this, new System.EventArgs());

            if (ValidateAllData(false, Common.Verification.TErrorProcessingMode.Epm_IgnoreNonCritical))
            {
                foreach (DataRow InspectDR in FMainDS.MExtractMaster.Rows)
                {
                    InspectDR.EndEdit();
                }

                if (!FPetraUtilsObject.HasChanges)
                {
                    return(true);
                }
                else
                {
                    FPetraUtilsObject.WriteToStatusBar("Saving data...");
                    this.Cursor = Cursors.WaitCursor;

                    TSubmitChangesResult SubmissionResult;

                    MExtractMasterTable SubmitDT = new MExtractMasterTable();

                    if (FMainDS.MExtractMaster.GetChangesTyped() != null)
                    {
                        SubmitDT.Merge(FMainDS.MExtractMaster.GetChangesTyped());
                    }
                    else
                    {
                        // There is nothing to be saved.
                        // Update UI
                        FPetraUtilsObject.WriteToStatusBar(Catalog.GetString("There is nothing to be saved."));
                        this.Cursor = Cursors.Default;

                        // We don't have unsaved changes anymore
                        FPetraUtilsObject.DisableSaveButton();

                        return(true);
                    }

                    // Submit changes to the PETRAServer
                    try
                    {
                        SubmissionResult = TRemote.MPartner.Partner.WebConnectors.SaveExtractMaster
                                               (ref SubmitDT);
                    }
                    catch (ESecurityDBTableAccessDeniedException Exp)
                    {
                        FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataException);
                        this.Cursor = Cursors.Default;

                        TMessages.MsgSecurityException(Exp, this.GetType());

                        ReturnValue = false;
                        FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        return(ReturnValue);
                    }
                    catch (EDBConcurrencyException Exp)
                    {
                        FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataException);
                        this.Cursor = Cursors.Default;

                        TMessages.MsgDBConcurrencyException(Exp, this.GetType());

                        ReturnValue = false;
                        FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        return(ReturnValue);
                    }
                    catch (Exception)
                    {
                        FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataException);
                        this.Cursor = Cursors.Default;

                        FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        throw;
                    }

                    switch (SubmissionResult)
                    {
                    case TSubmitChangesResult.scrOK:

                        // Call AcceptChanges to get rid now of any deleted columns before we Merge with the result from the Server
                        FMainDS.MExtractMaster.AcceptChanges();

                        // Merge back with data from the Server (eg. for getting Sequence values)
                        FMainDS.MExtractMaster.Merge(SubmitDT, false);

                        // need to accept the new modification ID
                        FMainDS.MExtractMaster.AcceptChanges();

                        // Update UI
                        FPetraUtilsObject.WriteToStatusBar("Data successfully saved.");
                        this.Cursor = Cursors.Default;

                        // TODO EnableSave(false);

                        // We don't have unsaved changes anymore
                        FPetraUtilsObject.DisableSaveButton();

                        SetPrimaryKeyReadOnly(true);

                        // TODO OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        return(true);

                    case TSubmitChangesResult.scrError:

                        // TODO scrError
                        this.Cursor = Cursors.Default;
                        break;

                    case TSubmitChangesResult.scrNothingToBeSaved:

                        // TODO scrNothingToBeSaved
                        this.Cursor = Cursors.Default;
                        return(true);

                    case TSubmitChangesResult.scrInfoNeeded:

                        // TODO scrInfoNeeded
                        this.Cursor = Cursors.Default;
                        break;
                    }
                }
            }

            return(false);
        }
Esempio n. 16
0
        /// <summary>
        /// Verifies the Date value.
        /// </summary>
        /// <param name="AValueText">the new value of the textbox</param>
        /// <param name="AShowVerificationError">Set to true to show errors if verification
        /// failed, or to false to suppress error messages</param>
        /// <returns>true if the Control has a valid date</returns>
        private Boolean VerifyDate(string AValueText, Boolean AShowVerificationError)
        {
            TVerificationResult DateVerificationResult = null;

            if (!FAllowVerification)
            {
                return(true);
            }

            if (CountVerifyDateRunningInstances > 0)
            {
                // the LostFocus and the DateValidated events overlap, and would display too messageboxes if the text can not be parsed for a date
                return(false);
            }

            CountVerifyDateRunningInstances++;

            try
            {
                // Convert TextBox's Text to Date
                DateTime Text2Date = DataBinding.LongDateStringToDateTime2(
                    AValueText,
                    FDateDescription,
                    out DateVerificationResult,
                    AShowVerificationError, null);

                if (DateVerificationResult != null)
                {
                    // Date conversion was NOT successful
                    return(false);
                }
                else
                {
                    // Conversion was successful
                    if (!AllowFutureDate)
                    {
                        DateVerificationResult = TDateChecks.IsCurrentOrPastDate(Text2Date, FDateDescription);

                        if (DateVerificationResult != null)
                        {
                            if (AShowVerificationError)
                            {
                                // Show appropriate Error Message to the user
                                TMessages.MsgGeneralError(DateVerificationResult, this.FindForm().GetType());
                            }

                            return(false);
                        }
                    }

                    if (!AllowPastDate)
                    {
                        DateVerificationResult = TDateChecks.IsCurrentOrFutureDate(Text2Date, FDateDescription);

                        if (DateVerificationResult != null)
                        {
                            if (AShowVerificationError)
                            {
                                // Show appropriate Error Message to the user
                                TMessages.MsgGeneralError(DateVerificationResult, this.FindForm().GetType());
                            }

                            return(false);
                        }
                    }

                    if (!FAllowEmpty)
                    {
                        DateVerificationResult = TDateChecks.IsNotUndefinedDateTime(Text2Date, FDateDescription);

                        if (DateVerificationResult != null)
                        {
                            if (AShowVerificationError)
                            {
                                // Show appropriate Error Message to the user
                                TMessages.MsgGeneralError(DateVerificationResult, this.FindForm().GetType());
                            }

                            return(false);
                        }
                    }

                    // Store the Date for later use
                    if (Text2Date != DateTime.MinValue)
                    {
                        FDate = Text2Date;
                    }
                    else
                    {
                        FDate = null;
                    }

                    // set tag to "SuppressChangeDetection" so text change is not detected by TFrmPetraEditUtils.MultiEventHandler
                    object OriginalTag = this.Tag;
                    this.Tag = MCommonResourcestrings.StrCtrlSuppressChangeDetection;
                    FSuppressTextChangeEvent = true;

                    // Now update the TextBox's Text with the newly formatted date
                    if (FDate != null)
                    {
                        if (DateTime.Compare(minimalDateValue, FDate.Value) > 0)
                        {
                            TMessages.DateValueMessageMinUnderrun(minimalDateValue);
                        }

                        if (DateTime.Compare(FDate.Value, maximalDateValue) > 0)
                        {
                            TMessages.DateValueMessageMaxOverrun(maximalDateValue);
                        }

                        String NewText = DataBinding.DateTimeToLongDateString2(FDate.Value);

                        if (this.Text != NewText) // Don't set anything that's unchanged
                        {
                            base.Text = NewText;  // I'm not calling my own Text Property, because I don't want to end up back here...
                        }
                    }
                    else
                    {
                        if (this.Text != "") // Don't set anything that's unchaged
                        {
                            base.Text = "";  // I'm not calling my own Text Property, because I don't want to end up back here...
                        }
                    }

                    // reset tag to original state
                    this.Tag = OriginalTag;
                    FSuppressTextChangeEvent = false;
                    return(true);
                }
            }
            finally
            {
                FDateVerificationResult = DateVerificationResult;

                CountVerifyDateRunningInstances--;
            }
        }
Esempio n. 17
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="AChangingPartnerTypeRow"></param>
        /// <param name="AIsRemoval"></param>
        /// <returns></returns>
        public Boolean PerformPartnerTypeAddOrRemoval(DataRow AChangingPartnerTypeRow, out Boolean AIsRemoval)
        {
            const String TYPECODE_COSTCENTRE = "COSTCENTRE";

            Boolean ReturnValue = false;

            AIsRemoval = false;
            String            TypeCode;
            DataRow           ExistingMatchingDataRow;
            PPartnerTypeTable PartnerTypeTable;
            PPartnerTypeRow   TheNewRow;
            PTypeRow          CheckTypeRow;

            DataRowView[] CheckTypeRows;
            DialogResult  CheckTypeRowsAnswer;
            TRecalculateScreenPartsEventArgs RecalculateScreenPartsEventArgs;
            String CostCentreLink;

            PartnerTypeTable = FMainDS.PPartnerType;

            try
            {
                TypeCode = AChangingPartnerTypeRow["TypeCode"].ToString();

                ExistingMatchingDataRow = PartnerTypeTable.Rows.Find(new Object[] { ((PPartnerRow)FMainDS.PPartner.Rows[0]).PartnerKey, TypeCode });

                if (ExistingMatchingDataRow == null)
                {
                    /*
                     * Add Special Type
                     */

                    // Check security permission
                    if (!UserInfo.GUserInfo.IsTableAccessOK(TTableAccessPermission.tapCREATE, PPartnerTypeTable.GetTableDBName()))
                    {
                        TMessages.MsgSecurityException(new ESecurityDBTableAccessDeniedException("", "create",
                                                                                                 PPartnerTypeTable.GetTableDBName()), this.GetType());

                        AChangingPartnerTypeRow.CancelEdit();   // reset to unchecked
                        return(false);
                    }

                    // Check: is this Partner Type assignable?

//                  MessageBox.Show("Perform check: is PartnerType assignable?  TypeCode: " + TypeCode);
                    CheckTypeRows = FDataCache_PartnerTypeListDV.FindRows(TypeCode);

                    if (CheckTypeRows.Length > 0)
                    {
                        CheckTypeRow = (PTypeRow)CheckTypeRows[0].Row;

                        if (!CheckTypeRow.ValidType)
                        {
                            /*CheckTypeRowsAnswer = TMessages.MsgQuestion(
                             *  ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_VALUEUNASSIGNABLE, TypeCode),
                             *  this.GetType(), false);*/

                            CheckTypeRowsAnswer = MessageBox.Show(
                                string.Format(StrTheCodeIsNoLongerActive, TypeCode),
                                Catalog.GetString("Invalid Data Entered"),
                                MessageBoxButtons.YesNo,
                                MessageBoxIcon.Question,
                                MessageBoxDefaultButton.Button2);

                            if (CheckTypeRowsAnswer == DialogResult.No)
                            {
                                // reset to unchecked
                                AChangingPartnerTypeRow.CancelEdit();
                                return(false);
                            }
                        }
                    }

                    // add new row to PartnerType table
                    PartnerTypeTable      = FMainDS.PPartnerType;
                    TheNewRow             = PartnerTypeTable.NewRowTyped();
                    TheNewRow.PartnerKey  = FMainDS.PPartner[0].PartnerKey;
                    TheNewRow.TypeCode    = TypeCode;
                    TheNewRow.CreatedBy   = UserInfo.GUserInfo.UserID;
                    TheNewRow.DateCreated = DateTime.Now.Date;
                    PartnerTypeTable.Rows.Add(TheNewRow);

                    // Fire OnRecalculateScreenParts event
                    RecalculateScreenPartsEventArgs            = new TRecalculateScreenPartsEventArgs();
                    RecalculateScreenPartsEventArgs.ScreenPart = TScreenPartEnum.spCounters;
                    OnRecalculateScreenParts(RecalculateScreenPartsEventArgs);

                    ReturnValue = true;
                    AIsRemoval  = false;
                }
                else
                {
                    /*
                     * Remove Special Type
                     */

                    // Check security permission
                    if (!UserInfo.GUserInfo.IsTableAccessOK(TTableAccessPermission.tapDELETE, PPartnerTypeTable.GetTableDBName()))
                    {
                        TMessages.MsgSecurityException(new ESecurityDBTableAccessDeniedException("", "delete",
                                                                                                 PPartnerTypeTable.GetTableDBName()), this.GetType());

                        // reset to checked
                        AChangingPartnerTypeRow.CancelEdit();
                        return(false);
                    }

                    // perform check: If COSTCENTRE is to be removed then check whether Partner has a link to costcentre set up
                    if (TypeCode == TYPECODE_COSTCENTRE)
                    {
                        try
                        {
                            if (FPartnerEditUIConnector.HasPartnerCostCentreLink(out CostCentreLink))
                            {
                                MessageBox.Show(String.Format(StrPartnerHasCostCentreLink, CostCentreLink,
                                                              StrPartnerHasCostCentreLinkTitle));

                                // reset to checked
                                AChangingPartnerTypeRow.CancelEdit();
                                return(false);
                            }
                        }
                        catch (ESecurityAccessDeniedException Exp)
                        {
                            TMessages.MsgSecurityException(Exp, this.GetType());
                            MessageBox.Show(StrSecurityPreventsRemoval, StrSecurityPreventsRemovalTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);

                            // reset to checked
                            AChangingPartnerTypeRow.CancelEdit();
                            return(false);
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }

                    // Delete row from PartnerType table
                    ExistingMatchingDataRow.Delete();

                    // Fire OnRecalculateScreenParts event
                    RecalculateScreenPartsEventArgs            = new TRecalculateScreenPartsEventArgs();
                    RecalculateScreenPartsEventArgs.ScreenPart = TScreenPartEnum.spCounters;
                    OnRecalculateScreenParts(RecalculateScreenPartsEventArgs);

                    ReturnValue = true;
                    AIsRemoval  = true;
                }

                /*
                 * Check if this change could be applied to Family Members
                 */
// TODO PartnerTypeFamilyMembersPropagationSelectionWinForm Dialog still missing
#if TODO
                if (SharedTypes.PartnerClassStringToEnum(FMainDS.PPartner[0].PartnerClass) == TPartnerClass.FAMILY)
                {
                    if (HasFamilyFamilyMembers())
                    {
                        if (FDelegatePartnerTypePropagationSelection != null)
                        {
                            if (!AIsRemoval)
                            {
                                FMainDS.Merge(FDelegatePartnerTypePropagationSelection(TypeCode, "ADD"));
                            }
                            else
                            {
                                FMainDS.Merge(FDelegatePartnerTypePropagationSelection(TypeCode, "DELETE"));
                            }
                        }
                    }
                }
#endif
            }
            catch (Exception E)
            {
                MessageBox.Show(E.ToString());
                ReturnValue = false;
            }

            return(ReturnValue);
        }
Esempio n. 18
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="AParseDate"></param>
        /// <param name="ADescription"></param>
        /// <param name="AParsedDate"></param>
        /// <param name="AShowVerificationError"></param>
        /// <param name="ATypeWhichCallsVerification"></param>
        /// <returns></returns>
        private static Boolean LongDateStringToDateTimeInternal(String AParseDate,
                                                                String ADescription,
                                                                out object AParsedDate,
                                                                Boolean AShowVerificationError,
                                                                System.Type ATypeWhichCallsVerification)
        {
            Boolean ReturnValue;
            Int32   DayOffset;
            String  TmpYear;
            String  TmpMonth;
            String  TmpDay;
            String  TmpMonthDayExchange = "";
            String  TmpShortDatePattern;
            Int16   YearStart = 0;
            Int16   RestStart = 0;

            // see StringHelper.DateToLocalizedString
            // Mono and .Net return different strings for month of March in german culture

            TExecutingOSEnum OSVersion = Utilities.DetermineExecutingOS();

            bool   IsPossiblyWin10 = ((OSVersion == TExecutingOSEnum.eosWin8Plus) || (OSVersion == TExecutingOSEnum.eosWin10));
            string CurrentCulture  = Thread.CurrentThread.CurrentCulture.ToString();

            List <string> CulturesToIgnore = new List <string>();

            CulturesToIgnore.Add("de-BE");
            CulturesToIgnore.Add("de-CH");
            CulturesToIgnore.Add("de-LI");
            CulturesToIgnore.Add("de-LU");

            if ((CultureInfo.CurrentCulture.TwoLetterISOLanguageName == "de") &&
                !(CurrentCulture == "de-AT") &&
                !(IsPossiblyWin10 && CulturesToIgnore.Contains(CurrentCulture)))
            {
                AParseDate = AParseDate.Replace("MÄR", "MRZ");
            }

            AParsedDate = null;
            DateTimeFormatInfo CurrentDateTimeFormatInfo;

            ReturnValue = false;
            try
            {
                // TODO: implement parsing of localised short month names like 4GL does (according to user's default language setting), eg. accept 'M�R' instead of 'MAR' for March if the user's language setting is DE (German)
                // MessageBox.Show('AParseDate: ' + AParseDate);
                if (TDateChecks.IsValidDateTime(AParseDate, "") != null)
                {
                    // MessageBox.Show('No regular DateTime');
                    if ((AParseDate.StartsWith("-")) || ((AParseDate.StartsWith("+")) && (AParseDate.Length != 1)))
                    {
                        // MessageBox.Show('Calculating date from the amount that follows the + or  sign...');
                        // calculate date from the amount that follows the + or  sign
                        if (TNumericalChecks.IsValidInteger(AParseDate.Substring(1), "") == null)
                        {
                            DayOffset = System.Convert.ToInt32(AParseDate.Substring(1));

                            // MessageBox.Show('DayOffset: ' + DayOffset.ToString);
                            if (AParseDate.StartsWith("+"))
                            {
                                AParseDate = DateTime.Now.Date.AddDays(DayOffset).ToString("D");
                            }
                            else
                            {
                                AParseDate = DateTime.Now.Date.Subtract(new TimeSpan(DayOffset, 0, 0, 0)).ToString("D");
                            }
                        }
                        else
                        {
                            // characters following the + or  are not an Int32
                            if (AShowVerificationError)
                            {
                                TMessages.MsgGeneralError(TDateChecks.GetInvalidDateVerificationResult(ADescription), ATypeWhichCallsVerification);
                            }

                            return(ReturnValue);
                        }
                    }
                    else if ((AParseDate.Length <= 8) &&
                             (AParseDate.Length != 1) &&
                             (TNumericalChecks.IsValidInteger(AParseDate, "") == null))
                    {
//                        MessageBox.Show("Checking for dates entered like eg. 211105 or 21112005 ...");

                        /*
                         * Checking for dates entered like eg. 211105 or 21112005.
                         *
                         * Notes:
                         * Petra.NET accepts date entry dependent on current Culture
                         * (=settings are taken from Windows Control Panel -> Regional and
                         * Language Options).
                         * However, 4GL Petra parses dates according to the server-wide setting
                         * '-d'in startup.pf (Progress home directory). This should normally be
                         * the same than the Windows Control Panel setting on the user's
                         * machines, so there should be no deviation.
                         */
                        CurrentDateTimeFormatInfo = DateTimeFormatInfo.CurrentInfo;
                        TmpShortDatePattern       = CurrentDateTimeFormatInfo.ShortDatePattern.ToUpper();

                        if (TmpShortDatePattern.StartsWith("Y"))
                        {
                            YearStart = 0;

                            switch (AParseDate.Length)
                            {
                            case 8:
                                RestStart = 4;
                                break;

                            case 6:
                                RestStart = 2;
                                break;

                            case 4:
                                RestStart = 0;
                                YearStart = -1;
                                break;
                            }
                        }
                        else
                        {
                            RestStart = 0;

                            switch (AParseDate.Length)
                            {
                            case 6:
                            case 8:
                                YearStart = 4;
                                break;

                            case 4:
                                YearStart = -1;
                                break;
                            }
                        }

//MessageBox.Show("TmpShortDatePattern: " + TmpShortDatePattern + "; TmpDateSeparator: " + TmpDateSeparator +
//    "\r\nYearStart: " + YearStart.ToString() + "; RestStart: " + RestStart.ToString());
                        if (AParseDate.Length <= 6)
                        {
                            if (YearStart != -1)
                            {
                                TmpYear = AParseDate.Substring(YearStart, 2);

                                // Determine the correct century for twodigit years.
                                // For compatibility reasons: This is the way how it's done in 4GL,
                                // in sp_date.p/ConvertStringToDate
                                if (Convert.ToInt32(TmpYear) < 80)
                                {
                                    TmpYear = "20" + TmpYear;
                                }
                                else if (Convert.ToInt32(TmpYear) < 100)
                                {
                                    TmpYear = "19" + TmpYear;
                                }

                                //
                                // This would be the Windows way of doing it...
                                // I (ChristianK) found no way to retrieve the correct century from
                                // .NET, so it's hardcoded here, taking the default values of Windows
                                // XP :(
                                //
                                // if Convert.ToInt32(TmpYear) <= 29 then
                                // begin
                                // TmpYear := '20' + TmpYear;
                                // end
                                // else
                                // begin
                                // TmpYear := '19' + TmpYear;
                                // end;
                            }
                            else
                            {
                                TmpYear = DateTime.Now.Year.ToString();
                            }
                        }
                        else
                        {
                            TmpYear = AParseDate.Substring(YearStart, 4);
                        }

                        if ((AParseDate.Length == 4) || (AParseDate.Length == 6) || (AParseDate.Length == 8))
                        {
                            if (TmpShortDatePattern.IndexOf('M') < TmpShortDatePattern.IndexOf('D'))
                            {
                                TmpMonth = AParseDate.Substring(RestStart, 2);
                                TmpDay   = AParseDate.Substring(RestStart + 2, 2);
                            }
                            else
                            {
                                TmpDay   = AParseDate.Substring(RestStart, 2);
                                TmpMonth = AParseDate.Substring(RestStart + 2, 2);
                            }
                        }
                        else
                        {
                            // format with other number of digits not supported
                            if (AShowVerificationError)
                            {
                                TMessages.MsgGeneralError(TDateChecks.GetInvalidDateVerificationResult(ADescription), ATypeWhichCallsVerification);
                            }

                            return(ReturnValue);
                        }

                        if (Convert.ToInt16(TmpMonth) > 12)
                        {
                            TmpMonthDayExchange = TmpMonth;
                            TmpMonth            = TmpDay;
                            TmpDay = TmpMonthDayExchange;
                        }

                        // AParseDate := TmpYear + TmpDateSeparator + TmpMonth + TmpDateSeparator + TmpDay;    For testing purposes
                        // MessageBox.Show('AParseDate (1): ' + AParseDate);    For testing purposes
                        try
                        {
                            // TmpMonth + '/' + TmpDay + '/' + TmpYear;
                            AParseDate = new DateTime(Convert.ToInt32(TmpYear), Convert.ToInt32(TmpMonth), Convert.ToInt32(TmpDay)).ToString("D");

                            if (TmpMonthDayExchange != "")
                            {
                                MessageBox.Show(StrMonthDayExchangedInfo, StrMonthDayExchangedInfoTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                        }
                        catch (Exception)
                        {
                            if (AShowVerificationError)
                            {
                                TMessages.MsgGeneralError(TDateChecks.GetInvalidDateVerificationResult(ADescription), ATypeWhichCallsVerification);
                            }

                            return(ReturnValue);
                        }

//MessageBox.Show("TmpShortDatePattern: " + TmpShortDatePattern + "; TmpDateSeparator: " + TmpDateSeparator +
//                                        "\r\nYearStart: " + YearStart.ToString() + "; RestStart: " + RestStart.ToString() +
//"; TmpDay: " + TmpDay + "; TmpMonth: " + TmpMonth + "; TmpYear: " + TmpYear + "\r\nAParseDate: " + AParseDate);
                        AParsedDate = AParseDate;
                        ReturnValue = true;
                        return(ReturnValue);
                    }
                    else if (AParseDate == string.Empty)
                    {
                        AParsedDate = DBNull.Value;
                        ReturnValue = true;
                        return(ReturnValue);
                    }
                    else if ((AParseDate == "=") || (AParseDate == "+") || (AParseDate.ToLower() == Catalog.GetString("today").ToLower()))
                    {
                        AParsedDate = DateTime.Now.ToString("D");
                        ReturnValue = true;
                        return(ReturnValue);
                    }
                    else
                    {
                        if (AShowVerificationError)
                        {
                            // not an accepted date parse string
                            TMessages.MsgGeneralError(TDateChecks.GetInvalidDateVerificationResult(ADescription), ATypeWhichCallsVerification);
                        }

                        return(ReturnValue);
                    }
                }

                // AParseDate ready to be parsed
                AParsedDate = DateTime.Parse(AParseDate).ToString("D");
                ReturnValue = true;
            }
            catch (Exception /* Exp */)
            {
                if (AShowVerificationError)
                {
                    TMessages.MsgGeneralError(TDateChecks.GetInvalidDateVerificationResult(ADescription), ATypeWhichCallsVerification);
                }
            }

            return(ReturnValue);
        }