private void BtnCompleteCheckout_Click(object sender, EventArgs e) { CHECKOUTIN choi = new CHECKOUTIN(); try { using (AccetManagementEntities db = new AccetManagementEntities()) { var statusId = db.STATUS.Where(c => c.STATUSNAME == cmbStatus.Text).OrderBy(c => c.STATUSNAME).Select(c => c.STATUSID).ToList(); var LocationId = db.LOCATIONs.Where(c => c.LOCATIONNAME == cmbLocation.Text).OrderBy(c => c.LOCATIONID).Select(c => c.LOCATIONID).ToList(); // UPDATE ASSETS TABLE staId = statusId[0]; locId = LocationId[0]; UpdateAssetTable(); choi.EMPNAME = cmbCheckout.Text.ToString().Trim();// CommonData.Fname + " " + CommonData.Lname; choi.ASSETNO = this.dgvItemsCheckedOut.CurrentRow.Cells[1].Value.ToString(); choi.COMMENT = rctComment.Text.ToString(); choi.DUEDATE = Convert.ToDateTime(dtpDate.Text.ToString()); choi.STATUSID = statusId[0]; choi.LOCATIONID = LocationId[0]; choi.DESCRIPTION = this.dgvItemsCheckedOut.CurrentRow.Cells[0].Value.ToString(); choi.CHECKOUTDATE = DateTime.Now; choi.COMPNAME = Environment.MachineName; //choi.EMPID = CommonData.PersonalNumber; db.CHECKOUTINs.Add(choi); db.SaveChanges(); this.Close(); MessageBox.Show("Saved Successfully to Database."); Application.Restart(); //Main newMain = new Main(); //newMain.ShowDialog(); } } catch (Exception ex) { MessageBox.Show("Invalid entry. Ensure you do not repeat the same entry on AssetNo" + ex); //throw; } }
private void InsetCheckinTable() { CHECKOUTIN choi = new CHECKOUTIN(); try { using (AccetManagementEntities db = new AccetManagementEntities()) { var statusId = db.STATUS.Where(c => c.STATUSNAME == cmbStatus.Text).OrderBy(c => c.STATUSNAME).Select(c => c.STATUSID).ToList(); var LocationId = db.LOCATIONs.Where(c => c.LOCATIONNAME == cmbLocation.Text).OrderBy(c => c.LOCATIONID).Select(c => c.LOCATIONID).ToList(); choi.EMPNAME = CommonData.Fname + " " + CommonData.Lname; choi.ASSETNO = this.dgvCheckin.CurrentRow.Cells[0].Value.ToString(); choi.COMMENT = richTextBoxComent.Text.ToString(); choi.DUEDATE = Convert.ToDateTime(this.dgvCheckin.CurrentRow.Cells[3].Value.ToString()); choi.STATUSID = statusId[0]; choi.LOCATIONID = LocationId[0]; choi.DESCRIPTION = this.dgvCheckin.CurrentRow.Cells[1].Value.ToString(); choi.CHECKOUTDATE = Convert.ToDateTime(this.dgvCheckin.CurrentRow.Cells[2].Value.ToString()); choi.COMPNAME = Environment.MachineName; choi.CHECKINDATE = DateTime.Now; //choi.EMPID = CommonData.PersonalNumber; db.CHECKOUTINs.Add(choi); db.SaveChanges(); this.Close(); MessageBox.Show("Saved Successfully to Database."); Application.Restart(); //Main newMain = new Main(); //newMain.ShowDialog(); } } catch (Exception ex) { MessageBox.Show("Invalid entry. Ensure you do not repeat the same entry on AssetNo" + ex); //throw; } }