private void btnAdd_Click(object sender, EventArgs e) { try { DataClassesJobDataContext db = new DataClassesJobDataContext(); ApplyJobDetail jobDetail = new ApplyJobDetail(); //check if item already exists in sales detail table with same transId //var item = from i in db.ApplyJobDetails // where i.ItemId.Equals(DropDownListItemName.SelectedItem.Value) && i.SaleId == LabelSaleId.Text // select i; //if (item.Any()) //{ // LabelMessage.ForeColor = System.Drawing.Color.Red; // LabelMessage.Text = DropDownListItemName.SelectedItem.Text + " already exists. please update or delete it to make a new entry"; // // txtNetTotal.Text = "0"; // return; //} // generate Sale Id manually by random // var random = Guid.NewGuid().ToString().Replace("-", null); if (cboId.Text == "*" || cboId.Text == "") { MessageBox.Show("please click the new button"); return; } /* * vendor.ItemTypeId = Convert.ToInt32(DropDownList1.SelectedItem.Value); * vendor.itemTypeName = DropDownList1.SelectedItem.Text; * * insert data into master table (sale) before inserting data into child table(saleDetail) */ #region insert data into master tabel // insert data into master table var queryResults = from s in db.ApplyJobs where s.Id == cboId.Text select s; if (queryResults.Any()) { MessageBox.Show("id already exists"); return; } else { //insert new transId ApplyJob job = new ApplyJob(); job.Id = cboId.Text; job.Transdate = Convert.ToDateTime(dtpDate.Text); db.ApplyJobs.InsertOnSubmit(job); db.SubmitChanges(); } #endregion jobDetail.JobId = (int)cboJob.SelectedValue; jobDetail.CompanyId = (int)cboCompany.SelectedValue; jobDetail.ApplyJobId = cboId.Text; db.ApplyJobDetails.InsertOnSubmit(jobDetail); db.SubmitChanges(); MessageBox.Show("item added in detail"); // bind saleDetail data to grid view var applyDetail = from s in db.ApplyJobDetails where s.ApplyJobId == cboId.Text select s; // var list = new List<object> { queryResults }; dataGridViewJob.DataSource = applyDetail; // show notification for delete notifyIconRightClick.ShowBalloonTip(3, "Tip", "right click on datagrid to get context menu", ToolTipIcon.Info); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
partial void UpdateApplyJob(ApplyJob instance);
partial void DeleteApplyJob(ApplyJob instance);
partial void InsertApplyJob(ApplyJob instance);