コード例 #1
0
ファイル: Form1.cs プロジェクト: sumeyyeym/personeltakip2
        public static List <Personel> Personeller = new List <Personel>(); //static olarak işaretlediğimiz için projedeki her formdan buna ulaşmak mümkün olur.

        #region Save Click
        private void btnSave_Click(object sender, EventArgs e)
        {
            Personel personel = new Personel();

            personel.Mail      = txtMail.Text;
            personel.Phone     = txtPhone.Text;
            personel.Address   = txtAddress.Text;
            personel.LastName  = txtLastName.Text;
            personel.FirstName = txtFirstName.Text;
            personel.BirthDate = dtBirthDate.Value;

            personel.Department = (Department)Enum.Parse(typeof(Department), cmbDepartment.Text);

            #region Uzun yol
            //if (rdFemale.Checked)
            //{
            //    personel.Gender = Gender.Female;
            //}
            //else if (rdMale.Checked)
            //{
            //    personel.Gender = Gender.Male;
            //}
            //else if (rdRandom.Checked)
            //{
            //    personel.Gender = Gender.Random;
            //}
            #endregion

            foreach (Control item in metroPanel1.Controls)
            {
                if (item is MetroRadioButton)//MetroRadioButton'un çalışması için yukarıya "using MetroFramework.Controls" ekle

                {
                    MetroRadioButton rd = (MetroRadioButton)item;
                    if (rd.Checked)
                    {
                        personel.Gender = (Gender)Enum.Parse(typeof(Gender), rd.Text);
                    }
                }
            }

            if (pcbImageUrl.Tag != null)
            {
                personel.ImageUrl = pcbImageUrl.Tag.ToString();
            }

            Personeller.Add(personel);
        }
コード例 #2
0
        private void pcbImageUrl_DoubleClick(object sender, EventArgs e)
        {
            OpenFileDialog opf = new OpenFileDialog();

            opf.Filter = "jpg files (*.jpg)|*jpg|png files (*.png)|*.png";
            if (opf.ShowDialog() == DialogResult.OK)
            {
                if (personel == null)
                {
                    personel = new Personel();
                }

                pcbImageUrl.Image = Image.FromFile(opf.FileName);
                personel.ImageUrl = $"{Guid.NewGuid()}.{System.IO.Path.GetExtension(opf.FileName)}";
                pcbImageUrl.Image.Save($@"{Environment.CurrentDirectory}\..\..\Images\{ personel.ImageUrl}");
                personel.HasImage = true;
            }
        }
コード例 #3
0
        private void Form3_Load(object sender, EventArgs e)
        {
            Personel personel = Context.Personels.Find(_iD);

            foreach (PropertyInfo property in personel.GetType().GetProperties())
            {
                var controls = this.Controls.Find(property.Name, true);

                if (controls[0] is Label)
                {
                    controls[0].Text = property.GetValue(personel).ToString();
                }
                else if (controls[0] is PictureBox)
                {
                    PictureBox pcb = (PictureBox)controls[0];
                    pcb.Image = Image.FromFile(Environment.CurrentDirectory + @"\..\..\Images" + property.GetValue(personel).ToString());
                }
            }
        }
コード例 #4
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (personel == null)
            {
                personel = new Personel();
            }

            if (!personel.HasImage)
            {
                MessageBox.Show(this, "Lütfen resim yükleyiniz", "Resim Yükleme Bildirimi", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            personel.Name      = txtFirstName.Text;
            personel.LastName  = txtLastName.Text;
            personel.BirthDate = dtBirthDate.Value;
            personel.Mail      = txtMail.Text;
            for (int i = 0; i < metroPanel1.Controls.Count; i++)
            {
                if (metroPanel1.Controls[i] is RadioButton)
                {
                    RadioButton rd = (RadioButton)metroPanel1.Controls[i];
                    if (rd.Checked)
                    {
                        personel.Gender = (Gender)Enum.Parse(typeof(Gender), rd.Text);
                    }
                }
            }
            personel.Address = txtAddress.Text;
            personel.Phone   = txtPhone.Text;
            personel.Department.DepartmentID = (Guid)cmbDepartment.SelectedValue;

            context.Personels.Add(personel);
            bool result = context.SaveChanges() > 0;

            personel = null;

            ClearControls(this);
            MessageBox.Show(this, result ? "Resim Eklendi":"Kayıt Başarısız Oldu", "Kayıt Ekleme Bildirimi", MessageBoxButtons.OK, result ? MessageBoxIcon.Information : MessageBoxIcon.Warning);

            MessageBox.Show(this, result ? "Kayıt Eklendi" : "Kayıt Ekleme İşlemi Başarısız", "Kayıt Ekleme İşlemi", MessageBoxButtons.OK,
                            result ? MessageBoxIcon.Information : MessageBoxIcon.Warning);
        }
コード例 #5
0
ファイル: Form4.cs プロジェクト: akifharmandar/PersonelListDB
        private void Form4_Load(object sender, EventArgs e)
        {
            cmbDepartment.DataSource    = context.Personels.ToList();
            cmbDepartment.DisplayMember = "Name";
            cmbDepartment.ValueMember   = "DepartmentID";

            personel_ = context.Personels.Find(_iD);

            txtFirstName.Text           = personel_.Name;
            txtLastName.Text            = personel_.LastName;
            dtBirthDate.Value           = personel_.BirthDate;
            txtMail.Text                = personel_.Mail;
            txtAddress.Text             = personel_.Address;
            txtPhone.Text               = personel_.Phone;
            cmbDepartment.SelectedValue = personel_.Department.DepartmentID;

            var         collection = metroPanel1.Controls.Find("rd" + personel_.Gender.ToString(), true);
            RadioButton radio      = (RadioButton)collection[0];

            radio.Checked     = true;
            pcbImageUrl.Image = Image.FromFile(Environment.CurrentDirectory + @"\..\..\Images\" + personel_.ImageUrl);
        }
コード例 #6
0
 public Form4(Personel personel) : this()
 {
     this.personel = personel;
 }