コード例 #1
0
        private void them_Click(object sender, EventArgs e)
        {
            if (ho_ten.Text != "" && dia_chi.Text != "" && so_dien_thoai.Text != "" && hinh_anh.Text != "")
            {
                if (!utils.validate_PhoneNumberInput(so_dien_thoai.Text))
                {
                    MessageBox.Show("So dien thoai khong hop le!");
                    return;
                }
                GIAOVIEN gv = new GIAOVIEN();
                gv.tengv  = ho_ten.Text;
                gv.sdt    = so_dien_thoai.Text;
                gv.diachi = dia_chi.Text;
                gv.mamh   = bomon_dict[bo_mon.Items[bo_mon.SelectedIndex].ToString()];
                string sex = gioi_tinh.Items[gioi_tinh.SelectedIndex].ToString();
                if (sex == "Nam")
                {
                    gv.gt = true;
                }
                else
                {
                    gv.gt = false;
                }
                gv.ngaysinh   = ngay_sinh.Value;
                gv.ngayvaolam = ngay_vao_lam.Value;
                Image img = Image.FromFile(hinh_anh.Text);
                //convert image into linq.binary
                using (MemoryStream ms = new MemoryStream())
                {
                    img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                    var binary = new System.Data.Linq.Binary(ms.GetBuffer());
                    gv.hinhanh = binary;
                }
                gv.magv = utils.generatePrimaryKey("GV", GVtable.Rows.Count);

                // begin insert record
                frmLogin._database.GIAOVIENs.InsertOnSubmit(gv);
                try
                {
                    frmLogin._database.SubmitChanges();
                    GVtable.Rows.Add(gv.magv, gv.tengv, gv.gt, gv.ngaysinh, gv.ngayvaolam,
                                     bo_mon.Items[bo_mon.SelectedIndex].ToString(), gv.diachi, gv.sdt, img);
                }
                catch (Exception err)
                {
                    MessageBox.Show("Them du lieu loi " + err.Message);
                    Console.WriteLine(err.Message);
                }
            }
            else
            {
                //error
                MessageBox.Show("Mot so truong de trong, hay nhap vao!");
            }
        }
コード例 #2
0
 private void xoa_Click(object sender, EventArgs e)
 {
     if (selected_mgv != "" && GVtable_selected_index != -1)
     {
         var r = MessageBox.Show("Ban co muon xoa " + ho_ten.Text + " khong ?"
                                 , "Chu Y", MessageBoxButtons.YesNo);
         if (r == DialogResult.Yes)
         {
             GIAOVIEN gv = frmLogin._database.GIAOVIENs.Where(item => item.magv == selected_mgv).Single();
             frmLogin._database.GIAOVIENs.DeleteOnSubmit(gv);
             try
             {
                 frmLogin._database.SubmitChanges();
                 GVtable.Rows.RemoveAt(GVtable_selected_index);
             }
             catch (Exception err)
             {
                 MessageBox.Show("Loi Xoa : " + ho_ten.Text);
                 MessageBox.Show(err.Message);
                 Console.WriteLine(err.Message);
             }
         }
     }
 }
コード例 #3
0
 partial void UpdateGIAOVIEN(GIAOVIEN instance);
コード例 #4
0
 partial void DeleteGIAOVIEN(GIAOVIEN instance);
コード例 #5
0
 partial void InsertGIAOVIEN(GIAOVIEN instance);