Beispiel #1
0
        internal static void CheckSubGroupFieldName(Model.Common.ArchiveCommonDataClassesDataContext dc, List <Model.Archive.ArchiveDataClassesDataContext> archivesDataContext, string label, int archiveGroupFieldID)
        {
            Model.Common.ArchiveGroupField archiveGroupField = dc.ArchiveGroupFields.Where(t => t.ID == archiveGroupFieldID).Single();

            if (dc.ArchiveGroupSubGroupFields.Where(t => t.ArchiveGroupFieldID == archiveGroupFieldID && t.Label == label).Count() > 0)
            {
                throw new Exception(string.Format("فیلد '{0}' در زیرگروه جدولی '{1}' وجود دارد. لطفا نام دیگری را انتخاب کنید", label, archiveGroupField.Label));
            }

            foreach (Model.Archive.ArchiveDataClassesDataContext dcArchive in archivesDataContext)
            {
                foreach (var archiveTab in dcArchive.ArchiveTabs.Where(t => t.IDParent == archiveGroupField.ArchiveGroupTabID && t.Deleted == false))
                {
                    foreach (var archiveField in archiveTab.ArchiveFields.Where(t => t.IDParent == archiveGroupFieldID))
                    {
                        if (archiveField.ArchiveSubGroupFields.Where(t => t.Label == label).Count() > 0)
                        {
                            throw new Exception(string.Format("فیلد '{0}' در زیرگروه جدولی '{1}' مربوط به گروه اطلاعاتی '{2}' و بایگانی '{3}' وجود دارد. لطفا نام دیگری را انتخاب کنید", label, archiveField.Label, archiveTab.Title, Controller.Common.ArchiveController.GetArchiveTitle(dcArchive.Connection.Database)));
                        }
                    }
                }
            }
        }
Beispiel #2
0
        internal static int AddField(Field field, int archiveGroupTabID, int archiveGroupID)
        {
            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();

                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);
                }

                CheckFieldName(commonDataContext, archivesDataContext, field.Label, archiveGroupTabID);

                Model.Common.ArchiveGroupTab archiveGroupTab = commonDataContext.ArchiveGroupTabs.Where(t => t.ID == archiveGroupTabID).Single();
                int index = 1;
                if (archiveGroupTab.ArchiveGroupFields.Count > 0)
                {
                    index = archiveGroupTab.ArchiveGroupFields.Max(t => t.Index) + 1;
                }
                Model.Common.ArchiveGroupField archiveGroupField = Model.Common.ArchiveGroupField.GetNewInstance(archiveGroupID, archiveGroupTab.ID, field.Label, field.FieldName, field.FieldTypeCode, field.StatusCode, field.BoxTypeCode, field.AutoComplete, field.MinLength, field.MaxLength, field.MinValue, field.MaxValue, field.DefaultValue, index);
                commonDataContext.ArchiveGroupFields.InsertOnSubmit(archiveGroupField);
                commonDataContext.SubmitChanges();

                try
                {
                    Setting.User.ThisProgram.AddLog(commonDataContext, Setting.User.UserOparatesPlaceNames.گروه_بایگانی, Setting.User.UserOparatesNames.ثبت, null, "افزودن فیلد '" + archiveGroupField.Label + "' به گروه اطلاعاتی '" + archiveGroupField.ArchiveGroupTab.Title + "'");
                }
                catch
                {
                    throw new Exception("خطا در ذخیره عملکرد کاربر جاری");
                }

                foreach (var dc in archivesDataContext)
                {
                    Controller.Archive.ArchiveFieldController.AddField(dc, archiveGroupField);
                }

                commonDataContext.Transaction.Commit();
                foreach (var dcArchive in archivesDataContext)
                {
                    dcArchive.Transaction.Commit();
                }

                return(archiveGroupField.ID);
            }
            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();
                }
            }
        }
Beispiel #3
0
 internal static string GetArchiveGroupFieldLabel(int archiveGroupFieldID)
 {
     Model.Common.ArchiveGroupField field = Model.Common.ArchiveCommonDataClassesDataContext.GetNewInstance().ArchiveGroupFields.Where(t => t.ID == archiveGroupFieldID).SingleOrDefault();
     return(field == null ? "" : field.Label);
 }
