@Aiti
2019-03-21T09:14:13.000000Z
字数 13676
阅读 404
可在浏览器中检查对应控件的ID,ID.value进行赋值;asp控件加上属性ClientIDMode="Static",可直接使用ID或者可用document.getElementById()对进行操作
JS:
function Clear() {
txtProjectName.value = "";
txtName.value = "";
txtBuildType_I.value = "";
txtType_I.value = "";
btnSearch.click();
}
页面:
<div class="search-name">立项名称:<asp:TextBox runat="server" ClientIDMode="Static" ID="txtProjectName" /></div>
<div class="search-name">申请人姓名:<asp:TextBox runat="server" ClientIDMode="Static" ID="txtName" /></div>
<div class="search-name">立项类型: <dx:ASPxComboBox runat="server" ID="txtBuildType" ClientIDMode="Static" style="float:right; margin-top:-10px;">
<Items>
<dx:ListEditItem Value="科研" Text="科研" />
<dx:ListEditItem Value="工法" Text="工法" />
</Items>
</dx:ASPxComboBox></div>
XpoDs.Criteria = CriteriaOperator.Parse("StartsWith(Scope,?) AND LastUpdateTime BETWEEN(?,?) AND QualiTime BETWEEN(?,?)", dep.FullCode,
StartDate.Date, EndDate.Date == DateTime.MinValue ? DateTime.MaxValue : EndDate.Date , txtStart.Date,txtEnd.Date).ToString();
XpoProject.Criteria = $"StartsWith(Scope,'{ScopeHelper.CurrentScope()}')";
var op = CriteriaOperator.Parse("StartsWith(Scope,?)", ScopeService.CurrentScope());
op =CriteriaOperator.And(op,CriteriaOperator.Parse($"Department.Oid='{cmbDept.Value.ToString()}'"));
op = CriteriaOperator.And(op,CriteriaOperator.Parse($"Number like '%{txtNumber.Text}%'"));
op = CriteriaOperator.And(op, CriteriaOperator.Parse($"PlanTime <= #{txtEnd.Text}#"));
XpoProject.Criteria = op.ToString();
Gridview 加事件 OnHtmlRowPrepared="gvExpert_HtmlRowPrepared"
页面
<dx:GridViewDataTextColumn VisibleIndex="3" FieldName="Num" Caption="序号">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
表:[DisplayName("序号"), NonPersistent]
public int Num;
后台:
protected void gvExpert_HtmlRowPrepared(object sender,DevExpress.Web.ASPxGridViewTableRowEventArgs e)
{
e.Row.Cells[0].Text = (e.VisibleIndex + 1).ToString();
}
Js:
function AllRStatusChange(s, e) {
chxRStatus.SetEnabled(!s.GetValue());
}
$(function () {
chxRStatus.SetEnabled(!AllRStatus.GetValue());
});
页面
<div class="search-name">研发状态:
<dx:ASPxCheckBoxList runat="server" ID="chxRStatus" CssClass="Rnb" RepeatDirection="Horizontal" ClientIDMode="Static">
</dx:ASPxCheckBoxList>
<dx:ASPxCheckBox runat="server" ID="AllRStatus" ClientIDMode="Static" Text="全部" CssClass="Rnb" Checked="true">
<ClientSideEvents CheckedChanged="AllRStatusChange" />
</dx:ASPxCheckBox> </div>
加载:
if (!IsPostBack){
EnumHelper.SetListControl(chxRStatus, typeof(ResearchStatus));
chxRStatus.Items[0].Selected = chxRStatus.Items[1].Selected = true;
}
查询:
if (!AllRStatus.Checked)
{
CriteriaOperator pStatus = CriteriaOperator.Parse("1=0");
foreach (var i in chxRStatus.SelectedValues)
{
pStatus = CriteriaOperator.Or(pStatus, CriteriaOperator.Parse("ResearchStatus=?", i));
}
op = CriteriaOperator.And(op, pStatus);
}
<dx:GridViewDataComboBoxColumn FieldName="Title!Key" VisibleIndex="8" Caption="职称">
<PropertiesComboBox TextField="Name" ValueField="Oid" DataSourceID="XpoTitle">
</PropertiesComboBox>
</dx:GridViewDataComboBoxColumn>
protected void gvAll_CustomColumnDisplayText(object sender, DevExpress.Web.ASPxGridViewColumnDisplayTextEventArgs e)
{
if (e.Column.ToString()=="项目类别")
{
e.DisplayText = EnumHelper.GetDescription(e.Value);
}
}
protected void gvAll_CellEditorInitialize(object sender, DevExpress.Web.ASPxGridViewEditorEventArgs e)
{
if (e.Column.FieldName == "ProjectType")
{
ASPxComboBox combo = e.Editor as ASPxComboBox;
EnumHelper.SetListControl(combo, typeof(TechManager.Module.Component.Techs.ProjectType));
}
}
protected void gvAll_CommandButtonInitialize(object sender, ASPxGridViewCommandButtonEventArgs e)
{
if (e.ButtonType == ColumnCommandButtonType.New)
{
e.Visible = true;
}
}
//....TreeList 枚举类
<dx:TreeListComboBoxColumn FieldName="Type" Caption="类别" VisibleIndex="3">
<DataCellTemplate><%# bim999.OA.Module.Engine.EnumHelper.GetDescription(Eval("Type")) %></DataCellTemplate>
</dx:TreeListComboBoxColumn>
(http://www.cnblogs.com/Leon-Jenny/p/4923399.html)
<dx:GridViewDataTextColumn FieldName="Proposer" VisibleIndex="5" Caption="申请人姓名">
<PropertiesTextEdit>
<ValidationSettings>
<RequiredField IsRequired="true" ErrorText="不能为空" />
</ValidationSettings>
</PropertiesTextEdit>
</dx:GridViewDataTextColumn>
<dx:GridViewDataMemoColumn FieldName="Actuality" VisibleIndex="18" Caption="国内外现状">
<PropertiesMemoEdit>
<ValidationSettings>
<RequiredField IsRequired="true" ErrorText="不能为空" />
</ValidationSettings>
</PropertiesMemoEdit>
<PropertiesMemoEdit Rows="5" >
</PropertiesMemoEdit>
<EditFormSettings Visible="True" ColumnSpan="2" />
</dx:GridViewDataMemoColumn>
<dx:GridViewDataTextColumn FieldName="Email" VisibleIndex="4">
<PropertiesTextEdit>
<ValidationSettings>
<RegularExpression ErrorText="请填写正确Email"ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" />
<RegularExpression ErrorText="请填写数字" ValidationExpression="^[1-9]\d*$" />
</ValidationSettings>
</PropertiesTextEdit>
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="Actual" VisibleIndex="5" Caption="保留四位小数">
<PropertiesTextEdit DisplayFormatString="0.0000"> </PropertiesTextEdit>
</dx:GridViewDataTextColumn>
一对多
public class Order : XPObject
{
public Order(Session session) : base(session) { }
[DisplayName("单号")]
public string No;
[DisplayName("日期")]
public DateTime Time;
[DisplayName("备注")]
public string Note;
[Association("OrderSalesMan", typeof(Emp))]
public XPCollection SalesMans => GetCollection("SalesMans");
}
public class Emp : XPObject
{
public Emp(Session session) : base(session) { }
[Indexed(Unique = true)]
[DisplayName("编号")]
public string Number;
[DisplayName("名称")]
public string Name;
[Association("OrderSalesMan")]
public Order Order;
}
如果需求是 当Emp中已经存在了一条关联Order记录,将不予再建记录加判断条件
op = CriteriaOperator.And(op, CriteriaOperator.Parse("OrderSalesMan.Count=0"));
<asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="javascript: WeChat();return ture;"
CausesValidation="False" Onclick="page_clcik"><i class="**"></i>绑定微信</asp:LinkButton>
其中return ture;是继续执行后面的代码;可能导致窗口重新刷新;fasle则不继续执行;
<appSettings>
<add key="XpoUserConnectionString" value="XpoProvider=MSSqlServer;data source=.;user id=sa;password=cx1234;initial catalog=CrecSh_TechMgr1;Persist Security Info=true" />
<add key="XpoConnectionString" value="XpoProvider=MSSqlServer;data source=.;user id=sa;password=cx1234;initial catalog=CrecSh_TechMgr1;Persist Security Info=true" />
<add key="Company" value="中铁上海工程局集团有限公司" />
<add key="License" value="12F2129B6574DDE5240BB49A02ECE0B4" />
<add key="DateFormat" value="yyyy-MM-dd" />
<add key="AppCode" value="TechMgr" />
<add key="SmsApiUrl" value="http://192.168.1.240:806/api" />
<add key="SmsGroup" value="itech" />
<add key="SmsKey" value="itech_99" />
<add key="WeChatPID" value="itech_1" />
</appSettings>
使用以下代码获取:
Company.Text = ConfigurationManager.AppSettings["Company"];
查询单个记录
session.FindObject<User>(CriteriaOperator.Parse("LoginName=?", name));
查询多个条记录
1、2、查询得到的数据类型不一样/XPCollection可以直接作为数据源;而XPQuery没有继承List接口?
所以要
var data = new XPQuery(session).ToList();
pds.DataSource = data;
caine
//1、查询得到的数据类型不一样/
var views = new XPCollection<View>(Session, CriteriaOperator.Parse("Article.Oid=?", Oid));
//or
//2、
new ArrayList(new XPQuery<Department>(session).Where(o => (o.IsScope && !o.Invalid && o.Level <= 2)).OrderBy(o => o.Level).ThenBy(o => o.Order).Select(o=>o.Name).ToArray());
//or:
string UID = "LILIN";
var list = new XPQuery<ApprovalRecord>(session).Where(o => (o.IsExecute==false && o.Actor.LoginName== UID));
//or:
var ar = session.Query<ApprovalRecord>() as IQueryable<ApprovalRecord>;
ar = ar.Where(o => o.Actor.LoginName == User.Identity.Name && o.Type == "Scheme" && o.IsExecute);
//3、查询
PatentOwner = "3,4,8"
var owner = PatentOwner?.Trim(',');
var names = new XPCollection(Session, typeof(Department), CriteriaOperator.Parse($"Oid IN ({owner})"));
//4、查询xpcList中不包含ActID=5的项
var list = xpcList.Where(o => o.ActID == 5).ToList();
xpcList = xpcList.Where(o => !list.Select(p => p.Oid).Contains(o.Oid)).ToList();
<dx:GridViewDataTextColumn VisibleIndex="0" Caption="审批内容">
<DataItemTemplate>
<asp:Literal runat="server" Text='<%#TechManager.Module.Engine.ApprovalHelper.GetUrl(session,Eval("Type"),Eval("TargetId"), Eval("Name")) %>'> </asp:Literal>
</DataItemTemplate>
</dx:GridViewDataTextColumn>
//类
public static string GetUrl(Session session,object objCode, object oId ,object name)
{
string code = objCode.ToString();
int id = int.Parse(oId.ToString());
string s = "<a href='{0}' target='_blank'>{1}</a>";
string url = "", text = "";
CriteriaOperator op = CriteriaOperator.Parse("Oid=?", id);
try
{
switch (code)
{
case "Person":
var person = session.FindObject<Person>(op);
url = "../Persons/ViewAll.aspx?id=" + id;
text = $"[{person.Department.FullName}]{person.Name}";
break;
case "PersonTest":
var personT = session.FindObject<Person>(op);
url = "../Test/PersonView.aspx?id=" + id;
text = $"[{personT.Department.FullName}]{personT.Name}";
break;
}
}catch
{
return "";
}
return string.Format(s, url, text);
}
其中Eval();就是针对控件使用的;
错误可能:是否为null;没有new初始化对象;
protected ArrayList AppList = new ArrayList();
string s = GetType(a.Key);
AppList.Add(s);
如果不new AppList;只定义protected ArrayList AppList;将提示这个错误;
String s = “abcat”;
String s1 = s.replace(‘a’,‘1’);
string sourceString = "Ni hao 123";
sourceString.Replace("123", "abc");
replace的参数是char和CharSequence,即可以支持字符的替换,也支持字符串的替换(CharSequence即字符串序列的意思,说白了也就是字符串);
replaceAll的参数是regex,即基于规则表达式的替换,比如:可以通过replaceAll("\d", "*")把一个字符串所有的数字字符都换成星号;
[Key, DisplayName("登录名"), Size(20)]
public string LoginName;
[DisplayName("内容"), Size(int.MaxValue)]
public string Content;
[DisplayName("机构"),Indexed(Unique =true)]
public Department Department;
[DisplayName("性别"), Size(2)]
public string Sex;
//
<dx:GridViewDataComboBoxColumn FieldName="Sex" VisibleIndex="6">
<PropertiesComboBox ClientInstanceName="Sex">
<Items>
<dx:ListEditItem Value="男" />
<dx:ListEditItem Value="女" />
</Items>
<ValidationSettings>
<RequiredField IsRequired="true" ErrorText="不能为空" />
</ValidationSettings>
</PropertiesComboBox>
</dx:GridViewDataComboBoxColumn>
第一种不存入数据库,临时运算
[DisplayName("字段")]
public double CoalNum;
private double _SO2;
[DisplayName("SO2"),NonPersistent]
public double SO2 {
get { return _SO2; }
set {
_SO2 = (CoalNum * 0.012 * 0.8 * 2);
}
}
第二种字段存入数据库;但是运算过后数据会延迟存入数据库
[DisplayName("字段")]
public double CoalNum;
private double _SO2;
[DisplayName("SO2")]
public double SO2 {
get { return _SO2; }
set {
_SO2 = (CoalNum * 0.012 * 0.8 * 2);
}
}
第三种都存入数据库
[DisplayName("字段")]
public double CoalNum;
[DisplayName("SO2")]
public double SO2;
protected override void OnSaving(){
SO2 = (CoalNum * 0.012 * 0.8 * 2);
}
<dx:GridViewDataMemoColumn FieldName="ContentAbstract" VisibleIndex="16" Caption="研究内容提要" Visible="false">
<PropertiesMemoEdit Rows="5" >
</PropertiesMemoEdit>
<EditFormSettings Visible="True" ColumnSpan="2" />
</dx:GridViewDataMemoColumn>
protected void gvAll_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
{
e.NewValues["Author"] = currentUser;
e.NewValues["列名"] = DateTime.Now;
}
//单列数据颜色HtmlDataCellPrepared
protected void gvAll_HtmlDataCellPrepared(object sender,ASPxTreeList.TreeListHtmlDataCellEventArgs e)
{
if (e.Column.FieldName == "Order")
e.Cell.BackColor = System.Drawing.Color.Red;
}
//正行数据颜色HtmlRowPrepared
protected void gvAll_HtmlRowPrepared(object sender, ASPxGridViewTableRowEventArgs e)
{
if (!gvAll.IsEditing && gvAll.EditingRowVisibleIndex < 0 && e.VisibleIndex >= 0 && e.RowType == GridViewRowType.Data)
{
var InspectDate = gvAll.GetRowValues(e.VisibleIndex, "InspectDate");
var eq = gvAll.GetRow(e.VisibleIndex) as EquipmentMeasure;
if (InspectDate != null && ((DateTime)InspectDate).Subtract(DateTime.Now).TotalDays < 30 && eq.IsFirstComplete && eq.EquipmentStatus == EquipmentStatus.Normal)
e.Row.BackColor = System.Drawing.Color.Red;
}
}
要用 is null
XpoDs.Criteria = CriteriaOperator.Parse("Parent is null").ToString();
方式一:
function Clear() {
txtName.value = "";
txtStart_I.value = "";
txtEnd_I.value = "";
Aspx.ETextChanged("txtStart");
Aspx.ETextChanged("txtEnd");
btnSearch.click();
}
/***********/
<div class="search">开始时间:<dx:ASPxDateEdit ID="txtStart" runat="server" ClientIDMode="Static"> </dx:ASPxDateEdit></div>
<div class="search">结束时间:<dx:ASPxDateEdit ID="txtEnd" runat="server" ClientIDMode="Static"> </dx:ASPxDateEdit></div>
如果不加ClientIDMode="Static";在JS函数中该控件的ID “有可能” 就不是这个;可在网页检查中看该控件的 ID就知道了!
方式二:
function Clear() {
txtName.value = "";
txtStart.SetValue();
txtEnd.SetValue();
btnSearch.click();
}
*注意!!注意!!
ID.value ="";清空数据后;调用changed函数,括号里的id 跟上面用的ID 不一样!这个函数可以在网页检查里控件上看到;一个是网页端的ID,一个是控件在后台的id。
protected void gvUsers_CellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e)
{
if (e.Column.FieldName == "Password")
if (gvUsers.IsNewRowEditing)
e.Editor.Visible = true;
else
e.Editor.Visible = false;
else if (e.Column.FieldName == "LoginName")
if (gvUsers.IsNewRowEditing)
e.Editor.ReadOnly = false;
else
e.Editor.ReadOnly = true;
else if (e.Column.FieldName == "Rank!Key")
{
if (gvUsers.IsNewRowEditing == true)
XpoRank.Criteria = CriteriaOperator.Parse("Invalid=false").ToString();
else
{
var rankid = gvUsers.GetRowValues(e.VisibleIndex, "Rank!Key");
XpoRank.Criteria = CriteriaOperator.Parse("Oid=? or Invalid=false", rankid).ToString();
}
}
}
下面的几个if是编辑时绑定已建好的数据;使其在编辑时不为空
protected void gvFunds_CellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e)
{
//((ProjectContractModel)gvAll.GetRow(e.VisibleIndex)).Num//可行
var s = ((sender as ASPxGridView).GetRow(e.VisibleIndex) as ProjectContractFunds).Subject;
if (e.Column.FieldName == "Subject")
e.Editor.ReadOnly = true;
}
[DisplayName("序号"), NonPersistent]
public int Num;
[DisplayName("姓名")]
public string Name;
[DisplayName("性别"), Size(2)]
public string Sex;
[DisplayName("生日")]
public DateTime Birthday;
[DisplayName("出生地")]
public string Birthplace;
#if DEBUG
[DisplayName("身份证号码"), Size(18)]
#else
[DisplayName("身份证号码"), Size(18),Indexed (Unique = true)]
#endif
public string IDNumber;
[DisplayName("毕业院校")]
public string School;
op = CriteriaOperator.Parse("Department.Level=3 AND (Roles[Code=?].Count>0 )", r.Substring(2));