private void panChat_DragDrop(object sender, DragEventArgs e) { try { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { var files = (string[])e.Data.GetData(DataFormats.FileDrop); foreach (var filePath in files) { FileInfo F = new FileInfo(filePath); int isfolder = DBase.IsFolder(filePath); if (isfolder == 1) { continue; } byte[] content = new byte[3]; content = System.IO.File.ReadAllBytes(filePath); dtitem.Rows[0]["TYPE"] = F.Extension; dtitem.Rows[0]["FILENAME"] = F.Name; dtitem.Rows[0]["THUMBNAIL"] = new byte[3]; if (F.Extension.ToUpper() == ".JPG" || F.Extension.ToUpper() == ".PNG" || F.Extension.ToUpper() == ".BMP" || F.Extension.ToUpper() == ".GIF") { try { dtitem.Rows[0]["THUMBNAIL"] = DBase.ImageToByte(DBase.ResizeImage(Image.FromFile(filePath), 50, 50)); } catch (Exception ex) { continue; } } else { try { dtitem.Rows[0]["THUMBNAIL"] = DBase.ImageToByte(Icon.ExtractAssociatedIcon(filePath).ToBitmap()); } catch (Exception ex) { continue; } } dtitem.Rows[0]["TEXT"] = Text; dtitem.Rows[0]["CDATETIME"] = DHuy.GetServerTime(); dtitem.Rows[0]["FILEDATA"] = content; int kq = DHuy.INSERT_IDENTITY("CHAT", dtitem); if (kq > 0) { edtChat.Focus(); edtChat.Text = ""; RefreshChat_Append(); } } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void btnOK_Click(object sender, EventArgs e) { Text = edtChat.Text; if (Text.Replace(" ", "") == "") { return; } dtitem.Rows[0]["TEXT"] = Text; dtitem.Rows[0]["TYPE"] = ""; dtitem.Rows[0]["FILENAME"] = ""; dtitem.Rows[0]["FILEDATA"] = new byte[3]; dtitem.Rows[0]["THUMBNAIL"] = new byte[3]; dtitem.Rows[0]["CDATETIME"] = DHuy.GetServerTime(); int kq = DHuy.INSERT_IDENTITY("CHAT", dtitem); if (kq > 0) { edtChat.Focus(); edtChat.Text = ""; RefreshChat_Append(); } }