コード例 #1
0
ファイル: Form1.cs プロジェクト: xpoi5010/TimeTable
 private void toolStripButton2_Click(object sender, EventArgs e)
 {
     try
     {
         Dialog.AddEvent ae = new Dialog.AddEvent(Dialog.AddEvent.mode.Add);
         if (ae.ShowDialog() == DialogResult.OK)
         {
             ListViewItem lvi   = new ListViewItem(new string[] { ae.Time, ae.Event, ae.Week1, ae.Week2 });
             int          index = listView1.Items.Count;
             int          i     = 0;
             foreach (ListViewItem lvii in listView1.Items)
             {
                 DateTime dt  = DateTime.ParseExact(lvii.Text, "HH:mm", new System.Globalization.CultureInfo("zh-TW"));
                 DateTime dtt = DateTime.ParseExact(lvi.Text, "HH:mm", new System.Globalization.CultureInfo("zh-TW"));
                 if (dtt < dt)
                 {
                     index = i;
                     break;
                 }
                 else if (dtt == dt)
                 {
                     index = i + 1;
                     break;
                 }
                 i++;
             }
             listView1.Items.Insert(index, lvi);
             Changed = true;
         }
     }
     catch (Exception ex)
     {
         Dialog.ErrorBox errorBox = new Dialog.ErrorBox(0x0003, this, ex);
     }
 }
コード例 #2
0
ファイル: Form1.cs プロジェクト: xpoi5010/TimeTable
 private void listView1_DoubleClick(object sender, EventArgs e)
 {
     if (listView1.SelectedItems != null)
     {
         ListViewItem lvi   = listView1.SelectedItems[0];
         int          index = lvi.Index;
         string[]     temp  = new string[lvi.SubItems.Count];
         temp[0] = lvi.Text;
         Array.ConvertAll(lvi.SubItems.Cast <ListViewItem.ListViewSubItem>().ToArray(), a => a.Text).CopyTo(temp, 0);
         Dialog.AddEvent ae = new Dialog.AddEvent(Dialog.AddEvent.mode.modify);
         ae.Time  = temp[0];
         ae.Event = temp[1];
         ae.Week1 = temp[2];
         ae.Week2 = temp[3];
         if (ae.ShowDialog() == DialogResult.OK)
         {
             listView1.Items.RemoveAt(index);
             ListViewItem lvii   = new ListViewItem(new string[] { ae.Time, ae.Event, ae.Week1, ae.Week2 });
             int          index_ = listView1.Items.Count;
             int          i      = 0;
             foreach (ListViewItem lviii in listView1.Items)
             {
                 DateTime dt  = DateTime.ParseExact(lviii.Text, "HH:mm", new System.Globalization.CultureInfo("zh-TW"));
                 DateTime dtt = DateTime.ParseExact(lvii.Text, "HH:mm", new System.Globalization.CultureInfo("zh-TW"));
                 if (dtt < dt)
                 {
                     index_ = i;
                     break;
                 }
                 else if (dtt == dt)
                 {
                     index_ = i + 1;
                     break;
                 }
                 i++;
             }
             listView1.Items.Insert(index_, lvii);
             Changed = true;
         }
     }
 }