public void SaveLicense(TBL_LICENSE_TYPE license) { using (_context = new LicenseDataContext()) { _context.TBL_LICENSE_TYPEs.InsertOnSubmit(license); _context.SubmitChanges(); }; }
private void btnSave_Click(object sender, EventArgs e) { if (!invalid()) { try { using (TBL_LICENSE_TYPE_DATA_ACCESS lda = new TBL_LICENSE_TYPE_DATA_ACCESS()) { using (_context = new LicenseDataContext()) { TBL_LICENSE_TYPE lt = new TBL_LICENSE_TYPE(); lt.LICENSE_ID = LICENSE_ID; if (cboColor.SelectedIndex == 0) { lt.PERCENTAGE = 100; lt.COLOR_ID = 1; } if (cboColor.SelectedIndex == 1) { lt.PERCENTAGE = 75; lt.COLOR_ID = 2; } else if (cboColor.SelectedIndex == 2) { lt.PERCENTAGE = 50; lt.COLOR_ID = 3; } lt.CREATE_DATE = DateTime.Now; lt.IS_ACTIVE = true; lt.CREATE_BY = "admin"; lda.SaveLicense(lt); } } this.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } } else { } GC.Collect(); }
private void btnSave_Click(object sender, EventArgs e) { try { using (TBL_LICENSE_TYPE_DATA_ACCESS ltda = new TBL_LICENSE_TYPE_DATA_ACCESS()) { using (_context = new LicenseDataContext()) { TBL_LICENSE_TYPE lt = (from l in _context.TBL_LICENSE_TYPEs where l.LICENSE_ID == LICENSE_ID select l).FirstOrDefault(); if (cboColor.SelectedIndex == 0) { lt.COLOR_ID = 1; lt.PERCENTAGE = 100; } else if (cboColor.SelectedIndex == 1) { lt.COLOR_ID = 2; lt.PERCENTAGE = 75; } else if (cboColor.SelectedIndex == 2) { lt.COLOR_ID = 3; lt.PERCENTAGE = 50; } else if (cboColor.SelectedIndex == 3) { lt.COLOR_ID = 4; lt.PERCENTAGE = 0; } _context.SubmitChanges(); } } this.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } }
private void btnDelete_Click(object sender, EventArgs e) { int ID = 0; foreach (DataGridViewRow row in dataGridViewLicense.SelectedRows) { ID = Convert.ToInt32(row.Cells["LICENSE_TYPE_ID"].Value); } try { if (ID != 0) { using (_context = new LicenseDataContext()) { TBL_LICENSE_TYPE license = (from l in _context.TBL_LICENSE_TYPEs where l.LICENSE_TYPE_ID == ID select l).FirstOrDefault(); _context.TBL_LICENSE_TYPEs.DeleteOnSubmit(license); _context.SubmitChanges(); } } else { } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } finally { using (TBL_LICENSE_TYPE_DATA_ACCESS ltda = new TBL_LICENSE_TYPE_DATA_ACCESS()) { dataGridViewLicense.DataSource = ltda.ShowLicenseTypeSpecial(); }; } }