/********************************************************************************/ public void viewOptScheduleModel(oadrOptScheduleModel optScheduleModel) { txtOptID.Text = optScheduleModel.OptID; cmbOptType.SelectedItem = optScheduleModel.OptType; cmbOptReason.SelectedItem = optScheduleModel.OptReason; txtMarketContext.Text = optScheduleModel.MarketContext; txtResource.Text = optScheduleModel.ResourceID; // dataGridViewSchedule.DataSource = optScheduleModel.ScheduleList; lvAvailability.Items.Clear(); foreach (OadrAvailable available in optScheduleModel.ScheduleList) { ListViewItem lvi = new ListViewItem(available.StartDate.ToString("ddd MMM dd yyyy hh:mm tt")); lvi.SubItems.Add(available.Duration.ToString()); lvAvailability.Items.Add(lvi); } dtStart.Value = DateTime.Now; numericUpDownDuration.Value = 1; }
/**********************************************************/ private void btnNewSchedule_Click(object sender, EventArgs e) { frmOADRNewScheduleView newSchedule = new frmOADRNewScheduleView(); DialogResult result = newSchedule.ShowDialog(); if (result != DialogResult.OK) { return; } oadrOptScheduleModel optScheduleModel = newSchedule.getOptScheduleModel(); ListViewItem lvi = new ListViewItem(optScheduleModel.Name); lvi.SubItems.Add(optScheduleModel.OptID); lvi.SubItems.Add("False"); lstSchedules.Items.Add(lvi); m_scheduleLvi.Add(optScheduleModel.OptID, lvi); m_schedulesByOptId.Add(optScheduleModel.OptID, optScheduleModel); // createOptSchedules(optScheduleModel); }
/********************************************************************************/ public oadrOptScheduleModel getOptScheduleModel(oadrOptScheduleModel optScheduleModel = null) { if (optScheduleModel == null) { optScheduleModel = new oadrOptScheduleModel(); } optScheduleModel.OptType = cmbOptType.SelectedItem.ToString(); optScheduleModel.OptReason = cmbOptReason.SelectedItem.ToString(); optScheduleModel.MarketContext = txtMarketContext.Text; optScheduleModel.ResourceID = txtResource.Text; optScheduleModel.ScheduleList = new List <OadrAvailable>(); int nRow = lvAvailability.Items.Count; for (int i = 0; i < nRow; i++) { OadrAvailable obj = new OadrAvailable(); ListViewItem lvi = lvAvailability.Items[i]; obj.StartDate = Convert.ToDateTime(lvi.SubItems[0].Text); obj.Duration = Convert.ToInt32(lvi.SubItems[1].Text); optScheduleModel.ScheduleList.Add(obj); } return(optScheduleModel); }
/********************************************************************************/ private void editToolStripMenuItem_Click(object sender, EventArgs e) { if (lstSchedules.SelectedItems.Count == 0) { return; } string optID = lstSchedules.SelectedItems[0].SubItems[1].Text; oadrOptScheduleModel optScheduleModel = m_schedulesByOptId[optID]; frmOADRNewScheduleView newSchedule = new frmOADRNewScheduleView(); newSchedule.loadOadrOptScheduleModel(optScheduleModel); DialogResult result = newSchedule.ShowDialog(); if (result != DialogResult.OK) { return; } // update the model optScheduleModel = newSchedule.getOptScheduleModel(optScheduleModel); m_schedulesByOptId[optID] = optScheduleModel; ListViewItem lvi = m_scheduleLvi[optID]; lvi.SubItems[0].Text = optScheduleModel.Name; // m_schedulesByOptId.Add(optScheduleModel.OptID, optScheduleModel); }
/********************************************************************************/ private void lstSchedules_SelectedIndexChanged(object sender, EventArgs e) { if (lstSchedules.SelectedItems.Count == 0) { return; } string optID = lstSchedules.SelectedItems[0].SubItems[1].Text; oadrOptScheduleModel optScheduleModel = m_schedulesByOptId[optID]; MethodInvoker mi = new MethodInvoker(delegate { try { ucOptScheduleView1.viewOptScheduleModel(optScheduleModel); } catch (Exception ex) { Logger.logException(ex); } }); // BeginInvoke only needs to be called if we're tyring to update the UI from // a thread that did not create it if (this.InvokeRequired) { this.BeginInvoke(mi); } else { mi.Invoke(); } }
/**********************************************************/ public oadrOptScheduleModel getOptScheduleModel(oadrOptScheduleModel model = null) { model = ucOptScheduleView1.getOptScheduleModel(model); model.Name = tbScheduleName.TextBoxText; return(model); }
/**********************************************************/ private void createOptSchedules(oadrOptScheduleModel optScheduleModel) { oadrlib.lib.oadr2b.OptSchedule optSchedule; if ((optSchedule = optScheduleModel.getOptSchedule()) != null) { m_manageOptSchedules.createOptSchedule(optSchedule); } }
/********************************************************************************/ private void sendToolStripMenuItem_Click(object sender, EventArgs e) { if (lstSchedules.SelectedItems.Count == 0) { return; } DialogResult result = MessageBox.Show("This action will resend the opt schedule to the VTN. Click OK to confirm.", "Resend Opt Schedule?", MessageBoxButtons.OKCancel); if (result != DialogResult.OK) { return; } string optID = lstSchedules.SelectedItems[0].SubItems[1].Text; oadrOptScheduleModel optScheduleModel = m_schedulesByOptId[optID]; createOptSchedules(optScheduleModel); }
/********************************************************************************/ public void addOptSchedule(CreateOpt createOpt) { MethodInvoker mi = new MethodInvoker(delegate { try { string optId = createOpt.response.optID; if (!m_schedulesByOptId.ContainsKey(optId)) { return; } oadrOptScheduleModel optScheduleModel = m_schedulesByOptId[optId]; optScheduleModel.OptInRegistered = true; optScheduleModel.OptOutRegistered = true; m_scheduleLvi[optId].SubItems[2].Text = "True"; } catch (Exception ex) { Logger.logException(ex); } // lstSchedules.Items.Add(createOpt.response.optID); }); // BeginInvoke only needs to be called if we're tyring to update the UI from // a thread that did not create it if (this.InvokeRequired) { this.BeginInvoke(mi); } else { mi.Invoke(); } }
/**********************************************************/ public void loadOadrOptScheduleModel(oadrOptScheduleModel model) { ucOptScheduleView1.viewOptScheduleModel(model); tbScheduleName.TextBoxText = model.Name; }