public void SaveLicenseGenerate(TBL_LICENSE_GENERATE lg)
 {
     using (_context = new LicenseDataContext())
     {
         _context.TBL_LICENSE_GENERATEs.InsertOnSubmit(lg);
         _context.SubmitChanges();
     };
 }
        private void dataGridViewFollowUP_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewRow row = this.dataGridViewFollowUP.Rows[e.RowIndex];

            //        var dialog = MessageBox.Show(this, "Are you sure to change this?", "", MessageBoxButtons.OKCancel);

            if (row != null)
            {
                try
                {
                    int    license_generate_id = Convert.ToInt32(row.Cells["LICENSE_GENERATE_ID"].Value);
                    string note;
                    // MessageBox.Show(row.Cells["CREATE_BY"].Value.ToString());
                    if (row.Cells["NOTE"].Value == null)
                    {
                        note = "";
                        //MessageBox.Show("NullExpection");
                    }
                    else
                    {
                        note = row.Cells["NOTE"].Value.ToString();
                    }
                    //MessageBox.Show(license_generate_id.ToString());
                    using (_context = new LicenseDataContext())
                    {
                        TBL_LICENSE_GENERATE lg = (from l in _context.TBL_LICENSE_GENERATEs
                                                   where l.LICENSE_GENERATE_ID == license_generate_id
                                                   select l).FirstOrDefault();
                        lg.NOTE          = note;
                        lg.LAST_MODIFIED = DateTime.Now;
                        lg.FOLLOW_UP_BY  = row.Cells["FOLLOW_UP_BY"].Value.ToString();
                        _context.SubmitChanges();
                    };
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.ToString());
                }
            }
        }
 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);
     }
 }