private void btnAdd_Click(object sender, EventArgs e) { try { DataClassesJobDataContext db = new DataClassesJobDataContext(); InterviewDetail interviewDetail = new InterviewDetail(); //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.Interviews where s.Id == cboId.Text select s; if (queryResults.Any()) { // MessageBox.Show("id already exists"); // return; goto childTable; } else { //insert new transId Interview interview = new Interview(); interview.Id = cboId.Text; interview.TransDate = dtpTransDate.Value; interview.CompanyId = Convert.ToInt32(cboCompany.SelectedValue); interview.CompanyName = cboCompany.Text; db.Interviews.InsertOnSubmit(interview); db.SubmitChanges(); } #endregion childTable: interviewDetail.InterviewId = cboId.Text; interviewDetail.QuestionId = (int)cboQuestion.SelectedValue; interviewDetail.Question = cboQuestion.Text; db.InterviewDetails.InsertOnSubmit(interviewDetail); db.SubmitChanges(); MessageBox.Show("item added in detail"); // bind saleDetail data to grid view var interDetail = from s in db.InterviewDetails where s.InterviewId == cboId.Text select s; // var list = new List<object> { queryResults }; dataGridViewQuestion.DataSource = interDetail; // 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 UpdateInterview(Interview instance);
partial void DeleteInterview(Interview instance);
partial void InsertInterview(Interview instance);