Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="RefundCostume"></param>
        /// <param name="times">打印次数</param>
        public void Print(RefundCostume RefundCostume, int times, DataGridView dataGridView)
        {
            this.RefundCostume = RefundCostume;

            InteractResult <RetailPrintType> rPrintType = CommonGlobalCache.ServerProxy.GetRetailPrintType();

            if (rPrintType.ExeResult == ExeResult.Success)
            {
                if (rPrintType.Data == RetailPrintType.SmallTickets)
                {
                    InteractResult <PrintTemplateInfo> result = CommonGlobalCache.ServerProxy.GetPrintTemplateInfo(PrintTemplateType.Retail);
                    if (result.ExeResult == ExeResult.Success)
                    {
                        PrintTemplateInfo PTemplateInfo = result.Data;
                        this.CurrentPTemplate = PTemplateInfo;
                        PrintHelper printer = new PrintHelper(RefundCostume_PrintPage2);
                        printer.printDocument.DefaultPageSettings.Margins   = new Margins(1, 1, 5, 1);
                        printer.printDocument.DefaultPageSettings.PaperSize = new PaperSize(RefundCostume.RefundOrder.RefundOrderID, PrintHelper.GetInch(8), 600);
                        printer.DirectlyPrint(this.CurrentPTemplate.PrintCount);
                    }
                }
                else
                {
                    setPrintDataGridView(RefundCostume, dataGridView, PrintTemplateType.RetailOrder);
                }
            }
        }
Esempio n. 2
0
 public ConfirmRefundForm(RefundCostume costume, string shopId, DataGridView dgv, decimal sourceTotalMoneyReceived = 0, int returntype = 0)
 {
     InitializeComponent();
     this.refundCostume  = costume;
     keepCostume         = costume;
     deepSourceDgv       = dgv;
     STotalMoneyReceived = sourceTotalMoneyReceived;
     this.Initialize();
     LoadConfig();
     this.ShopID    = shopId;
     ReturnType     = returntype;
     MenuPermission = Common.Core.RolePermissionMenuEnum.退货;
 }
Esempio n. 3
0
        /// <summary>
        /// 获取每件款号颜色的退货件数
        /// </summary>
        /// <param name="refundCostume"></param>
        /// <returns>key:"ShopID_CostumeID_ColorName_SizeName", value:退货件数</returns>
        private Dictionary <string, int> GetRefundStatus(RefundCostume refundCostume)
        {
            Dictionary <string, int> dictionary = new Dictionary <string, int>();
            List <RetailDetail>      list       = refundCostume.RefundDetailList;

            foreach (RetailDetail detail in list)
            {
                string key = string.Format("{0}_{1}_{2}_{3}_{4}_{5}_{6}", refundCostume.RefundOrder.ShopID, detail.CostumeID, detail.ColorName, detail.SizeName, detail.Discount, detail.InSalesPromotion, detail.GiftTickets);
                if (!dictionary.ContainsKey(key))
                {
                    dictionary.Add(key, 0);
                }
                dictionary[key] = dictionary[key] + detail.BuyCount;
            }
            return(dictionary);
        }
Esempio n. 4
0
        private void Print(RetailOrder retailOrder)
        {
            RefundOrderPrintUtil printHelper      = new RefundOrderPrintUtil();
            List <RetailDetail>  retailDetailList = CommonGlobalCache.ServerProxy.GetRetailDetailList(retailOrder.ID);

            foreach (var item in retailDetailList)
            {
                Costume costume = CommonGlobalCache.GetCostume(item.CostumeID);
                // 显示自己设置的尺码组和对应的尺码列表
                item.SizeDisplayName = CostumeStoreHelper.GetCostumeSizeName(item.SizeName, CommonGlobalCache.GetSizeGroup(costume.SizeGroupName));
            }

            RefundCostume retailCostume = new RefundCostume()
            {
                RefundDetailList = retailDetailList,
                RefundOrder      = retailOrder,
            };
            int          times = CommonGlobalUtil.ConvertToInt32(CommonGlobalCache.GetParameter(ParameterConfigKey.PrintCount).ParaValue);
            DataGridView dgv   = deepCopyDataGridView();

            printHelper.Print(retailCostume, times, dgv);
        }
