Exemple #1
0
 public override CounterFieldSetting GetCounterFieldProperties(int fieldID)
 {
     Model.Common.CounterFieldSetting counterFieldSetting = Controller.Common.ArchiveGroupFieldController.GetCounterFieldProperties(fieldID);
     if (counterFieldSetting == null)
     {
         return(null);
     }
     return(new CounterFieldSetting(counterFieldSetting.ArchiveGroupFieldID, (Enums.FixedValueTypes)counterFieldSetting.FixedValueType, counterFieldSetting.FixedValue, counterFieldSetting.Separator));
 }
        internal static void DeleteField(Model.Archive.ArchiveDataClassesDataContext dc, Model.Common.ArchiveGroupField archiveGroupField)
        {
            Model.Archive.ArchiveField originalArchiveField = dc.ArchiveFields.Where(t => t.IDParent == archiveGroupField.ID).Single();
            string originalLabel    = originalArchiveField.Label;
            string originalTabTitle = originalArchiveField.ArchiveTab.Title;

            if (originalArchiveField.IDParent.HasValue)
            {
                originalArchiveField.IDParent = null;
                dc.SubmitChanges();
                foreach (var item in dc.ArchiveSubGroupFields.Where(t => t.ArchiveFieldID == originalArchiveField.ID))
                {
                    item.IDParent = null;
                }
                dc.SubmitChanges();
                Model.Common.CounterFieldSetting archiveGroupFieldCounterSetting = Controller.Common.ArchiveGroupFieldController.GetCounterFieldProperties(archiveGroupField.ID);
                if (archiveGroupFieldCounterSetting != null)
                {
                    Controller.Archive.ArchiveFieldController.SetCounterFieldProperties(dc, originalArchiveField.ID, archiveGroupFieldCounterSetting.FixedValueType, archiveGroupFieldCounterSetting.FixedValue, archiveGroupFieldCounterSetting.Separator);
                }
            }
            else
            {
                SqlHelper.DeleteArchiveField(dc, originalArchiveField);

                dc.ArchiveSubGroupFields.DeleteAllOnSubmit(originalArchiveField.ArchiveSubGroupFields);
                dc.SubmitChanges();

                dc.CounterFieldSettings.DeleteAllOnSubmit(originalArchiveField.CounterFieldSettings);
                dc.SubmitChanges();

                dc.ArchiveFields.DeleteOnSubmit(originalArchiveField);
                dc.SubmitChanges();

                try
                {
                    Setting.User.ThisProgram.AddLog(Setting.User.UserOparatesPlaceNames.بایگانی, Setting.User.UserOparatesNames.حذف, null, "حذف فیلد '" + originalLabel + "' در گروه اطلاعاتی '" + originalTabTitle + "' در بایگانی '" + dc.GetArchive().Title + "'");
                }
                catch
                {
                    throw new Exception("خطا در ذخیره عملکرد کاربر جاری");
                }
            }
        }
Exemple #3
0
        internal static void SetCounterFieldProperties(int archiveGroupFieldID, int fixedValueType, string fixedValue, string separator)
        {
            Model.Common.ArchiveCommonDataClassesDataContext   commonDataContext   = new Model.Common.ArchiveCommonDataClassesDataContext(Setting.Sql.ThisProgram.DatabaseConnection.ConnectionString);
            List <Model.Archive.ArchiveDataClassesDataContext> archivesDataContext = new List <Model.Archive.ArchiveDataClassesDataContext>();

            try
            {
                commonDataContext.Connection.Open();
                commonDataContext.Transaction = commonDataContext.Connection.BeginTransaction();
                int archiveGroupTabID = commonDataContext.ArchiveGroupFields.Where(t => t.ID == archiveGroupFieldID).Single().ArchiveGroupTabID;

                IEnumerable <string> archivesConnections = Controller.Common.ArchiveGroupTabController.GetArchivesConnectionStrings(archiveGroupTabID);
                foreach (string connectionString in archivesConnections)
                {
                    Model.Archive.ArchiveDataClassesDataContext dcArchive = new Model.Archive.ArchiveDataClassesDataContext(connectionString);
                    dcArchive.Connection.Open();
                    dcArchive.Transaction = dcArchive.Connection.BeginTransaction();
                    archivesDataContext.Add(dcArchive);
                }

                if (commonDataContext.CounterFieldSettings.Where(t => t.ArchiveGroupFieldID == archiveGroupFieldID).Count() > 0)
                {
                    Model.Common.CounterFieldSetting obj = commonDataContext.CounterFieldSettings.Where(t => t.ArchiveGroupFieldID == archiveGroupFieldID).Single();
                    obj.FixedValueType = fixedValueType;
                    obj.FixedValue     = fixedValue;
                    obj.Separator      = separator;
                    commonDataContext.SubmitChanges();
                }
                else
                {
                    Model.Common.CounterFieldSetting obj = Model.Common.CounterFieldSetting.GetNewInstance(archiveGroupFieldID, fixedValueType, fixedValue, separator);
                    commonDataContext.CounterFieldSettings.InsertOnSubmit(obj);
                    commonDataContext.SubmitChanges();
                }

                foreach (var dcArchive in archivesDataContext)
                {
                    int archiveFieldID = dcArchive.ArchiveFields.Where(t => t.IDParent == archiveGroupFieldID).Single().ID;
                    Controller.Archive.ArchiveFieldController.SetCounterFieldProperties(dcArchive, archiveFieldID, fixedValueType, fixedValue, separator);
                }

                commonDataContext.Transaction.Commit();
                foreach (var dcArchive in archivesDataContext)
                {
                    dcArchive.Transaction.Commit();
                }
            }
            catch
            {
                commonDataContext.Transaction.Rollback();
                foreach (var dcArchive in archivesDataContext)
                {
                    dcArchive.Transaction.Rollback();
                }
                throw;
            }
            finally
            {
                foreach (var dcArchive in archivesDataContext)
                {
                    if (dcArchive.Connection.State == System.Data.ConnectionState.Open)
                    {
                        dcArchive.Connection.Close();
                    }
                }
                if (commonDataContext.Connection.State == System.Data.ConnectionState.Open)
                {
                    commonDataContext.Connection.Close();
                }
            }
        }