Пример #1
0
        //This function Saves a new Profile to XML file
        //Clears Persoonal detail Fields
        //Reset ID for new Profile
        private void btnCreateProfile_Click(object sender, EventArgs e)
        {
            //Save filled form as a new profile in XML file

            xmldoc = XDocument.Load(InputFileName);

            XElement newProfile = new XElement("Profile",
                                               new XAttribute("ID", txtProfileID.Text),
                                               new XAttribute("UserName", txtProfileUserName.Text),
                                               new XElement("PersonalDetails",
                                                            new XElement("FirstName", txtProfileFirstName.Text),
                                                            new XElement("LastName", txtProfileLastName.Text)),
                                               new XElement("LeftCameraParameters",
                                                            new XElement("Luminance",
                                                                         new XElement("Gain", txtProfileGainLeft.Text),
                                                                         new XElement("Brightness", txtProfileBrightnessLeft.Text),
                                                                         new XElement("Contrast", txtProfileContrastLeft.Text),
                                                                         new XElement("Exposure", txtProfileExposureLeft.Text)),
                                                            new XElement("Color",
                                                                         new XElement("Saturation", txtProfileSaturationLeft.Text),
                                                                         new XElement("WhiteBalance", txtProfileWhiteBalLeft.Text),
                                                                         new XElement("Hue", txtProfileHueLeft.Text)),
                                                            new XElement("BackgroundThreshold", txtProfileBackgroundThresholdLeft.Text)),
                                               new XElement("RightCameraParameters",
                                                            new XElement("Luminance",
                                                                         new XElement("Gain", txtProfileGainRight.Text),
                                                                         new XElement("Brightness", txtProfileBrightnessRight.Text),
                                                                         new XElement("Contrast", txtProfileContrastRight.Text),
                                                                         new XElement("Exposure", txtProfileExposureRight.Text)),
                                                            new XElement("Color",
                                                                         new XElement("Saturation", txtProfileSaturationRight.Text),
                                                                         new XElement("WhiteBalance", txtProfileWhiteBalRight.Text),
                                                                         new XElement("Hue", txtProfileHueRight.Text)),
                                                            new XElement("BackgroundThreshold", txtProfileBackgroundThresholdRight.Text)));

            xmldoc.Element("Profiles").Add(newProfile);
            xmldoc.Save(InputFileName);

            // Generate Message for successfully saving profile

            lblProfileNotFound.Text    = "Profile Saved!";
            lblProfileNotFound.Visible = true;

            // Reset Personal detail Fields

            txtProfileUserName.Text  = "";
            txtProfileFirstName.Text = "";
            txtProfileLastName.Text  = "";

            // Set a latest ID

            int MaxID = parentForm.FindMaximumProfileID(xmldoc);

            txtProfileID.Text = (MaxID + 1).ToString();
        }
