public bool Delete() { if (this._currentDONoiDungTaiLieu != null) { long ID = this._currentDONoiDungTaiLieu.ID; if (DANoiDungTaiLieu.Delete(this._dataTb, ID)) { this._currentDONoiDungTaiLieu = null; return true; } return false; } else return false; }
public static bool UpdateTEN_FILE(string TbName, DONoiDungTaiLieu doNoidungtailieu) { string strSQL = "Update "+ TbName+" set TEN_FILE = @ten_file, URL = @url Where ID=@id "; DatabaseFB db = HelpDB.getDatabase(); DbCommand cmd = db.GetSQLStringCommand(strSQL); db.AddInParameter(cmd, "@id", DbType.Int64, doNoidungtailieu.ID); db.AddInParameter(cmd, "@ten_file", DbType.String, doNoidungtailieu.TEN_FILE); db.AddInParameter(cmd, "@url", DbType.String, doNoidungtailieu.URL); if (db.ExecuteNonQuery(cmd) > 0) return true; return false; }
public static bool Update(String TbName, DONoiDungTaiLieu doNoidung) { DatabaseFB db = HelpDB.getDatabase(); DbTransaction dbTrans = db.BeginTransaction(db.OpenConnection()); DbCommand cmd = db.GetSQLStringCommand("Update " + TbName + " set NOI_DUNG = @noi_dung, TEN_FILE = @ten_file, URL = @url Where ID=@id "); db.AddInParameter(cmd, "@id", DbType.Int64, doNoidung.ID); db.AddInParameter(cmd, "@noi_dung", DbType.Binary, doNoidung.NOI_DUNG); db.AddInParameter(cmd, "@ten_file", DbType.String, doNoidung.TEN_FILE); db.AddInParameter(cmd, "@url", DbType.String, doNoidung.URL); try { int value = db.ExecuteNonQuery(cmd, dbTrans); db.CommitTransaction(dbTrans); } catch (Exception ex) { ex.StackTrace.ToString(); db.RollbackTransaction(dbTrans); return false; } finally { db.Close(); } return true; }
public static DONoiDungTaiLieu getNOI_DUNG_TAI_LIEU(string TbName, long id) { DONoiDungTaiLieu DO = new DONoiDungTaiLieu(); DataSet ds = HelpDB.getDatabase().LoadDataSet("select * from " + TbName + " where ID = " + id); if (ds.Tables.Count > 0) if (ds.Tables[0].Rows.Count > 0) { DataRow row = ds.Tables[0].Rows[0]; DO.ID = HelpNumber.ParseInt64(row["ID"]); DO.NOI_DUNG = (byte[])row["NOI_DUNG"]; DO.TEN_FILE = row["TEN_FILE"].ToString(); DO.URL = row["URL"].ToString(); return DO; } return null; }
private void btnUp_Down_Click(object sender, EventArgs e) { string path = null; OpenFileDialog openFile = new OpenFileDialog(); openFile.Title = "Chọn file để cập nhật tài liệu:"; DialogResult value = openFile.ShowDialog(); if (value == DialogResult.OK) { path = openFile.FileName; //Kiểm tra độ lớn của file if (!HelpFile.CheckFileSize(path, _maxFilesize)) { //Độ lớn của file lớn hơn độ lớn qui định HelpMsgBox.ShowNotificationMessage("Bạn không được chọn file lớn hơn " + _maxFilesize.ToString() + "MB."); path = null; btnUp_Down_Click(sender, e); } } else if(value == DialogResult.Cancel) { path = null; this._currentDONoiDungTaiLieu = null; return; } Thread.Sleep(200); if (path != null) { //Chuyển file sang byte[] byte[] bytes = HelpFile.FileToBytes(path); long ID = -1; //Nếu chưa có dữ liệu thì là thêm mới if (_gridview.GetRowCellValue(_gridview.FocusedRowHandle, _gridview.Columns[_columnField.FieldName]).ToString() == "") { ID = HelpDB.getDatabase().GetID(HelpGen.G_FW_DM_ID); _gridview.SetRowCellValue(_gridview.FocusedRowHandle, _columnField, ID); this._currentDONoiDungTaiLieu = new DONoiDungTaiLieu(ID, bytes, Path.GetFileName(path), FrameworkParams.TEMP_FOLDER + @"\" + Path.GetFileName(path)); } else { this._currentDONoiDungTaiLieu = new DONoiDungTaiLieu( HelpNumber.ParseInt64(_gridview.GetRowCellValue(_gridview.FocusedRowHandle, _columnField)), bytes, Path.GetFileName(path), FrameworkParams.TEMP_FOLDER + @"\" + Path.GetFileName(path)); } } }
public void GetCurrentDO(object sender, DONoiDungTaiLieu doNoidungtailieu) { this._currentDONoiDungTaiLieu = doNoidungtailieu; }