예제 #1
0
        private void Button2_Click(object sender, EventArgs e)
        {
            em.employee_picture = ImageToByteArray(pictureBox1.Image);
            bindingSource1.EndEdit();

            int save = context.SaveChanges();
            if (save > 0)
            {
                MessageBox.Show("แก้ไขข้อมูลเรียบร้อยแล้ว");
                emForm.updateDataSource();
                this.Close();
            }
        }
예제 #2
0
        private void Button2_Click(object sender, EventArgs e)
        {
            try
            {
                var result = context.Employees
                             .Where(m => m.employee_user == textBox5.Text).First();


                MessageBox.Show("username นี้ถูกใช้ไปแล้ว!!!");
            }
            catch
            {
                var result = context.Employees
                             .OrderByDescending(m => m.employee_ID).First();
                int      emId    = int.Parse(result.employee_ID);
                int      newId   = emId + 1;
                string   newEmId = "";
                Employee newEm   = new Employee();
                if (newId < 10)
                {
                    newEmId = string.Format("00{0}", newId);
                }
                else if (newId < 100)
                {
                    newEmId = string.Format("0{00}", newId);
                }
                else
                {
                    newEmId = string.Format("{000}", newId);
                }
                newEm.employee_ID      = newEmId.ToString();
                newEm.employee_name    = textBox1.Text;
                newEm.employee_addr    = textBox2.Text;
                newEm.employee_tel     = textBox3.Text;
                newEm.employee_salary  = float.Parse(textBox4.Text, CultureInfo.InvariantCulture.NumberFormat);
                newEm.employee_picture = ImageToByteArray(pictureBox1.Image);
                newEm.employee_date    = DateTime.Now.Date;
                if (radioButton1.Checked)
                {
                    newEm.employee_position = "เจ้าของร้าน";
                }
                else if (radioButton2.Checked)
                {
                    newEm.employee_position = "พนักงานขายหน้าร้าน";
                }
                else if (radioButton3.Checked)
                {
                    newEm.employee_position = "พนักงานคลังสินค้า";
                }
                newEm.employee_user   = textBox5.Text;
                newEm.employee_pass   = textBox6.Text;
                newEm.employee_status = 1;
                context.Employees.Add(newEm);

                int add = context.SaveChanges();
                if (add > 0)
                {
                    MessageBox.Show("เพิ่มพนักงานเรียบร้อย");
                    em.updateDataSource();
                    this.Close();
                }
            }
        }