protected void tcField_NodeClick(object sender, TNodeEventArgs e) { try { if (e.Node.Attributes["IsEntity"] == "true") { return; } var model = new SysReportQueryField(); var _firstIndex = e.Node.Value.IndexOf('-'); model.Field1Id = e.Node.Value.Substring(0, _firstIndex).ToLong(); model.Relation1Id = e.Node.Value.Substring(_firstIndex + 1); var _Field1 = this.EntityCache.FindById <SysField>(model.Field1Id); model.DefaultDisplayText = string.Format("{0}-{1}", e.Node.Parent.Text, _Field1.DisplayText); model.QueryFieldId = this.DataHelper.GetNextIdentity_Int(); model.ReportId = this.__Id; model.FunctionType = (int)ReportFunctionTypeEnum.JustAdd; model.Field1Name = _Field1.FieldName; model.Aliases = _Field1.FieldName; //保证本报表中没有别名相同的,至于它具体是什么,不要在意细节啊~ while (this.DataHelper.FirstOrDefault <SysReportQueryField>(p => p.ReportId == this.__Id && p.Aliases == model.Aliases) != null) { model.Aliases = string.Format("{0}{1}", _Field1.FieldName, this.GetRandomCode()); } model.DisplayText = _Field1.DisplayText; this.DataHelper.Insert(model); InitGrid(); //清空选择 tcField.CheckedValue = new List <string>(); } catch (Exception ex) { this.AjaxAlert(ex); } }
protected void btnQueryFieldFuntion_Click(object sender, EventArgs e) { var _FunctionType = (sender as LinkButton).CommandArgument.ToInt(); var _SelectValue = this.gcList.SelectedValues; var model = new SysReportQueryField(); if (_SelectValue.Count != 2) { this.AjaxAlertAndEnableButton("查询字段的二次操作必须先选择两个已有的查询字段!"); return; } if (string.IsNullOrEmpty(this.tcDisplayTextSub.Text)) { this.AjaxAlertAndEnableButton("二次查询字段名称不能为空!"); return; } model.QueryFieldId = this.DataHelper.GetNextIdentity_Int(); model.ReportId = this.__Id; model.Field1Id = _SelectValue[0].ToLong(); model.Field2Id = _SelectValue[1].ToLong(); var _QueryField1 = this.DataHelper.FindById <SysReportQueryField>(model.Field1Id); var _QueryField2 = this.DataHelper.FindById <SysReportQueryField>(model.Field2Id); model.FunctionType = _FunctionType; model.Aliases = string.Format("{0}_{1}", _QueryField1.Aliases, _QueryField2.Aliases); //保证本报表中没有别名相同的,至于它具体是什么,不要在意细节啊~ while (this.DataHelper.FirstOrDefault <SysReportQueryField>(p => p.ReportId == this.__Id && p.Aliases == model.Aliases) != null) { model.Aliases = string.Format("{0}_{1}_{2}", _QueryField1.Aliases, _QueryField2.Aliases, this.GetRandomCode()); } model.DefaultDisplayText = string.Format("{0}{1}{2}", _QueryField1.DisplayText, EnumHelper.GetDescription(typeof(ReportFunctionTypeEnum), _FunctionType), _QueryField2.DisplayText); model.DisplayText = this.tcDisplayTextSub.Text; model.IsParent = true; this.DataHelper.Insert(model); InitGrid(); }
protected void btnFuntion_Click(object sender, EventArgs e) { try { var _FunctionType = (sender as LinkButton).CommandArgument.ToInt(); var _CheckedValue = this.tcField.CheckedValue; var model = new SysReportQueryField(); if (_CheckedValue.Count == 0) { this.AjaxAlertAndEnableButton("至少选择一个字段!"); return; } var _firstIndex = _CheckedValue[0].IndexOf('-'); model.Field1Id = _CheckedValue[0].Substring(0, _firstIndex).ToLong(); model.Relation1Id = _CheckedValue[0].Substring(_firstIndex + 1); var _Field1 = this.EntityCache.FindById <SysField>(model.Field1Id); var _CheckNode1 = this.tcField.GetNodeByValue(_CheckedValue[0]); switch ((ReportFunctionTypeEnum)_FunctionType) { case ReportFunctionTypeEnum.JustAdd: if (_CheckedValue.Count != 1) { this.AjaxAlertAndEnableButton("此功能只能且必须选择一个字段!"); return; } model.DefaultDisplayText = string.Format("{0}-{1}{2}", _CheckNode1.Parent.Text, _Field1.DisplayText, EnumHelper.GetDescription(typeof(ReportFunctionTypeEnum), _FunctionType)); break; case ReportFunctionTypeEnum.GetYear: case ReportFunctionTypeEnum.GetMonth: case ReportFunctionTypeEnum.GetDate: if (_CheckedValue.Count != 1) { this.AjaxAlertAndEnableButton("此功能只能且必须选择一个字段!"); return; } if (_Field1.DataType != (int)DataTypeEnum.pdatetime) { this.AjaxAlertAndEnableButton("此功能只支持日期类型字段!"); return; } model.DefaultDisplayText = string.Format("{0}-{1}{2}", _CheckNode1.Parent.Text, _Field1.DisplayText, EnumHelper.GetDescription(typeof(ReportFunctionTypeEnum), _FunctionType)); break; case ReportFunctionTypeEnum.Add: case ReportFunctionTypeEnum.Minus: case ReportFunctionTypeEnum.Mul: case ReportFunctionTypeEnum.Div: case ReportFunctionTypeEnum.ReDiv: case ReportFunctionTypeEnum.ReMinus: if (_CheckedValue.Count != 2) { this.AjaxAlertAndEnableButton("此功能只能且必须选择两个字段!"); return; } _firstIndex = _CheckedValue[1].IndexOf('-'); model.Field2Id = _CheckedValue[1].Substring(0, _firstIndex).ToLong(); model.Relation2Id = _CheckedValue[1].Substring(_firstIndex + 1); var _Field2 = this.EntityCache.FindById <SysField>(model.Field2Id); var _CheckNode2 = this.tcField.GetNodeByValue(_CheckedValue[1]); if (_Field1.DataType != (int)DataTypeEnum.pint && _Field1.DataType != (int)DataTypeEnum.plong && _Field1.DataType != (int)DataTypeEnum.pdecimal && _Field1.DataType != (int)DataTypeEnum.pfloat) { this.AjaxAlertAndEnableButton("此功能只支持数字类型字段!"); return; } if (_Field2.DataType != (int)DataTypeEnum.pint && _Field2.DataType != (int)DataTypeEnum.plong && _Field2.DataType != (int)DataTypeEnum.pdecimal && _Field2.DataType != (int)DataTypeEnum.pfloat) { this.AjaxAlertAndEnableButton("此功能只支持数字类型字段!"); return; } model.Field2Name = _Field2.FieldName; model.DefaultDisplayText = string.Format("({0}-{1}){2}({3}-{4})", _CheckNode1.Parent.Text, _Field1.DisplayText, EnumHelper.GetDescription(typeof(ReportFunctionTypeEnum), _FunctionType), _CheckNode2.Parent.Text, _Field2.DisplayText); break; } model.QueryFieldId = this.DataHelper.GetNextIdentity_Int(); model.ReportId = this.__Id; model.FunctionType = _FunctionType; model.Field1Name = _Field1.FieldName; model.Aliases = _Field1.FieldName; //保证本报表中没有别名相同的,至于它具体是什么,不要在意细节啊~ while (this.DataHelper.FirstOrDefault <SysReportQueryField>(p => p.ReportId == this.__Id && p.Aliases == model.Aliases) != null) { model.Aliases = string.Format("{0}{1}", _Field1.FieldName, this.GetRandomCode()); } model.DisplayText = this.tcDisplayText.Text; this.DataHelper.Insert(model); InitGrid(); //清空选择 tcField.CheckedValue = new List <string>(); this.AjaxAlertAndEnableButton(string.Empty); } catch (Exception ex) { this.AjaxAlertAndEnableButton(ex); } }
private string CreateSelect(SysReportQueryField _ReportQueryField) { var result = string.Empty; if (_ReportQueryField.IsParent == true) { var _ReportQueryField1 = this._ReportQueryFields.FirstOrDefault(p => p.QueryFieldId == _ReportQueryField.Field1Id); var _ReportQueryField2 = this._ReportQueryFields.FirstOrDefault(p => p.QueryFieldId == _ReportQueryField.Field2Id); switch ((ReportFunctionTypeEnum)_ReportQueryField.FunctionType) { case ReportFunctionTypeEnum.Add: result = string.Format("({0})+({1})", CreateSelect(_ReportQueryField1), CreateSelect(_ReportQueryField2)); break; case ReportFunctionTypeEnum.Div: result = string.Format("({0})/({1})", CreateSelect(_ReportQueryField1), CreateSelect(_ReportQueryField2)); break; case ReportFunctionTypeEnum.ReDiv: result = string.Format("({0})/({1})", CreateSelect(_ReportQueryField2), CreateSelect(_ReportQueryField1)); break; case ReportFunctionTypeEnum.Minus: result = string.Format("({0})-({1})", CreateSelect(_ReportQueryField1), CreateSelect(_ReportQueryField2)); break; case ReportFunctionTypeEnum.ReMinus: result = string.Format("({0})-({1})", CreateSelect(_ReportQueryField2), CreateSelect(_ReportQueryField1)); break; case ReportFunctionTypeEnum.Mul: result = string.Format("({0})*({1})", CreateSelect(_ReportQueryField1), CreateSelect(_ReportQueryField2)); break; } } else { var _Field = _entityCache.FindById <SysField>(_ReportQueryField.Field1Id); StringBuilder sb; switch ((ReportFunctionTypeEnum)_ReportQueryField.FunctionType) { case ReportFunctionTypeEnum.Add: result = string.Format("ISNULL({0}.{1},0) + ISNULL({2}.{3},0) ", GetTableAliase(_ReportQueryField.Relation1Id), _ReportQueryField.Field1Name, GetTableAliase(_ReportQueryField.Relation2Id), _ReportQueryField.Field2Name); break; case ReportFunctionTypeEnum.Div: result = string.Format("case {2}.{3} when 0 then 0 else {0}.{1}/{2}.{3} end ", GetTableAliase(_ReportQueryField.Relation1Id), _ReportQueryField.Field1Name, GetTableAliase(_ReportQueryField.Relation2Id), _ReportQueryField.Field2Name); break; case ReportFunctionTypeEnum.ReDiv: result = string.Format("case {2}.{3} when 0 then 0 else {0}.{1}/{2}.{3} end ", GetTableAliase(_ReportQueryField.Relation2Id), _ReportQueryField.Field2Name, GetTableAliase(_ReportQueryField.Relation1Id), _ReportQueryField.Field1Name); break; case ReportFunctionTypeEnum.GetDate: result = string.Format("CONVERT(varchar(10),{0}.{1},120) ", GetTableAliase(_ReportQueryField.Relation1Id), _ReportQueryField.Field1Name); break; case ReportFunctionTypeEnum.GetMonth: result = string.Format("CONVERT(varchar(7),{0}.{1},120)+'月' ", GetTableAliase(_ReportQueryField.Relation1Id), _ReportQueryField.Field1Name); break; case ReportFunctionTypeEnum.GetYear: result = string.Format("CONVERT(varchar(4),{0}.{1},120)+'年' ", GetTableAliase(_ReportQueryField.Relation1Id), _ReportQueryField.Field1Name); break; case ReportFunctionTypeEnum.JustAdd: //如果是枚举 if (_Field.DataType == (int)DataTypeEnum.penum) { sb = new StringBuilder(); sb.AppendFormat("case {0}.{1}", GetTableAliase(_ReportQueryField.Relation1Id), _ReportQueryField.Field1Name); foreach (var item in _Field.RefEnum.EnumItems) { sb.AppendFormat(" when {0} then '{1}'", item.ItemValue, item.DisplayText); } sb.Append(" end "); result = sb.ToString(); } else if (_Field.DataType == (int)DataTypeEnum.pbool) { result = string.Format("case {0}.{1} when 1 then '是' else '否' end ", GetTableAliase(_ReportQueryField.Relation1Id), _ReportQueryField.Field1Name); } else { result = string.Format("{0}.{1} ", GetTableAliase(_ReportQueryField.Relation1Id), _ReportQueryField.Field1Name); } break; case ReportFunctionTypeEnum.Minus: result = string.Format("ISNULL({0}.{1},0) - ISNULL({2}.{3},0) ", GetTableAliase(_ReportQueryField.Relation1Id), _ReportQueryField.Field1Name, GetTableAliase(_ReportQueryField.Relation2Id), _ReportQueryField.Field2Name); break; case ReportFunctionTypeEnum.ReMinus: result = string.Format("ISNULL({0}.{1},0) - ISNULL({2}.{3},0) ", GetTableAliase(_ReportQueryField.Relation2Id), _ReportQueryField.Field2Name, GetTableAliase(_ReportQueryField.Relation1Id), _ReportQueryField.Field1Name); break; case ReportFunctionTypeEnum.Mul: result = string.Format("{0}.{1}*{2}.{3} ", GetTableAliase(_ReportQueryField.Relation1Id), _ReportQueryField.Field1Name, GetTableAliase(_ReportQueryField.Relation2Id), _ReportQueryField.Field2Name); break; } } return(result); }