private void SetStyleBYQ(ProStyleBO style) { var byq = VMGlobal.BYQs.Find(o => o.BrandID == style.BrandID && o.Year == style.Year && o.Quarter == style.Quarter); if (byq != null) { style.BYQID = byq.ID; } else { byq = LinqOP.Search <ProBYQ>(o => o.BrandID == style.BrandID && o.Year == style.Year && o.Quarter == style.Quarter).FirstOrDefault(); if (byq != null) { style.BYQID = byq.ID; VMGlobal.BYQs.Add(byq); } else { byq = new ProBYQ { BrandID = style.BrandID, Year = style.Year, Quarter = style.Quarter }; int byqID = LinqOP.Add <ProBYQ, int>(byq, o => o.ID); style.BYQID = byqID; byq.ID = byqID; VMGlobal.BYQs.Add(byq); } } }
public ProBYQBO(ProBYQ byq) { this.ID = byq.ID; this.BrandID = byq.BrandID; Year = byq.Year; Quarter = byq.Quarter; }
private bool UploadPictureForSingleStyle(ProBYQ byq, string filePath, ILargeDataTransfer transfer) { InstanceContext instanceContext = new InstanceContext(transfer); bool flag = false; using (DuplexChannelFactory <IStylePictureUploadService> channelFactory = new DuplexChannelFactory <IStylePictureUploadService>(instanceContext, "StylePictureUploadSVC")) { IStylePictureUploadService proxy = channelFactory.CreateChannel(); flag = proxy.UploadPicture(byq.BrandID, byq.Year, byq.Quarter, System.IO.Path.GetFileName(filePath)); } return(flag); }
//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(); }