//价格区间显示 private void gridviewPriceRange_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e) { if (e.ListSourceRowIndex < 0) { return; } IList <PriceRange> details = this.bsPriceAndRange.DataSource as IList <PriceRange>; if (details == null || details.Count < 1) { return; } PriceRange prcur = details[e.ListSourceRowIndex] as PriceRange; if (prcur != null) { switch (e.Column.Name) { case "gridColumn11": case "gridColumn15": e.DisplayText = prcur.endRange == 999999999999 ? "無限大" : prcur.endRange.ToString(); break; } } }
//解析价格区间 //DEMO: 0/0/0,0/0/0,0/0/0,0/0/0,0/0/0,0/0/0,0/999999999999/0 //Means: {起始数量/终止数量/价格} private void AnalyzePriceRange(string priceR) { if (string.IsNullOrEmpty(priceR)) { priceR = "1/999999999999/0"; } this._priceRangeList.Clear(); string[] inPriceR; if (priceR.Contains(',')) { inPriceR = priceR.Split(','); } else { inPriceR = new string[] { priceR } }; PriceRange pr = null; foreach (string s in inPriceR) { string[] prs = s.Split('/'); pr = new PriceRange(); pr.startRange = Convert.ToDouble(prs[0]); pr.endRange = Convert.ToDouble(prs[1]); pr.RangePrice = Convert.ToDouble(prs[2]); this._priceRangeList.Add(pr); } }
//检验价格区间是否正确 private void VerificationPriceRange() { IList <PriceRange> priceRList = this.bsPriceAndRange.DataSource as IList <PriceRange>; if (priceRList != null && priceRList.Count > 0) { try { if (priceRList.Last().endRange != 999999999999) { throw new Exception(); } double ComSR, ComER, ComPrice, InSr, InEr, InPrice; bool isContinue = true; PriceRange prFirst = priceRList.First(); ComSR = prFirst.startRange; ComER = prFirst.endRange; ComPrice = prFirst.RangePrice; foreach (PriceRange pr in priceRList) { InSr = pr.startRange; InEr = pr.endRange; InPrice = pr.RangePrice; if (priceRList.IndexOf(pr) == 0) { if (InSr != 1 || InPrice <= 0 || InSr > InEr) { throw new Exception(); } } else { if (InSr != ComER + 1 || InPrice <= 0 || InSr > InEr) { throw new Exception(); } } ComSR = pr.startRange; ComER = pr.endRange; InPrice = pr.RangePrice; } } catch { throw new Helper.InvalidValueException("PriceRange.Error"); } } }
//增加价格区间 private void grdConSupProcProPric_KeyDown(object sender, KeyEventArgs e) { if (this.action == "insert" || this.action == "update") { switch (e.KeyData) { case Keys.Enter: PriceRange pradd = this._priceRangeList.Last(); if (pradd.endRange != 999999999999) { this._priceRangeList.Add(new PriceRange { startRange = pradd.endRange + 1, endRange = 999999999999, RangePrice = 0 }); } break; case Keys.Delete: PriceRange prdel = this.bsPriceAndRange.Current as PriceRange; if (prdel.endRange != 999999999999) { int pr_index = this._priceRangeList.IndexOf(prdel); PriceRange prnext = this._priceRangeList[pr_index]; prnext.startRange = prdel.endRange + 1; this._priceRangeList.Remove(prdel); if (this._priceRangeList.Count == 0) { this._priceRangeList.Add(new PriceRange { startRange = 1, endRange = 999999999999, RangePrice = 0 }); } } break; } this.grdConSupProductPric.RefreshDataSource(); } }