Esempio n. 5
0
        private decimal CalGiftTicket(RefundCostume costume)
        {
            decimal moneyBuyByTicket = 0;

            if (costume.RefundDetailList != null)
            {  //只有退货部分
                foreach (var item in originalRetailCostume.RetailDetailList)
                {
                    /* RetailDetail retailDetail = null;
                     * foreach (var retail in this.originalRetailCostume.RetailDetailList)
                     * {
                     *
                     *   if (retail.CostumeID.ToUpper() == item.CostumeID.ToUpper() && retail.ColorName == item.ColorName && retail.SizeName == item.SizeName)
                     *   {
                     *       //找到对应的订购明细
                     *       retailDetail = retail;
                     *       break;
                     *   }
                     * }*/

                    if (item.GiftTicketMoney > 0)
                    {
                        int returnCount = 0;
                        if (!item.IsRefund)
                        {
                            returnCount = 0;
                        }
                        else
                        {
                            returnCount = item.RefundCount;
                        }
                        moneyBuyByTicket += decimal.Round(item.GiftTicketMoney / item.BuyCount * (item.BuyCount - returnCount), 2);
                    }
                    else
                    {
                        moneyBuyByTicket += item.GiftTicketMoney;
                    }

                    /* if (!String.IsNullOrEmpty(item.GiftTickets))
                     * {
                     *
                     *   List<GiftTicket> list = GlobalCache.ServerProxy.GetGiftTicket4RetailDetail(item.GiftTickets);
                     *   //计算最少的优惠券金额
                     *   List<GiftTicket> minList = new List<GiftTicket>();
                     *   if (list != null)
                     *   {
                     *
                     *
                     *       RetailDetail retailDetail = null;
                     *       foreach (var retail in this.originalRetailCostume.RetailDetailList)
                     *       {
                     *
                     *           if (retail.CostumeID.ToUpper() == item.CostumeID.ToUpper() && retail.ColorName == item.ColorName && retail.SizeName == item.SizeName)
                     *           {
                     *               //找到对应的订购明细
                     *               retailDetail = retail;
                     *               break;
                     *           }
                     *       }
                     *       //只拿买入的
                     *       for (int i = 0; i < retailDetail.BuyCount - item.RefundCount; i++)
                     *       {
                     *           //if (item.RefundCount)
                     *           GiftTicket minTicket = null;
                     *           foreach (var ticket in list)
                     *           {
                     *               if (minTicket != null)
                     *               {
                     *                   if (ticket.Denomination < minTicket.Denomination)
                     *                   {
                     *                       minTicket = ticket;
                     *                   }
                     *               }
                     *               else
                     *               {
                     *                   minTicket = ticket;
                     *               }
                     *           }
                     *           minList.Add(minTicket);
                     *           list.Remove(minTicket);
                     *       }
                     *   }
                     *
                     *   if (minList != null)
                     *   {
                     *       foreach (var minItem in minList)
                     *       {
                     *           //买入的优惠券
                     *           moneyBuyByTicket += minItem.Denomination;
                     *       }
                     *   }
                     * }*/
                }
            }


            /*if (originalRetailCostume.RetailDetailList.Count > costume.RefundDetailList.Count)
             * {
             *  //有未打钩的,加上
             *  List<RetailDetail> notRefundList = new List<RetailDetail>();
             *  //原始单,要过滤有退货的款
             *  notRefundList.AddRange(originalRetailCostume.RetailDetailList);
             *  foreach (var refund in costume.RefundDetailList)
             *  {
             *      RetailDetail retailDetail = notRefundList.Find(item => refund.CostumeID.ToUpper() == item.CostumeID.ToUpper() && refund.ColorName == item.ColorName && refund.SizeName == item.SizeName);
             *      notRefundList.Remove(retailDetail);
             *  }
             *
             *  //过滤后剩下没有勾选的款,notRefundList
             *
             *
             *  //添加所有的优惠券
             *
             *  //不退的优惠券,就是买的那几件的优惠券
             *  if (notRefundList != null)
             *  {
             *      foreach (var item in notRefundList)
             *      {
             *          if (!String.IsNullOrEmpty(item.GiftTickets))
             *          {
             *              List<GiftTicket> list = GlobalCache.ServerProxy.GetGiftTicket4RetailDetail(item.GiftTickets);
             *              foreach (var ticket in list)
             *              {
             *                  moneyBuyByTicket += ticket.Denomination;
             *              }
             *          }
             *      }
             *  }
             * }
             */
            return(moneyBuyByTicket);
        }
