public bool Them_Chu_ky(CHU_KY chu_ky) { string query = "THEM_CHU_KY"; string[] para; para = new string[8]; para[0] = "@ma_chu_ky"; para[1] = "@ma_user"; para[2] = "@thoi_gian_cap"; para[3] = "@thoi_gian_het_han"; para[4] = "@duong_dan_chu_ky"; para[5] = "@ten_chu_ky"; para[6] = "@duong_dan_anh"; para[7] = "@kieu_chu_ky"; object[] values; values = new object[8]; values[0] = chu_ky.Ma_chu_ky; values[1] = chu_ky.Ma_user; values[2] = chu_ky.Thoi_gian_cap1; values[3] = chu_ky.Thoi_gin_het_han1; values[4] = chu_ky.Duong_dan_chu_ky1; values[5] = chu_ky.Ten_chu_ky; values[6] = chu_ky.Duong_dan_anh1; values[7] = chu_ky.Kieu_chu_ky1; try { int a = connection.Excute_Sql(query, CommandType.StoredProcedure, para, values); if (a != 0) { return(true); } return(false); } catch (SqlException ex) { //DialogResult d; //d = MessageBox.Show("Thông tin thêm không hợp lệ!"); return(false); } finally { connection.close(); } }
private void bt_luu_Click(object sender, EventArgs e) { //them moi if (status == 2) { if (Kiem_tra_cac_truong() == true) { CHU_KY temp = new CHU_KY(); temp.Ma_user = ma_user; string sqlcmd = "SELECT MAX(Ma_chu_ky) FROM dbo.CHU_KY"; int ma_chu_ky = Convert.ToInt32(connection.docGiaTri(sqlcmd)) + 1; temp.Ma_chu_ky = ma_chu_ky; temp.Ten_chu_ky = tbTen_mau.Text; temp.Kieu_chu_ky1 = Kieu_chu_ky(); temp.Thoi_gian_cap1 = System.DateTime.Now; temp.Thoi_gin_het_han1 = System.DateTime.Now.AddYears(1); if (temp.Kieu_chu_ky1 == 3) { temp.Duong_dan_anh1 = ""; } else { temp.Duong_dan_anh1 = Path.GetFileName(fileName); } string fname = tbTen_mau.Text + ".jpg"; string folder = @"E:\Desktop\Thuc_tap_CNTT\Anh\" + ma_user + @"\Chu_ky"; string pathstring = Path.Combine(folder, fname); temp.Duong_dan_chu_ky1 = fname; //luu chu ky vao file image_chu_ky.Save(pathstring); bool add = CHU_KY_SQL.Them_Chu_ky(temp); if (add == true) { MessageBox.Show("Thêm thành công"); InitCbBox(); } else { MessageBox.Show("Lỗi hệ thống"); } } else { MessageBox.Show("Ban phai dien day du cac truong"); } } else //chinh sua { int ma_chu_ky = Convert.ToInt32(cbBoxTen_chu_ky.SelectedValue.ToString()); bool update = CHU_KY_SQL.Sua_Chu_ky(ma_chu_ky, tbTen_mau.Text); if (update == true) { MessageBox.Show("Sửa thành công"); InitCbBox(); } else { MessageBox.Show("Không được phép sửa"); } } }