Пример #2
0
        // Constructure Called when this Form is being created
        public NewOrEditProfile(Form parentCaller)
        {
            this.parentForm = parentCaller as FrmProfileHandler;
            // Obtain input profiles file name
            InputFileName = parentForm.InputFileName;
            // initialize all controls first
            InitializeComponent();

            if (parentForm.ButtonPressed == "Edit")
            {
                //UN-Hide Combo Box,delete, Update Button
                comboEditProfile.Visible    = true;
                btnAdvCameraOptions.Visible = true;
                btnDeleteProfile.Visible    = true;
                btnUpdateProfile.Visible    = true;
                lblProfileNotFound.Visible  = true;
                txtProfileUserName.ReadOnly = true;
                // Set Label accordingly
                lblCreateEdit.Text      = "Please choose a profile to edit";
                lblProfileNotFound.Text = "*Not listed? Did you create this profile first?";

                //Hide Create button
                btnCreateProfile.Visible = false;

                // Finally Populate All profiles IDs and their Names in ComboBox

                xmldoc = XDocument.Load(InputFileName);

                // Traverse through all Profile Names and fill them in a Dropdown menu
                String profName;
                int    pID = 0;
                foreach (XElement el in xmldoc.Root.Elements())
                {
                    //Profile ProfileItem = new Profile();
                    profName = el.Attribute("UserName").Value;
                    pID      = Convert.ToInt32(el.Attribute("ID").Value);
                    comboEditProfile.Items.Add(new Profiles(profName, pID));
                }
                comboEditProfile.Sorted           = true;
                comboEditProfile.AutoCompleteMode = AutoCompleteMode.Suggest;
            }
            else if (parentForm.ButtonPressed == "New")
            {
                //Hide Combo Box,delete, Update Button
                comboEditProfile.Visible    = false;
                btnAdvCameraOptions.Visible = false;
                btnDeleteProfile.Visible    = false;
                btnUpdateProfile.Visible    = false;
                lblProfileNotFound.Visible  = false;
                // Set Label accordingly
                lblCreateEdit.Text = "Please fill profile details.\nDefault camera options are already filled:";


                // Enable controls to make them editable
                txtProfileUserName.Enabled  = true;
                txtProfileUserName.ReadOnly = false;
                btnAdvCameraOptions.Enabled = true;
                btnAdvCameraOptions.Visible = true;

                // Now Load values from Default Profile into the text fields
                // Read All profiles
                // Find profile with ID=1 which is Default Profile
                xmldoc = XDocument.Load(InputFileName);

                ProfileDetails = parentForm.FindaProfile(xmldoc, 1);

                // Now ProfileDetails contains TextFields Names as Keys and their values to fill in

                //--------New Profile ID will be assigned automatically by looking at all previous IDs and find ing the latest one--------//
                int MaxID = parentForm.FindMaximumProfileID(xmldoc);
                txtProfileID.Text = (MaxID + 1).ToString();


                //-------Left Camera Options ------------//

                if (ProfileDetails.ContainsKey("GainLeft"))
                {
                    txtProfileGainLeft.Text = ProfileDetails["GainLeft"];
                }
                if (ProfileDetails.ContainsKey("BrightnessLeft"))
                {
                    txtProfileBrightnessLeft.Text = ProfileDetails["BrightnessLeft"];
                }
                if (ProfileDetails.ContainsKey("ContrastLeft"))
                {
                    txtProfileContrastLeft.Text = ProfileDetails["ContrastLeft"];
                }
                if (ProfileDetails.ContainsKey("ExposureLeft"))
                {
                    txtProfileExposureLeft.Text = ProfileDetails["ExposureLeft"];
                }
                if (ProfileDetails.ContainsKey("SaturationLeft"))
                {
                    txtProfileSaturationLeft.Text = ProfileDetails["SaturationLeft"];
                }
                if (ProfileDetails.ContainsKey("WhiteBalanceLeft"))
                {
                    txtProfileWhiteBalLeft.Text = ProfileDetails["WhiteBalanceLeft"];
                }
                if (ProfileDetails.ContainsKey("HueLeft"))
                {
                    txtProfileHueLeft.Text = ProfileDetails["HueLeft"];
                }
                if (ProfileDetails.ContainsKey("BackgroundThresholdLeft"))
                {
                    txtProfileBackgroundThresholdLeft.Text = ProfileDetails["BackgroundThresholdLeft"];
                }

                //-------Right Camera Options ------------//

                if (ProfileDetails.ContainsKey("GainRight"))
                {
                    txtProfileGainRight.Text = ProfileDetails["GainRight"];
                }
                if (ProfileDetails.ContainsKey("BrightnessRight"))
                {
                    txtProfileBrightnessRight.Text = ProfileDetails["BrightnessRight"];
                }
                if (ProfileDetails.ContainsKey("ContrastRight"))
                {
                    txtProfileContrastRight.Text = ProfileDetails["ContrastRight"];
                }
                if (ProfileDetails.ContainsKey("ExposureRight"))
                {
                    txtProfileExposureRight.Text = ProfileDetails["ExposureRight"];
                }
                if (ProfileDetails.ContainsKey("SaturationRight"))
                {
                    txtProfileSaturationRight.Text = ProfileDetails["SaturationRight"];
                }
                if (ProfileDetails.ContainsKey("WhiteBalanceRight"))
                {
                    txtProfileWhiteBalRight.Text = ProfileDetails["WhiteBalanceRight"];
                }
                if (ProfileDetails.ContainsKey("HueRight"))
                {
                    txtProfileHueRight.Text = ProfileDetails["HueRight"];
                }
                if (ProfileDetails.ContainsKey("BackgroundThresholdRight"))
                {
                    txtProfileBackgroundThresholdRight.Text = ProfileDetails["BackgroundThresholdRight"];
                }
            }
        }