var UserInfo = JsonHelper.DeserializeJsonToObject<TUser>(Url.ActionContext.HttpContext.User.Claims.Where(p => p.Type == "UserInfo").FirstOrDefault().Value);
var MenuMode = Url.ActionContext.HttpContext.Request.Cookies["MenuMode"];
var controllerName = routeData.Values["area"].ToString(); //routeData是ControllerBase类中定义的RouteData属性
var actionName = routeData.Values["Controller"].ToString();
-------------------------------------------------------------------------------------------------------------------------
//取当前操作人员的姓名
string currentName = UserInfo.USER_NAME;
--------------------------------------------------------------------------------------------------------------------
#region 回调 后端CS代码调用视图页面的javascript函数 传入一个字符串
if (ISSuccess)
{
new FlowMenuHelp(db, Url).SendMessage(ord, msgNexts, "待办");
if (rowguid > 0)
{
PageContext.RegisterStartupScript("onFinishClick('提交成功');");
}
else
{
PageContext.RegisterStartupScript("onOperationClick('" + cusstring + "提交成功, 项目编号为" + ord.Item_no + "');");
}
}
----------------------------------------------------------------------------------------------------------------------
//求两个字符串数组的交集
if (arr1.Intersect(arr2).Count() == 0)
{
continue;//如果没有权限则跳出
}
----------------------------------------------------------------------------------------------------------------------
renderField.RendererArgument = "yyyy-MM-dd HH:mm:ss";
----------------------------------------------------------------------------------------------------------------------
//经常用到的反射来获取类中的属性
Type t = control.GetType();
//获取实体类所有的公共属性
List<PropertyInfo> propertyInfos = t.GetProperties(BindingFlags.Instance | BindingFlags.Public).ToList();
//创建实体属性字典集合
Dictionary<string, PropertyInfo> dicPropertys = new Dictionary<string, PropertyInfo>();
//将实体属性中要修改的属性名 添加到字典集合中 键:属性名 值:属性对象
propertyInfos.ForEach(p =>
{
dicPropertys.Add(p.Name, p);
});
----------------------------------------------------------------------------------------------------------------------
//下拉框联动字段
[{"ClassName":"Model.TUser","ColumnName":"COMPANY_ID"}]
----------------------------------------------------------------------------------------------------------------------
//表单配置里的服务器事件配置方法MistakeBigClass-inputEl
[{"EventName":"change","Action":"MistakeBig_SelectChanged","Controller":"SFSaleAfter","Fields":"MistakeBigClass","area":"OrderFlow","Parameters":[{"Name":"proName","Value":"F.ui.proName.value"}]}]
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//流程配置里 客户端事件写法
[{"EventName":"change","Handler":"IsBiddingChange();"}]
[{"EventName":"click","Handler":"Print();"}]
-------------------------------------------------------------------------------------------------------------------------------------------------------------
//表单里个性化设置里使用正则表达式
[{"Name":"Regex","Value":"\D{2,3}\d{6}-\d{2}"},{"Name":"RegexMessage","Value":"外部合同号格式错误!例:HNd180609-01"}]
//表格单元格的个性化设置 分别设置(类RenderField)的两个属性 dataField属性,是该列取数据源的哪一个属性的值,前台的渲染js函数的参数value会得到数据源这个属性的值
[{"Name":"RendererFunction","Value":"renderAction"},{"Name":"DataField","Value":"SaleAfterDTID"}]
-------------------------------------------------------------------------------------------------------------------------------------------------------------
//取controller和action的修改
//原来的var controllerName = routeData.Values["area"].ToString();
//原来的var actionName = routeData.Values["Controller"].ToString();
var action = routeData.Values["action"] == null ? "" : routeData.Values["action"].ToString();
string controllerName, actionName;
if (action == "Index")
{
controllerName = routeData.Values["area"].ToString();
actionName = routeData.Values["Controller"].ToString();
}
else
{
controllerName = routeData.Values["Controller"].ToString();
actionName = routeData.Values["action"].ToString();
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------
//直接在后台代码进行弹窗
public IActionResult AfterSaleAndDemmand(int MainComID, int OrderId)
{
var window1 = UIHelper.Window("Window1");
string openUrl = Url.Action("AfterSaleAndDemmandPrint", new { OrderId = MainComID });
PageContext.RegisterStartupScript(window1.GetShowReference(openUrl, "客户特殊要求售后服务信息打印", 800, 650));
return UIHelper.Result();
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------
Grid 保存按钮 "btnSave" 以下的js方法写在wecome.js中
OnClientClick rowguid 这个就是后台代码定义的id
GridModifiedValidator(F.ui.表格的id,'/OrderFlow/SFSaleAfter/表格的id_Save','rowguid')
删除按钮 "btnDelete"
OnClientClick
deleteGridRow(F.ui.rowguid);
异出按钮 ID "btnExport" string
+ OnClick {FineUICore.Event} FineUICore.Event
Action "/OrderFlow/SFSaleAfter/rowguid_Export" string
Fields "rowguid,MainPanel" string
- Parameters Count = 2 FineUICore.ParameterCollection
[0] Name Columns Value F.toJSON( getGridColumns(F.ui.rowguid))
[1]Name title F.ui.rowguidTitle.getText()
-------------------------------------------------------------------------------------------------------------------------------------------------------------
//Grid单击保存的方法 注意点 GridJiShu 为指定的grid1.ID = "GridJiShu"; 默认使用 grid1.ID = "Grid1";
/// <summary>
/// 技术售后信息列表_保存
/// </summary>
/// <param name="Grid1_fields">字段集合</param>
/// <param name="Grid1_modifiedData">已修改的数据JSON</param>
/// <param name="Columns">字段集合</param>
/// <returns></returns>
[CheckPower(ISPower = false, Name = "技术售后信息列表_保存")]
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult GridJiShu_Save(string GridJiShu_Query, string GridJiShu, JArray GridJiShu_fields, JArray GridJiShu_modifiedData, JArray Columns, JArray GridJiShu_filteredData, string GridJiShu_sortField, string GridJiShu_sortDirection, int GridJiShu_pageIndex, int GridJiShu_PageSize, int mainComID)
{
List<CustomerSaleAterInfo> models = UpdateModel<CustomerSaleAterInfo>(GridJiShu_modifiedData);
if (models != null)
{
db.SaveChanges();
var Grid1data = GetJiShuData(GridJiShu_Query, GridJiShu_filteredData, mainComID);
UIHelper.Grid("GridJiShu").DataSource(Paging(GridJiShu_fields, Grid1data, GridJiShu_pageIndex, GridJiShu_PageSize, Grid1data.Count(), GridJiShu_sortField, GridJiShu_sortDirection), GridJiShu_fields);
UIHelper.Grid("GridJiShu").RecordCount(Grid1data.Count());
Alert.Show("保存成功,并已重新绑定数据", MessageBoxIcon.Success);
}
return UIHelper.Result();
}
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Grid表格查询数据的方法 注意点返回的是IQueryable类型
public IQueryable<CustomerSaleAterInfo> GetJiShuData(string GridOrderItem_Query, JArray GridOrderItem_filteredData = null, int mainComID = 0)
{
LambdaHelper<CustomerSaleAterInfo> lamada = new LambdaHelper<CustomerSaleAterInfo>();
GridFilterHelp.SetFilter(lamada, GridOrderItem_filteredData, GridOrderItem_Query);//将过滤条件转换为兰姆达表达式
// lamada.And(m => m.SaleAfterID.Equals(mainComID));
// var models = db.SFAccessory.Where(lamada.andwhere).AsNoTracking().ToList();//开启查询
//先查出客户id
var xxxxx = from sfs in db.SFSaleAfter
join torders in db.TOrders on sfs.TOrderID equals torders.rowguid
where sfs.SaleAfterID == mainComID
select new { torders.Custom_no };
string custom_no = xxxxx.FirstOrDefault().Custom_no;
//查售后信息表的所有该客户的记录
var test = db.CustomerSaleAterInfo.Where(p => p.CustomerID == custom_no).ToList();
var ViewCustomSaleAfterInfoToJiShuEF = from cusInfo in db.CustomerSaleAterInfo
where cusInfo.CustomerID == custom_no
select new CustomerSaleAterInfo
{
rowguid=cusInfo.rowguid,
InfoType=cusInfo.InfoType,
DealDescribe=cusInfo.DealDescribe
};
return ViewCustomSaleAfterInfoToJiShuEF.Where(lamada.andwhere).AsNoTracking();
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------
查询时间写法
DeliveredTimeEnd = DeliveredTimeEnd.AddDays(1).AddTicks(-1);
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
EF join查询 on后面的多条件写法
join tm in db.TTransMain on new { sfsid=sfs.SaleAfterID.ToString(), tableName= "SFSaleAfter" } equals new {sfsid= tm.MainComID, tableName=tm.TMDataTbale }
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
EF Grop 多个字段分组查询
var querTorderInfoByPro_name = from gpPname in queryTorderInfo
group gpPname by new { gpPname.CountTime, gpPname.CompanyName, gpPname.CompanyID, gpPname.Pro_name } into a
select new UnionServicPercentList
{
CompleteCount = a.Count(),
CountTime = a.Key.CountTime,
CompanyName = a.Key.CompanyName,
CompanyID = a.Key.CompanyID,
Pro_name = a.Key.Pro_name,
TpyeFlag = 1
};
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1:uninall (不支持远程unionall 只能本地先转成list) 2:order by
//所有信息汇总后排序
var queryResultNotOrderby = querGropByPro_name.ToList().Concat(querTorderInfoByPro_name.ToList()).Concat(querNotGropByPro_name.ToList()).Concat(querTorderInfoNotByPro_name.ToList()).ToList();
//排序后的总数据
var queryResultOrderby = queryResultNotOrderby.OrderBy(p => p.CompanyName).ThenBy(p => p.Pro_name).ThenBy(p => p.CountTime).ThenBy(p => p.TpyeFlag);
linq to sql 中 orderby flowNR.FNRID ascending/descending
多条件写法
orderby leftcom.CompanyID,leftcom.CompanyID
orderby leftcom.CompanyID descending
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
js格式化百分比函数
function changeToPercent(num) {
if (!/d+.+d+/.test(num)) {
return num;
}
var result = (num * 100).toString();
index = result.indexOf(".");
// console.log(index);110.00000000000001
// return result.substr(0, index + 5);
if (index == -1 || result.substr(index + 1).length <= 4) {
return result + '%';
}
return result.substr(0, index + 3) + "%";
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
星标//表单显示以及表单更新时,调用框架的方法
public IActionResult UpdateSaleAfterDTID(int id ,string proname,string isupdate, IFormCollection values)
{
if (!string.IsNullOrEmpty(isupdate)) {
//表单提交时触发事件
var fchelpAdd = new FormConfigHelp(db, Url);
var AllConfigs = fchelpAdd.GetBodies(RouteData, "MainForm1");
var cvalue = values.Where(p => AllConfigs.Where(q => q.ClassName == "Model.SFSaleAfterDT").Select(q => q.ControlID).Contains(p.Key)).ToList();
var SFSaleAfterDTID = Convert.ToInt32(values["SaleAfterDTID"]);
var sfdt = db.SFSaleAfterDT.Where(p => p.SaleAfterDTID == SFSaleAfterDTID).FirstOrDefault();
fchelpAdd.SetAttribute(sfdt, cvalue);
db.SaveChanges();
PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
return UIHelper.Result();
}
var model = db.SFSaleAfterDT.Where(p => p.SaleAfterDTID == id).FirstOrDefault();
var tOrders = new TOrders() { Item_name = proname };
#region Form
var fchelp = new FormConfigHelp(db, Url);
var objs = new List<object>();
objs.Add(tOrders);
objs.Add(model);
var form = fchelp.GetForm(RouteData, "MainForm1", objs.ToArray());
HiddenField hfProName = new HiddenField() { ID = "proName", Text = proname };
var panl = form.Items[0] as Panel;
if (panl != null)
{
panl.Items.Add(hfProName);
//----------------------------------------------------------------------------
var ddlResponsibilityDepartment = panl.Items.Where(p => p.ID == "ResponsibilityDepartment").FirstOrDefault() as DropDownList;
if (ddlResponsibilityDepartment != null)
{
ddlResponsibilityDepartment.DataValueField = "CompanyName";
ddlResponsibilityDepartment.DataTextField = "CompanyName";
//责任科室根据登入人的公司信息进行绑定
var userid = UserInfo.ROWGUID;
int cmid = Convert.ToInt32(UserInfo.COMPANY_ID);//公司id TreeFatherNo
var responsibilityDepartmentData = from tc1 in db.TCompany
join tc2 in db.TCompany on tc1.ROWGUID.ToString() equals tc2.TreeFatherNo
into r1
from tm in r1.DefaultIfEmpty()
where tc1.ROWGUID == cmid
select new
{
CompanyName = tm.CompanyName
};
ddlResponsibilityDepartment.DataSource = responsibilityDepartmentData;
ddlResponsibilityDepartment.DataBind();
}
}
#endregion
ViewBag.Form = form;
ViewBag.buttonText = "修改";
return View();
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/// <summary>
///创建人:蒋云峰
///日 期:2019/11/14
///描 述:Distinct扩展方法
/// </summary>
public static class DistinctByClass
{
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
{
HashSet<TKey> seenKeys = new HashSet<TKey>();
foreach (TSource item in source)
{
if (seenKeys.Add(keySelector(item)))
{
yield return item;
}
}
}
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
迁移更新数据库命令
每个包都由其所有者许可给你。NuGet 不负责第三方包,也不授予其许可证。一些包可能包括受其他许可证约束的依赖关系。单击包源(源) URL 可确定任何依赖关系。
程序包管理器控制台主机版本 4.9.3.5777
键入 "get-help NuGet" 可查看所有可用的 NuGet 命令。
PM> Add-Migration jyf1
To undo this action, use Remove-Migration.
PM> update-database
Applying migration '20191120003207_jyf1'.
Done.
PM>
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
枚举转为数字
@{
var frrid= (int)Enum.Parse(typeof(SfsFnrEnum), "异议登记");
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
?.的用法 一般用于点号取值
sfacc.AccessoryName = sfacc.AccessoryName?.Replace(" ", " ");
sfacc.Material = sfacc.Material?.Replace(" ", " ");
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
监控数据库的连接数
select COUNT( * ) from master.dbo.sysprocesses
select COUNT( * ) from master.dbo.sysprocesses where dbid=DB_ID('WKOMS') and hostname='OMS-APP'
select COUNT( * ) from master.dbo.sysprocesses where dbid=DB_ID('WKOMS') and hostname<>'OMS-APP'
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------