private void FormLicenseAvailableByCreateOn_Load(object sender, EventArgs e) { lblHeader.Text = ControlSurvey.SEASON_NAME; lblDate.Text = ControlSurvey.DATE.ToLongDateString() + " " + ControlSurvey.DATE.ToShortTimeString(); lblBy.Text = ControlSurvey.BY; using (TBL_LICENSE_GENERATE_DATA_ACCESS lgda = new TBL_LICENSE_GENERATE_DATA_ACCESS()) { dataGridViewFollowUP.DataSource = lgda.ShowLicenseByCreateOn(ControlSurvey.DATE); } }
private void btnGenerate_Click(object sender, EventArgs e) { frmmain = new FormMain(); try { using (TBL_LICENSE_GENERATE_DATA_ACCESS lgda = new TBL_LICENSE_GENERATE_DATA_ACCESS()) { List <int> SCHEDULE_ID = new List <int>(); List <int> temp = new List <int>(); List <int> result = new List <int>(); //MessageBox.Show(SEASON_ID.ToString()); foreach (var schedule_id in lgda.RunningAvailableLicenseBySeasonID(SEASON_ID)) { SCHEDULE_ID.Add(schedule_id.SCHEDULE_ID); // MessageBox.Show(schedule_id.SCHEDULE_ID.ToString()); } Random rnd = new Random(); for (int i = 0; i < SCHEDULE_ID.Count; i++) { int num = rnd.Next(SCHEDULE_ID.Count); if (!temp.Contains(num)) { temp.Add(num); result.Add(SCHEDULE_ID[num]); } else { i--; } } try { // MessageBox.Show(cboUser.Text.ToString()); foreach (var item in result.Take(Convert.ToInt32(cboTake.SelectedItem))) { using (_context = new LicenseDataContext()) { TBL_LICENSE_GENERATE lg = new TBL_LICENSE_GENERATE() { SCHEDULE_ID = Convert.ToInt32(item), CREATE_ON = Convert.ToDateTime(dateTimePickerLicenseGenerate.Value.ToString("yyy-MM-dd hh:mm")), CREATE_BY = cboUser.Text, NOTE = "Not yet.", FOLLOW_UP_BY = cboFollowUpBy.Text, LAST_MODIFIED = DateTime.Now, IS_ACTIVE = true }; lgda.SaveLicenseGenerate(lg); } } var dialog = MetroMessageBox.Show(this, Properties.Resources.SUCCESSFULL, Properties.Resources.INFORMATION, MessageBoxButtons.OK); if (dialog == System.Windows.Forms.DialogResult.OK) { frmmain.RefreshMain(); frmmain.ShowWork(null, null); this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); this.Close(); } } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } }