private void btn_AddAttachment_Click(object sender, EventArgs e) { var openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog() == DialogResult.OK) { using (var fsRead = new FileStream(openFileDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { if (fsRead.CanRead) { var eqptAttachmentBll = new EqptAttachment(); var eqptAttachmentModel = new Model.EqptAttachment(); var fsSize = Convert.ToInt32(fsRead.Length); var btRead = new byte[fsSize]; fsRead.Read(btRead, 0, fsSize); fsRead.Close(); eqptAttachmentModel.Attachment = btRead; eqptAttachmentModel.LayerName = _layerInfo.LayerName; eqptAttachmentModel.Name = Path.GetFileName(openFileDialog.FileName); eqptAttachmentModel.SmId = _smId; XtraMessageBox.Show(eqptAttachmentBll.Add(eqptAttachmentModel) > 0 ? "添加成功!" : "添加失败!", "提示"); InitAttachmentGrid(); } } } }
private void btn_AddAttachment_Click(object sender, EventArgs e) { var openFileDialog = new OpenFileDialog(); if(openFileDialog.ShowDialog()==DialogResult.OK) { using (var fsRead = new FileStream(openFileDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { if (fsRead.CanRead) { var eqptAttachmentBll = new EqptAttachment(); var eqptAttachmentModel = new Model.EqptAttachment(); var fsSize = Convert.ToInt32(fsRead.Length); var btRead = new byte[fsSize]; fsRead.Read(btRead, 0, fsSize); fsRead.Close(); eqptAttachmentModel.Attachment = btRead; eqptAttachmentModel.LayerName = _layerInfo.LayerName; eqptAttachmentModel.Name = Path.GetFileName(openFileDialog.FileName); eqptAttachmentModel.SmId = _smId; XtraMessageBox.Show(eqptAttachmentBll.Add(eqptAttachmentModel) > 0 ? "添加成功!" : "添加失败!", "提示"); InitAttachmentGrid(); } } } }