Beispiel #4
0
        internal static void DeleteField(int archiveGroupFieldID, int archiveGroupTabID)
        {
            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();

                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);
                }

                Model.Common.ArchiveGroupField originalArchiveGroupField = commonDataContext.ArchiveGroupFields.Where(t => t.ID == archiveGroupFieldID).Single();
                string originalLabel    = originalArchiveGroupField.Label;
                string originalTabTitle = originalArchiveGroupField.ArchiveGroupTab.Title;

                foreach (var dc in archivesDataContext)
                {
                    Controller.Archive.ArchiveFieldController.DeleteField(dc, originalArchiveGroupField);
                }

                commonDataContext.CounterFieldSettings.DeleteAllOnSubmit(commonDataContext.CounterFieldSettings.Where(t => t.ArchiveGroupFieldID == originalArchiveGroupField.ID));
                commonDataContext.SubmitChanges();

                commonDataContext.ArchiveGroupFields.DeleteOnSubmit(originalArchiveGroupField);
                commonDataContext.SubmitChanges();

                try
                {
                    Setting.User.ThisProgram.AddLog(commonDataContext, Setting.User.UserOparatesPlaceNames.گروه_بایگانی, Setting.User.UserOparatesNames.حذف, null, "حذف فیلد '" + originalLabel + "' از گروه اطلاعاتی '" + originalTabTitle + "'");
                }
                catch
                {
                    throw new Exception("خطا در ذخیره عملکرد کاربر جاری");
                }

                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();
                }
            }
        }
        internal static void AddField(Model.Archive.ArchiveDataClassesDataContext dc, Model.Common.ArchiveGroupField archiveGroupField)
        {
            Model.Archive.ArchiveTab archiveTab = dc.ArchiveTabs.Where(t => t.IDParent == archiveGroupField.ArchiveGroupTabID).Single();

            if (ArchiveFieldController.FieldNameAlreadyExist(dc, archiveTab.ID, archiveGroupField.Label))
            {
                throw new Exception(string.Format("فیلد '{0}' در گروه اطلاعاتی '{1}' وجود دارد. لطفا نام دیگری انتخاب کنید", archiveGroupField.Label, archiveTab.Title));
            }

            if (archiveTab.Exist == false)
            {
                SqlHelper.CreateTableForArchiveTab(dc, archiveTab);
                archiveTab.Exist = true;
                dc.SubmitChanges();
            }

            int index = 1;
            var q     = dc.ArchiveFields.Where(t => t.ArchiveTabID == archiveTab.ID).Select(t => t.Index);

            if (q.Count() > 0)
            {
                index = (q.Max() + 1);
            }
            Model.Archive.ArchiveField archiveField = Model.Archive.ArchiveField.GetNewInstance(archiveTab.ID, archiveGroupField.Label, null, archiveGroupField.FieldTypeCode, archiveGroupField.StatusCode, archiveGroupField.BoxTypeCode, archiveGroupField.AutoComplete, archiveGroupField.MinLength, archiveGroupField.MaxLength, archiveGroupField.MinValue, archiveGroupField.MaxValue, archiveGroupField.DefaultValue, archiveGroupField.ID, index);
            dc.ArchiveFields.InsertOnSubmit(archiveField);
            dc.SubmitChanges();

            SqlHelper.CreateArchiveField(dc, archiveField);

            try
            {
                Setting.User.ThisProgram.AddLog(Setting.User.UserOparatesPlaceNames.بایگانی, Setting.User.UserOparatesNames.ثبت, null, "افزودن فیلد '" + archiveField.Label + "' به گروه اطلاعاتی '" + archiveField.ArchiveTab.Title + "' در بایگانی '" + dc.GetArchive().Title + "'");
            }
            catch
            {
                throw new Exception("خطا در ذخیره عملکرد کاربر جاری");
            }
        }
        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("خطا در ذخیره عملکرد کاربر جاری");
                }
            }
        }
        internal static void UpdateField(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;
            int    originalBoxTypeCode  = originalArchiveField.BoxTypeCode;
            string originalDefaultValue = originalArchiveField.DefaultValue;

            Model.Archive.ArchiveTab archiveTab = dc.ArchiveTabs.Where(t => t.ID == originalArchiveField.ArchiveTabID).Single();

            if (ArchiveFieldController.FieldNameAlreadyExist(dc, archiveTab.ID, archiveGroupField.Label, originalArchiveField.ID))
            {
                throw new Exception(string.Format("فیلد '{0}' در گروه اطلاعاتی '{1}' وجود دارد. لطفا نام دیگری انتخاب کنید", archiveGroupField.Label, archiveTab.Title));
            }

            Model.Archive.ArchiveField archiveField = Model.Archive.ArchiveField.GetNewInstance(originalArchiveField.ID, archiveTab.ID, archiveGroupField.Label, originalArchiveField.FieldName, archiveGroupField.FieldTypeCode, archiveGroupField.StatusCode, archiveGroupField.BoxTypeCode, archiveGroupField.AutoComplete, archiveGroupField.MinLength, archiveGroupField.MaxLength, archiveGroupField.MinValue, archiveGroupField.MaxValue, archiveGroupField.DefaultValue, archiveGroupField.ID, originalArchiveField.Index);
            Model.Archive.ArchiveField.Copy(originalArchiveField, archiveField);
            dc.SubmitChanges();

            try
            {
                Setting.User.ThisProgram.AddLog(Setting.User.UserOparatesPlaceNames.بایگانی, Setting.User.UserOparatesNames.ویرایش, null, "ویرایش فیلد '" + originalLabel + "' در گروه اطلاعاتی '" + originalTabTitle + "' در بایگانی '" + dc.GetArchive().Title + "'");
            }
            catch
            {
                throw new Exception("خطا در ذخیره عملکرد کاربر جاری");
            }

            SqlHelper.UpdateArchiveField(dc, originalArchiveField, (Enums.BoxTypes)originalBoxTypeCode, originalDefaultValue);
        }