示例#1
0
        private void buttonAddSubject_Click(object sender, EventArgs e)
        {
            try
            {
                using (Database db = Leadtools.Ccow.Server.Utils.GetDatabase())
                {
                    SubjectDialog subjectDialog = new SubjectDialog(db);
                    bool          doAdd         = true;

                    try
                    {
                        Monitor.Enter(CcowServer.LockObject);
                        subjectDialog.Subject = new CCOWSubject()
                        {
                            Id = Guid.NewGuid()
                        };
                        db.CCOWSubject.InsertOnSubmit(subjectDialog.Subject);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        doAdd = false;
                    }
                    finally
                    {
                        Monitor.Exit(CcowServer.LockObject);
                    }

                    if (doAdd)
                    {
                        if (subjectDialog.ShowDialog(this) == DialogResult.OK)
                        {
                            try
                            {
                                Monitor.Enter(CcowServer.LockObject);
                                db.SubmitChanges();
                                AddSubject(subjectDialog.Subject);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            finally
                            {
                                Monitor.Exit(CcowServer.LockObject);
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#2
0
        private void buttonEditSubject_Click(object sender, EventArgs e)
        {
            try
            {
                using (Database db = Leadtools.Ccow.Server.Utils.GetDatabase())
                {
                    DataLoadOptions o         = new DataLoadOptions();
                    Guid            subjectid = (Guid)listViewSubjects.SelectedItems[0].Tag;
                    SubjectDialog   subjectDialog;
                    CCOWSubject     subject;

                    o.LoadWith <CCOWSubjectItems>(i => i.CCOWSubject);
                    o.LoadWith <CCOWSubjectDependency>(d => d.CCOWSubject);
                    o.LoadWith <CCOWSubjectApplication>(f => f.CCOWApplication);
                    db.LoadOptions = o;

                    try
                    {
                        Monitor.Enter(CcowServer.LockObject);
                        subject = db.CCOWSubject.First(s => s.Id == subjectid);
                    }
                    finally
                    {
                        Monitor.Exit(CcowServer.LockObject);
                    }

                    subjectDialog = new SubjectDialog(db, subject);

                    if (subjectDialog.ShowDialog(this) == DialogResult.OK)
                    {
                        try
                        {
                            Monitor.Enter(CcowServer.LockObject);
                            db.SubmitChanges();
                            UpdateItem(listViewSubjects.SelectedItems[0], subject);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        finally
                        {
                            Monitor.Exit(CcowServer.LockObject);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "Database access failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }