Ejemplo n.º 1
0
        private void LoadDataAndBindIntoControls()
        {
            DbSQLServer dbSQLServer = new DbSQLServer(AppSetting.ConnectionString());
            DataTable   dataTabe    = dbSQLServer.GetDataList("usp_EmployeesGetEmployeesDetailsById", new DbParameter
            {
                Parameter = "@EmployeeId",
                Value     = this.EmployeeId
            });

            DataRow dtRow = dataTabe.Rows[0];

            EmployeeIDTextBox.Text           = dtRow["EmployeeId"].ToString();
            FullNameTextBox.Text             = dtRow["FullName"].ToString();
            dateTimePicker1.Value            = Convert.ToDateTime(dtRow["DateOfBirth"]);
            NICTextBox.Text                  = dtRow["NICNumber"].ToString();
            EmailTextBox.Text                = dtRow["EmailAddress"].ToString();
            TelephoneTextBox.Text            = dtRow["Telephone"].ToString();
            MobileETextBox.Text              = dtRow["Mobile"].ToString();
            dateTimePicker2.Value            = Convert.ToDateTime(dtRow["EmploymentDate"]);
            AddressLineTextBox.Text          = dtRow["AddressLine"].ToString();
            PostCodeBox.Text                 = dtRow["PostCode"].ToString();
            CurrentSalaryTextBox.Text        = dtRow["CurrentSalary"].ToString();
            StartingSalaryTextBox.Text       = dtRow["StartingSalary"].ToString();
            CommentsTextBox.Text             = dtRow["Comments"].ToString();
            pictureBox1.Image                = (dtRow["Photo"] is DBNull) ? null : ImageManipulations.PutPhoto((byte[])dtRow["Photo"]);
            CityComboBox.SelectedValue       = dtRow["CityId"];
            DistrictComboBox.SelectedValue   = dtRow["DistrictId"];
            GenderComboBox.SelectedValue     = dtRow["GenderId"];
            BranchComboBox.SelectedValue     = dtRow["BranchId"];
            JobTitleComboBox.SelectedValue   = dtRow["JobTitleId"];
            HasLeftComboBox.Text             = (Convert.ToBoolean(dtRow["HasLeft"]) == true) ? "Yes" : "No";
            ReasonLeftComboBox.SelectedValue = dtRow["ReasonLeftId"];
            DateLeftDateTimePicker.Value     = Convert.ToDateTime(dtRow["DateLeft"]);
            CommentsTextBox.Text             = dtRow["Comments"].ToString();
        }
Ejemplo n.º 2
0
 private void BtnNegative_Click(object sender, EventArgs e)
 {
     manipulated         = ImageManipulations.MakeNegative(original);
     currentManipulation = "_negative";
     pbManipulated.Image = manipulated;
     manipulationMade    = true;
 }
Ejemplo n.º 3
0
 private void BtnBlurred_Click(object sender, EventArgs e)
 {
     manipulated         = ImageManipulations.MakeBlurry(original);
     currentManipulation = "_blurry";
     pbManipulated.Image = manipulated;
     manipulationMade    = true;
 }
Ejemplo n.º 4
0
 private void BtnGray_Click(object sender, EventArgs e)
 {
     manipulated         = ImageManipulations.MakeGray(original);
     currentManipulation = "_grayscale";
     pbManipulated.Image = manipulated;
     manipulationMade    = true;
 }
Ejemplo n.º 5
0
        public void GrayscaleWorks()
        {
            Color red   = Color.FromArgb(255, 0, 0);
            Color green = Color.FromArgb(0, 255, 0);
            Color blue  = Color.FromArgb(0, 0, 255);
            Color white = Color.FromArgb(255, 255, 255);

            Color[,] originalColors =
            {
                { red,  green },
                { blue, white }
            };

            Bitmap original = CreateImage(2, 2, originalColors);
            Bitmap actual   = ImageManipulations.MakeGray(original);
            bool   isGray   = false;

            for (int y = 0; y < actual.Height; y++)
            {
                for (int x = 0; x < actual.Width; x++)
                {
                    // Om värdena för R, G och B hos en pixel har samma värde ska den anses vara grå.
                    if (actual.GetPixel(x, y).R == actual.GetPixel(x, y).G&&
                        actual.GetPixel(x, y).R == actual.GetPixel(x, y).B)
                    {
                        isGray = true;
                    }
                    else
                    {
                        Assert.Fail();
                    }
                }
            }
            Assert.IsTrue(isGray);
        }
Ejemplo n.º 6
0
        public void ExtraBlurryWorks()
        {
            Color white = Color.FromArgb(255, 255, 255);
            Color black = Color.FromArgb(0, 0, 0);

            Color[,] assignColors =
            {
                { white, white, black, white, white },
                { white, white, black, white, white },
                { white, white, black, white, white },
                { white, white, black, white, white },
                { white, white, black, white, white }
            };

            Bitmap original = CreateImage(5, 5, assignColors);
            Bitmap actual   = ImageManipulations.MakeExtraBlurry(original);

            for (int y = 0; y < actual.Height; y++)
            {
                for (int x = 0; x < actual.Width; x++)
                {
                    int colorSum = actual.GetPixel(x, y).R + actual.GetPixel(x, y).G + actual.GetPixel(x, y).B;

                    if (colorSum > 0 && colorSum < 765)
                    {
                    }
                    else
                    {
                        Assert.Fail();
                    }
                }
            }
            Assert.Pass();
        }
