private void sort(List <cClassData> ll)
 {
     for (int j = 0; j < ll.Count; j++)
     {
         for (int i = j + 1; i < ll.Count; i++)
         {
             if (ll[i].EndTime <= ll[i - 1].EndTime)
             {
                 cClassData temp = ll[i];
                 ll[i]     = ll[i - 1];
                 ll[i - 1] = temp;
             }
         }
     }
 }
Esempio n. 2
0
 private void btnBrowse_Click(object sender, EventArgs e)
 {
     //OpenFileDialog openFileDialog = new OpenFileDialog();
     //openFileDialog.Filter = "CSV files (*.csv)|*.csv|XML files (*.xml)|*.xml";
     try
     {
         string         filename = "";
         OpenFileDialog dialog   = new OpenFileDialog();
         dialog.Title = "Open csv and txt  File";
         //dialog.Filter = "CSV Files (*.txt)|*.txt";
         //dialog.Filter = "CSV Files (*.csv)|*.csv";
         dialog.ShowDialog();
         filename        = dialog.FileName;
         TBFileName.Text = filename;
         try
         {
             StreamReader reader = new StreamReader(File.OpenRead(@filename));
             while (!reader.EndOfStream)
             {
                 var line = reader.ReadLine();
                 if (!String.IsNullOrWhiteSpace(line))
                 {
                     string[] values = line.Split(',');
                     if (values.Length >= 3)
                     {
                         cClassData myclass = new cClassData();
                         myclass.ClassName = values[0];
                         myclass.StartTime = Convert.ToInt32(values[1]);
                         myclass.EndTime   = Convert.ToInt32(values[2]);
                         classStore.Add(myclass);
                     }
                 }
             }
             MessageBox.Show("Data Loaded Successfully...!!!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
             showInputClass();
         }
         catch
         {
             MessageBox.Show("Can't Read or load specified file...!!!", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     catch
     {
         MessageBox.Show("Error while opening CSV file...!!!", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        private void btnInsert_Click(object sender, EventArgs e)
        {
            classN = TBclassName.Text;
            cClassData mydata = new cClassData();

            if (classN != "")
            {
                mydata.ClassName = classN;
                mydata.StartTime = startT;
                mydata.EndTime   = endT;
            }
            else
            {
                MessageBox.Show("class name can't be empty", "invalid", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            classStore.Add(mydata);
            TBclassName.Text = CBendTIme.Text = CBstartTime.Text = "";  //reset data
            showAllClass();
        }
Esempio n. 4
0
 // insert button
 public void btnInsert_Click(object sender, EventArgs e)
 {
     if (txtNumberofrooms.Text.Trim() != "")                //validating room number
     {
         try
         {
             maxRoomCap = Convert.ToInt32(txtNumberofrooms.Text.Trim());
             if (maxRoomCap > 0 && maxRoomCap < 100)
             {
                 className = TBclassName.Text.Trim();          //validating class name
                 if (className != "")
                 {
                     try
                     {
                         startTime = Convert.ToInt32(CBstartTime.Text.Trim());     //validating start time
                         try
                         {
                             endTime = Convert.ToInt32(CBendTime.Text.Trim());
                             if (startTime < endTime)                  // validating end time
                             {
                                 cClassData mydata = new cClassData(); //create a object
                                 mydata.ClassName = className;
                                 mydata.StartTime = startTime;
                                 mydata.EndTime   = endTime;
                                 //add new data object (new class) in to classStore
                                 classStore.Add(mydata);
                                 //reset GUI data input fields
                                 CBstartTime.Text = "";
                                 CBendTime.Text   = "";
                                 TBclassName.Text = "";
                                 className        = "";
                                 startTime        = 0;
                                 endTime          = 24;
                                 //whole data on datagrid view
                                 showInputClass();
                             }
                             else
                             {
                                 MessageBox.Show("Start time must be less than endtime of class", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error);
                             }
                         }
                         catch
                         {
                             MessageBox.Show("Select a valid end time for a class", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error);
                         }
                     }
                     catch
                     {
                         MessageBox.Show("Select a valid start time for a class", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error);
                     }
                 }
                 else
                 {
                     MessageBox.Show("Enter a class name", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
             else
             {
                 MessageBox.Show("Number of rooms must be between 0 to 9", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         catch
         {
             MessageBox.Show("Number of rooms must be numaric values", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     else
     {
         MessageBox.Show("Enter maximum number of rooms available...!!!", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }