/// <summary> /// 判断指定优惠设置是否与现有设置存在交叉,true:有交叉;false:没有交叉 /// </summary> /// <returns>Return a object of System.Boolean</returns> private bool TryParseCross(List <RangeValueItem> list, RangeValueItem info) { if (list == null || list.Count <= 0) { return(false); } bool state = false; foreach (RangeValueItem item in list) { if (info.LowerValue >= item.LowerValue && info.LowerValue < item.UpperValue) { state = true; break; } if (info.UpperValue > item.LowerValue && info.UpperValue <= item.UpperValue) { state = true; break; } } return(state); }
private void AddItem(RangeValueItem item) { //1. validation if (item == null) { return; } RowStyle rs = new RowStyle(SizeType.Absolute, 30F); tlpItems.RowStyles.Insert(this._RowIndex, rs); var txt1 = this.CreateTextBox(item.LowerValue.ToString("F2")); this._TxtLowerLimit.Add(txt1); tlpItems.Controls.Add(txt1, 0, this._RowIndex); var txt2 = this.CreateTextBox(item.UpperValue.ToString("F2")); this._TxtUpperLimit.Add(txt2); tlpItems.Controls.Add(txt2, 1, this._RowIndex); var txt3 = this.CreateTextBox(item.Value.ToString("F2")); this._TxtValue.Add(txt3); tlpItems.Controls.Add(txt3, 2, this._RowIndex); ////button var btn = this.CreateDelLinkBtn(this._RowIndex); tlpItems.Controls.Add(btn, 3, this._RowIndex); ////Scroll tlpItems.RowCount++; tlpItems.Width -= 1; tlpItems.Refresh(); this._RowIndex++; }
/// <summary> /// 验证读取优惠设置信息,true:验证成功,输入合法;false:验证失败,输入不合法 /// </summary> /// <param name="message">The message.</param> /// <param name="list">The list.</param> /// <returns>Return a object of System.Boolean</returns> private bool TryParseInput(out string message, List <RangeValueItem> list) { message = string.Empty; int len = this._TxtValue.Count(); if (len <= 0) { message = "不能保存空数据!"; return(false); } decimal lower; decimal upper; decimal value; RangeValueItem item; for (int i = 0; i < len; i++) { if (this._TxtLowerLimit[i] == null || this._TxtLowerLimit[i].Visible == false) { continue; } ////上限必须大于下限;不可有范围交叉 if (decimal.TryParse(this._TxtLowerLimit[i].Text.Trim(), out lower) && decimal.TryParse(this._TxtUpperLimit[i].Text.Trim(), out upper) && decimal.TryParse(this._TxtValue[i].Text.Trim(), out value) ) { item = new RangeValueItem(); item.LowerValue = lower; item.UpperValue = upper; item.Value = value; //判断交叉 if (this.TryParseCross(list, item)) { message = "范围设置与前面的范围设置存在交叉,请重新设置!"; this._TxtLowerLimit[i].Focus(); this._TxtLowerLimit[i].SelectAll(); return(false); } else { list.Add(item); } } else { this._TxtLowerLimit[i].Focus(); this._TxtLowerLimit[i].SelectAll(); string temp = message == string.Empty ? "上限必须大于下限,且输入必须为有效的数值类型" : message; message = "输入有误!" + temp; return(false); } } return(true); }