Ejemplo n.º 7
0
        public void BlurryWorks()
        {
            Color white = Color.FromArgb(255, 255, 255);
            Color black = Color.FromArgb(0, 0, 0);

            Color[,] assignColors =
            {
                { white, black, white },
                { white, black, white },
                { white, black, white }
            };

            Bitmap original = CreateImage(3, 3, assignColors);
            Bitmap actual   = ImageManipulations.MakeBlurry(original);

            // Om suddalgoritmen ovan har fungerat, så ska det inte finnas en enda pixel i testbilden
            // som är helt svart eller helt vit. Loopen nedan testar detta.
            for (int y = 0; y < actual.Height; y++)
            {
                for (int x = 0; x < actual.Width; x++)
                {
                    int colorSum = actual.GetPixel(x, y).R + actual.GetPixel(x, y).G + actual.GetPixel(x, y).B;

                    // En helt vit pixel är 255 * 3 = 765, medan en helt svart är 0.
                    if (colorSum == 0 || colorSum == 765)
                    {
                        Assert.Fail();
                    }
                }
            }
            Assert.Pass();
        }
Ejemplo n.º 8
0
        private Branch GetObject()
        {
            Branch branch = new Branch();

            branch.BranchId    = (this.IsUpdate) ? this.BranchId : 0;
            branch.BranchName  = BranchNameTextBox.Text;
            branch.Email       = EmailTextBox.Text;
            branch.Mobile      = MobileTextBox.Text;
            branch.Website     = WebAddressTextBox.Text;
            branch.AddressLine = AddressLineTextBox.Text;
            branch.CityId      = Convert.ToInt32(CityComboBox1.SelectedValue);
            branch.DistrictId  = Convert.ToInt32(DistrictComboBox2.SelectedValue);
            branch.PostCode    = PostCodeTextBox.Text;
            branch.BranchImage = (LogoPictureBox.Image == null) ? null : ImageManipulations.GetPhoto(LogoPictureBox);
            branch.CreatedBy   = LoggedInUser.UserName;

            return(branch);
        }
Ejemplo n.º 9
0
        private Employee GetObject()
        {
            Employee emp = new Employee();

            emp.EmployeeId   = Convert.ToInt32(EmployeeIDTextBox.Text);
            emp.FullName     = FullNameTextBox.Text;
            emp.DateOfBirth  = dateTimePicker1.Value.Date;
            emp.NICNumber    = NICTextBox.Text.Trim();
            emp.EmailAddress = EmailTextBox.Text.Trim();
            emp.Mobile       = MobileETextBox.Text.Trim();
            emp.Telephone    = TelephoneTextBox.Text.Trim();
            emp.GenderId     = (GenderComboBox.SelectedIndex == -1) ? 0 : Convert.ToInt32(GenderComboBox.SelectedValue);

            emp.BranchId = (BranchComboBox.SelectedIndex == -1) ? 0 : Convert.ToInt32(BranchComboBox.SelectedValue);

            emp.EmploymentDate = dateTimePicker2.Value.Date;

            emp.Photo = (pictureBox1.Image == null) ? null : ImageManipulations.GetPhoto(pictureBox1);

            emp.AddressLine = AddressLineTextBox.Text.Trim();

            emp.CityId = (CityComboBox.SelectedIndex == -1) ? 0 : Convert.ToInt32(CityComboBox.SelectedValue);

            emp.DistrictId = (DistrictComboBox.SelectedIndex == -1) ? 0 : Convert.ToInt32(DistrictComboBox.SelectedValue);

            emp.PostCode = PostCodeBox.Text.Trim();

            emp.JobTitleId = (JobTitleComboBox.SelectedIndex == -1) ? 0 : Convert.ToInt32(JobTitleComboBox.SelectedValue);

            emp.CurrentSalary  = Convert.ToDecimal(CurrentSalaryTextBox.Text.Trim());
            emp.StartingSalary = Convert.ToDecimal(StartingSalaryTextBox.Text.Trim());

            emp.HasLeft  = (HasLeftComboBox.Text.Trim() == "Yes") ? true : false;
            emp.DateLeft = DateLeftDateTimePicker.Value.Date;

            emp.ReasonLeftId = (ReasonLeftComboBox.SelectedIndex == -1) ? 0 : Convert.ToInt32(ReasonLeftComboBox.SelectedValue);

            emp.Comments  = CommentsTextBox.Text.Trim();
            emp.CreatedBy = LoggedInUser.UserName;

            return(emp);
        }
