private void Add_Click(object sender, EventArgs e) { correct = true; Email_Notice_Template newTemplate = new Email_Notice_Template(); if (txtDescription.Text == "") { MessageBox.Show("Please enter a Template Description"); correct = false; } if (txtText.Text == "") { MessageBox.Show("Please enter Template Text"); correct = false; } if (correct == true) { newTemplate.Template_Description = txtDescription.Text; newTemplate.Template_Text = txtText.Text; db.Email_Notice_Template.Add(newTemplate); db.SaveChanges(); int Template_ID = newTemplate.Template_Id; string Template_Value = Convert.ToString(newTemplate); Audit_Log Current_Audit = new Audit_Log(); Current_Audit.Table_Name = "Notification Template"; Current_Audit.Active_User_ID = clsGlobals.Userlogin.Active_User_Id; Current_Audit.Date_Time = DateTime.Now; db.Audit_Log.Add(Current_Audit); db.SaveChanges(); int Log_ID = Current_Audit.Audit_Log_Id; Audit_Create_Delete Current_Create = new Audit_Create_Delete(); Current_Create.Audit_Log_Id = Log_ID; Current_Create.Created = true; Current_Create.PK_Row_Effected = Template_ID; Current_Create.Value = Template_Value; db.Audit_Create_Delete.Add(Current_Create); db.SaveChanges(); MessageBox.Show("Notification template created successfully"); this.Close(); } }
private void btnDelete_Click(object sender, EventArgs e) { DialogResult dialogResult = MessageBox.Show("Would you like to delete this Template?", "Delete Template", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { try { Email_Notice_Template template = new Email_Notice_Template(); template = db.Email_Notice_Template.Find(tempID); db.Email_Notice_Template.Remove(template); db.SaveChanges(); int Marketing_Template_ID = template.Template_Id; string Marketing_Template_Value = Convert.ToString(template); Audit_Log Current_Audit = new Audit_Log(); Current_Audit.Table_Name = "Marketing_Template"; Current_Audit.Active_User_ID = clsGlobals.Userlogin.Active_User_Id; Current_Audit.Date_Time = DateTime.Now; db.Audit_Log.Add(Current_Audit); db.SaveChanges(); int Log_ID = Current_Audit.Audit_Log_Id; Audit_Create_Delete Current_Create = new Audit_Create_Delete(); Current_Create.Audit_Log_Id = Log_ID; Current_Create.Created = false; Current_Create.PK_Row_Effected = Marketing_Template_ID; Current_Create.Value = Marketing_Template_Value; db.Audit_Create_Delete.Add(Current_Create); db.SaveChanges(); MessageBox.Show("Notification Template Successfully Deleted"); this.Close(); } catch (Exception) { MessageBox.Show("Error has occured, and template was not deleted successfully"); } } }
public ActionResult Edit([Bind(Include = "Adopter_ID,Adopter_Name,Adopter_Surname,Adopter_Email,Title_ID,Adopter_Address,Adopter_PostalAddress,Adopter_HomeNumber,Adopter_WorkNumber,Adopter_CellNumber,Adopter_CarRegistartion_Number,Adopter_Employer,Adopter_Status_ID,Amount_of_Family_Memebers,No_of_Children,Age_of_Children,Property_Securely_Closed,Properyty_Include_Pool,Pool_Secured,Animal_Shelter_Available,Sick_Animal,Sick_Animal_Diagnosis,Animal_Sleep_Location,Given_Animal_Away,HomeCheck_Suburb,Type_of_House,Adopted_Before,Complex_or_Flat,Animal_Allowed,Animal_Captivity,Animal_Vaccines_Updated, Adopter_Occupation")] Adopter adopter) { if (ModelState.IsValid) { db.Entry(adopter).State = EntityState.Modified; db.SaveChanges(); Audit_Log audit = new Audit_Log(); audit.Auditlog_DateTime = DateTime.Now; db.Audit_Log.Add(audit); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Title_ID = new SelectList(db.Titles, "Title_ID", "Title_Description", adopter.Title_ID); ViewBag.Adopter_Status_ID = new SelectList(db.Adopter_Status, "Adopter_Status_ID", "Adopter_Status_Name", adopter.Adopter_Status_ID); return(View(adopter)); }
public static void SaveAuditLog(int _userID, short _form, short _operation, DateTime _date, int PID) { try { using (var ctx = new HRMEntities()) { Audit_Log auditEntry = new Audit_Log(); auditEntry.AuditUserID = _userID; auditEntry.FormID = _form; auditEntry.OperationID = _operation; auditEntry.AuditDateTime = _date; auditEntry.IPAddress = GetIPAddress(); auditEntry.PID = PID; ctx.Audit_Log.Add(auditEntry); ctx.SaveChanges(); } } catch (Exception ex) { } }
public bool Audit(AuditLogViewModel ALViewModel) { using (CFMMCDEntities db = new CFMMCDEntities()) { Audit_Log alRow = new Audit_Log(); alRow.Id = new Random().Next(1, 999999999); // To be changed soon alRow.UserId = ALViewModel.UserId; alRow.Date_Time = DateTime.Parse(ALViewModel.Date_Time); alRow.Page = ALViewModel.Page; alRow.ItemId = ALViewModel.ItemId; alRow.Page_Action = ALViewModel.Page_Action; alRow.Name = ALViewModel.Name; try { db.Audit_Log.Add(alRow); db.SaveChanges(); return(true); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Source); System.Diagnostics.Debug.WriteLine(e.Message); System.Diagnostics.Debug.WriteLine(e.StackTrace); System.Diagnostics.Debug.WriteLine(e.InnerException); Exception f = e.InnerException; while (f != null) { System.Diagnostics.Debug.WriteLine("INNER:"); System.Diagnostics.Debug.WriteLine(f.Message); System.Diagnostics.Debug.WriteLine(f.Source); f = f.InnerException; } System.Diagnostics.Debug.WriteLine(e.Data); return(false); } } }
//Called before an action method executes. //Important: Currently it is not used void IActionFilter.OnActionExecuting(ActionExecutingContext filterContext) { string parameterInfo = string.Empty; StringBuilder CompleteParam = new StringBuilder(); ThreadPool.QueueUserWorkItem(delegate { try { //Append all the parameters to stringbuilder variable if (filterContext.ActionParameters != null) { foreach (KeyValuePair<string, object> parameter in filterContext.ActionParameters) { parameterInfo = string.Format("Parameter name: {0} – Parameter value: {1}", parameter.Key, parameter.Value == null ? "null" : parameter.Value); CompleteParam.Append(parameterInfo + Environment.NewLine); } } //Log the parameters, action, user name and current date time into Audit_Logs table Audit_Log log = new Audit_Log(); log.Event_Result = true; log.Log_Datetime = System.DateTime.Now; log.User_Action = filterContext.Controller.GetType().Name + "\\" + filterContext.ActionDescriptor.ActionName; log.User_identity = filterContext.RequestContext.HttpContext.User.Identity.Name; log.User_Parameters = CompleteParam.ToString(); DataStore.Connection.ConnectionString = ConfigurationManager.ConnectionStrings["FeedbackScriptConnectionString"].ConnectionString; DataStore.Audit_Logs.InsertOnSubmit(log); DataStore.SubmitChanges(); } catch { return; } finally { } }); }
//Called before an action method executes. //Important: Currently it is not used void IActionFilter.OnActionExecuting(ActionExecutingContext filterContext) { string parameterInfo = string.Empty; StringBuilder CompleteParam = new StringBuilder(); ThreadPool.QueueUserWorkItem(delegate { try { //Append all the parameters to stringbuilder variable if (filterContext.ActionParameters != null) { foreach (KeyValuePair <string, object> parameter in filterContext.ActionParameters) { parameterInfo = string.Format("Parameter name: {0} – Parameter value: {1}", parameter.Key, parameter.Value == null ? "null" : parameter.Value); CompleteParam.Append(parameterInfo + Environment.NewLine); } } //Log the parameters, action, user name and current date time into Audit_Logs table Audit_Log log = new Audit_Log(); log.Event_Result = true; log.Log_Datetime = System.DateTime.Now; log.User_Action = filterContext.Controller.GetType().Name + "\\" + filterContext.ActionDescriptor.ActionName; log.User_identity = filterContext.RequestContext.HttpContext.User.Identity.Name; log.User_Parameters = CompleteParam.ToString(); DataStore.Connection.ConnectionString = ConfigurationManager.ConnectionStrings["FeedbackScriptConnectionString"].ConnectionString; DataStore.Audit_Logs.InsertOnSubmit(log); DataStore.SubmitChanges(); } catch { return; } finally { } }); }
private void btnAddUser_Click(object sender, EventArgs e) { if (txtUsername.Text == "" || txtPassword.Text == "") { MessageBox.Show("Please enter all fields"); } else if (txtPassword.Text == txtConfirmPassword.Text) { try { SHA1CryptoServiceProvider sh = new SHA1CryptoServiceProvider(); UTF8Encoding utf8 = new UTF8Encoding(); string hash = BitConverter.ToString(sh.ComputeHash(utf8.GetBytes(txtConfirmPassword.Text))); SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=SP;Integrated Security=True"); SqlCommand cmd = new SqlCommand("insert into Active_User(Username,pass, Access)values(@User_Name,@Password,@access)", con); cmd.Parameters.AddWithValue("@User_Name", txtUsername.Text); cmd.Parameters.AddWithValue("@Password", hash); cmd.Parameters.AddWithValue("@access", (cbAccessLevelName.SelectedValue)); con.Open(); //var q = db.Access_L.Where(u => u.Access_Level_Name == cbAccessLevelName.Text).FirstOrDefault(); //int Aid = Convert.ToInt32(q.Access_Level_Id.ToString()); //NewUser.Access = Aid; //db.Active_User.Add(NewUser); string check = @"(Select count(*) from Active_User where Username='******')"; SqlCommand cmda = new SqlCommand(check, con); int count = (int)cmda.ExecuteScalar(); if (count > 0) { MessageBox.Show("A user with that username already exists"); } else { try { //int description = 0; //var AccessL = db.Access_L.Where(emp => emp.Access_Level_Name == cbAccessLevelName.Text).Select(u => u.Access_Level_Id).FirstOrDefault(); //description = AccessL; //NewUser.Access = AccessL; //NewAccess.Access_Level_Id = description; //NewUser.Access = NewAccess.Access_Level_Id; cmd.ExecuteNonQuery(); //db.Active_User.Add(NewUser); //int myUser = NewUser.Active_User_Id; } catch (Exception ex) { MessageBox.Show("" + ex); } Active_User newuser = new Active_User(); MessageBox.Show("User successfully registered!"); this.Hide(); this.Close(); //Audit Log int accessidz = newuser.Active_User_Id; string user_Value = Convert.ToString(newuser); Audit_Log Current_Audit6 = new Audit_Log(); Current_Audit6.Table_Name = "User"; // Current_Audit3.Users_Id = Globals.Users_Id; Current_Audit6.Date_Time = DateTime.Now; db.Audit_Log.Add(Current_Audit6); db.SaveChanges(); int Log_ID6 = Current_Audit6.Audit_Log_Id; Audit_Create_Delete Current_Create6 = new Audit_Create_Delete(); Current_Create6.Audit_Log_Id = Log_ID6; Current_Create6.Created = true; Current_Create6.PK_Row_Effected = accessidz; Current_Create6.Value = user_Value; db.Audit_Create_Delete.Add(Current_Create6); db.SaveChanges(); this.Close(); this.Hide(); } } catch (SqlException ex) { if (ex.Number == 2627) { } else { MessageBox.Show("An Error:" + ex.Message); } } } else if (txtPassword.Text != txtConfirmPassword.Text) { MessageBox.Show("Password and confirm Password fields do not match"); } }
private void btnUpdate_Click(object sender, EventArgs e) { correct = true; if (txtDescription.Text == "") { MessageBox.Show("Please enter a Template Description"); correct = false; } else if (txtText.Text == "") { MessageBox.Show("Please enter a Template Text"); correct = false; } DialogResult dialogResult = MessageBox.Show("Would you like to update this Template?", "Update Template", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { if (correct == true) { try { if (correct == true) { var query = db.Email_Notice_Template.Where(co => co.Template_Id == tempID).FirstOrDefault(); query.Template_Description = txtDescription.Text; query.Template_Text = txtText.Text; db.SaveChanges(); Audit_Log Current_Audit = new Audit_Log(); Current_Audit.Table_Name = "Notification Template"; Current_Audit.Active_User_ID = clsGlobals.Userlogin.Active_User_Id; Current_Audit.Date_Time = DateTime.Now; db.Audit_Log.Add(Current_Audit); db.SaveChanges(); int Log_ID = Current_Audit.Audit_Log_Id; if (txtText.Text != iText) { Audit_Update Update_Name1 = new Audit_Update(); Update_Name1.PK_Row_Effected = Convert.ToInt32(query.Template_Id); Update_Name1.Field_Effected = "Text"; Update_Name1.Before_Value = iText.ToString(); Update_Name1.After_Value = txtText.Text.ToString(); Update_Name1.Audit_Log_Id = Log_ID; db.Audit_Update.Add(Update_Name1); db.SaveChanges(); } if (txtDescription.Text != Desc) { Audit_Update Update_Name2 = new Audit_Update(); Update_Name2.PK_Row_Effected = Convert.ToInt32(query.Template_Id); Update_Name2.Field_Effected = "Description"; Update_Name2.Before_Value = Desc.ToString(); Update_Name2.After_Value = txtDescription.Text.ToString(); Update_Name2.Audit_Log_Id = Log_ID; db.Audit_Update.Add(Update_Name2); db.SaveChanges(); } MessageBox.Show("Marketing Template Successfully Updated"); this.Close(); } } catch (Exception ex) { MessageBox.Show("Error has occured, and template was not updated successfully" + ex); } } } }
private void btnAdd_Click(object sender, EventArgs e) { correct = true; Vehicle vehicle = new Vehicle(); try { if (ValidateIfVehicleExists(txtRegNo.Text) == true) { MessageBox.Show("Vehicles registration number already exists"); correct = false; } if (txtMake.Text == "" || txtModel.Text == "" || txtRegNo.Text == "" || txtVIN.Text == "") { MessageBox.Show("Please Enter Vehicles details"); correct = false; } if (txtRegNo.Text == "") { lblReg.Visible = true; correct = false; } if (txtModel.Text == "") { lblModel.Visible = true; correct = false; } if (txtVIN.Text == "") { lblVIN.Visible = true; correct = false; } if (txtMake.Text == "") { lblMake.Visible = true; correct = false; } if (correct == true) { vehicle.Vehicle_Make = txtMake.Text; vehicle.Vehicle_Model = txtModel.Text; vehicle.Vehicle_Registration_Number = txtRegNo.Text; Vehicle_Status st = cbxStatus.SelectedItem as Vehicle_Status; vehicle.Vehicle_Status_ID = st.Vehicle_Status_ID; vehicle.Last_Serviced = dtpLastServiced.Value; //vehicle.Vehicle_Status.Vehicle_Status_Description = "Active";// cbxStatus.Text; vehicle.VIN_Number = txtVIN.Text; db.Vehicles.Add(vehicle); string Vehicle_value = Convert.ToString(vehicle); db.SaveChanges(); MessageBox.Show("Vehicles Added Successfully"); //Audit Log int avehicle = vehicle.Vehicle_ID; string vehicle_Value = Convert.ToString(vehicle); Audit_Log Current_Audit5 = new Audit_Log(); Current_Audit5.Table_Name = "Vehicle"; // Current_Audit3.Users_Id = Globals.Users_Id; Current_Audit5.Date_Time = DateTime.Now; db.Audit_Log.Add(Current_Audit5); db.SaveChanges(); int Log_ID5 = Current_Audit5.Audit_Log_Id; Audit_Create_Delete Current_Create5 = new Audit_Create_Delete(); Current_Create5.Audit_Log_Id = Log_ID5; Current_Create5.Created = true; Current_Create5.PK_Row_Effected = avehicle; Current_Create5.Value = vehicle_Value; db.Audit_Create_Delete.Add(Current_Create5); db.SaveChanges(); this.Close(); this.Hide(); this.Close(); } } catch { } }
private void btnConfirm_Click(object sender, EventArgs e) { if (txtAccessName.Text == "") { MessageBox.Show("Please enter Access Level Name"); } else { try { if (cbxAdminScreen.Checked == true || cbxUserAccessLevelScreen.Checked == true || cbxEmployeeScreen.Checked == true || cbxSupplierOrderScreen.Checked == true || cbxPurchaseOrderScreen.Checked == true || cbxProductScreen.Checked == true || cbxClient.Checked == true || cbxReportsScreen.Checked == true || cbxSaleScreen.Checked == true || cbxVehicleScreen.Checked == true) { if (db.Access_Level.Where(al => al.Access_Level_Name == txtAccessName.Text.ToUpper()).Count() == 0) { NewRole.Admin_Role = cbxAdminScreen.Checked; NewRole.Client_Role = cbxClient.Checked; NewRole.Employee_Role = cbxEmployeeScreen.Checked; NewRole.Product_Role = cbxProductScreen.Checked; NewRole.Reports_Role = cbxReportsScreen.Checked; NewRole.Sale_Role = cbxSaleScreen.Checked; NewRole.Supplier_Order_Role = cbxSupplierOrderScreen.Checked; NewRole.Client_Order_Role = cbxPurchaseOrderScreen.Checked; NewRole.Vehicle_Role = cbxVehicleScreen.Checked; NewRole.User_And_Access_Level_Role = cbxUserAccessLevelScreen.Checked; NewRole.Website_Role = false; db.User_Role.Add(NewRole); NewAccess.Access_Level_Name = txtAccessName.Text.ToUpper(); NewAccess.Role_Id = NewRole.User_Role_Id; db.Access_Level.Add(NewAccess); db.SaveChanges(); MessageBox.Show("Access level added successfully"); //Audit Log int accessidz = NewAccess.Access_Level_Id; string access_Value = Convert.ToString(NewAccess); Audit_Log Current_Audit4 = new Audit_Log(); Current_Audit4.Table_Name = "Access Level"; // Current_Audit3.Users_Id = Globals.Users_Id; Current_Audit4.Date_Time = DateTime.Now; db.Audit_Log.Add(Current_Audit4); db.SaveChanges(); int Log_ID4 = Current_Audit4.Audit_Log_Id; Audit_Create_Delete Current_Create4 = new Audit_Create_Delete(); Current_Create4.Audit_Log_Id = Log_ID4; Current_Create4.Created = true; Current_Create4.PK_Row_Effected = accessidz; Current_Create4.Value = access_Value; db.Audit_Create_Delete.Add(Current_Create4); db.SaveChanges(); this.Close(); this.Hide(); } else { MessageBox.Show("Access level already exists"); } } else { MessageBox.Show("Please select atleast one access level"); } } catch (Exception ex) { MessageBox.Show("Whoops, An Error Occured, Please try again" + ex); } } }