/// <summary> /// 移出上架计划 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnOutPlan_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (nick == string.Empty) { return; } else if (!g_AutoListDic.ContainsKey(nick)) { return; } List <int> checkedRowsList = GetCheckedRows(); if (checkedRowsList == null || checkedRowsList.Count == 0) { XtraMessageBox.Show("请选择需要移出上架计划的宝贝"); return; } foreach (int row in checkedRowsList) { Alading.Entity.Item item = gridViewItem.GetRow(row) as Alading.Entity.Item; if (item != null && g_AutoListDic[nick].ContainsKey(item.iid)) { g_AutoListDic[nick].Remove(item.iid);//从上架计划列表中删除 } } /*重新安排时间*/ AddToPlan(); }
/// <summary> /// 加入上架计划 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnInPlan_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (nick == string.Empty) { return; } List <int> checkedRowsList = GetCheckedRows(); if (!g_AutoListDic.ContainsKey(nick)) { g_AutoListDic.Add(nick, new Dictionary <string, string>()); } foreach (int row in checkedRowsList) { Alading.Entity.Item item = gridViewItem.GetRow(row) as Alading.Entity.Item; if (item != null && !g_AutoListDic[nick].ContainsKey(item.iid)) { g_AutoListDic[nick].Add(item.iid, string.Empty);//添加到上架计划列表 } } if (g_AutoListDic[nick] == null || g_AutoListDic[nick].Count == 0) { XtraMessageBox.Show("请选择需要加入上架计划的宝贝"); return; } AddToPlan(); }
/// <summary> /// 焦点行改变触发 展示已经上架了的宝贝,打钩 /// </summary> private void PageChange() { Dictionary <string, string> autoListDic = g_AutoListDic.FirstOrDefault(i => i.Key == nick).Value; if (autoListDic == null) { return; } for (int i = 0; i < gridViewItem.RowCount; i++) { Alading.Entity.Item item = gridViewItem.GetRow(i) as Alading.Entity.Item; if (item != null && autoListDic.ContainsKey(item.iid)) { //加入上架 gridViewItem.SetRowCellValue(i, "IsInAutoPlan", true); gridViewItem.SetRowCellValue(i, "list_time", autoListDic[item.iid]); } else { //移出上架 gridViewItem.SetRowCellValue(i, "IsInAutoPlan", false); gridViewItem.SetRowCellValue(i, "list_time", string.Empty); } } }
private void btnStart_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { try { if (string.IsNullOrEmpty(ccbNick.Text)) { XtraMessageBox.Show("请选择店铺!"); return; } #region 买家自定义类目 //读取买家自定义类目列表中被选中的子节点 string sellercids = string.Empty; foreach (TreeListNode node in treeListSellerCat.Nodes) { if (node.HasChildren) { foreach (TreeListNode childNode in node.Nodes) { if (childNode.CheckState == CheckState.Checked) { sellercids += string.Format("{0},", childNode.Tag.ToString()); } } } else { if (node.CheckState == CheckState.Checked) { sellercids += string.Format("{0},", node.Tag.ToString()); } } } itemreq.SellerCids = sellercids.TrimEnd(','); #endregion /*在这里判断stockItem中是否存在此商品,不存在要生成一个*/ string session = SystemHelper.GetSessionKey(ccbNick.Text); ItemRsp addRsp = TopService.ItemAdd(session, itemreq); //上传成功执行 if (addRsp != null && addRsp.Item != null) { ItemRsp rsp = TopService.ItemGet(session, ccbNick.Text, addRsp.Item.Iid, null); Alading.Entity.Item item = new Alading.Entity.Item(); if (rsp.Item == null) { rsp.Item = itemreq as Taobao.Entity.Item; } UIHelper.ItemCopyData(item, rsp.Item); ItemService.AddItem(item); } } catch (Exception ex) { XtraMessageBox.Show(ex.Message); } }
/// <summary> /// 获取选中行 /// </summary> /// <returns></returns> private List <int> GetCheckedRows() { List <int> checkedRowsList = new List <int>(); for (int i = 0; i < gridViewItem.RowCount; i++) { Alading.Entity.Item item = gridViewItem.GetRow(i) as Alading.Entity.Item; if (item != null) { if (item.IsSelected == true) { checkedRowsList.Add(i); } } } return(checkedRowsList); }
void worker_DoWork(object sender, DoWorkEventArgs e) { ItemTask itemTask = e.Argument as ItemTask; List <Taobao.Entity.Item> items = itemTask.ItemList; BackgroundWorker worker = (BackgroundWorker)sender; int totalCount = itemTask.totalCount; for (int i = 0; i < items.Count; i++) { lock (lockObject) { //进度递增 progressCurrent++; } if (worker.CancellationPending) { e.Cancel = true; break; } try { ItemRsp myrsp = TopService.ItemGet(SystemHelper.GetSessionKey(items[i].Nick), items[i].Nick, items[i].Iid, string.Empty); if (myrsp != null && myrsp.Item != null) { Alading.Entity.Item item = new Alading.Entity.Item(); UIHelper.ItemCopyData(item, myrsp.Item); //添加到数据库,如果存在则更新,否则添加 ReturnType result = ItemService.AddItem(item); //计算进度条值 int progress = (int)((float)progressCurrent / (float)totalCount * 100); if (result == ReturnType.Success) { UserState state = new UserState(); state.Index = i + 1; state.Iid = items[i].Iid; state.ItemTaskIndex = itemTask.Index; state.Message = "下载成功!"; worker.ReportProgress(progress, state); } else { UserState state = new UserState(); state.Message = "数据库存储发生错误。"; state.Index = i + 1; state.Iid = items[i].Iid; state.ItemTaskIndex = itemTask.Index; //发生数据库错误的报告 worker.ReportProgress(-1, state); } } } catch (Exception ex) { UserState state = new UserState(); state.Message = ex.Message; state.Index = i + 1; state.Iid = items[i].Iid; state.ItemTaskIndex = itemTask.Index; //发生下载错误的报告 worker.ReportProgress(-1, state); } } e.Result = itemTask.Index; }
void worker_DoWork(object sender, DoWorkEventArgs e) { ItemTask itemTask = e.Argument as ItemTask; List <string> iidlist = itemTask.iidList; BackgroundWorker worker = (BackgroundWorker)sender; int n = iidlist.Count; for (int i = 0; i < n; i++) { //完成数加1 itemCompleteNum++; if (isCancel) { e.Cancel = true; break; } string iid = iidlist[i]; ReturnType returntype = ItemService.IsItemExisted(iid); if (checkEditIsUpdate.CheckState != CheckState.Checked && returntype == ReturnType.PropertyExisted) { /*跳过本次下载*/ worker.ReportProgress(-2, string.Format("线程号{0},数据库已存在第{1}个宝贝,跳过下载", itemTask.threadIndex, i + 1)); continue; } string session = itemTask.sessionKey; string nick = itemTask.shopNic; try { ItemRsp myrsp = TopService.ItemGet(session, nick, iid, string.Empty); if (myrsp != null && myrsp.Item != null) { Alading.Entity.Item item = new Alading.Entity.Item(); UIHelper.ItemCopyData(item, myrsp.Item); ItemService.AddItem(item, checkEditIsUpdate.Checked); } else { if (failedDownload.iidList == null) { failedDownload.iidList = new List <string>(); } failedDownload.iidList.Add(iid); failedDownload.shopNick = nick; failedDownload.sessionKey = session; } //int progress = (int)((float)(i + 1) / (float)n * 100); worker.ReportProgress(itemCompleteNum, string.Format("{0}已成功下载第{1}个宝贝,线程号{2}", DateTime.Now.ToString(Constants.DATE_TIME_FORMAT), itemCompleteNum, itemTask.threadIndex)); } catch (System.Exception ex) { MyException myexc = new MyException(); myexc.position = i + 1; myexc.iid = iid; myexc.msg = ex.Message; myexc.threadIndex = itemTask.threadIndex; worker.ReportProgress(-1, myexc); if (failedDownload.iidList == null) { failedDownload.iidList = new List <string>(); } failedDownload.iidList.Add(iid); failedDownload.shopNick = nick; failedDownload.sessionKey = session; } } e.Result = itemTask.threadIndex; }
/// <summary> /// 加入上架计划 /// </summary> private void AddToPlan() { if (nick == string.Empty) { return; } Dictionary <string, string> autoListDic = g_AutoListDic[nick]; List <int> checkedRowsList = GetCheckedRows(); List <int> checkedHours = GetCheckedHours(); if (checkedHours == null || checkedHours.Count == 0) { XtraMessageBox.Show("请设置上架时间段"); return; } int dayOfWeek = 1;//表示星期一 switch (DateTime.Now.DayOfWeek.ToString()) { case "Monday": dayOfWeek = 1; break; case "Tuesday": dayOfWeek = 2; break; case "Wednesday": dayOfWeek = 3; break; case "Thursday": dayOfWeek = 4; break; case "Friday": dayOfWeek = 5; break; case "Saturday": dayOfWeek = 6; break; case "Sunday": dayOfWeek = 7; break; } /*在这里设定上架时间*/ //选择日期均匀上架 List <string> dateTimeStrList = new List <string>(); if (radioGroupSet.SelectedIndex == 1) { dateTimeStrList = TimeSet(dayOfWeek, checkedHours, autoListDic); }// if (radioGroupSet.SelectedIndex == 1) else { #region //系统默认设置上架 int num = int.Parse(spinEditNum.Text); //每次几个 int MinutePerOnce = int.Parse(spinEditTime.Text); //每几分钟一次 int minuteToHour = 0; //由分钟数加到了小时 bool alreadyFull = false; int addDay = 0; while (alreadyFull == false) { addDay++; for (int i = 0; i < checkedHours.Count; i++) { int minute = 0; int count = 0; minute = MinutePerOnce; minute *= count; if (MinutePerOnce > 60) { minuteToHour = minuteToHour / 60; } while (minute < 60) { string date = string.Empty; if (i + minuteToHour < checkedHours.Count) { //从第二天开始 date = string.Format("{0} {1}:{2}:0", DateTime.Now.AddDays(addDay).ToString("yyyy-MM-dd"), checkedHours[i + minuteToHour], minute); //每次上架几个 for (int j = 0; j < num; j++) { dateTimeStrList.Add(date); } } minute += MinutePerOnce; } if (dateTimeStrList.Count >= autoListDic.Count) { alreadyFull = true; break; } count++; } } #endregion } //int dCount = 0;//dateTimeStrList的下标 List <string> keyStr = autoListDic.Keys.ToList(); if (keyStr.Count <= dateTimeStrList.Count) { for (int i = 0; i < keyStr.Count; i++) { autoListDic[keyStr[i]] = dateTimeStrList[i]; //dCount++; } } else { int times = 1;//当安排的时间不够时重复设置一些 if (keyStr.Count % dateTimeStrList.Count == 0) { times = keyStr.Count / dateTimeStrList.Count; } else { times = keyStr.Count / dateTimeStrList.Count + 1; } for (int key = 0; key < keyStr.Count; key++) { for (int i = 0; i < times && key < dateTimeStrList.Count; i++) { autoListDic[keyStr[key]] = dateTimeStrList[key]; } } } if (autoListDic.Count <= dateTimeStrList.Count) { for (int i = 0; i < gridViewItem.RowCount; i++) { Alading.Entity.Item item = gridViewItem.GetRow(i) as Alading.Entity.Item; if (item != null && autoListDic.ContainsKey(item.iid)) { //加入上架 gridViewItem.SetRowCellValue(i, "IsInAutoPlan", true); gridViewItem.SetRowCellValue(i, "list_time", autoListDic[item.iid]); } else { //移出上架 gridViewItem.SetRowCellValue(i, "IsInAutoPlan", false); gridViewItem.SetRowCellValue(i, "list_time", string.Empty); } } } }