private void btnSubmit_Click(object sender, EventArgs e) { MacrocommEntities context = new MacrocommEntities(); tblLogFault objLog = new tblLogFault(); if (cmbFaultType.Text == "" || cmbCustomerType.Text == "" || txtComment.Text == "") { MessageBox.Show("Please enter all requered field.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { try { // Adding logs to the FaultLogs table. objLog.Log_Type = cmbFaultType.Text; objLog.Consumer_Type = cmbCustomerType.Text; objLog.Comment = txtComment.Text; context.tblLogFaults.Add(objLog); context.SaveChanges(); MessageBox.Show("Log request Successfully logged.", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information); Clear(); } catch { MessageBox.Show("Something went wrong please try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Clear(); } } using (MacrocommEntities db = new MacrocommEntities()) { tblViewLog view = new tblViewLog(); var logg = (from p in db.tblLogFaults join r in db.tblViewLogs on p.Ref_No equals r.LogID where p.Log_Type == "Water,Electricity,Refuse,Sawege" select new { ID = p.Ref_No, cmbFaultType = p.Log_Type, cmbCustomerType = p.Consumer_Type, txtComment = p.Comment, lID = r.LogID, fault = r.Fault_Type, comsumer = r.Consumer_Status, comments = r.Comment }).ToList(); context.tblViewLogs.Add(view); context.SaveChanges(); } }
private void btnSubmit_Click(object sender, EventArgs e) { try { MacrocommEntities context = new MacrocommEntities(); tblLogOther objOther = new tblLogOther(); objOther.Fault_Type = cmbFaultType.Text; objOther.ConsumerType = cmbCustomerType.Text; objOther.Location = txtLocation.Text; objOther.Comment = txtComment.Text; context.tblLogOthers.Add(objOther); context.SaveChanges(); MessageBox.Show("Request Logged successfully", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information); Clear(); cmbFaultType.Focus(); } catch { MessageBox.Show("Request not logged, Please check all fields", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Clear(); cmbFaultType.Focus(); } }
private void btnDelete_Click(object sender, EventArgs e) { tblLogFault fault = new tblLogFault(); if (dgvViewLog.CurrentRow.Index != -1) { model.LogID = Convert.ToInt32(dgvViewLog.CurrentRow.Cells["LogID"].Value); using (MacrocommEntities db = new MacrocommEntities()) { model = db.tblViewLogs.Where(x => x.LogID == model.LogID).FirstOrDefault(); if (MessageBox.Show("Are you sure to delete this record ?", "EF CRUD Operation", MessageBoxButtons.YesNo) == DialogResult.Yes) { var entry = db.Entry(model); if (entry.State == EntityState.Detached) { db.tblViewLogs.Attach(model); } db.tblViewLogs.Remove(model); db.SaveChanges(); MessageBox.Show("Deleted Successfully"); } } } }
private void btnSave_Click(object sender, EventArgs e) { if (txtFirstName.Text == "" || txtSurname.Text == "" || txtMobile.Text == "" || txtEmail.Text == "" || txtPassword.Text == "" || txtPasswordConfirm.Text == "") { MessageBox.Show("Please enter all fields"); Clear(); } else if (txtPassword.Text != txtPasswordConfirm.Text) { MessageBox.Show("Password Does not match!"); txtPassword.Text = ""; txtPasswordConfirm.Text = ""; } // if exists, show a message error else if (context.tblRegistrations.Any(o => o.Mobile == txtMobile.Text)) { lblErrorUser.Visible = true; txtMobile.Text = ""; txtMobile.Focus(); txtEmail.Text = ""; txtPassword.Text = ""; txtPasswordConfirm.Text = ""; } else if (!EmailValidation.IsValidEmailAddress(txtEmail.Text.ToString())) { lblEmailValidation.Visible = true; txtEmail.Text = ""; txtPassword.Text = ""; txtPasswordConfirm.Text = ""; } else { try { objReg.FirstName = txtFirstName.Text; objReg.Surname = txtSurname.Text; objReg.Mobile = txtMobile.Text; objReg.Password = txtPassword.Text; objReg.Email = txtEmail.Text; objReg.UserRole = cbUserRole.Text; objReg.images = ConvertFiltoByte(this.imgProfile.ImageLocation); context.tblRegistrations.Add(objReg); context.SaveChanges(); MessageBox.Show("New Record created", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information); lblErrorUser.Visible = false; Clear(); } catch { MessageBox.Show("User not registered please check all fields.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Clear(); } } }
private void btnDelete_Click(object sender, EventArgs e) { if (MessageBox.Show("Are you sure to delete this record ?", "EF CRUD Operation", MessageBoxButtons.YesNo) == DialogResult.Yes) { using (MacrocommEntities db = new MacrocommEntities()) { var entry = db.Entry(model); if (entry.State == EntityState.Detached) { db.tblRegistrations.Attach(model); } db.tblRegistrations.Remove(model); db.SaveChanges(); MessageBox.Show("Deleted Successfully"); this.Close(); } } }
private void btnSave_Click(object sender, EventArgs e) { //txtFirstName.Visible = false; //txtEmail.Visible = false; //txtMobile.Visible = false; //txtSurname.Visible = false; //tblroles.Visible = false; //btnUpload.Visible = false; //btnSave.Visible = false; //btnEditProfile.Visible = true; //lblFirstName.Visible = true; //lblEmail.Visible = true; //lblMobile.Visible = true; //lblrole.Visible = true; //lblSurname.Visible = true; if (txtFirstName.Text == "" || txtSurname.Text == "" || txtMobile.Text == "" || txtEmail.Text == "" || imgProfile.Image == null) { MessageBox.Show("Please enter all fields"); txtFirstName.Visible = true; txtSurname.Visible = true; txtEmail.Visible = true; txtMobile.Visible = true; tblroles.Visible = true; cmbUserRole.Visible = true; btnUpload.Visible = true; btnSave.Visible = true; btnEditProfile.Visible = false; btnCancel.Visible = false; btnDelete.Visible = false; btnCancel2.Visible = true; lblFirstName.Visible = false; lblSurname.Visible = false; lblrole.Visible = false; lblEmail.Visible = false; lblMobile.Visible = false; } else { try { //MacrocommEntities context = new MacrocommEntities(); model.FirstName = txtFirstName.Text; model.Surname = txtSurname.Text; model.Email = txtEmail.Text; model.UserRole = cmbUserRole.Text; model.Mobile = txtMobile.Text; //model.images = ConvertFiltoByte(this.imgProfile.ImageLocation); using (MacrocommEntities context = new MacrocommEntities()) { context.Entry(model).State = EntityState.Modified; context.SaveChanges(); } MessageBox.Show("Record Modified", "Confirmation"); txtFirstName.Visible = false; txtEmail.Visible = false; txtMobile.Visible = false; txtSurname.Visible = false; tblroles.Visible = false; cmbUserRole.Visible = false; btnUpload.Visible = false; btnSave.Visible = false; btnEditProfile.Visible = true; btnCancel2.Visible = true; btnDelete.Visible = false; lblFirstName.Visible = true; lblEmail.Visible = true; lblMobile.Visible = true; lblrole.Visible = true; lblSurname.Visible = true; } catch { txtFirstName.Visible = true; txtSurname.Visible = true; txtEmail.Visible = true; txtMobile.Visible = true; tblroles.Visible = true; btnUpload.Visible = true; btnSave.Visible = true; btnEditProfile.Visible = false; btnCancel.Visible = false; btnDelete.Visible = false; btnCancel2.Visible = true; lblFirstName.Visible = false; lblSurname.Visible = false; lblrole.Visible = false; lblEmail.Visible = false; lblMobile.Visible = false; MessageBox.Show("User not Updated", "Confirmation"); } } }