Пример #1
0
        private void AProdConfirmBtn_Click(object sender, EventArgs e)
        {
            Product      InsightProduct   = new Product();
            ProductPrice InsightProdPrice = new ProductPrice();

            InsightProduct.ProductDescription = Descr;
            InsightProduct.ProductQuantity    = Quantity;

            InsightProdPrice.ProductPriceDate   = DateTime.Now;
            InsightProdPrice.ProductPriceAmount = Price;

            //Determine Decimal points for values without decimals on entry

            using (InsightEntities db = new InsightEntities())
            {
                var Ty = db.ProductTypes.SingleOrDefault(x => x.ProductTypeDescription == Type);
                InsightProduct.ProductTypeID = Ty.ProductTypeID;
                InsightProdPrice.ProductID   = InsightProduct.ProductID;
                db.ProductPrices.Add(InsightProdPrice);
                db.Products.Add(InsightProduct);
                db.SaveChanges();
                //Selecting the ID to save into the Price Table
                //var ID = db.Products.Select(x => x.ProductDescription == InsightProduct.ProductDescription);
            }

            AddProductTab.SelectedIndex = 2;
        }
        private void button162_Click(object sender, EventArgs e)
        {
            string         today = DateTime.Today.ToString("yyyy/MM/dd");
            ProjectRequest InsightProjectRequest = new ProjectRequest();
            Address        ProjectRequestAd      = new Address();

            InsightProjectRequest.ProjectRequestDescription = PRconfirmtxt.Text;
            InsightProjectRequest.ProjectRequestTypeID      = Convert.ToInt32(PRcbx.SelectedValue);
            InsightProjectRequest.ProjectRequestDate        = Convert.ToDateTime(today);

            ProjectRequestAd.CityID = Convert.ToInt32(citycbx.SelectedValue);

            string projectRequestAddress = addressline1lbl.Text + ", " + addressline2lbl.Text + ", " + addressline3lbl.Text;

            ProjectRequestAd.AddressDescription = projectRequestAddress;

            using (InsightEntities db = new InsightEntities())
            {
                db.Addresses.Add(ProjectRequestAd);
                db.SaveChanges();
            }

            int addressID = ProjectRequestAd.AddressID;

            using (InsightEntities db = new InsightEntities())
            {
                InsightProjectRequest.AddressID = addressID;
                InsightProjectRequest.ProjectRequestStatusID = 1;
                InsightProjectRequest.ClientID = 2; //temporary: needs to be replaced with logged in clientID
                db.ProjectRequests.Add(InsightProjectRequest);
                db.SaveChanges();
            }
        }
Пример #3
0
        private void ConfirmBtn_Click(object sender, EventArgs e)
        {
            Supplier      InsightSupplier = new Supplier();
            ContactPerson InsightCP       = new ContactPerson();
            Address       InsightAddress  = new Address();



            InsightSupplier.SupplierName      = SupName;
            InsightAddress.AddressDescription = AddL1 + " " + AddL2 + " " + AddL3;
            //InsightAddress.City = City;
            //InsightAddress.County = Country;
            InsightCP.ContactPersonName           = CPName;
            InsightCP.ContactPersonPhoneNumber    = Convert.ToInt32(CPNumber);
            InsightCP.ContactPersonJobDescription = JobD;
            InsightCP.ContactPersonEmailAddress   = CPEmail;

            InsightCP.SupplierID      = InsightSupplier.SupplierID;
            InsightSupplier.AddressID = InsightAddress.AddressID;

            using (InsightEntities db = new InsightEntities())
            {
                db.Suppliers.Add(InsightSupplier);
                db.ContactPersons.Add(InsightCP);
                db.Addresses.Add(InsightAddress);
                db.SaveChanges();
            }
        }
Пример #4
0
        private void RemoveBtn_Click(object sender, EventArgs e)
        {
            Vehicle InsightVehicle = new Vehicle();

            using (InsightEntities db = new InsightEntities())
            {
                var V = db.Vehicles.SingleOrDefault(x => x.VehicleID == VID);
                db.Vehicles.Remove(V);
                db.SaveChanges();
            }
        }