Ejemplo n.º 10
0
        public void NegativeWorks()
        {
            // Color.Red skapar HEX8-koden FFFF0000 medan Color.FromArgb(255, 0, 0) skapar
            // HEX-koden FF0000. I manipulationsalgoritmerna använder jag Color.FromArgb() för att
            // sätta ihop uträkningarna av R, G och B till en färg. Därför måste jag
            // skapa färgerna nedan istället för att exempelvis använda Color.Red. Annars är koderna
            // inte jämförbara.

            Color red   = Color.FromArgb(255, 0, 0);
            Color green = Color.FromArgb(0, 255, 0);
            Color blue  = Color.FromArgb(0, 0, 255);
            Color white = Color.FromArgb(255, 255, 255);

            Color cyan    = Color.FromArgb(0, 255, 255);
            Color magenta = Color.FromArgb(255, 0, 255);
            Color yellow  = Color.FromArgb(255, 255, 0);
            Color black   = Color.FromArgb(0, 0, 0);

            Color[,] originalColors =
            {
                { red,  green },
                { blue, white }
            };

            Color[,] negativeColors =
            {
                { cyan,   magenta },
                { yellow, black   }
            };

            Bitmap original = CreateImage(2, 2, originalColors);
            Bitmap expected = CreateImage(2, 2, negativeColors);
            Bitmap actual   = ImageManipulations.MakeNegative(original);

            // Bilden består av 4 pixlar vardera, så nedan kollas varenda pixel av båda bilderna.
            bool check = expected.GetPixel(0, 0).Name == actual.GetPixel(0, 0).Name&&
                         expected.GetPixel(0, 1).Name == actual.GetPixel(0, 1).Name&&
                         expected.GetPixel(1, 0).Name == actual.GetPixel(1, 0).Name&&
                         expected.GetPixel(1, 1).Name == actual.GetPixel(1, 1).Name;

            Assert.IsTrue(check);
        }
Ejemplo n.º 11
0
        private void LoadDataAndBindToControlIfUpdate()
        {
            if (this.IsUpdate)
            {
                DbSQLServer dbSQLServer = new DbSQLServer(AppSetting.ConnectionString());
                //DbParameter dbPara = new DbParameter();
                //dbPara.Parameter = "@BranchId";
                //dbPara.Value = this.BranchId;
                DataTable dtBranchTable = dbSQLServer.GetDataList("usp_BranchesGetBrancheDetailByBranchId", new DbParameter {
                    Parameter = "@BranchId", Value = this.BranchId
                });
                DataRow row = dtBranchTable.Rows[0];

                BranchNameTextBox.Text          = row["BranchName"].ToString();
                EmailTextBox.Text               = row["Email"].ToString();
                MobileTextBox.Text              = row["Mobile"].ToString();
                WebAddressTextBox.Text          = row["Website"].ToString();
                LogoPictureBox.Image            = (row["branchImage"] is DBNull)? null : ImageManipulations.PutPhoto((byte[])row["branchImage"]);
                AddressLineTextBox.Text         = row["AddressLine"].ToString();
                CityComboBox1.SelectedValue     = row["CityId"];
                DistrictComboBox2.SelectedValue = row["DistrictId"];
                PostCodeTextBox.Text            = row["PostCode"].ToString();
            }
        }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            string path = null;

            if (args.Length > 0)
            {
                path = args[0];
            }
            else
            {
                bool   retry        = false;
                string message      = "Please enter the path to your image: ";
                string retryMessage = "\nCould not find image, please try again: ";

                while (!File.Exists(path))
                {
                    Console.Write(retry ? retryMessage : message);
                    path  = Console.ReadLine();
                    retry = true;
                }
            }

            Console.WriteLine("Working...");

            Bitmap original;

            try
            {
                // Kolla om filen är en bildfil och tilldela isf den till "original"
                original = new Bitmap(path);
            }
            catch (ArgumentException)
            {
                Console.WriteLine("The file is not an acceptable format.");
                return;
            }

            if (original.Width >= 5000 || original.Height >= 5000)
            {
                Console.WriteLine("The image cannot be over 5000 pixels in height or width.");
                return;
            }

            Bitmap negative = ImageManipulations.MakeNegative(original);

            negative.Save(PathManipulations.EditFileName(path, "_negative"));
            Console.WriteLine("Negative saved");

            Bitmap gray = ImageManipulations.MakeGray(original);

            gray.Save(PathManipulations.EditFileName(path, "_grayscale"));
            Console.WriteLine("Grayscale saved");

            Bitmap blurry = ImageManipulations.MakeBlurry(original);

            blurry.Save(PathManipulations.EditFileName(path, "_blurred"));
            Console.WriteLine("The blurry image saved");

            // Om vi inte har anledning att misstänka att en server använder programmet,
            // så låt den eventuella användaren läsa eventuella meddelanden innan programmet avslutas.
            if (args.Length == 0)
            {
                Console.WriteLine("\nPress any key to exit...");
                Console.ReadKey();
            }
        }