Exemple #1
0
        private void toolStripButton_calendar_new_Click(object sender, EventArgs e)
        {
            string strError = "";

            CalendarDialog dlg = new CalendarDialog();
            MainForm.SetControlFont(dlg, this.Font, false);

            DateTime now = DateTime.Now;

            dlg.Text = "创建日历";
            dlg.IsGlobalUser = Global.IsGlobalUser(this.Channel.LibraryCodeList);
            dlg.OwnerLibraryCodes = GetOwnerLibraryCodes();
            dlg.CreateMode = true;
            dlg.CalendarName = Global.BuildCalendarName(Global.GetFirstLibraryCode(this.Channel.LibraryCodeList), "新建日历");    // 当前用户所在分馆
            dlg.Range = DateTimeUtil.DateTimeToString8(new DateTime(now.Year, 1, 1)) + "-" + DateTimeUtil.DateTimeToString8(new DateTime(now.Year + 2, 12, 31));   // 最近两年
            dlg.Comment = "";
            dlg.Content = "";

            REDO:
            this.MainForm.AppInfo.LinkFormState(dlg, "CalendarDialog_state");
            dlg.ShowDialog(this);
            this.MainForm.AppInfo.UnlinkFormState(dlg);

            if (dlg.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                return;

            // 日历名查重
            ListViewItem dup = ListViewUtil.FindItem(this.listView_calendar, dlg.CalendarName, COLUMN_CALENDAR_NAME);
            if (dup != null)
            {
                ListViewUtil.SelectLine(dup, true);
                MessageBox.Show(this, "日历名 '"+dlg.CalendarName+"' 和现有的日历名重复了,请修改");
                goto REDO;
            }

            ListViewItem item = new ListViewItem();

            ListViewUtil.ChangeItemText(item, COLUMN_CALENDAR_NAME, dlg.CalendarName);
            ListViewUtil.ChangeItemText(item, COLUMN_CALENDAR_RANGE, dlg.Range);
            ListViewUtil.ChangeItemText(item, COLUMN_CALENDAR_COMMENT, dlg.Comment);
            ListViewUtil.ChangeItemText(item, COLUMN_CALENDAR_CONTENT, dlg.Content);

            SetCalendarItemState(item, ITEMTYPE_NEW);

            this.listView_calendar.Items.Add(item);
            ListViewUtil.SelectLine(item, true);

            this.CalendarDefChanged = true;
            m_nCalendarVersion++;

            return;
        ERROR1:
            MessageBox.Show(this, strError);
        }
Exemple #2
0
        private void toolStripButton_calendar_modify_Click(object sender, EventArgs e)
        {
            string strError = "";

            if (this.listView_calendar.SelectedItems.Count == 0)
            {
                strError = "尚未选定要修改的日历事项";
                goto ERROR1;
            }

            ListViewItem item = this.listView_calendar.SelectedItems[0];

            if (item.ImageIndex == ITEMTYPE_DELETED)
            {
                DialogResult result = MessageBox.Show(this,
    "此日历事项当前为已删除状态。\r\n\r\n需要恢复它么?\r\n\r\n(Yes: 恢复并编辑; No: 不恢复,以只读状态观察; Cancel: 放弃本次编辑操作)",
    "ManagerForm",
    MessageBoxButtons.YesNoCancel,
    MessageBoxIcon.Question,
    MessageBoxDefaultButton.Button2);
                if (result == System.Windows.Forms.DialogResult.Cancel)
                    return;
                if (result == System.Windows.Forms.DialogResult.Yes)
                {
                    SetCalendarItemState(item, ITEMTYPE_CHANGED);
                    m_nCalendarVersion++;
                }
            }

            string strCalendarName = ListViewUtil.GetItemText(item, COLUMN_CALENDAR_NAME);
            // 如果不是当前用户管辖的分馆,则对话框为只读状态
            bool bOwner = true;
            {
                string strLibraryCode = "";
                string strPureName = "";

                Global.ParseCalendarName(strCalendarName,
            out strLibraryCode,
            out strPureName);

                if (Global.IsGlobalUser(this.Channel.LibraryCodeList) == false
                    && StringUtil.IsInList(strLibraryCode, this.Channel.LibraryCodeList) == false)
                    bOwner = false;
           }

            CalendarDialog dlg = new CalendarDialog();
            MainForm.SetControlFont(dlg, this.Font, false);

            dlg.OwnerLibraryCodes = GetOwnerLibraryCodes();
            dlg.IsGlobalUser = Global.IsGlobalUser(this.Channel.LibraryCodeList);
            dlg.CreateMode = false;
            dlg.ReadOnly = item.ImageIndex == ITEMTYPE_DELETED || bOwner == false;
            if (dlg.ReadOnly)
                dlg.Text = "日历";
            else
                dlg.Text = "修改日历";
            dlg.CalendarName = strCalendarName;
            dlg.Range = ListViewUtil.GetItemText(item, COLUMN_CALENDAR_RANGE);
            dlg.Comment = ListViewUtil.GetItemText(item, COLUMN_CALENDAR_COMMENT);
            dlg.Content = ListViewUtil.GetItemText(item, COLUMN_CALENDAR_CONTENT);
            this.MainForm.AppInfo.LinkFormState(dlg, "CalendarDialog_state");
            dlg.ShowDialog(this);
            this.MainForm.AppInfo.UnlinkFormState(dlg);

            if (dlg.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                return;

            ListViewUtil.ChangeItemText(item, COLUMN_CALENDAR_NAME, dlg.CalendarName);
            ListViewUtil.ChangeItemText(item, COLUMN_CALENDAR_RANGE, dlg.Range);
            ListViewUtil.ChangeItemText(item, COLUMN_CALENDAR_COMMENT, dlg.Comment);
            ListViewUtil.ChangeItemText(item, COLUMN_CALENDAR_CONTENT, dlg.Content);

            if (item.ImageIndex != ITEMTYPE_NEW)
                SetCalendarItemState(item, ITEMTYPE_CHANGED);

            this.CalendarDefChanged = true;

            // 一般编辑的时候,不可能修改日历名,所以 m_nCalendarVersion++; 就不用了

            return;
        ERROR1:
            MessageBox.Show(this, strError);
        }