Пример #5
0
        private void USConfirmBtn_Click(object sender, EventArgs e)
        {
            Skill InsightSkill = new Skill();

            InsightSkill.SkillID          = SkillID;
            InsightSkill.SkillDescription = USkill;

            using (InsightEntities db = new InsightEntities())
            {
            }
        }
Пример #6
0
        private void AJTConfirmBtn_Click(object sender, EventArgs e)
        {
            JobType InsightJobType = new JobType();

            InsightJobType.JobTypeDescription = JT;

            using (InsightEntities db = new InsightEntities())
            {
                db.JobTypes.Add(InsightJobType);
                db.SaveChanges();
            }
        }
        private void DETDeleteBtn_Click(object sender, EventArgs e)
        {
            using (InsightEntities db = new InsightEntities())
            {
                var EmpType = db.EmployeeTypes.SingleOrDefault(x => x.EmployeeTypeID == 5);

                if (EmpType != null)
                {
                    db.EmployeeTypes.Remove(EmpType);
                    db.SaveChanges();
                }
            }
        }
Пример #8
0
        private void ASConfirmBtn_Click(object sender, EventArgs e)
        {
            Skill InsightSkill = new Skill();

            InsightSkill.SkillDescription = Skill;

            using (InsightEntities db = new InsightEntities())
            {
                db.Skills.Add(InsightSkill);
                db.SaveChanges();
            }
            AddSkillTab.SelectedIndex = 2;
        }
Пример #9
0
        private void AVTConfirmBtn_Click(object sender, EventArgs e)
        {
            VehicleType InsightVehicleType = new VehicleType();

            InsightVehicleType.VehicleTypeDescription = VehicleType;

            using (InsightEntities db = new InsightEntities())
            {
                db.VehicleTypes.Add(InsightVehicleType);
                db.SaveChanges();
                AddVehicleTypeTab.SelectedIndex = 2;
            }
        }
Пример #10
0
        private void DVTConfirmBtn_Click(object sender, EventArgs e)
        {
            using (InsightEntities db = new InsightEntities())
            {
                var VType = db.VehicleTypes.SingleOrDefault(x => x.VehicleTypeID == 2);

                if (VType != null)
                {
                    db.VehicleTypes.Remove(VType);
                    db.SaveChanges();
                }
            }
        }
Пример #11
0
 private void DEqBtn_Click(object sender, EventArgs e)
 {
     //Are we going to delete a certain quantity of of equipment or all of them?
     using (InsightEntities db = new InsightEntities())
     {
         var Eq = db.Equipments.SingleOrDefault(x => x.EquipmentID == 2);
         if (Eq != null)
         {
             db.Equipments.Remove(Eq);
             db.SaveChanges();
         }
     }
 }
Пример #12
0
        private void AOTConfirmBtn_Click(object sender, EventArgs e)
        {
            OrganisationType InsightOrgType = new OrganisationType();

            InsightOrgType.OrganisationTypeDescription = OrgType;

            using (InsightEntities db = new InsightEntities())
            {
                db.OrganisationTypes.Add(InsightOrgType);
                db.SaveChanges();
                AddOrganisationTypeTab.SelectedIndex = 2;
            }
        }
Пример #13
0
        private void AProdTConfirmBtn_Click(object sender, EventArgs e)
        {
            ProductType InsightProdType = new ProductType();

            InsightProdType.ProductTypeDescription = ProdType;

            using (InsightEntities db = new InsightEntities())
            {
                db.ProductTypes.Add(InsightProdType);
                db.SaveChanges();
            }
            AddProductTypeTab.SelectedIndex = 2;
        }
Пример #14
0
        private void DProdTDeleteBtn_Click(object sender, EventArgs e)
        {
            using (InsightEntities db = new InsightEntities())
            {
                var ProdType = db.ProductTypes.SingleOrDefault(x => x.ProductTypeID == 2);

                if (ProdType != null)
                {
                    db.ProductTypes.Remove(ProdType);
                    db.SaveChanges();
                }
            }
        }
