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");
                }
            }
        }
Beispiel #3
0
        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");
            }
        }
Beispiel #4
0
        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
            {
            }
        }
Beispiel #5
0
        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);
                }
            }
        }