Esempio n. 6
0
        private void BaseButton_ConfirmRefund_Click(object sender, EventArgs e)
        {
            try
            {
                if (originalRetailCostume == null)
                {
                    GlobalMessageBox.Show("请选择销售单!");
                    return;
                }
                if (!string.IsNullOrEmpty(this.originalRetailCostume.RetailOrder.RefundOrderID))
                {
                    GlobalMessageBox.Show("该销售单号已经退过货,不能再次退货!");
                    return;
                }
                if (this.originalRetailCostume.RetailOrder.IsCancel)
                {
                    GlobalMessageBox.Show("该销售单号已被冲单!");
                    return;
                }

                if (this.guideComboBox1.SelectedIndex == 0)
                {
                    GlobalMessageBox.Show("该笔单的导购员不能为空!");
                    return;
                }
                string id = IDHelper.GetID(OrderPrefix.RefundOrder, GlobalCache.GetShop(shopID).AutoCode);

                //if (this.currentRetailCostume.RetailOrder.ShopID != shopID || this.currentRetailCostume.RetailOrder.EmOnline)
                //{
                //    GlobalMessageBox.Show("该商品不是在本店销售的,不能退货!");
                //    return;
                //}
                bool isNoHasGuidFlag = false;
                if (this.currentRetailCostume.RetailDetailList != null && this.currentRetailCostume.RetailDetailList.Count > 0)
                {
                    foreach (RetailDetail detail in this.currentRetailCostume.RetailDetailList)
                    {
                        if (detail.GuideID == null || detail.GuideID == "")
                        {
                            isNoHasGuidFlag = true;
                            break;
                        }
                    }
                }
                if (isNoHasGuidFlag)
                {
                    GlobalMessageBox.Show("导购员不能为空,请检查列表里所有款号的导购员!");
                    return;
                }

                #region 创建RefundCostume对象


                string selectShopid = ValidateUtil.CheckEmptyValue(this.skinComboBoxShopID.SelectedValue);

                List <Guide> guideList = CommonGlobalCache.GuideList.FindAll(t => t.State == 0 && t.ShopID == selectShopid);

                this.GuideName.DataSource    = guideList;
                this.GuideName.DisplayMember = "Name";
                this.GuideName.ValueMember   = "ID";

                RefundCostume costume = new RefundCostume()
                {
                    RefundOrder      = null,
                    RefundDetailList = new List <RetailDetail>()
                };
                int     totalCount = 0;
                decimal totalPrice = 0;
                decimal totalCost  = 0;
                foreach (RetailDetail detail in this.currentRetailCostume.RetailDetailList)
                {
                    if (detail.IsRefund && detail.RefundCount > 0)
                    {
                        totalCount += detail.RefundCount;
                        totalPrice += detail.RefundCount * detail.Price;
                        totalCost  += detail.RefundCount * detail.CostPrice;

                        costume.RefundDetailList.Add(this.RetailDetailToRefundDetail(detail, id));
                    }
                }
                List <String> costumeIds = new List <string>();
                foreach (var item in costume.RefundDetailList)
                {
                    if (!costumeIds.Contains(item.CostumeID))
                    {
                        costumeIds.Add(item.CostumeID);
                    }
                }

                if (costumeIds != null && costumeIds.Count > 0)
                {
                    //判断是否又禁用的商品,并提示返回
                    InteractResult interactResult = GlobalCache.ServerProxy.IsCostumeValid(costumeIds);
                    if (interactResult.ExeResult == ExeResult.Error)
                    {
                        GlobalMessageBox.Show(interactResult.Msg);
                        return;
                    }
                }

                RetailOrder refundOrder = new RetailOrder()
                {
                    ID            = id,
                    IsRefundOrder = true,
                    OriginOrderID = this.currentRetailCostume.RetailOrder.ID,
                    // GuideID = this.currentRetailCostume.RetailOrder.GuideID,
                    //  OperateGuideID = this.currentRetailCostume.RetailOrder.GuideID,
                    GuideID          = (string)this.guideComboBox1.SelectedValue,
                    ShopID           = shopID,
                    MemeberID        = this.currentRetailCostume.RetailOrder.MemeberID,
                    SalesPromotionID = this.currentRetailCostume.RetailOrder.SalesPromotionID,
                    PromotionText    = this.currentRetailCostume.RetailOrder.PromotionText,
                    EntryUserID      = CommonGlobalCache.CurrentUserID,
                    //   TotalMoneyReceived = this.currentRetailCostume.RetailOrder.TotalMoneyReceived,
                    // TotalMoneyReceivedActual = this.currentRetailCostume.RetailOrder.TotalMoneyReceivedActual,
                    MoneyBankCard     = 0,
                    MoneyWeiXin       = 0,
                    MoneyAlipay       = 0,
                    MoneyOther        = 0,
                    SmallMoneyRemoved = 0,
                    MoneyChange       = 0,
                    TotalCount        = totalCount * -1,
                    TotalCost         = totalCost * -1,
                    TotalPrice        = totalPrice * -1,
                    MoneyDiscounted   = -totalCount == this.originalRetailCostume.RetailOrder.TotalCount ? this.originalRetailCostume.RetailOrder.MoneyDiscounted * -1 : 0,//若是全部退款,折扣金额为原始折扣金额,否则为0
                    Remarks           = this.skinTextBox_RefundReason.SkinTxt.Text.Trim(),
                    CreateTime        = dateTimePicker_Start.Value,
                    EntryTime         = DateTime.Now,
                    IsNotPay          = this.currentRetailCostume.RetailOrder.IsNotPay,
                };
                costume.RefundOrder = refundOrder;
                #endregion
                decimal sourceTotalMoneyReceived = this.currentRetailCostume.RetailOrder.TotalMoneyReceived;

                #region 根据活动获取退款的金额,并赋值给RefundCostume
                decimal originalDonate = 0;
                if (this.originalRetailCostume.RetailOrder.MoneyVipCard != 0)
                {
                    originalDonate = this.originalRetailCostume.RetailOrder.MoneyVipCardDonate / this.originalRetailCostume.RetailOrder.MoneyVipCard;
                }
                //应该退还的金额

                decimal moneyBuyByTicket = CalGiftTicket(costume);

                SettlementMoney settlementMoney = new SettlementMoney(balanceRound);

                RefundMoney refundMoney = settlementMoney.GetRefundMoney(this.originalRetailCostume, costume, moneyBuyByTicket, GlobalCache.GetSalesPromotionFromAll(this.originalRetailCostume.RetailOrder.SalesPromotionID), GlobalCache.CurrentShop.MinDiscount);
                costume.RefundOrder.MoneyCash          = refundMoney.RefundCash * -1;
                costume.RefundOrder.MoneyCash2         = costume.RefundOrder.MoneyCash;
                costume.RefundOrder.MoneyIntegration   = refundMoney.RefundIntegration * -1;
                costume.RefundOrder.MoneyVipCard       = refundMoney.RefundStoredCard * -1;
                costume.RefundOrder.MoneyVipCardMain   = refundMoney.RefundStoredCard * (1 - originalDonate) * -1;
                costume.RefundOrder.MoneyVipCardDonate = refundMoney.RefundStoredCard * originalDonate * -1;
                //costume.RefundOrder.MoneyBuyByTicket = moneyBuyByTicket;
                costume.RefundOrder.RetailMoneyDeductedByTicket = originalRetailCostume.RetailOrder.MoneyDeductedByTicket;
                costume.RefundOrder.MoneyDeductedByTicket       = moneyBuyByTicket;

                //总计=现金+积分+VIP卡+优惠券
                //这笔单的应收金额 - (不退的那几件以原价* 数量 -满减金额) - (退的那几件)优惠券
                costume.RefundOrder.TotalMoneyReceived       = costume.RefundOrder.MoneyCash + costume.RefundOrder.MoneyIntegration + costume.RefundOrder.MoneyVipCard;
                costume.RefundOrder.TotalMoneyReceivedActual = costume.RefundOrder.MoneyCash + costume.RefundOrder.MoneyVipCardMain;
                costume.RefundOrder.Benefit = costume.RefundOrder.TotalMoneyReceivedActual - costume.RefundOrder.TotalCost;
                ////平摊

                #endregion
                if (Math.Abs(costume.RefundOrder.TotalCount) < 1)
                {
                    GlobalMessageBox.Show("退货数量不能小于1");
                    return;
                }


                //foreach (RetailDetail detail in costume.RefundDetailList)
                //{
                //    if (detail.IsRefund && detail.RefundCount > 0)
                //    {
                //        detail.SinglePrice = detail.SumMoney / detail.BuyCount * -1;
                //    }
                //}

                ConfirmRefundForm confirmRefundForm = new ConfirmRefundForm(costume, shopID, this.dataGridView1, sourceTotalMoneyReceived, 1);
                DialogResult      result            = confirmRefundForm.ShowDialog();
                if (result == DialogResult.Cancel)
                {
                    return;
                }
                this.ResetForm();
            }
            catch (Exception ee)
            {
                GlobalUtil.ShowError(ee);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// 获取退货后退款情况
        /// </summary>
        /// <param name="retailCostume"></param>
        /// <param name="refundCostume"></param>
        /// <param name="salesPromotion"></param>
        /// <returns></returns>
        public RefundMoney GetRefundMoney(RetailCostume retailCostume, RefundCostume refundCostume, decimal moneyBuyByTicket, SalesPromotion salesPromotion, decimal minDiscount)
        {
            if (retailCostume.RetailOrder.ID != refundCostume.RefundOrder.OriginOrderID)
            {
                throw new Exception("销售单的id与退货单id不一致");
            }
            else
            {
                /* foreach (RetailDetail rDetailSource in retailCostume.RetailDetailList)
                 * {
                 *   foreach (RetailDetail rDetailRe in refundCostume.RefundDetailList)
                 *   {
                 *       if (rDetailSource.RetailOrderID == refundCostume.RefundOrder.OriginOrderID  && rDetailSource.CostumeID == rDetailRe.CostumeID
                 *           && rDetailSource.ColorName==rDetailRe.ColorName && rDetailSource.BrandName==rDetailRe.BrandName && rDetailSource.SizeName==rDetailRe.SizeName)
                 *       {
                 *           rDetailSource.SalePrice = rDetailRe.SalePrice;
                 *       }
                 *   }
                 * }*/
            }
            if (retailCostume.RetailOrder.IsNotPay)
            {
                return(new RefundMoney());
            }

            Dictionary <string, RetailCostumeInfo>           retailDictionary     = new Dictionary <string, RetailCostumeInfo>();
            Dictionary <string, InSalesPromotionCostumeInfo> inSalesPromotionDict = new Dictionary <string, InSalesPromotionCostumeInfo>();

            //有活动的时候没有打折
            this.GetRetailStatus(retailCostume, retailDictionary, inSalesPromotionDict);

            Dictionary <string, int> refundDict = this.GetRefundStatus(refundCostume);

            foreach (KeyValuePair <string, int> kvp in refundDict)
            {
                if (retailDictionary.ContainsKey(kvp.Key))
                {
                    retailDictionary[kvp.Key].BuyCount += kvp.Value;
                }
                else if (inSalesPromotionDict.ContainsKey(kvp.Key))
                {
                    inSalesPromotionDict[kvp.Key].BuyCount += kvp.Value;
                }
            }

            decimal supporedMoney = this.GetTotalMoneySupposed(retailDictionary, inSalesPromotionDict, salesPromotion, minDiscount);
            // 应收金额(因为要退积分,不能去掉)+要买的那件衣服的优惠券-总的优惠金额-结算销售单的应收金额-运费
            decimal refundMoney = retailCostume.RetailOrder.TotalMoneyReceived + moneyBuyByTicket - retailCostume.RetailOrder.MoneyDeductedByTicket
                                  - supporedMoney - retailCostume.RetailOrder.CarriageCost;

            if (refundMoney <= 0)
            {
                return(new RefundMoney());
            }

            if (refundMoney <= retailCostume.RetailOrder.MoneyIntegration)
            {
                return(new RefundMoney()
                {
                    RefundIntegration = refundMoney,
                    RefundStoredCard = 0,
                    RefundCash = 0
                });
            }
            else
            {
                refundMoney -= retailCostume.RetailOrder.MoneyIntegration;
                if (refundMoney <= retailCostume.RetailOrder.MoneyVipCard)
                {
                    return(new RefundMoney()
                    {
                        RefundIntegration = retailCostume.RetailOrder.MoneyIntegration,
                        RefundStoredCard = refundMoney,
                        RefundCash = 0
                    });
                }
                else
                {
                    refundMoney -= retailCostume.RetailOrder.MoneyVipCard;
                    return(new RefundMoney()
                    {
                        RefundIntegration = retailCostume.RetailOrder.MoneyIntegration,
                        RefundStoredCard = retailCostume.RetailOrder.MoneyVipCard,
                        RefundCash = refundMoney
                    });
                }
            }
        }
Esempio n. 8
0
        private static void setPrintDataGridView(RefundCostume item, DataGridView dataGridView2, PrintTemplateType type)
        {
            InteractResult <PrintTemplateInfo> result = CommonGlobalCache.ServerProxy.GetPrintTemplateInfo(type);

            //行列数基本不受限制,但超过一页失去意义,因为以Body为主,以其它为辅
            //   Header header = new Header(4, 2);
            //可以指定每页是否重复打印
            if (result.ExeResult == ExeResult.Success)
            {
                PrintTemplateInfo CurrentPTemplate = result.Data;
                for (int c = 0; c < CurrentPTemplate.PrintCount; c++)
                {
                    MisGoldPrinterOfReWrite misGoldPrinter = new MisGoldPrinterOfReWrite(false, new PrinterMargins(20, 20, 20, 20, 800, 1129));


                    misGoldPrinter.Title = CurrentPTemplate.OrderName; //主标题(C#用\n表示换行)	}

                    misGoldPrinter.Caption = "";

                    double headRow = Math.Round(Convert.ToSingle(CurrentPTemplate.SystemVariables.Count / 2));

                    Header header = new Header(Convert.ToInt32(headRow) + 1, 2);
                    // CommonGlobalUtil.WriteLog("变量总数=" + CurrentPTemplate.SystemVariables.Count + "\r\n" + "应显示行号=" + headRow);
                    header.IsDrawAllPage = true;
                    #region
                    Member _member = null;
                    if (item.RefundOrder.MemeberID != null)
                    {
                        _member = CommonGlobalCache.ServerProxy.GetOneMember(item.RefundOrder.MemeberID);
                    }
                    for (int i = 0; i < CurrentPTemplate.SystemVariables.Count; i++)
                    {
                        int curR = 0;
                        if (i < 2)
                        {
                            curR = 0;
                        }
                        else
                        {
                            double resRow = i / 2;
                            curR = Convert.ToInt32(Math.Round(resRow));
                        }
                        string KeyStr = "";
                        if (CurrentPTemplate.SystemVariables[i] == "销售单号")
                        {
                            KeyStr = "销售单号:";
                            header.SetText(curR, i % 2, CurrentPTemplate.SystemVariables[i] + ":" + item.RefundOrder.ID);
                        }
                        else if (CurrentPTemplate.SystemVariables[i] == "单据日期")
                        {
                            KeyStr = "单据日期:";
                            header.SetText(curR, i % 2, KeyStr + item.RefundOrder.CreateTime.GetDateTimeFormats('f')[0].ToString());
                        }
                        else if (CurrentPTemplate.SystemVariables[i] == "客户名称")
                        {
                            KeyStr = "客户名称:";
                            string userName = string.Empty;
                            if (_member != null)
                            {
                                userName = _member.Name;
                            }
                            header.SetText(curR, i % 2, KeyStr + userName);
                        }
                        else if (CurrentPTemplate.SystemVariables[i] == "客户电话")
                        {
                            KeyStr = "客户电话:";
                            string tel = string.Empty;
                            if (_member != null)
                            {
                                tel = _member.PhoneNumber;
                            }
                            header.SetText(curR, i % 2, KeyStr + tel);
                        }
                        else if (CurrentPTemplate.SystemVariables[i] == "客户地址")
                        {
                            KeyStr = "客户地址:";

                            string address = string.Empty;
                            if (_member != null)
                            {
                                address = _member.DetailAddress;
                            }
                            header.SetText(curR, i % 2, KeyStr + address);
                        }
                        else if (CurrentPTemplate.SystemVariables[i] == "操作人")
                        {
                            KeyStr = "操 作 人:";
                            header.SetText(curR, i % 2, KeyStr + CommonGlobalCache.GetUserName(item.RefundOrder.GuideID));
                        }
                        else if (CurrentPTemplate.SystemVariables[i] == "单据备注")
                        {
                            KeyStr = "备    注:";
                            header.SetText(curR, i % 2, KeyStr + item.RefundOrder.Remarks.ToString());
                        }
                    }
                    #endregion

                    misGoldPrinter.Header = header;

                    // List<PrintColumnInfo> dataGV = CurrentPTemplate.PrintColumnInfos;


                    List <PrintColumnInfo> dataGV           = new List <PrintColumnInfo>();
                    PrintColumnInfo        prinAutoIDColumn = new PrintColumnInfo();
                    prinAutoIDColumn.Name = "序列号";
                    prinAutoIDColumn.Rate = 5;
                    dataGV.Add(prinAutoIDColumn);
                    dataGV.AddRange(CurrentPTemplate.PrintColumnInfos);

                    string ColumnsList = string.Empty;
                    foreach (PrintColumnInfo itemC in dataGV)
                    {
                        ColumnsList += itemC.Name + ",";
                    }
                    CommonGlobalUtil.WriteLog("模板设置打印列表头为=" + ColumnsList + "\r\n");
                    //表格是否为零条记录
                    bool isflag = false;
                    if (dataGV.Count == 0)
                    {
                        isflag = true;
                    }

                    List <int> columnCount         = new List <int>();
                    int        pinrtColNum         = 0;
                    string     dataGridColumnsList = string.Empty;
                    if (dataGridView2.Columns.Count > 0)
                    {
                        for (int i = 0; i < dataGridView2.Columns.Count; i++)
                        {
                            DataGridViewColumn column = dataGridView2.Columns[i];

                            if (dataGV.FindAll(t => t.Name == column.HeaderText).Count > 0)
                            {
                                columnCount.Add(i);
                                dataGridColumnsList += column.HeaderText + ",";
                                pinrtColNum++;
                            }
                            else
                            {
                                if (dataGV.FindAll(t => t.Name == column.DataPropertyName).Count > 0)
                                {
                                    columnCount.Add(i);
                                    column.HeaderText    = column.HeaderText.Replace("\r\n", " ");
                                    dataGridColumnsList += column.DataPropertyName + ",";
                                    pinrtColNum++;
                                }
                                else
                                {
                                    if (column.DataPropertyName.Contains("XL"))
                                    {
                                        string name = column.DataPropertyName;  //XL3
                                                                                //3XL
                                        string newname  = name.Replace("XL", "");
                                        string checkstr = newname + "XL";
                                        if (dataGV.FindAll(t => t.Name == checkstr).Count > 0)
                                        {
                                            columnCount.Add(i);
                                            column.HeaderText    = column.HeaderText.Replace("\r\n", " ");
                                            dataGridColumnsList += column.DataPropertyName + ",";
                                            pinrtColNum++;
                                        }
                                        else
                                        {
                                            column.Visible = false;
                                        }
                                    }
                                    else
                                    {
                                        column.Visible = false;
                                    }
                                }
                            }
                            if (isflag)
                            {
                                if (i == 0)
                                {
                                    //打印设置模板不设置任何列,但由于MisGoldPrinter这个类的打印主体为DataGridView,所有必须设置一列默认空的
                                    columnCount.Add(i);
                                    column.Visible    = true;
                                    column.HeaderText = "";

                                    DataTable  dt = new DataTable();
                                    DataColumn c1 = new DataColumn();
                                    c1.ColumnName = "HeaderText";

                                    dt.Columns.Add(c1);
                                    dataGridView2.DataSource = null;
                                    dataGridView2.DataSource = dt;
                                }
                            }
                            //}
                        }

                        CommonGlobalUtil.WriteLog("DataGridView能打印的列为=" + dataGridColumnsList);


                        MultiHeader multiHeader = new MultiHeader(1, dataGV.Count);
                        for (int a = 0; a < dataGV.Count; a++)
                        {
                            multiHeader.SetText(0, a, dataGV[a].Name);
                        }


                        misGoldPrinter.DataSource        = DataGridViewUtil.ToStringArray(dataGridView2, false, true);
                        misGoldPrinter.RowsPerPage       = CurrentPTemplate.Rows + 1; //根据设置传值
                        misGoldPrinter.IsSubTotalPerPage = true;
                        int footerRowsNum = 0;
                        if (((GoldPrinter.Body)(misGoldPrinter.Body)).Rows >= 2)
                        {
                            footerRowsNum = ((GoldPrinter.Body)(misGoldPrinter.Body)).Rows;
                        }
                        else
                        {
                            footerRowsNum = 2;
                        }

                        Footer footer         = new Footer(footerRowsNum, dataGV.Count);
                        int    colIndex       = -1;
                        int    colIndexSecond = -1;
                        for (int b = 0; b < dataGV.Count; b++)
                        {
                            if (dataGV[b].Name == "金额")
                            {
                                colIndex = b;
                            }
                            if (dataGV[b].Name == "数量")
                            {
                                colIndexSecond = b;
                            }
                        }
                        string addressStr = string.Empty;
                        for (int a = 0; a < CurrentPTemplate.SystemVariables.Count; a++)
                        {
                            //if (dataGridView2.Rows.Count >= 2)
                            //{
                            if (CurrentPTemplate.SystemVariables[a] == "店铺地址")
                            {
                                Shop curShop = CommonGlobalCache.GetShop(item.RefundOrder.ShopID);
                                if (curShop != null)
                                {
                                    footer.SetText(0, 0, "店铺地址:" + curShop.Address);
                                }
                            }
                            if (CurrentPTemplate.SystemVariables[a] == "联系电话")
                            {
                                Shop curShop = CommonGlobalCache.GetShop(item.RefundOrder.ShopID);
                                if (curShop != null)
                                {
                                    footer.SetText(1, 0, "联系电话:" + curShop.PhoneNumber);
                                }
                            }
                            //}
                            //else if(dataGridView2.Rows.Count >= 1)
                            //{

                            //    if (CurrentPTemplate.SystemVariables[a] == "店铺地址")
                            //    {
                            //        if (item.RefundOrder.ShopID != null && item.RefundOrder.ShopID != "_online")
                            //        {
                            //            addressStr += "店铺地址:" + CommonGlobalCache.GetShop(item.RefundOrder.ShopID).Address;
                            //        }
                            //    }
                            //    if (CurrentPTemplate.SystemVariables[a] == "联系电话")
                            //    {
                            //        if (addressStr != string.Empty)
                            //        {
                            //            addressStr += "       ";
                            //        }
                            //        if (item.RefundOrder.ShopID != null && item.RefundOrder.ShopID != "_online")
                            //        {
                            //            addressStr += "联系电话:" + CommonGlobalCache.GetShop(item.RefundOrder.ShopID).PhoneNumber;
                            //        }
                            //    }

                            //}
                        }

                        //if (dataGridView2.Rows.Count == 1)
                        //{
                        //    footer.SetText(0, 0, addressStr);
                        //}
                        MoneyConvertChinese MConvertC = new MoneyConvertChinese();
                        //if (dataGridView2.Rows.Count > 1)
                        //{
                        //    footer.SetText(0, 0, "合计 金额大写 " + MConvertC.MoneyToChinese(item.RefundOrder.TotalMoneyReceived.ToString()));

                        //}
                        //else
                        //{
                        //    footer.SetText(0, 0, addressStr+ " 合计 金额大写 " + MConvertC.MoneyToChinese(item.RefundOrder.TotalMoneyReceived.ToString()));

                        //}

                        misGoldPrinter.EndSubTotalColsList = MConvertC.MoneyToChinese(item.RefundOrder.TotalMoneyReceived.ToString()) + ":" + item.RefundOrder.TotalMoneyReceived.ToString();
                        //  footer.SetText(0, 1, "合计:" + item.RefundOrder.TotalMoneyReceived);

                        /*  if (dataGridView2.Rows.Count > 1 )
                         * {
                         *    //if (dataGV.Count >= 2)
                         *    //{
                         *
                         *        footer.SetText(1, 1, "合计:" + item.RefundOrder.TotalMoneyReceived);
                         *    //}
                         *    //else
                         *    //{
                         *
                         *    //    footer.SetText(1, dataGV.Count, "合计:" + item.RefundOrder.TotalMoneyReceived);
                         *    //}
                         * }
                         * else
                         * {
                         *    //if (dataGV.Count >= 2)
                         *    //{
                         *        footer.SetText(0, 1, "合计:" + item.RefundOrder.TotalMoneyReceived);
                         *    //}
                         *    //else
                         *    //{
                         *
                         *    //    footer.SetText(0, dataGV.Count, "合计:" + item.RefundOrder.TotalMoneyReceived);
                         *    //}
                         * }*/

                        // PrinterBase pbase = footer.CalculatePageInfo();

                        //if (Math.Ceiling((decimal)dataGridView2.Rows.Count / CurrentPTemplate.Rows) > 1)
                        //{
                        //    footer.IsDrawAllPage = false;
                        //}
                        //else
                        //{

                        //    footer.IsDrawAllPage = true;
                        //}


                        misGoldPrinter.IsTotalIsDrawAllPage = false;
                        footer.IsDrawAllPage = false;


                        Bottom bottom = new Bottom();

                        bottom.IsDrawAllPage = true;

                        // bottom.TopMargin
                        // bottom.SetText("联系电话:"+CommonGlobalCache.GetShop(item.RetailOrder.ShopID).PhoneNumber);

                        misGoldPrinter.SubTotalColsList = (colIndex).ToString() + ";" + (colIndexSecond).ToString();      //用分号分隔的要求小计的列

                        /*   if (!Directory.Exists(CommonGlobalUtil.SystemDir + "EXPORTS\\"))
                         * {
                         * Directory.CreateDirectory(CommonGlobalUtil.SystemDir + "EXPORTS\\");
                         * }
                         * misGoldPrinter.FileName = CommonGlobalUtil.SystemDir + "EXPORTS\\" + item.RetailOrder.ID + ".jpg";*/
                        ((GoldPrinter.Body)(misGoldPrinter.Body)).Font = dataGridView2.Font;


                        int[] widths = new int[dataGV.Count];
                        for (int j = 0; j < dataGV.Count; j++)
                        {
                            widths[j] = Convert.ToInt32(dataGV[j].Rate);
                        }

                        List <int> widthList = new List <int>();

                        /*   for (int i = 0; i < CurrentPTemplate.PrintColumnInfos.Count; i++)
                         * {
                         *     DataGridViewColumn column = dataGridView2.Columns[columnCount[i]];
                         *     if (column.Visible && !String.IsNullOrEmpty(column.HeaderText))
                         *     {
                         *         widthList.Add(widths[i]);
                         *     }
                         *
                         * }*/
                        if (isflag)
                        {
                            widths    = new int[1];
                            widths[0] = 100;
                            // widthList.Add(widths[0]);
                        }

                        //   widths = widthList.ToArray();
                        int newWidth = 800;

                        /*  int totalWidth = 0;
                         * for (int i = 0; i < widths.Length; i++)
                         * {
                         *    totalWidth += widths[i];
                         * }*/
                        //if (dataGridView2.Columns.Count > 0)
                        //{
                        for (int i = 0; i < widths.Length; i++)
                        {
                            widths[i] = decimal.ToInt32(Math.Round((widths[i] * newWidth * (decimal)0.1), 0, MidpointRounding.AwayFromZero));
                            // widths[i] = decimal.ToInt32(Math.Round((widths[i] * newWidth * (decimal)1.0 / totalWidth), 0, MidpointRounding.AwayFromZero));
                        }
                        CommonGlobalUtil.WriteLog("实际打印数量=" + pinrtColNum + "\r\n" + "设置能打印的列数量=" + widths.Length.ToString());

                        /*    bottomFooter.ColsWidth = widths;*/
                        footer.ColsWidth      = widths;
                        misGoldPrinter.Footer = footer;
                        /* misGoldPrinter.BottomFooter = bottomFooter;*/
                        misGoldPrinter.Bottom      = bottom;
                        multiHeader.ColsWidth      = widths;
                        misGoldPrinter.MultiHeader = multiHeader;
                        multiHeader.ColsWidth      = widths;

                        ((GoldPrinter.Body)(misGoldPrinter.Body)).IsAverageColsWidth = false;
                        ((GoldPrinter.Body)(misGoldPrinter.Body)).ColsWidth          = widths;
                        misGoldPrinter.Preview();
                        misGoldPrinter.Dispose();
                        misGoldPrinter = null;
                    }
                }
            }
        }
Esempio n. 9
0
        private void baseButton3_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.guideComboBox1.SelectedIndex == 0)
                {
                    GlobalMessageBox.Show("该笔单的导购员不能为空!");
                    return;
                }

                string id = IDHelper.GetID(OrderPrefix.RefundOrder, CommonGlobalCache.GetShop(shopID).AutoCode);

                bool isNoHasGuidFlag = false;
                bool isSuperlen      = false;
                if (this.retailDetailList != null && this.retailDetailList.Count > 0)
                {
                    foreach (RetailDetail detail in this.retailDetailList)
                    {
                        if (detail.GuideID == null || detail.GuideID == "")
                        {
                            isNoHasGuidFlag = true;
                            break;
                        }
                        if (Math.Abs(detail.SumMoney) > 0 && Math.Abs(detail.SumMoney) > Convert.ToDecimal(99999999.99))
                        {
                            isSuperlen = true;
                            break;
                        }
                    }
                }

                if (isNoHasGuidFlag)
                {
                    GlobalMessageBox.Show("导购员不能为空,请检查列表里所有款号的导购员!");
                    return;
                }
                if (isSuperlen)
                {
                    GlobalMessageBox.Show("请检查列表里所有款号的金额是否大于99999999.99!");
                    return;
                }


                #region 创建RefundCostume对象


                RefundCostume costume = new RefundCostume()
                {
                    RefundOrder      = null,
                    RefundDetailList = new List <RetailDetail>()
                };
                int     totalCount = 0;
                decimal totalPrice = 0;
                decimal totalCost  = 0;
                decimal moneyCash  = 0;
                foreach (RetailDetail detail in this.
                         retailDetailList)
                {
                    if (detail.IsRefund && detail.RefundCount > 0)
                    {
                        detail.Refunded  = true;
                        totalCount      += detail.RefundCount;
                        totalPrice      += detail.RefundCount * detail.Price;
                        totalCost       += detail.RefundCount * detail.CostPrice;
                        moneyCash       += detail.SumMoney;
                        detail.SalePrice = detail.Price;
                        costume.RefundDetailList.Add(this.RetailDetailToRefundDetail(detail, id));
                    }
                }

                List <String> costumeIds = new List <string>();
                foreach (var item in costume.RefundDetailList)
                {
                    if (!costumeIds.Contains(item.CostumeID))
                    {
                        costumeIds.Add(item.CostumeID);
                    }
                }

                if (costumeIds != null && costumeIds.Count > 0)
                {
                    //判断是否又禁用的商品,并提示返回
                    InteractResult interactResult = GlobalCache.ServerProxy.IsCostumeValid(costumeIds);
                    if (interactResult.ExeResult == ExeResult.Error)
                    {
                        GlobalMessageBox.Show(interactResult.Msg);
                        return;
                    }
                }

                RetailOrder refundOrder = new RetailOrder()
                {
                    ID            = id,
                    IsRefundOrder = true,
                    OriginOrderID = string.Empty,
                    //GuideID = (string)("-1".Equals(this.guideComboBox2.SelectedValue) ? string.Empty : this.guideComboBox2.SelectedValue),
                    //  OperateGuideID = (string)this.guideComboBox1.SelectedValue,
                    GuideID          = (string)this.guideComboBox1.SelectedValue,
                    ShopID           = shopID,
                    MemeberID        = this.memberIDTextBox2.Text,
                    SalesPromotionID = string.Empty,
                    PromotionText    = string.Empty,
                    //   TotalMoneyReceived = this.currentRetailCostume.RetailOrder.TotalMoneyReceived,
                    // TotalMoneyReceivedActual = this.currentRetailCostume.RetailOrder.TotalMoneyReceivedActual,
                    MoneyBankCard     = 0,
                    MoneyWeiXin       = 0,
                    MoneyOther        = 0,
                    MoneyAlipay       = 0,
                    SmallMoneyRemoved = 0,
                    MoneyChange       = 0,
                    TotalCount        = totalCount * -1,
                    TotalCost         = totalCost * -1,
                    TotalPrice        = totalPrice * -1,
                    EntryUserID       = CommonGlobalCache.CurrentUserID,
                    MoneyDiscounted   = 0,//若是全部退款,折扣金额为原始折扣金额,否则为0
                    Remarks           = this.skinTextBox_RefundReason.SkinTxt.Text.Trim(),
                    CreateTime        = DateTime.Now,
                };
                costume.RefundOrder = refundOrder;


                #endregion
                costume.RefundOrder.MoneyCash          = moneyCash * -1;
                costume.RefundOrder.MoneyCash2         = costume.RefundOrder.MoneyCash;
                costume.RefundOrder.MoneyIntegration   = 0;
                costume.RefundOrder.MoneyVipCard       = 0;
                costume.RefundOrder.MoneyVipCardMain   = 0;
                costume.RefundOrder.MoneyVipCardDonate = 0;
                costume.RefundOrder.CreateTime         = dateTimePicker_Start.Value;
                costume.RefundOrder.EntryTime          = DateTime.Now;
                //总计=现金+积分+VIP卡+优惠券
                //这笔单的应收金额 - (不退的那几件以原价* 数量 -满减金额) - (退的那几件)优惠券
                costume.RefundOrder.TotalMoneyReceived       = costume.RefundOrder.MoneyCash + costume.RefundOrder.MoneyIntegration + costume.RefundOrder.MoneyVipCard;
                costume.RefundOrder.TotalMoneyReceivedActual = costume.RefundOrder.MoneyCash + costume.RefundOrder.MoneyVipCardMain;
                costume.RefundOrder.Benefit = costume.RefundOrder.TotalMoneyReceivedActual - costume.RefundOrder.TotalCost;

                //     this.moneyDiscounted = costume.RefundOrder.to- costume.RefundOrder ;
                costume.IsNotHaveRetailOrder = true;
                if (Math.Abs(costume.RefundOrder.TotalCount) < 1)
                {
                    GlobalMessageBox.Show("退货数量不能小于1");
                    return;
                }
                ConfirmRefundForm confirmRefundForm = new ConfirmRefundForm(costume, shopID, dataGridView1);
                DialogResult      result            = confirmRefundForm.ShowDialog();
                if (result == DialogResult.Cancel)
                {
                    return;
                }
                this.ResetForm();
            }
            catch (Exception ee)
            {
                GlobalUtil.ShowError(ee);
            }
        }