Пример #15
0
        private void AETConfirmBtn_Click(object sender, EventArgs e)
        {
            EmployeeType InsightEmployeeType = new EmployeeType();

            InsightEmployeeType.EmployeeTypeDescription = EType;

            using (InsightEntities db = new InsightEntities())
            {
                db.EmployeeTypes.Add(InsightEmployeeType);
                db.SaveChanges();
                AddEmployeeTypeTab.SelectedIndex = 2;
            }
        }
        private void UVSConfirmBtn_Click(object sender, EventArgs e)
        {
            Vehicle InsightVehicle = new Vehicle();

            InsightVehicle.VehicleStatusID = VStatusCmb.SelectedIndex + 1;

            using (InsightEntities db = new InsightEntities())
            {
                var curVehicle = db.Vehicles.SingleOrDefault(x => x.VehicleID == 3);
                curVehicle.VehicleStatusID = InsightVehicle.VehicleStatusID;
                db.SaveChanges();
            }
            UpdateVehicleStatusTab.SelectedIndex = 2;
        }
Пример #17
0
        private void AEqTConfirmBtn_Click(object sender, EventArgs e)
        {
            EquipmentType InsightEquipType = new EquipmentType();

            InsightEquipType.EquipmentTypeDescription = EquipType;

            using (InsightEntities db = new InsightEntities())
            {
                db.EquipmentTypes.Add(InsightEquipType);
                db.SaveChanges();
            }

            AddEquipmentTypeTab.SelectedIndex = 2;
        }
Пример #18
0
        private void DEmpDeleteBtn_Click(object sender, EventArgs e)
        {
            //Add deletion of Login and Address as well as getting ID Value from view form
            //Bind all labels to the ID

            using (InsightEntities db = new InsightEntities())
            {
                var Emp = db.Employees.SingleOrDefault(x => x.EmployeeID == 2);

                if (Emp != null)
                {
                    db.Employees.Remove(Emp);
                    db.SaveChanges();
                }
            }
        }
Пример #19
0
        private void AEqConfirmBtn_Click(object sender, EventArgs e)
        {
            Equipment InsightEquipment = new Equipment();

            InsightEquipment.EquipmentDescription = EqDescr;
            InsightEquipment.EquipmentQuantity    = EqQuantity;

            using (InsightEntities db = new InsightEntities())
            {
                var Ty = db.EquipmentTypes.SingleOrDefault(x => x.EquipmentTypeDescription == EqType);
                InsightEquipment.EquipmentTypeID = Ty.EquipmentTypeID;
                db.Equipments.Add(InsightEquipment);
                db.SaveChanges();
            }

            AddEquipmentTab.SelectedIndex = 2;
        }
        private void DOTDeleteBtn_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Are you sure you want to delete this Organisation Type?");
            //OrganisationType InsightOrgType = new OrganisationType();


            using (InsightEntities db = new InsightEntities())
            {
                var OType = db.OrganisationTypes.SingleOrDefault(x => x.OrganisationTypeID == 2);
                //replace number with ID from the View OType Screen.
                if (OType != null)
                {
                    db.OrganisationTypes.Remove(OType);
                    db.SaveChanges();
                }
            }
        }
Пример #21
0
        private void button8_Click(object sender, EventArgs e)
        {
            Job InsightJob = new Job();

            InsightJob.JobDescription = JobDescr;
            InsightJob.JobStartDate   = StartD;
            InsightJob.JobEndDate     = EndD;

            using (InsightEntities db = new InsightEntities())
            {
                var Ty = db.JobTypes.SingleOrDefault(x => x.JobTypeDescription == JobType);
                var St = db.JobStatus.SingleOrDefault(x => x.JobStatusDescription == Stat);
                InsightJob.JobTypeID   = Ty.JobTypeID;
                InsightJob.JobStatusID = St.JobStatusID;
                db.Jobs.Add(InsightJob);
            }

            this.Close();
        }
        private void button8_Click(object sender, EventArgs e)
        {
            ProjectPhase InsightProPhase = new ProjectPhase();

            InsightProPhase.ProjectPhaseDescription = PhaseDescr;
            InsightProPhase.ProjectPhaseEndDate     = PhaseEDate;
            InsightProPhase.ProjectPhaseStartDate   = PhaseSDate;
            InsightProPhase.ProjectID = ProjID;

            using (InsightEntities db = new InsightEntities())
            {
                var Ty   = db.ProjectPhaseTypes.SingleOrDefault(x => x.ProjectPhaseTypeDescription == PhaseTy);
                var Stat = db.ProjectPhaseStatus.SingleOrDefault(x => x.ProjectPhaseStatusDescription == PhaseStat);
                InsightProPhase.ProjectPhaseTypeID   = Ty.ProjectPhaseTypeID;
                InsightProPhase.ProjectPhaseStatusID = Stat.ProjectPhaseStatusID;
                db.ProjectPhases.Add(InsightProPhase);
                db.SaveChanges();
            }
            this.Close();
        }
