Esempio n. 1
0
 /// <summary>
 /// Сохранение данных в БД определенной сессии.
 /// </summary>
 public static void SaveTable <Type>(Session targetSession)
 {
     if (TypeEx.IsSubclassOf(typeof(Type), typeof(XPObjectEx)))
     {
         XPCollection <Type> stores = new XPCollection <Type>();
         foreach (Type store in stores)
         {
             XPObjectEx newItem = Activator.CreateInstance(typeof(Type), targetSession) as XPObjectEx;
             newItem.GetData <Type>(store);
             newItem.Save();
         }
     }
 }
Esempio n. 2
0
        public void DataNavigatorEx_ButtonClick(object sender, NavigatorButtonClickEventArgs e)
        {
            DateTime t0 = DateTime.Now;

            Error = false;
            XPCollection xpcBase = DataSource as XPCollection;

            switch (e.Button.ButtonType)
            {
            case NavigatorButtonType.EndEdit:
            {
                try
                {
                    if (DataBaseSaving != null)
                    {
                        DataBaseSaving(sender, EventArgs.Empty);
                    }

                    if (xpcBase.Session is UnitOfWork)
                    {
                        (xpcBase.Session as UnitOfWork).CommitChanges();
                    }
                    else
                    {
                        xpcBase.Session.Save(xpcBase);
                    }

                    if (DataBaseSaved != null)
                    {
                        DataBaseSaved(sender, EventArgs.Empty);
                    }
                }
                catch (Exception ex)
                {
                    Error = true;
                    XtraMessageBox.Show(
                        ex.Message,
                        ex.Source,
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Warning,
                        MessageBoxDefaultButton.Button1);
                }
                finally
                {
                    if (!Error)
                    {
                        if (sender == this)
                        {
                            DataNavigatorEx_ButtonClick(null, new NavigatorButtonClickEventArgs(Buttons.CancelEdit));
                        }

                        TimeSpan diff = DateTime.Now - t0;

                        XtraMessageBox.Show(
                            string.Format("Данные таблицы \"{0}\" сохранены за {1:0} мс.", TableCaption, diff.TotalMilliseconds),
                            "Информация",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information,
                            MessageBoxDefaultButton.Button1);
                    }
                    else
                    {
                        XtraMessageBox.Show(
                            "Произошла ошибка сохранения.",
                            "Ошибка",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Warning,
                            MessageBoxDefaultButton.Button1);
                    }
                }

                break;
            }

            case NavigatorButtonType.CancelEdit:
            {
                object currentRecord = xpcBase[Position];
                try
                {
                    if (DateBaseUpdating != null)
                    {
                        DateBaseUpdating(this, EventArgs.Empty);
                    }
                    else
                    {
                        xpcBase.Session.DropIdentityMap();
                        xpcBase.Reload();
                    }
                }
                catch (System.Exception ex)
                {
                    XtraMessageBox.Show(
                        ex.InnerException.Message,
                        ex.InnerException.Source,
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Warning,
                        MessageBoxDefaultButton.Button1);
                }

                if (currentRecord is XPObject)
                {
                    Position = XPObjectEx.FindRecordPossition(xpcBase, (XPObject)currentRecord);
                }

                break;
            }

            case NavigatorButtonType.Remove:
            {
                if (Position == 0)
                {
                    //e.Handled = true;
                    Buttons.EndEdit.Enabled = true;
                }
                break;
            }
            }
        }