using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using LYFZ.Command; using LYFZ.ComponentLibrary; using System.Collections; using LYFZ.Software.MainBusiness.DoorCityProcess; using LYFZ.Software.MainBusiness.InitialSet; using LYFZ.Model; using System.Net; using System.IO; namespace LYFZ.Software.MainBusiness.MicroApplet { public partial class frmPackagesUpload : LYFZ.Software.MicroApplet.frmPackagesUpload { LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder(); LYFZ.BLL.BLL_ErpProduct ptbll = new BLL.BLL_ErpProduct(); LYFZ.BLL.BLL_ErpPackages pkbll = new BLL.BLL_ErpPackages(); LYFZ.BLL.BLL_ErpTheScenery tsbll = new BLL.BLL_ErpTheScenery(); LYFZ.BLL.BLL_ErpPackagesGiftMerchandise pgmbll = new BLL.BLL_ErpPackagesGiftMerchandise(); public frmPackagesUpload(string StrType = "0") { if (!string.IsNullOrEmpty(StrType)) { this.StrPackagesType = Convert.ToInt32(StrType); } else { this.StrPackagesType = 0; } this.Load += PackagesGoodsSetFormMain_Load; this.Shown += PackagesGoodsSetFormMain_Shown; this.cmbtreev_PackageName.ComboBoxTree_NodeMouseClick += cmbtreev_PackageName_ComboBoxTree_NodeMouseClick; this.btnSaveed.Click += btnSaveed_Click; this.btnCloseed.Click += btnCloseed_Click; this.TabControl.SelectedIndexChanged += TabControl_SelectedIndexChanged; this.btnPicSelect.Click += BtnPicSelect_Click; this.btnListImgSelect.Click += BtnListImgSelect_Click; this.btnSelectVideo_url.Click += BtnSelectVideo_url_Click; } /// /// 选择视频 /// /// /// private void BtnSelectVideo_url_Click(object sender, EventArgs e) { OpenFileDialog open = new OpenFileDialog(); open.Multiselect = false; open.Title = "选择图片"; open.Filter = "视频|*.mp4;*.flv;*.mov;*.wmv;*.avi;*.mpeg;*.mpeg;"; if (open.ShowDialog() == DialogResult.OK) { this.txtVideo_url.Text = open.FileName; Video_url = open.FileName; } } MicroAppLoginReturn _appLoginModel = new MicroAppLoginReturn(); public MicroAppLoginReturn AppLoginModel { get { return _appLoginModel; } set { _appLoginModel = value; } } /// /// 上传套系 /// /// /// void btnSaveed_Click(object sender, EventArgs e) { try { if (packModel != null && !string.IsNullOrEmpty(this.cmbtreev_PackageName.Text.Trim())) { LYFZ.Command.Result res = (LYFZ.Command.Result)pkbll.GetSelectTaoXiLeiXing(packModel); MicroAppReturn returnData = new MicroAppReturn(); if (!this.rdoErTong.Checked && !this.rdoHungSha.Checked && !this.rdoPuTong.Checked) { MessageBoxCustom.Show("请选择套系类型"); return; } //小程序套系分类 int categoty_id = -1; try { if (this.cbxFengLie.SelectedItem == null) { MessageBoxCustom.Show("请选择套系分类"); return; } else { ItemValue item = (ItemValue)this.cbxFengLie.SelectedItem; categoty_id = Convert.ToInt32(item.Value); } } catch (Exception ex) { MessageBoxCustom.Show("选择套系分类时出错:{0}", ex.Message); return; } this.picImagePath = this.txtPicImage.Text.Trim(); List UpdoadImageList = new List(); if (this.listImageList.Items.Count > 0) { foreach (string path in this.listImageList.Items) { UpdoadImageList.Add(path); } } //服务装套数 int clothCount = 1; //景点 string sceneName = ""; //入底 int negativeCount = 0; //入册 int meticulouslyCount = 0; if (this.rdoErTong.Checked) { clothCount = ErTongFuZhuangShu; sceneName = String.Join(", ", this.ErTongJingDianList.ToArray()); negativeCount = ErTongRuDiShu; meticulouslyCount = ErTongRuCheShu; } else { clothCount = PuTongFuZhuangShu; sceneName = String.Join(", ", this.PuTongJingDianList.ToArray()); negativeCount = PuTongRuDiShu; meticulouslyCount = PuTongRuCheShu; } dynamic TaoXiData = new { TaoXiBianMa = this.packModel.Pak_PackagesID, TaoXiMingCheng = this.packModel.Pak_Name, TaoXiJiaGe = this.packModel.Pak_UnitPrice, TaoXiLeiYongData = res.Data, }; if (String.IsNullOrEmpty(sceneName)) { MessageBoxCustom.Show("当前套系未设置对应的景点或拍摄阶段"); return; } LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate (object obj, BackgroundWorker backgroundWorker) { try { string uploadVideo_url = ""; if (this.Video_url.Trim().Length > 0) { backgroundWorker.ReportProgress(0, "正在上传视频..."); MicroAppReturn returnUploadPicData = UploadPhoto(this.Video_url.Trim()); if (returnUploadPicData.Code == 200) { dynamic PicData = Newtonsoft.Json.JsonConvert.DeserializeObject(returnUploadPicData.Data); uploadVideo_url = PicData["img_route"]; } else { returnData.Message = String.Format("视频上传失败:{0}", returnUploadPicData.Message); return; } } backgroundWorker.ReportProgress(0, "正在上传图片..."); string picImageUrl = ""; if (this.picImagePath.Trim().Length > 0) { MicroAppReturn returnUploadPicData = UploadPhoto(this.picImagePath.Trim()); if (returnUploadPicData.Code == 200) { dynamic PicData = Newtonsoft.Json.JsonConvert.DeserializeObject(returnUploadPicData.Data); picImageUrl = PicData["img_route"]; } else { returnData.Message = returnUploadPicData.Message; return; } } else { returnData.Message = "请选择标题图片"; return; } List imageUrlList = new List(); if (UpdoadImageList.Count > 0) { foreach (string path in UpdoadImageList) { MicroAppReturn tUploadPicData = UploadPhoto(path.Trim()); if (tUploadPicData.Code == 200) { dynamic tPicData = Newtonsoft.Json.JsonConvert.DeserializeObject(tUploadPicData.Data); string tempImageUrl = tPicData["img_route"]; imageUrlList.Add(tempImageUrl); } else { returnData.Message = tUploadPicData.Message; return; } } } else { returnData.Message = "请选择展示图片"; return; } backgroundWorker.ReportProgress(0, "正在上传套系数据..."); string tempstr = Newtonsoft.Json.JsonConvert.SerializeObject(TaoXiData); dynamic extraData = new { clothCount = clothCount.ToString(), sceneName = sceneName, duration = this.txtFuWuShiChang.Text.Trim(), negativeCount = negativeCount, meticulouslyCount = meticulouslyCount, orderDetail = this.ShangPingList.ToArray(), agreement = txtXieYi.lines, sceneIntro = this.HuFuList.ToArray(), purchaseNotes = txtGouMaiXuZhi.Text.Trim(), pictureUrl = imageUrlList.ToArray(), imgUrl = picImageUrl }; int series_type = this.rdoErTong.Checked ? 2 : this.rdoHungSha.Checked ? 1 : 3; dynamic PackageData = new { title = this.packModel.Pak_Name, categoty_id = categoty_id, price = this.nuDingJing.Value, price_original = this.packModel.Pak_UnitPrice, series_type = series_type, cover_url = picImageUrl, video_url = uploadVideo_url, series_id = "", extra = extraData, extra_id = String.Format("{0}{1}", this.packModel.Pak_PackagesID, series_type), third_party_data = TaoXiData }; string postData = Newtonsoft.Json.JsonConvert.SerializeObject(PackageData); string PostReturnString = frmMicroAppletAdmin.HttpWebRequestPOST(frmSynchronousData.addSeriesData, postData, _appLoginModel, Encoding.UTF8); if (PostReturnString.IndexOf("{") == 0) { dynamic postReturnObj = Newtonsoft.Json.JsonConvert.DeserializeObject(PostReturnString); if (Convert.ToInt32(postReturnObj["meta"]["code"]) == 200) { returnData.Code = 200; returnData.Data = Newtonsoft.Json.JsonConvert.SerializeObject(postReturnObj["body"]); } else { returnData.Message = postReturnObj["meta"]["message"]; } } else { returnData.Message = PostReturnString; } } catch (Exception ex) { MessageBoxCustom.Show(String.Format("上传套系数据时错误:{0}", ex.Message)); } }); if (returnData.Code == 200) { MessageBoxCustom.Show(String.Format("上传套系数据已上传成功")); } else { MessageBoxCustom.Show(String.Format("上传套系数据时失败:{0}", returnData.Message)); } } else { MessageBoxCustom.Show("请选择套系"); } } catch (Exception ex) { MessageBoxCustom.Show(String.Format("上传套系数据时出错误:{0}", ex.Message)); } } MicroAppReturn UploadPhoto(string photoPath) { MicroAppReturn data = new MicroAppReturn(); string PostReturnString = SendHttpRequestPost(frmSynchronousData.uploadImg, photoPath, _appLoginModel, Encoding.UTF8); if (PostReturnString.IndexOf("{") == 0) { dynamic postReturnObj = Newtonsoft.Json.JsonConvert.DeserializeObject(PostReturnString); if (Convert.ToInt32(postReturnObj["meta"]["code"]) == 200) { data.Code = 200; data.Data = Newtonsoft.Json.JsonConvert.SerializeObject(postReturnObj["body"]); } else { data.Message = postReturnObj["meta"]["message"]; } } else { data.Message = PostReturnString; } return data; } /// /// 向指定的URL地址发起一个POST请求,同时可以上传一些数据项以及上传文件。 /// /// 要请求的URL地址 /// 要上传的文件列表 /// 发送数据项,接收的字符编码方式 /// 服务器的返回结果 public string SendHttpRequestPost(string url, string filePath, MicroAppLoginReturn appLogin, Encoding encoding=null) { if (string.IsNullOrEmpty(url)) throw new ArgumentNullException("url"); if (encoding == null) encoding = Encoding.UTF8; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; // 要上传文件,一定要是POST方法 request.Headers.Add("token", appLogin.AppToken); request.Headers.Add("bindcode", appLogin.Bind_code); // 数据块的分隔标记,用于设置请求头,注意:这个地方最好不要使用汉字。 string boundary = "---------------------------" + Guid.NewGuid().ToString("N"); // 数据块的分隔标记,用于写入请求体。 // 注意:前面多了一段: "--" ,而且它们将独占一行。 byte[] boundaryBytes = Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n"); // 设置请求头。指示是一个上传表单,以及各数据块的分隔标记。 request.ContentType = "multipart/form-data; boundary=" + boundary; // 先得到请求流,准备写入数据。 Stream stream = request.GetRequestStream(); // 写入要上传的文件 // foreach (DictionaryEntry kvp in fileList)//KeyValuePair kvp { // 写入数据块的分隔标记 stream.Write(boundaryBytes, 0, boundaryBytes.Length); string photoFile = filePath;// kvp.Value.ToString(); /* if (".jpg,.png.jpge".Contains(System.IO.Path.GetExtension(photoFile).ToLower().Trim())) { Bitmap bmp = LYFZ.BLL.SelectPhotoHandling.GeneratePreviewBitmap(photoFile, 640, 960); photoFile = LYFZ.ImageFunction.ThumbImgae.SaveTemporaryCompressionImage(bmp, System.IO.Path.GetFileName(photoFile)); }*/ // 写入文件描述,这里设置一个通用的类型描述:application/octet-stream,具体的描述在注册表里有。 string description = string.Format( "Content-Disposition: form-data; name=\"file\"; filename=\"{0}\"\r\n" + "Content-Type: application/octet-stream\r\n\r\n", Path.GetFileName(photoFile.Trim())); // 注意:这里如果不使用UTF-8,对于汉字会有乱码。 byte[] header = Encoding.UTF8.GetBytes(description); stream.Write(header, 0, header.Length); // 写入文件内容 byte[] body = File.ReadAllBytes(photoFile.Trim()); stream.Write(body, 0, body.Length); /* if (".jpg,.png.jpge".Contains(System.IO.Path.GetExtension(photoFile).ToLower().Trim())) { LYFZ.ImageFunction.ThumbImgae.DeleteTemporaryCompressionImage(photoFile); }*/ } // 写入结束标记 boundaryBytes = Encoding.ASCII.GetBytes("\r\n--" + boundary + "--\r\n"); stream.Write(boundaryBytes, 0, boundaryBytes.Length); stream.Close(); try { // 开始发起请求,并获取服务器返回的结果。 using (WebResponse response = request.GetResponse()) { request.Timeout = 300000; using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding)) { return reader.ReadToEnd(); } } } catch (Exception ex){ return ex.Message; } } string Video_url = ""; string picImagePath = ""; List appImageList = new List(); private void BtnListImgSelect_Click(object sender, EventArgs e) { OpenFileDialog open = new OpenFileDialog(); open.Title = "选择图片"; open.Multiselect = true; open.Filter = "图片|*.jpg;*.png;*.gif;*.jpeg;"; if (open.ShowDialog() == DialogResult.OK) { appImageList.Clear(); this.listImageList.Items.Clear(); this.listImageList.Items.AddRange(open.FileNames); appImageList.AddRange(open.FileNames); } } private void BtnPicSelect_Click(object sender, EventArgs e) { OpenFileDialog open = new OpenFileDialog(); open.Multiselect = false; open.Title = "选择图片"; open.Filter = "图片|*.jpg;*.png;*.gif;*.jpeg;"; if (open.ShowDialog() == DialogResult.OK) { this.txtPicImage.Text = open.FileName; picImagePath = open.FileName; } } /// /// 套系大类类型 /// public int StrPackagesType; /// /// 是否保存 /// public bool IsSaveed = false; /// /// 存储产品略图集合 /// ImageList mlistImage = new ImageList(); /// /// true为首次运行 /// private bool IsFirstLoad = true; /// /// 窗体加载事件 /// /// /// void PackagesGoodsSetFormMain_Load(object sender, EventArgs e) { this.Location = new Point(LYFZ.EnumPublic.FormLocation_X, LYFZ.EnumPublic.FormLocation_Y); this.Size = new Size(LYFZ.EnumPublic.FormSize_Width, LYFZ.EnumPublic.FormSize_Height); switch (LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetBusinessType()) { case EnumPermissions.BusinessType.儿童版: this.rdoErTong.Checked = true; this.rdoHungSha.Hide(); break; case EnumPermissions.BusinessType.婚纱版: this.rdoHungSha.Checked = true; this.rdoErTong.Hide(); break; } if (this.StrPackagesType == 1) { // this.panelEx4.Visible = false; this.Text = "礼包套系商品设置"; this.labelEx6.Text = "套系礼包商品"; this.labelEx8.Text = "套系礼包服务"; } else { this.txtIntoBottom.WaterText = "-1表示全送"; } } /// /// 窗体加载事件 /// /// /// void PackagesGoodsSetFormMain_Shown(object sender, EventArgs e) { dynamic returnData = null; string errorMsg = ""; LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate (object obj, BackgroundWorker backgroundWorker) { try { string postData = Newtonsoft.Json.JsonConvert.SerializeObject(new { page = 1 }); string PostReturnString = frmMicroAppletAdmin.HttpWebRequestPOST(frmSynchronousData.categotyData, postData, _appLoginModel, Encoding.UTF8); if (PostReturnString.IndexOf("{") == 0) { dynamic postReturnObj = Newtonsoft.Json.JsonConvert.DeserializeObject(PostReturnString); if (Convert.ToInt32(postReturnObj["meta"]["code"]) == 200) { returnData = postReturnObj["body"]["data_list"];// Newtonsoft.Json.JsonConvert.SerializeObject(postReturnObj["body"]); } else { errorMsg = postReturnObj["meta"]["message"]; } } else { errorMsg = PostReturnString; } } catch (Exception ex) { errorMsg = ex.Message; } }); if (returnData != null) { try { foreach (dynamic itemObj in returnData) { ItemValue item = new ItemValue(Convert.ToInt32(itemObj.id), itemObj.name.ToString()); this.cbxFengLie.Items.Add(item); } } catch (Exception ex) { MessageBoxCustom.Show(String.Format("绑定小程序套系分类时出错:{0}",ex.Message)); } } else { MessageBoxCustom.Show(String.Format("获取小程序套系分类失败:{0}",errorMsg)); } //获取绑定拍摄次数 获取绑定套系名称 LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboBoxTreeView_PackagesCategoryAndName(this.cmbtreev_PackageName, StrParentCode: Enum.GetName(typeof(LYFZ.EnumPublic.EnumPackagesType), StrPackagesType).ToString().Trim()); this.tabPage1.Parent = null; this.tabPage2.Parent = null; switch (LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetBusinessType()) { case LYFZ.Software.MainBusiness.EnumPermissions.BusinessType.儿童版: if (!LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.IsEnablePhotoEdition) { this.tabPage2.Parent = this.TabControl; } else { this.tabPage1.Parent = this.TabControl; this.tabPage2.Parent = this.TabControl; } break; case LYFZ.Software.MainBusiness.EnumPermissions.BusinessType.婚纱版: this.tabPage1.Parent = this.TabControl; break; default: this.tabPage1.Parent = this.TabControl; this.tabPage2.Parent = this.TabControl; break; } #region 设置列表标题 #region 商品表标题 this.listViewData_Product.View = View.Details; this.listViewData_Product.GridLines = true; string[] StrColumns = "商品名称,数量,进货价格,销售单价".Split(','); int SurplusCount = 90 + 85 + 85 + 23; for (int i = 0; i < StrColumns.Length; i++) { ColumnHeader ch = new ColumnHeader(); ch.Text = StrColumns[i].Trim(); ch.TextAlign = HorizontalAlignment.Left; if (i == 0) { ch.Width = this.listViewData_Product.Width - SurplusCount; } else if (i == StrColumns.Length - 1) { ch.Width = 90; } else { ch.Width = 85; } switch (StrColumns[i].Trim()) { case "进货价格": case "销售单价": ch.TextAlign = HorizontalAlignment.Right; break; default: ch.TextAlign = HorizontalAlignment.Center; break; } this.listViewData_Product.Columns.Add(ch); } this.mlistImage.ImageSize = new Size(25, 25); this.mlistImage.ColorDepth = ColorDepth.Depth32Bit; this.listViewData_Product.SmallImageList = mlistImage; this.listViewData_Product.MultiSelect = true; #endregion #region 服务表标题 this.listViewData_Service.View = View.Details; this.listViewData_Service.GridLines = true; for (int i = 0; i < StrColumns.Length; i++) { ColumnHeader ch = new ColumnHeader(); ch.Text = StrColumns[i].Trim(); ch.TextAlign = HorizontalAlignment.Left; if (i == 0) { ch.Width = this.listViewData_Service.Width - SurplusCount; } else if (i == StrColumns.Length - 1) { ch.Width = 90; } else { ch.Width = 85; } switch (StrColumns[i].Trim()) { case "进货价格": case "销售单价": ch.TextAlign = HorizontalAlignment.Right; break; default: ch.TextAlign = HorizontalAlignment.Center; break; } this.listViewData_Service.Columns.Add(ch); } this.listViewData_Service.SmallImageList = mlistImage; this.listViewData_Service.MultiSelect = true; #endregion #region 景点表标题 this.listViewData_Sights.View = View.Details; this.listViewData_Sights.GridLines = true; ImageList imgList = new ImageList(); imgList.ImageSize = new Size(1, 25); this.listViewData_Sights.SmallImageList = imgList; StrColumns = "景点名称,服装套数,成本单价,销售单价".Split(','); SurplusCount = 90 + 85 + 85 + 23; for (int i = 0; i < StrColumns.Length; i++) { ColumnHeader ch = new ColumnHeader(); ch.Text = StrColumns[i].Trim(); ch.TextAlign = HorizontalAlignment.Left; if (i == 0) { ch.Width = this.listViewData_Sights.Width - SurplusCount; } else if (i == StrColumns.Length - 1) { ch.Width = 90; } else { ch.Width = 85; } switch (StrColumns[i].Trim()) { case "成本单价": case "销售单价": ch.TextAlign = HorizontalAlignment.Right; break; default: ch.TextAlign = HorizontalAlignment.Center; break; } this.listViewData_Sights.Columns.Add(ch); } #endregion #region 拍摄次数表标题 this.listViewData_Stages.View = View.Details; this.listViewData_Stages.GridLines = true; this.listViewData_Stages.SmallImageList = imgList; StrColumns = "次数名称,入册,入底,服装套数".Split(','); for (int i = 0; i < StrColumns.Length; i++) { ColumnHeader ch = new ColumnHeader(); ch.Text = StrColumns[i].Trim(); switch (StrColumns[i].Trim()) { case "次数名称": ch.Width = this.listViewData_Stages.Width - 270 - 23; break; case "入册": ch.Width = 90; break; case "入底": ch.Width = 90; break; case "服装套数": ch.Width = 90; break; } switch (StrColumns[i].Trim()) { case "次数名称": ch.TextAlign = HorizontalAlignment.Left; break; case "入册": case "入底": case "服装套数": ch.TextAlign = HorizontalAlignment.Center; break; } this.listViewData_Stages.Columns.Add(ch); } #endregion #endregion this.IsFirstLoad = false; } LYFZ.Model.Model_ErpPackages packModel = null; //普通单 List PuTongJingDianList = new List(); int PuTongRuDiShu = 0; int PuTongRuCheShu = 0; int PuTongFuZhuangShu = 0; //儿童单 List ErTongJingDianList = new List(); int ErTongRuDiShu = 0; int ErTongRuCheShu = 0; int ErTongFuZhuangShu = 0; List ShangPingList = new List(); List HuFuList = new List(); /// /// 套系名称选择设置 /// /// /// void cmbtreev_PackageName_ComboBoxTree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { this.listViewData_Product.Items.Clear(); this.listViewData_Product.Groups.Clear(); this.listViewData_Service.Items.Clear(); this.listViewData_Service.Groups.Clear(); this.listViewData_Sights.Items.Clear(); this.listViewData_Stages.Items.Clear(); this.PuTongJingDianList.Clear(); this.ErTongJingDianList.Clear(); this.ShangPingList.Clear(); this.HuFuList.Clear(); PuTongRuDiShu = 0; PuTongRuCheShu = 0; PuTongFuZhuangShu = 0; ErTongRuDiShu = 0; ErTongRuCheShu = 0; ErTongFuZhuangShu = 0; packModel = null; // this.IsDataChange = false; //获取套系名称资料 packModel = pkbll.GetModel("Pak_PackagesID", this.cmbtreev_PackageName.Tag.ToString().Trim()); // DataTable dt = orbll.GetView_Custom("tb_ErpPackages", StrWhere: "Pak_PackagesID='" + this.cmbtreev_PackageName.Tag.ToString().Trim() + "'", ShowColumnName: "Pak_UnitPrice,Pak_IntoTheArchive,Pak_IntoTheBook").Tables[0]; if (packModel.ID > 0) { this.lblPakUnitPrice.Text = "套系价格:" + packModel.Pak_UnitPrice.ToString();// dt.Rows[0]["Pak_UnitPrice"].ToString().Trim(); this.txtIntoRegister.Text = packModel.Pak_IntoTheBook.ToString();// dt.Rows[0]["Pak_IntoTheBook"].ToString().Trim(); this.txtIntoBottom.Text = packModel.Pak_IntoTheArchive.ToString();// dt.Rows[0]["Pak_IntoTheArchive"].ToString().Trim(); this.PuTongRuDiShu = packModel.Pak_IntoTheArchive; this.PuTongRuCheShu = packModel.Pak_IntoTheBook; #region 景点与次数 DataTable tblSights = orbll.GetView_Custom("tb_ErpPackagesGiftMerchandise Left Join tb_ErpTheScenery on tb_ErpTheScenery.ID = Pgm_ProductNumber", StrWhere: "Tsc_Name is not null And Pgm_PackagesCode = '" + this.cmbtreev_PackageName.Tag.ToString().Trim() + "' And Pgm_GiveType in (2,3)", ShowColumnName: "tb_ErpPackagesGiftMerchandise.ID,Pgm_GiveType,Pgm_PackagesCode,Pgm_ProductNumber,Pgm_Quantity,Tsc_Name,Tsc_CostPrice,Tsc_SalesPrice,Pgm_IntoRegisterQuantity,Pgm_IntoBottomQuantity").Tables[0]; for (int i = 0; i < tblSights.Rows.Count; i++) { ListViewItem lvItem = new ListViewItem(); lvItem.Tag = tblSights.Rows[i]["Pgm_ProductNumber"].ToString().Trim() + "|" + tblSights.Rows[i]["ID"].ToString().Trim(); lvItem.Text = tblSights.Rows[i]["Tsc_Name"].ToString().Trim(); if (tblSights.Rows[i]["Pgm_GiveType"].ToString().Trim() == "2") { this.PuTongJingDianList.Add(lvItem.Text); try { this.PuTongFuZhuangShu += Convert.ToInt32(tblSights.Rows[i]["Pgm_Quantity"].ToString()); } catch { } ListViewItem.ListViewSubItem ListSubItem = new ListViewItem.ListViewSubItem(); ListSubItem.Name = "服装套数"; ListSubItem.Text = tblSights.Rows[i]["Pgm_Quantity"].ToString().Trim(); lvItem.SubItems.Add(ListSubItem); ListSubItem = new ListViewItem.ListViewSubItem(); ListSubItem.Name = "成本单价"; ListSubItem.Text = tblSights.Rows[i]["Tsc_CostPrice"].ToString().Trim(); lvItem.SubItems.Add(ListSubItem); ListSubItem = new ListViewItem.ListViewSubItem(); ListSubItem.Name = "销售单价"; ListSubItem.Text = tblSights.Rows[i]["Tsc_SalesPrice"].ToString().Trim(); lvItem.SubItems.Add(ListSubItem); if ((this.listViewData_Sights.Items.Count % 2) > 0) { lvItem.BackColor = System.Drawing.Color.PapayaWhip; } else { lvItem.BackColor = System.Drawing.Color.PowderBlue; } this.listViewData_Sights.Items.Add(lvItem); } else if (tblSights.Rows[i]["Pgm_GiveType"].ToString().Trim() == "3") { this.ErTongJingDianList.Add(lvItem.Text); try { this.ErTongFuZhuangShu += Convert.ToInt32(tblSights.Rows[i]["Pgm_Quantity"].ToString()); this.ErTongRuDiShu += Convert.ToInt32(tblSights.Rows[i]["Pgm_IntoBottomQuantity"].ToString()); this.ErTongRuCheShu += Convert.ToInt32(tblSights.Rows[i]["Pgm_IntoRegisterQuantity"].ToString()); } catch { } ListViewItem.ListViewSubItem ListSubItem = new ListViewItem.ListViewSubItem(); ListSubItem.Name = "入册"; ListSubItem.Text = tblSights.Rows[i]["Pgm_IntoRegisterQuantity"].ToString().Trim(); lvItem.SubItems.Add(ListSubItem); ListSubItem = new ListViewItem.ListViewSubItem(); ListSubItem.Name = "入底"; ListSubItem.Text = tblSights.Rows[i]["Pgm_IntoBottomQuantity"].ToString().Trim(); lvItem.SubItems.Add(ListSubItem); ListSubItem = new ListViewItem.ListViewSubItem(); ListSubItem.Name = "服装套数"; ListSubItem.Text = tblSights.Rows[i]["Pgm_Quantity"].ToString().Trim(); lvItem.SubItems.Add(ListSubItem); if ((this.listViewData_Stages.Items.Count % 2) > 0) { lvItem.BackColor = System.Drawing.Color.PapayaWhip; } else { lvItem.BackColor = System.Drawing.Color.PowderBlue; } ListViewGroup man_lvg = new ListViewGroup(); man_lvg.Tag = lvItem.Text; man_lvg.Name = lvItem.Text; man_lvg.Header = lvItem.Text; man_lvg.HeaderAlignment = HorizontalAlignment.Left; this.listViewData_Product.Groups.Add(man_lvg); man_lvg = new ListViewGroup(); man_lvg.Tag = lvItem.Text; man_lvg.Name = lvItem.Text; man_lvg.Header = lvItem.Text; man_lvg.HeaderAlignment = HorizontalAlignment.Left; this.listViewData_Service.Groups.Add(man_lvg); this.listViewData_Stages.Items.Add(lvItem); } } #endregion #region 商品与服务 if (this.tabPage2.Parent == null) { string StrTableName = "(select Prod_Class,Sc_ClassName,Pgm_GiveType,Pgm_PackagesCode from tb_ErpPackagesGiftMerchandise Left Join tb_ErpProduct on Prod_Number = Pgm_ProductNumber " + "Left Join tb_ErpSystemCategory on Prod_Class = Sc_ClassCode Group by Prod_Class,Sc_ClassName,Pgm_GiveType,Pgm_PackagesCode ) as tb"; DataTable dtGroup = orbll.GetView_Custom(StrTableName, StrWhere: "Pgm_PackagesCode = '" + this.cmbtreev_PackageName.Tag.ToString().Trim() + "' And Pgm_GiveType in ('0','1')", ShowColumnName: "*").Tables[0]; ListViewGroup man_lvg = null; for (int i = 0; i < dtGroup.Rows.Count; i++) { man_lvg = new ListViewGroup(); man_lvg.Tag = dtGroup.Rows[i]["Sc_ClassName"].ToString().Trim(); man_lvg.Name = dtGroup.Rows[i]["Prod_Class"].ToString().Trim(); man_lvg.Header = dtGroup.Rows[i]["Sc_ClassName"].ToString().Trim(); man_lvg.HeaderAlignment = HorizontalAlignment.Left; if (dtGroup.Rows[i]["Pgm_GiveType"].ToString().Trim() == "0") { this.listViewData_Product.Groups.Add(man_lvg); } else if (dtGroup.Rows[i]["Pgm_GiveType"].ToString().Trim() == "1") { this.listViewData_Service.Groups.Add(man_lvg); } } } else { ListViewGroup man_lvg = new ListViewGroup(); man_lvg.Tag = ""; man_lvg.Name = "NotGroup"; man_lvg.Header = "未分组"; man_lvg.HeaderAlignment = HorizontalAlignment.Left; this.listViewData_Product.Groups.Add(man_lvg); man_lvg = new ListViewGroup(); man_lvg.Tag = ""; man_lvg.Name = "NotGroup"; man_lvg.Header = "未分组"; man_lvg.HeaderAlignment = HorizontalAlignment.Left; this.listViewData_Service.Groups.Add(man_lvg); } DataTable tblProduct = orbll.GetView_Custom("tb_ErpPackagesGiftMerchandise Left Join tb_ErpProduct on Prod_Number = Pgm_ProductNumber", StrWhere: "Pgm_PackagesCode = '" + this.cmbtreev_PackageName.Tag.ToString().Trim() + "' And Pgm_GiveType in ('0','1')", ShowColumnName: "tb_ErpPackagesGiftMerchandise.ID,Pgm_GiveType,Pgm_PackagesCode,Pgm_Quantity,Prod_Number,Prod_Name,Prod_Unit,Prod_CostPrice,Prod_SalesPrice,Prod_Thumbnail,Prod_Class,Pgm_ProductGroupName").Tables[0]; for (int i = 0; i < tblProduct.Rows.Count; i++) { if (!this.mlistImage.Images.Keys.Contains(tblProduct.Rows[i]["Prod_Number"].ToString().Trim())) { Image img = LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetProductImage(tblProduct.Rows[i]["Prod_Thumbnail"].ToString().Trim()); this.mlistImage.Images.Add(tblProduct.Rows[i]["Prod_Number"].ToString().Trim(), img); } ListViewItem lvItem = new ListViewItem(); lvItem.Tag = tblProduct.Rows[i]["Prod_Number"].ToString().Trim() + "|" + tblProduct.Rows[i]["ID"].ToString().Trim(); lvItem.ImageKey = tblProduct.Rows[i]["Prod_Number"].ToString().Trim(); lvItem.Text = tblProduct.Rows[i]["Prod_Name"].ToString().Trim(); if (tblProduct.Rows[i]["Prod_Number"] == null || string.IsNullOrEmpty(tblProduct.Rows[i]["Prod_Number"].ToString())) { lvItem.Text = "此产品已在产品设置表中删除"; lvItem.ForeColor = Color.Red; } ListViewItem.ListViewSubItem ListSubItem = new ListViewItem.ListViewSubItem(); ListSubItem.Name = "数量"; ListSubItem.Text = tblProduct.Rows[i]["Pgm_Quantity"].ToString().Trim(); lvItem.SubItems.Add(ListSubItem); ListSubItem = new ListViewItem.ListViewSubItem(); ListSubItem.Name = "进货价格"; ListSubItem.Text = tblProduct.Rows[i]["Prod_CostPrice"].ToString().Trim(); lvItem.SubItems.Add(ListSubItem); ListSubItem = new ListViewItem.ListViewSubItem(); ListSubItem.Name = "销售单价"; ListSubItem.Text = tblProduct.Rows[i]["Prod_SalesPrice"].ToString().Trim(); lvItem.SubItems.Add(ListSubItem); if (tblProduct.Rows[i]["Pgm_GiveType"].ToString().Trim() == "0") { this.ShangPingList.Add(String.Format("{0} {1} {2}",lvItem.Text, tblProduct.Rows[i]["Pgm_Quantity"].ToString().Trim(), tblProduct.Rows[i]["Prod_Unit"].ToString().Trim())); if (this.tabPage2.Parent == null) { if (this.listViewData_Product.Groups.Count > 0) { this.listViewData_Product.Groups[tblProduct.Rows[i]["Prod_Class"].ToString().Trim()].Items.Add(lvItem); } } else { if (!string.IsNullOrEmpty(tblProduct.Rows[i]["Pgm_ProductGroupName"].ToString().Trim())) { if (this.listViewData_Product.Groups[tblProduct.Rows[i]["Pgm_ProductGroupName"].ToString().Trim()] != null) { this.listViewData_Product.Groups[tblProduct.Rows[i]["Pgm_ProductGroupName"].ToString().Trim()].Items.Add(lvItem); } else { this.listViewData_Product.Groups["NotGroup"].Items.Add(lvItem); } } else { this.listViewData_Product.Groups["NotGroup"].Items.Add(lvItem); } } this.listViewData_Product.Items.Add(lvItem); } else if (tblProduct.Rows[i]["Pgm_GiveType"].ToString().Trim() == "1") { this.HuFuList.Add(String.Format("{0} {1} {2}", lvItem.Text, tblProduct.Rows[i]["Pgm_Quantity"].ToString().Trim(), tblProduct.Rows[i]["Prod_Unit"].ToString().Trim())); if (this.tabPage2.Parent == null) { if (this.listViewData_Service.Groups[tblProduct.Rows[i]["Prod_Class"].ToString().Trim()] != null) { this.listViewData_Service.Groups[tblProduct.Rows[i]["Prod_Class"].ToString().Trim()].Items.Add(lvItem); } } else { if (!string.IsNullOrEmpty(tblProduct.Rows[i]["Pgm_ProductGroupName"].ToString().Trim())) { if (this.listViewData_Service.Groups.Count > 0 && this.listViewData_Service.Groups[tblProduct.Rows[i]["Pgm_ProductGroupName"].ToString().Trim()] != null) { this.listViewData_Service.Groups[tblProduct.Rows[i]["Pgm_ProductGroupName"].ToString().Trim()].Items.Add(lvItem); } else { this.listViewData_Service.Groups["NotGroup"].Items.Add(lvItem); } } else { this.listViewData_Service.Groups["NotGroup"].Items.Add(lvItem); } } this.listViewData_Service.Items.Add(lvItem); } } this.ListViewDrawSingleOrDoubleRows(ListViewType.套系商品); this.ListViewDrawSingleOrDoubleRows(ListViewType.套系服务); #endregion } else { this.lblPakUnitPrice.Text = "套系价格:0"; MessageBoxCustom.Show(this.cmbtreev_PackageName.Text.ToString() + " 此类型无套系名称!请添加套系名称"); this.cmbtreev_PackageName.SetTextAndTag_ValueNull(); } this.GetSeriesCostsPriceStatistics(); } /// /// 关闭 /// /// /// void btnCloseed_Click(object sender, EventArgs e) { this.Close(); } /// /// 选择版本获取商品成本价,卖价 /// /// /// void TabControl_SelectedIndexChanged(object sender, EventArgs e) { if (!this.IsFirstLoad) { if (this.TabControl.SelectedTab != null) { this.GetSeriesCostsPriceStatistics(); } } } #region /// /// 获取套系成本统计 /// void GetSeriesCostsPriceStatistics() { decimal CostPrice = 0; decimal SalePrice = 0; if (this.TabControl.SelectedTab.Name.Trim() == "tabPage1") { this.GetProductPrice(ref CostPrice, ref SalePrice); this.GetServicePrice(ref CostPrice, ref SalePrice); this.GetSightsPrice(ref CostPrice, ref SalePrice); this.lblCostPrice.Text = Convert.ToDecimal(CostPrice).ToString("N2"); this.lblSalePrice.Text = Convert.ToDecimal(SalePrice).ToString("N2"); } else { this.GetProductPrice(ref CostPrice, ref SalePrice); this.GetServicePrice(ref CostPrice, ref SalePrice); this.lblCostPrice.Text = Convert.ToDecimal(CostPrice).ToString("N2"); this.lblSalePrice.Text = Convert.ToDecimal(SalePrice).ToString("N2"); } } decimal ConvertToDecimal(object obj) { try { if (obj != null && !string.IsNullOrEmpty(obj.ToString())) { decimal outdec = 0.00m; decimal.TryParse(obj.ToString().Trim(), out outdec); return outdec; } else { return 0.00m; } } catch { return 0.00m; } } /// /// 获取商品成本价 /// /// /// void GetProductPrice(ref decimal CostPrice, ref decimal SalesPrice) { for (int i = 0; i < this.listViewData_Product.Items.Count; i++) { CostPrice += ConvertToDecimal(this.listViewData_Product.Items[i].SubItems["数量"].Text.Trim()) * ConvertToDecimal(this.listViewData_Product.Items[i].SubItems["进货价格"].Text.Trim()); SalesPrice += ConvertToDecimal(this.listViewData_Product.Items[i].SubItems["数量"].Text.Trim()) * ConvertToDecimal(this.listViewData_Product.Items[i].SubItems["销售单价"].Text.Trim()); } } /// /// 获取服务成本价 /// /// /// void GetServicePrice(ref decimal CostPrice, ref decimal SalesPrice) { for (int i = 0; i < this.listViewData_Service.Items.Count; i++) { CostPrice += ConvertToDecimal(this.listViewData_Service.Items[i].SubItems["数量"].Text.Trim()) * ConvertToDecimal(this.listViewData_Service.Items[i].SubItems["进货价格"].Text.Trim()); SalesPrice += ConvertToDecimal(this.listViewData_Service.Items[i].SubItems["数量"].Text.Trim()) * ConvertToDecimal(this.listViewData_Service.Items[i].SubItems["销售单价"].Text.Trim()); } } /// /// 获取景点成本价 /// /// /// void GetSightsPrice(ref decimal CostPrice, ref decimal SalesPrice) { for (int i = 0; i < this.listViewData_Sights.Items.Count; i++) { CostPrice += ConvertToDecimal(this.listViewData_Sights.Items[i].SubItems["成本单价"].Text.Trim()); SalesPrice += ConvertToDecimal(this.listViewData_Sights.Items[i].SubItems["销售单价"].Text.Trim()); } } /// /// 绘制列表单双行 /// /// void ListViewDrawSingleOrDoubleRows(ListViewType ProcessType) { if (ProcessType == ListViewType.套系商品) { LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.ListViewDrawSingleOrDoubleRows(this.listViewData_Product); } else if (ProcessType == ListViewType.套系服务) { LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.ListViewDrawSingleOrDoubleRows(this.listViewData_Service); } else if (ProcessType == ListViewType.套系景点) { LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.ListViewDrawSingleOrDoubleRows(this.listViewData_Sights); } else if (ProcessType == ListViewType.套系次数) { LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.ListViewDrawSingleOrDoubleRows(this.listViewData_Stages); } } #endregion enum ListViewType { 套系商品, 套系服务, 套系景点, 套系次数 } } }