Пример #23
0
        private void AVConfirmBtn_Click(object sender, EventArgs e)
        {
            //VehicleType vehicleType = new VehicleType();
            Vehicle InsightVehicle = new Vehicle();

            InsightVehicle.VehicleRegistration = Reg;
            InsightVehicle.VehicleMake         = Make;
            InsightVehicle.VehicleModel        = Model;
            //InsightVehicle.VehicleYear = Convert.ToDateTime(Year);
            InsightVehicle.VehicleStatusID = 1;
            InsightVehicle.VehicleYear     = DateTime.Now;
            InsightVehicle.PurchaseDate    = Convert.ToDateTime(PDate);

            using (InsightEntities db = new InsightEntities())
            {
                InsightVehicle.VehicleType = db.VehicleTypes.SingleOrDefault(x => x.VehicleTypeDescription == Type);
                db.Vehicles.Add(InsightVehicle);
                db.SaveChanges();
                AddVehicleTab.SelectedIndex = 2;
            }
        }
Пример #24
0
        private void button19_Click(object sender, EventArgs e)
        {
            Globals       myglobalclass = new Globals();
            SqlConnection conn          = new SqlConnection(myglobalclass.myConn);
            SqlDataReader myReader;

            #region Check if user exists
            bool       duplicate = false;
            int        num       = 2;
            SqlCommand checkUser;
            String     username = Char.ToUpper(EmployeeNamelbl.Text[0]) + "." + EmployeeSurnamelbl.Text;
            while (duplicate)
            {
                try
                {
                    checkUser = new SqlCommand("SELECT EmployeeUsername FROM EmployeeLogin WHERE EmployeeUsername ="******"'" + username + "'", conn);
                    conn.Open();
                    myReader = checkUser.ExecuteReader();

                    if (myReader.HasRows)
                    {
                        duplicate = true;
                        //If duplicate, add identifier to name
                        username = Char.ToUpper(EmployeeNamelbl.Text[0]) + "." + EmployeeSurnamelbl.Text + num.ToString();
                        num++;
                    }
                    else
                    {
                        duplicate = false;
                    }
                    myReader.Close();
                    conn.Close();
                }
                catch (Exception myEx)
                {
                    MessageBox.Show("Error: " + myEx.Message);
                }
            }
            #endregion

            #region Adding employee details into database
            string employeeAddress = EmployeeAd1lbl.Text + "," + EmployeeAd2lbl.Text + "," + EmployeeAd3lbl.Text;

            Employee      InsightEmployee      = new Employee();
            Address       InsightAddress       = new Address();
            EmployeeLogin InsightEmployeeLogin = new EmployeeLogin();
            //dataGridView1.DataSource= InsightEmployee.Skills.ToList();

            //Using Employee Table
            InsightEmployee.EmployeeName         = EmployeeNamelbl.Text;
            InsightEmployee.EmployeeSurname      = EmployeeSurnamelbl.Text;
            InsightEmployee.EmployeeDateOfBirth  = EmployeeDOB.Value.Date;
            InsightEmployee.EmployeeEmailAddress = EmployeeEmaillbl.Text;
            //InsightEmployee.EmployeeNumber = Convert.ToInt32(EmployeeNumberlbl.Text);
            InsightEmployee.EmployeeGender = EmployeeGenderCbx.Text;
            InsightEmployee.EmployeeTypeID = Convert.ToInt32(EmployeeTypeCbx.SelectedValue);

            //Using Address Table
            InsightAddress.AddressDescription     = employeeAddress;
            InsightAddress.CityID                 = Convert.ToInt32(EmployeeCity.SelectedValue);
            InsightEmployeeLogin.EmployeeUsername = username;
            #endregion

            #region Hashing and storing the password
            string pass = username + "#123";

            //Generate hash
            HashAlgorithm hashFunc = SHA256.Create();
            byte[]        hold     = hashFunc.ComputeHash(Encoding.UTF8.GetBytes(pass));

            //Get hash string
            StringBuilder hashString = new StringBuilder();
            foreach (byte b in hold)
            {
                hashString.Append(b.ToString("X2"));
            }
            //Store hash string in database
            InsightEmployeeLogin.EmployeePassword = hashString.ToString();
            InsightEmployeeLogin.AccessLevelID    = 3;
            #endregion

            using (InsightEntities db = new InsightEntities())
            {
                db.Addresses.Add(InsightAddress);
                db.SaveChanges();
            }

            using (InsightEntities db = new InsightEntities())
            {
                db.EmployeeLogins.Add(InsightEmployeeLogin);
                db.SaveChanges();
            }

            //new primary keys
            int addressID       = InsightAddress.AddressID;
            int employeeLoginID = InsightEmployeeLogin.EmployeeLoginID;
            int employeeID      = InsightEmployee.EmployeeID;

            //Table carrying all foreign keys at the bottom
            using (InsightEntities db = new InsightEntities())
            {
                InsightEmployee.AddressID       = addressID;
                InsightEmployee.EmployeeLoginID = employeeLoginID;
                db.Employees.Add(InsightEmployee);
                db.SaveChanges();
            }

            //Entity Framework not putting assossiatives as classes

            var addedskill = AddedSkillList.Items.Cast <String>().ToList();

            SqlCommand insertEmployeeSkill;
            SqlCommand getSkillID;
            int        skillID = 0; //default
                                    //Insert skills into db
            foreach (string skillDesc in addedskill)
            {
                //  DataSet ds = new DataSet();
                #region Retrieve skill id for specific skill description
                try
                {
                    insertEmployeeSkill = new SqlCommand("Insert into EmployeeSkill(EmployeeID, SkillID) Values(@EmployeeID, @SkillID)", conn);
                    insertEmployeeSkill.Parameters.AddWithValue("@EmployeeID", employeeID);
                    getSkillID = new SqlCommand("SELECT SkillID FROM Skill WHERE SkillDescription =" + "'" + skillDesc + "'", conn);
                    conn.Open();
                    myReader = getSkillID.ExecuteReader();

                    //Getting skillId from database
                    while (myReader.Read())
                    {
                        skillID = Convert.ToInt32(myReader["SkillID"]);
                    }
                    myReader.Close();
                    #region Insert skill id with employeeId into EmployeeSkill
                    insertEmployeeSkill.Parameters.AddWithValue("@SkillID", skillID);
                    insertEmployeeSkill.ExecuteNonQuery();
                    #endregion
                    conn.Close();
                }
                catch (Exception myEx)
                {
                    MessageBox.Show("Error: " + myEx.Message);
                }
                #endregion
            }
        }
