Esempio n. 1
0
        public TestInterfaceContainerPanel()
        {
            _currentInControlDAO = CreateAppropriateDAO();

            createControl createUpDown = new createControl((string name, int inLambdaCount) =>
            {
                NumericUpDown locUpDown = new NumericUpDown();
                locUpDown.Value         = _rnd.Next((int)locUpDown.Minimum, (int)locUpDown.Maximum);
                locUpDown.Tag           = count;
                locUpDown.Width         = 50;
                if (inLambdaCount == 0)
                {
                    locUpDown.Enabled = false;
                }
                Label propName     = new Label();
                propName.Tag       = -2;
                propName.AutoSize  = true;
                propName.Text      = name;
                propName.Location  = new Point(5, 5 + 25 * count);
                propName.Width     = propName.Text.Length * 10;
                locUpDown.Location = new Point(propName.Location.X + propName.Width + 10, 5 + 25 * count);
                count++;
                this.Controls.Add(propName);
                this.Controls.Add(locUpDown);
            });

            _typeControlPair.Add(typeof(long), createUpDown);
            _typeControlPair.Add(typeof(int), createUpDown);

            createControl createTextBox = new createControl((string name, int inLambdaCount) =>
            {
                TextBox locTextBox = new TextBox();
                locTextBox.Text    = Statics.GetUniqueKeyOriginal_BIASED(_rnd.Next(5, 10)).FirstLetterToupper();
                locTextBox.Tag     = count;
                Label propName     = new Label();
                propName.Tag       = -2;
                propName.AutoSize  = true;
                propName.Text      = name;
                if (name == "Password")
                {
                    _txtPasswprd = locTextBox;
                }
                if (name == "UserName")
                {
                    _txtUserName = locTextBox;
                }
                propName.Location   = new Point(5, 5 + 25 * count);
                propName.Width      = propName.Text.Length * 10;
                locTextBox.Location = new Point(propName.Location.X + propName.Width + 10, 5 + 25 * count);
                count++;
                this.Controls.Add(propName);
                this.Controls.Add(locTextBox);
            });

            _typeControlPair.Add(typeof(string), createTextBox);

            createControl createDateTimePicker = new createControl((string name, int inLambdaCount) =>
            {
                DateTimePicker locPicker = new DateTimePicker();
                locPicker.Tag            = count;
                locPicker.Value          = new DateTime(_rnd.Next(locPicker.MinDate.Year, locPicker.MaxDate.Year), _rnd.Next(locPicker.MinDate.Month, locPicker.MaxDate.Month), _rnd.Next(locPicker.MinDate.Day, locPicker.MaxDate.Day));
                Label propName           = new Label();
                propName.Tag             = -2;
                propName.AutoSize        = true;
                propName.Text            = name;
                propName.Location        = new Point(5, 5 + 25 * count);
                propName.Width           = propName.Text.Length * 10;
                locPicker.Location       = new Point(propName.Location.X + propName.Width + 10, 5 + 25 * count);
                count++;
                this.Controls.Add(propName);
                this.Controls.Add(locPicker);
            });

            _typeControlPair.Add(typeof(DateTime), createDateTimePicker);

            AddingToMyself();
        }
Esempio n. 2
0
        private void AddingToMyself()
        {
            int locCount = 0;

            foreach (PropertyInfo s in typeof(T).GetProperties())
            {
                _typeControlPair[s.PropertyType](s.Name, locCount);
                locCount++;
            }
            if (_currentInControlDAO is UserBaseMSSQLDAO <T> )
            {
                _typeControlPair[typeof(String)]("Password", locCount++);
                _typeControlPair[typeof(String)]("UserName", locCount++);
            }


            Button btnAddRecord = new Button();

            btnAddRecord.AutoSize = true;
            btnAddRecord.Text     = $"Add {typeof(T).Name} [Add]";
            btnAddRecord.Tag      = -2;
            btnAddRecord.Click   += (object sender, EventArgs e) =>
            {
                bool ifSucseeded = false;
                try
                {
                    if (_currentInControlDAO is UserBaseMSSQLDAO <T> )
                    {
                        (_currentInControlDAO as UserBaseMSSQLDAO <T>).Add(BuildingAPoco(), _txtUserName.Text, _txtPasswprd.Text);
                    }
                    else
                    {
                        _currentInControlDAO.Add(BuildingAPoco());
                    }

                    foreach (var s in this.Controls)
                    {
                        if (s is TextBox)
                        {
                            (s as TextBox).Text = Statics.GetUniqueKeyOriginal_BIASED(_rnd.Next(5, 10)).FirstLetterToupper();
                        }
                        if (s is NumericUpDown)
                        {
                            (s as NumericUpDown).Value = _rnd.Next((int)(s as NumericUpDown).Minimum, (int)(s as NumericUpDown).Maximum);
                        }
                        if (s is DateTimePicker)
                        {
                            (s as DateTimePicker).Value = new DateTime(_rnd.Next((s as DateTimePicker).MinDate.Year, (s as DateTimePicker).MaxDate.Year), _rnd.Next((s as DateTimePicker).MinDate.Month, (s as DateTimePicker).MaxDate.Month), _rnd.Next((s as DateTimePicker).MinDate.Day, (s as DateTimePicker).MaxDate.Day));
                        }
                    }

                    ifSucseeded = true;
                }
                catch (Exception ex)
                {
                    ifSucseeded = false;
                    MessageBox.Show($"{ex.GetType().Name}\n\n{ex.Message}\n\n{ex.StackTrace}");
                }
                string messageToUser = string.Empty;
                if (ifSucseeded)
                {
                    messageToUser = "******";
                }
                else
                {
                    messageToUser = "******";
                }
                MessageBox.Show(messageToUser);
            };
            btnAddRecord.Location = new Point(5, 5 + 25 * count);
            this.Controls.Add(btnAddRecord);

            int thisHeight = 0;

            foreach (var s in this.Controls)
            {
                if (s.GetType().Name != "Label")
                {
                    thisHeight += (int)s.GetType().GetProperty("Height").GetValue(s) + 5;
                }
            }

            this.Height = thisHeight + 10;
            this.Width  = determiningThisLength();
            this.drawBorder(1, Color.Black);
        }