示例#1
0
        private void btnRemove_Click(object sender, RoutedEventArgs e)
        {
            ObservableCollection <StylePictureFile> pfiles = lvPictures.ItemsSource as ObservableCollection <StylePictureFile>;
            RadButton        btn  = sender as RadButton;
            StylePictureFile file = (StylePictureFile)btn.DataContext;

            pfiles.Remove(file);
        }
示例#2
0
        //private ProBYQ CheckSetting()
        //{
        //    RadComboBox cb1 = (RadComboBox)cbxBrand.Content;
        //    if (cb1.SelectedIndex == -1)
        //    {
        //        MessageBox.Show("请设置上传款式对应的品牌");
        //        cb1.Focus();
        //        return null;
        //    }
        //    RadComboBox cb2 = (RadComboBox)cbxQuarter.Content;
        //    if (cb2.SelectedIndex == -1)
        //    {
        //        MessageBox.Show("请设置上传款式对应的季度");
        //        cb2.Focus();
        //        return null;
        //    }
        //    RadDatePicker dp = (RadDatePicker)SYear.Content;
        //    if (string.IsNullOrEmpty(dp.DateTimeText))
        //    {
        //        MessageBox.Show("请设置上传款式对应的年份");
        //        dp.Focus();
        //        return null;
        //    }
        //    var byq = DomainLogicEncap.ProductLogic.GetBYQ((int)cb1.SelectedValue, dp.DateTimeText, (int)cb2.SelectedValue);
        //    if (byq == null)
        //    {
        //        MessageBox.Show("不存在对应的品牌年份季度信息");
        //        return null;
        //    }
        //    return byq;
        //}

        /// <summary>
        /// 上传款式图片
        /// </summary>
        /// <returns>是否上传成功</returns>
        private void UploadPictureForSingleStyle(ProBYQ byq, StylePictureFile file, RadProgressBar pbProgress, RadButton btn)
        {
            var filePath = file.FilePath;
            var image    = System.Drawing.Image.FromFile(filePath);
            //BitmapImage image = new BitmapImage(new Uri(filePath));
            var transfer = new LargeDataTransfer()
            {
                Data = image
            };

            transfer.CallbackEvent += delegate(int progress)
            {
                this.Dispatcher.Invoke(new Action(() =>
                {
                    pbProgress.Value = progress;
                }));
            };
            var           func     = new Func <ProBYQ, string, ILargeDataTransfer, bool>(UploadPictureForSingleStyle);
            AsyncCallback callback = new AsyncCallback(ar =>
            {
                //var func = (Func<ProStyleBYQ, string, ILargeDataTransfer, bool>)ar.AsyncState;
                var flag   = func.EndInvoke(ar);
                var result = ProductDataContext.SaveSCPicture(file);
                if (!flag || !result.IsSucceed)
                {
                    btn.IsEnabled       = true;
                    btn.Content         = "重新上传";
                    file.UploadProgress = 0;
                    file.UploadStatus   = "上传失败";
                    //MessageBox.Show("上传失败");
                }
                else
                {
                    //ProSCPicture scp = new ProSCPicture { SCCode = System.IO.Path.GetFileNameWithoutExtension(filePath), PictureName = System.IO.Path.GetFileName(filePath) };
                    file.UploadStatus = "上传成功";
                    //MessageBox.Show("上传成功");
                }
            });

            func.BeginInvoke(byq, filePath, transfer, callback, func);
            //IAsyncResult ar = func.BeginInvoke(byq, filePath, transfer, null, null);
            //WaitHandle waitHandle = ar.AsyncWaitHandle;
            //waitHandle.WaitOne();//主线程等待,这里将产生死锁

            //bool flag = false;//func.EndInvoke(ar);
            //new System.Threading.Thread(() =>
            //    {
            //        UploadPictureForSingleStyle(byq, filePath);
            //    }).Start();
        }
示例#3
0
        private void btnSingleUpload_Click(object sender, RoutedEventArgs e)
        {
            RadButton btn = (RadButton)sender;

            //var byq = this.CheckSetting();
            //if (byq != null)
            //{
            btn.IsEnabled = false;
            StylePictureFile file = (StylePictureFile)btn.DataContext;
            var tp       = btn.TemplatedParent;
            var tbStatus = View.Extension.UIHelper.GetVisualChild <TextBlock>(tp, "tbStatus");

            tbStatus.Text = "上传中";
            this.BeginInvoke(() =>
            {
                var pbProgress = View.Extension.UIHelper.GetVisualChild <RadProgressBar>(tp, "pbProgress");
                UploadPictureForSingleStyle(VMGlobal.BYQs.Find(o => o.ID == file.BYQID), file, pbProgress, btn);
            }, DispatcherPriority.Background);
            //}
        }