public static string SaveStuffFile(TaskStuff taskStuff)
        {
            string filePath = System.IO.Path.Combine(basePath, string.Format("{0}.{1}", taskStuff.Key, ((AT_BC.Data.IFileDescription)taskStuff).Extension));

            if (!System.IO.File.Exists(filePath))
            {
                if (!taskStuff.IsLoaded)
                {
                    PT_BS_Service.Client.Framework.BeOperationInvoker.Invoke <I_CO_IA.MonitorTask.I_CO_IA_MonitorTask>(channel =>
                    {
                        var result = channel.GetTaskStuffByGuid(taskStuff.Key);
                        if (result.Content != null && result.Content.Length > 0)
                        {
                            taskStuff.Content = result.Content;
                        }
                    });
                }
                using (var fs = System.IO.File.Create(filePath))
                {
                    fs.Write(taskStuff.Content, 0, taskStuff.Content.Length);
                    //fs.Close();
                }
            }
            return(filePath);
        }
Exemplo n.º 2
0
        private void buttonTaskStuffAdd_Click(object sender, RoutedEventArgs e)
        {
            var task = this.DataContext as CO_IA.Data.Task;

            if (task != null)
            {
                string         taskGuid = task.Key;
                byte[]         bytes    = null;
                OpenFileDialog dialog   = new OpenFileDialog();
                if (dialog.ShowDialog() == true)
                {
                    Stream fs = null;
                    try
                    {
                        fs    = dialog.OpenFile();
                        bytes = new byte[fs.Length];
                        fs.Read(bytes, 0, bytes.Length);
                    }
                    catch
                    {
                        throw;
                    }
                    finally
                    {
                        if (fs != null)
                        {
                            fs.Close();
                        }
                    }
                    if (bytes != null)
                    {
                        TaskStuff taskStuff = new TaskStuff();
                        taskStuff.Key           = Utility.NewGuid();
                        taskStuff.IsResultStuff = false;
                        taskStuff.IsLoaded      = true;
                        taskStuff.Content       = bytes;
                        taskStuff.ContentLength = bytes.Length;
                        taskStuff.Name          = dialog.SafeFileName;
                        taskStuff.OwnerGuid     = null;
                        taskStuff.TaskGuid      = task.Key;
                        taskStuff.SubmitUser    = RiasPortal.Current.UserSetting.UserName;
                        taskStuff.SubmitTime    = DateTime.Now;
                        PT_BS_Service.Client.Framework.BeOperationInvoker.Invoke <I_CO_IA.MonitorTask.I_CO_IA_MonitorTask>(channel =>
                        {
                            channel.SaveTaskStuff(taskStuff);
                        });
                        (this.listBoxTaskStuff.ItemsSource as ObservableCollection <TaskStuff>).Add(taskStuff);
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void buttonTaskStuffDownload_Click(object sender, RoutedEventArgs e)
        {
            var hyperlink = sender as Hyperlink;

            if (hyperlink != null)
            {
                TaskStuff      taskStuff = hyperlink.DataContext as TaskStuff;
                SaveFileDialog dialog    = new SaveFileDialog();
                dialog.FileName   = taskStuff.Name;
                dialog.DefaultExt = System.IO.Path.GetExtension(taskStuff.Name);
                dialog.Filter     = string.Format("*.{0}|*.{0}", dialog.DefaultExt);
                if (dialog.ShowDialog() == true)
                {
                    Stream fs = null;
                    try
                    {
                        fs = dialog.OpenFile();
                        if (taskStuff.IsLoaded)
                        {
                            fs.Write(taskStuff.Content, 0, taskStuff.Content.Length);
                        }
                        else
                        {
                            PT_BS_Service.Client.Framework.BeOperationInvoker.Invoke <I_CO_IA.MonitorTask.I_CO_IA_MonitorTask>(channel =>
                            {
                                var result = channel.GetTaskStuffByGuid(taskStuff.Key);
                                if (result.Content != null && result.Content.Length > 0)
                                {
                                    taskStuff.Content  = result.Content;
                                    taskStuff.IsLoaded = true;
                                    fs.Write(result.Content, 0, result.Content.Length);
                                }
                            });
                        }
                    }
                    catch
                    {
                        throw;
                    }
                    finally
                    {
                        if (fs != null)
                        {
                            fs.Close();
                        }
                    }
                }
            }
        }
        public static string GetDisplayFile(TaskStuff taskStuff)
        {
            string filePath = SaveStuffFile(taskStuff);

            if (!OfficeConverter.IsValidOfficeFile(filePath))
            {
                return(filePath);
            }
            else
            {
                string xpsFilePath = System.IO.Path.Combine(basePath, string.Format("{0}.xps", taskStuff.Key));
                OfficeConverter.ConvertToXps(filePath, xpsFilePath);
                return(xpsFilePath);
            }
        }
Exemplo n.º 5
0
        private void buttonTaskStuffDelete_Click(object sender, RoutedEventArgs e)
        {
            var hyperlink = sender as Hyperlink;

            if (hyperlink != null)
            {
                TaskStuff taskStuff = hyperlink.DataContext as TaskStuff;
                if (taskStuff != null)
                {
                    if (MessageBox.Show("确实要删除选中的资料吗?", "删除提示", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                    {
                        PT_BS_Service.Client.Framework.BeOperationInvoker.Invoke <I_CO_IA.MonitorTask.I_CO_IA_MonitorTask>(channel =>
                        {
                            channel.DeleteTaskStuff(taskStuff.Key);
                        });
                        (this.listBoxTaskStuff.ItemsSource as ObservableCollection <TaskStuff>).Remove(taskStuff);
                    }
                }
            }
        }
        public static BitmapImage GetImage(TaskStuff taskStuff)
        {
            if (!taskStuff.IsLoaded)
            {
                if (!taskStuff.IsLoaded)
                {
                    PT_BS_Service.Client.Framework.BeOperationInvoker.Invoke <I_CO_IA.MonitorTask.I_CO_IA_MonitorTask>(channel =>
                    {
                        var result = channel.GetTaskStuffByGuid(taskStuff.Key);
                        if (result.Content != null && result.Content.Length > 0)
                        {
                            taskStuff.Content = result.Content;
                        }
                    });
                }
            }
            MemoryStream stream = new MemoryStream(taskStuff.Content);
            BitmapImage  bmp    = new BitmapImage();

            bmp.BeginInit();           //初始化
            bmp.StreamSource = stream; //设置源
            bmp.EndInit();             //初始化结束
            return(bmp);
        }