OK









How do I use O K
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: FormXemDiem.cs Copy
85         private void btnXuatRaExcel_Click(object sender, EventArgs e)
86         {
87             try
88             {
89
90                 Excel.Application objExcelApp = new Excel.Application();
91                 Excel.Workbook objExcelWorkbook = objExcelApp.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);
92                 Excel.Worksheet objSheet = (Excel.Worksheet)objExcelWorkbook.Worksheets[1];
93                 //objSheet.Cells.Interior.Color.ToString() = 'blue';
94                 objSheet = (Excel.Worksheet)objExcelWorkbook.Sheets[1];
95                 objSheet.Cells.HorizontalAlignment = Excel.Constants.xlCenter;
96                 objSheet.Cells[2, 5] = "BẢNG ĐIỂM CỦA SINH VIÊN";
97                 objSheet.Cells[5, 3] = "Mã Học Phần";
98                 objSheet.Cells[5, 4] = "Mã Nhóm Học Phần";
99                 objSheet.Cells[5, 5] = "Tên Học Phần";
100                 objSheet.Cells[5, 6] = "Điểm Thi";
101                 objSheet.Cells[5, 7] = "Điểm Quá Trình";
102                 objSheet.Cells[5, 8] = "Điểm Xếp Loại";
103                 objSheet.Cells[3, 3] = "Mã Học Kỳ : "+cmbMaHK.SelectedValue.ToString()+"";
104                 objSheet.Cells[4, 3] = "Mã SV : " + txtMaSV.Text + "";
105                 objSheet.Cells[9,10] = "ĐIỂM TỔNG KẾT";
106                 objSheet.Cells[10,10] = "Hệ 10 : "+txtHe10.Text+"";
107                 objSheet.Cells[11,10] = "Hệ 4 : "+txtHe4.Text+"";
108                 for (int i = 0; i < dgvKetQua.Rows.Count ; i++)
109                 {
110                     for (int j = 0; j < dgvKetQua.Columns.GetColumnCount(DataGridViewElementStates.Displayed); j++)
111                     {
112                         objSheet.Cells[i + 6, j + 3] = dgvKetQua.Rows[i].Cells[j].Value.ToString();
113                         objSheet.Columns.AutoFit();
114                     }
115                 }
116                 objExcelApp.Visible = true;
117             }
118             catch (Exception ex)
119             {
120                 MessageBox.Show(ex.Message);
121             }
122         }
File name: FormXemDiemLop.cs Copy
77         private void btnXuatRaExcel_Click(object sender, EventArgs e)
78         {
79              try
80             {
81
82                 Excel.Application objExcelApp = new Excel.Application();
83                 Excel.Workbook objExcelWorkbook = objExcelApp.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);
84                 Excel.Worksheet objSheet = (Excel.Worksheet)objExcelWorkbook.Worksheets[1];
85                 //objSheet.Cells.Interior.Color.ToString() = 'blue';
86                 objSheet = (Excel.Worksheet)objExcelWorkbook.Sheets[1];
87                 objSheet.Cells.HorizontalAlignment = Excel.Constants.xlCenter;
88                 objSheet.Cells[2, 5] = "BẢNG ĐIỂM CỦA LỚP";
89                 objSheet.Cells[3, 3] = "Mã Học Kỳ : "+cmbMaHK.SelectedValue.ToString()+"";
90                 objSheet.Cells[4, 3] = "Mã Lớp : " + cmbMaLop.SelectedValue.ToString() + "";
91                 objSheet.Cells[5, 4] = "Mã Sinh Viên";
92                 objSheet.Cells[5, 5] = "Tên Sinh Viên";
93                 objSheet.Cells[5, 6] = "Điểm Trung Bình";
94                 //select sv.MaSV,TenSV,TrungBinhCuoiKyHe10
95
96                 for (int i = 0; i < dgvKetQua.Rows.Count ; i++)
97                 {
98                     for (int j = 0; j < dgvKetQua.Columns.GetColumnCount(DataGridViewElementStates.Displayed); j++)
99                     {
100                         objSheet.Cells[i + 6, j + 4] = dgvKetQua.Rows[i].Cells[j].Value.ToString();
101                         objSheet.Columns.AutoFit();
102                     }
103                 }
104                 objExcelApp.Visible = true;
105             }
106             catch (Exception ex)
107             {
108                 MessageBox.Show(ex.Message);
109             }
110         }
File name: frmDienTenTS.cs Copy
30         private void btbatdauthi_Click(object sender, EventArgs e)
31         {
32             try
33             {
34                 if (tbten.Text == "" || tbmathisinh.Text == "")
35                 {
36                     MessageBox.Show("Bạn phải điền đầy đủ thông tin");
37                 }
38                 else
39                 {
40                     string TenThSinh = tbten.Text;
41                     string MaThiSinh = tbmathisinh.Text;
42                     string strSQL = "insert THISINHTHI values('" + MaThiSinh + "','" + TenThSinh + "')";
43                     SqlCommand ObjCmd = new SqlCommand(strSQL, ObjCon);
44                     ObjCmd.ExecuteNonQuery();
45                     if (MessageBox.Show("Bạn có chắc chắn thi không ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
46                     {
47
48                         string dienten = this.tbten.Text;//chuyen thong tin sang form thithat
49                         string dienma = this.tbmathisinh.Text;
50                         frmThiThat thithat = new frmThiThat(dienten, dienma);
51                         thithat.ShowDialog();
52                         this.Close();
53
54
55                     }
56
57                 }
58             }
59             catch
60             {
61                 MessageBox.Show("Mã thí sinh trùng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
62             }
63
64     }
File name: frmKetQuathuthu.cs Copy
17         private void getdata()
18         {
19             strten = frmformthi1.ten;
20            strcapdokq = frmformthi1.strcapdo1;
21            strcauhoikq = frmformthi1.strsoluongcauhoi1;
22            diem = frmformthi1.diemkq;
23            lbdiem.Text = diem.ToString()+ " / " + strcauhoikq.ToString();
24            lbdung.Text = diem.ToString();
25            lbsai.Text = (int.Parse(strcauhoikq) - int.Parse(diem)).ToString();
26            lbhoten.Text = strten;
27             lbcapdo.Text = strcapdokq.ToString();
28             lbsl.Text = strcauhoikq.ToString();
29
30         }
File name: frmLogin.cs Copy
27         private void btThoat_Click(object sender, EventArgs e)
28         {
29             if (MessageBox.Show("Bạn có muốn thoát hay không ", "Thông Báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1) == DialogResult.OK)
30             {
31                 this.Close();
32             }
33         }
File name: frmLogin.cs Copy
66         private void btLog_Click(object sender, EventArgs e)
67         {
68             try
69             {
70                 if (txtdangnhap.Text == "" || txtmatkhau.Text == "")
71                 {
72                     MessageBox.Show("Bạn chưa điền đầy đủ thông tin", "Có lỗi xảy ra!");
73                     txtdangnhap.Focus();
74                     return;
75                 }
76                     if(txtdangnhap.Text=="admin" && txtmatkhau.Text=="admin")
77                     {
78                         if (MessageBox.Show("Chào mừng bạn đã đến với mục quản lý dành cho giáo viên", "Thông báo", MessageBoxButtons.OK) == DialogResult.OK)
79                         {
80                             this.Hide();
81                             frmQuanLy_Admin admin = new frmQuanLy_Admin();
82                             admin.ShowDialog();
83
84                         }
85
86                     }
87                 else
88                 {
89                     SqlConnection con = new SqlConnection("server=.\\SQLEXPRESS;database=QL_Thitracnghiem;integrated security=true");
90                     con.Open();
91                     SqlCommand cmd = new SqlCommand("Select MatKhau from THISINH where TenDangNhap ='" + txtdangnhap.Text + "'", con);
92                     SqlDataReader reader = cmd.ExecuteReader();
93                     reader.Read();
94                     if (txtmatkhau.Text == reader.GetValue(0).ToString())
95                     {
96                         MessageBox.Show("Bạn đã đăng nhập thành công!", "Thành công");
97                         reader.Close();
98                         con.Close();
99                         this.Close();
100                         frmLuaChon frmChon = new frmLuaChon();
101                         frmChon.ShowDialog();
102                         this.Hide();
103
104                     }
105                     else
106                     {
107                         MessageBox.Show("Sai Mật Khẩu");
108                         txtmatkhau.Focus();
109                     }
110                     reader.Close();
111                     con.Close();
112                 }
113
114             }
115
116             catch (Exception)
117             {
118
119                 MessageBox.Show("Tên đăng nhập và mật khẩu không hợp lệ","Có lỗi xảy ra");
120                 txtdangnhap.Focus();
121
122             }
123         }
File name: frmLuaChon.cs Copy
29         private void btThoat_Click(object sender, EventArgs e)
30         {
31             if (MessageBox.Show("Bạn có muốn thoát hay không","Thông Báo",MessageBoxButtons.OKCancel,MessageBoxIcon.Warning) == DialogResult.OK)
32             {
33                 this.Close();
34             }
35         }
File name: frmMain.cs Copy
41         private void button1_Click(object sender, EventArgs e)
42         {
43             if (MessageBox.Show("Bạn có chắc chắn muốn thoát ?","Thông báo",MessageBoxButtons.OKCancel,MessageBoxIcon.Question)==DialogResult.OK)
44
45             {
46                 Application.Exit();
47
48             }
49         }
File name: frmMain.cs Copy
51         private void thoátToolStripMenuItem1_Click(object sender, EventArgs e)
52         {
53             if (MessageBox.Show("Bạn có chắc chắn muốn thoát ?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
54             {
55                 Application.Exit();
56
57             }
58         }
File name: frmMain.cs Copy
113         private void thoátToolStripMenuItem2_Click_1(object sender, EventArgs e)
114         {
115             if (MessageBox.Show("Bạn có chắc chắn muốn thoát ?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
116             {
117                 Application.Exit();
118
119             }
120         }

Download file with original file name:OK

OK 134 lượt xem

Gõ tìm kiếm nhanh...