Пример #25
0
        private void button13_Click(object sender, EventArgs e)
        {
            string clientAddress = addressline1.Text + ", " + addressline2.Text + ", " + addressline3.Text;

            Client      InsightClient        = new Client();
            Individual  InsightIndividual    = new Individual();
            Address     InsightClientAddress = new Address();
            ClientLogin InsightClientLogin   = new ClientLogin();

            //Client Table
            InsightClient.ClientName   = clientNametxt.Text;
            InsightClient.ClientNumber = Convert.ToInt32(clientNumbertxt.Text);

            //Address Table
            InsightClientAddress.AddressDescription = clientAddress;
            InsightClientAddress.CityID             = Convert.ToInt32(citycbx.SelectedValue);

            #region store client and address info

            using (InsightEntities db = new InsightEntities())
            {
                db.Addresses.Add(InsightClientAddress);
                db.SaveChanges();
            }

            int clientTypeID = Convert.ToInt32(clientcbx.SelectedValue);
            int addressID    = InsightClientAddress.AddressID;

            using (InsightEntities db = new InsightEntities())
            {
                db.Clients.Add(InsightClient);
                InsightClient.ClientTypeID = clientTypeID;
                InsightClient.AddressID    = addressID;
                db.SaveChanges();
            }

            #endregion
            int clientID = InsightClient.ClientID;

            #region Individual
            if (clientcbx.Text == "Individual")
            {
                SqlConnection Myconn = new SqlConnection(globalClass.myConn);
                Myconn.Open();

                SqlCommand insertIndividual = new SqlCommand("Insert Into Individual(ClientID, IndividualEmailAddress, IndividualDateOfBirth) Values (@ClientID, @IndividualEmailAddress, @IndividualDateOfBirth)", Myconn);
                insertIndividual.Parameters.AddWithValue("@ClientID", clientID);
                insertIndividual.Parameters.AddWithValue("@IndividualEmailAddress", contactEmail.Text);
                insertIndividual.Parameters.AddWithValue("@IndividualDateOfBirth", clientDOB.Value.Date);
                insertIndividual.ExecuteNonQuery();
                Myconn.Close();
            }
            #endregion
            #region Organisation
            if (clientcbx.Text == "Organisation")
            {
                ContactPerson organisationContact = new ContactPerson();
                SqlConnection Myconn = new SqlConnection(globalClass.myConn);
                Myconn.Open();

                SqlCommand insertOrganisation = new SqlCommand("Insert into Organisation(ClientID, OrganisationTypeID) Values (@ClientID, @OrganisationTypeID)", Myconn);
                insertOrganisation.Parameters.AddWithValue("@ClientID", clientID);
                insertOrganisation.Parameters.AddWithValue("@OrganisationTypeID", organisationTypecbx.SelectedValue);
                insertOrganisation.ExecuteNonQuery();
                Myconn.Close();

                organisationContact.ContactPersonEmailAddress   = contactEmail.Text;
                organisationContact.ContactPersonJobDescription = contactJobtxt.Text;
                organisationContact.ContactPersonName           = contactNametxt.Text;
                organisationContact.ContactPersonPhoneNumber    = Convert.ToInt32(contactNumbertxt.Text);
                organisationContact.ClientID = clientID;

                using (InsightEntities db = new InsightEntities())
                {
                    db.ContactPersons.Add(organisationContact);
                    db.SaveChanges();
                }
            }
            #endregion

            string username = Char.ToUpper(clientcbx.Text[0]) + "." + clientNamelbl.Text;

            #region generate username and password

            SqlConnection conn = new SqlConnection(globalClass.myConn);
            SqlDataReader myReader;
            int           usernumber = 1;
            int           tmp        = 0;

            try
            {
                while (tmp == 0)
                {
                    SqlCommand checkUser = new SqlCommand("Select ClientUsername From ClientLogin Where ClientUsername ="******"'" + username + "'", conn);
                    conn.Open();
                    myReader = checkUser.ExecuteReader();

                    if (myReader.HasRows)
                    {
                        username = username + Convert.ToString(usernumber);
                        usernumber++;
                    }
                    else
                    {
                        myReader.Close();
                        conn.Close();
                        tmp = 1;
                    }
                }
            }
            catch (Exception error)
            {
                MessageBox.Show("Error: " + error.Message);
            }

            string pass = username + "#123";

            //Generate hash
            HashAlgorithm hashFunc = SHA256.Create();
            byte[]        hold     = hashFunc.ComputeHash(Encoding.UTF8.GetBytes(pass));

            StringBuilder hashString = new StringBuilder();
            foreach (byte b in hold)
            {
                hashString.Append(b.ToString("X2"));
            }
            //Store hash string in database
            InsightClientLogin.ClientPassword = hashString.ToString();
            InsightClientLogin.AccessLevelID  = 2;
            #endregion

            using (InsightEntities db = new InsightEntities())
            {
                db.ClientLogins.Add(InsightClientLogin);
                db.SaveChanges();
            }

            //email feature
            MessageBox.Show("Successful, Username: "******" Password: " + pass);
        }