HTML:
MR.Lee提供解决无法自动加载焦点方案:
<Listeners> <DocumentReady Handler="create();create2();" /> </Listeners>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CustomerVisitsAdd.aspx.cs" Inherits="DzPlatForm.CRM.AddCustomerVisits" ValidateRequest="false" %> <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>客户拜访记录</title> <link href="../../../resources/css/examples.css" rel="stylesheet" type="text/css" /> <meta charset="utf-8" content="" /> <link rel="stylesheet" href="../../kindeditor/themes/default/default.css" /> <link rel="stylesheet" href="../../kindeditor/plugins/code/prettify.css" /> <script charset="utf-8" src="../../kindeditor/kindeditor.js" type="text/javascript"></script> <script charset="utf-8" src="../../kindeditor/lang/zh_CN.js" type="text/javascript"></script> <script charset="utf-8" src="../../kindeditor/plugins/code/prettify.js" type="text/javascript"></script> <script type="text/javascript"> function create() { var editor1 = KindEditor.create('#txtVisitCotent', { cssPath: '../plugins/code/prettify.css', uploadJson: '../asp.net/upload_json.ashx', fileManagerJson: '../asp.net/file_manager_json.ashx', allowFileManager: false }); prettyPrint(); } </script> <script type="text/javascript"> function create2() { var editor2 = KindEditor.create('#txtActionItem', { cssPath: '../plugins/code/prettify.css', uploadJson: '../asp.net/upload_json.ashx', fileManagerJson: '../asp.net/file_manager_json.ashx', allowFileManager: false }); prettyPrint(); } </script> <style type="text/css"> .dot-label { font-weight: bold; font-size: 20px; } .form-toolbar { top: 1px; position: relative; } </style> </head> <body> <form id="form1" runat="server"> <ext:ResourceManager ID="ResourceManager1" runat="server" > <Listeners> <DocumentReady Handler="create();create2();" /> </Listeners> </ext:ResourceManager> <ext:Hidden ID="txtType" runat="server" Text="" /> <ext:Hidden ID="txtId" runat="server" Text="" /> <ext:FormPanel ID="FormPanel1" runat="server" Title="" AutoHeight="true" Width="710" Padding="5" DefaultAnchor="0" Border="false"> <Items> <ext:FieldSet ID="FieldSet1" runat="server" Title="基本信息" Collapsible="true" Layout="form"> <Items> <ext:CompositeField ID="CompositeField1" runat="server" MsgTarget="Side" AnchorHorizontal="-20" FieldLabel="公司别"> <Items> <ext:ComboBox ID="cbxCompany" runat="server" FieldLabel="公司别" Width="100" AllowBlank="false"> <Items> <ext:ListItem Text="电子公司" Value="ZE" /> <ext:ListItem Text="磁电公司" Value="ZM" /> </Items> </ext:ComboBox> <ext:DisplayField ID="DisplayField5" runat="server" Text="拜访日期" /> <ext:DateField ID="dfVisitDate" runat="server" FieldLabel="拜访日期" DataIndex="VisitDate" AllowBlank="false" /> </Items> </ext:CompositeField> <ext:CompositeField ID="CompositeField2" runat="server" FieldLabel="客户编码" MsgTarget="Under"> <Items> <ext:TextField ID="txtCustomerCode" runat="server" DataIndex="CustomerCode" Width="100" AllowBlank="false" /> <ext:DisplayField ID="DisplayField2" runat="server" Text="客户名称" /> <ext:TextField ID="txtCusomerName" runat="server" DataIndex="CusomerName" Width="250" AllowBlank="false" Margins="0 5 0 0" /> </Items> </ext:CompositeField> <ext:CompositeField ID="CompositeField3" runat="server" FieldLabel="拜访者编号" CombineErrors="false"> <Items> <ext:Label ID="lblVisitorCode" runat="server" Text="" Width="100"> </ext:Label> <ext:DisplayField ID="DisplayField3" runat="server" Text="拜访者" /> <ext:Label ID="lblVisitor" runat="server" Text=""> </ext:Label> </Items> </ext:CompositeField> <ext:TextField ID="txtMetWith" runat="server" Flex="1" DataIndex="MetWith" AllowBlank="false" FieldLabel="受访人员" AnchorHorizontal="-20" /> <ext:TextField ID="txtVistorPurpose" runat="server" DataIndex="VistorPurpose" FieldLabel="拜访目的" AnchorHorizontal="-20" /> </Items> </ext:FieldSet> <ext:FieldSet ID="FieldSet2" runat="server" Title="拜访内容" Collapsible="true" Layout="form"> <Content> <textarea id="txtVisitCotent" cols="100" style="width: 670px; height: 300px; visibility: hidden;" runat="server" name="S1"></textarea> </Content> </ext:FieldSet> <ext:FieldSet ID="FieldSet3" runat="server" Title="行动方案" Collapsible="true" Layout="form"> <Content> <textarea id="txtActionItem" cols="100" style="width: 670px; height: 300px; visibility: hidden;" runat="server" name="S1"></textarea> </Content> </ext:FieldSet> </Items> <Buttons> <ext:Button ID="btnSave" runat="server" Text="保存"> <DirectEvents> <Click OnEvent="SaveData" Before="return #{FormPanel1}.isValid();"> <%-- <ExtraParams> <ext:Parameter Name="values" Value="#{FormPanel1}.getForm().getValues()" Mode="Raw" Encode="true" /> </ExtraParams>--%> </Click> </DirectEvents> </ext:Button> <ext:Button ID="btnReset" runat="server" Text="重置"> <Listeners> <Click Handler="#{FormPanel1}.getForm().reset();" /> </Listeners> </ext:Button> </Buttons> </ext:FormPanel> </form> </body> </html>
后台:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Ext.Net; using System.Text; using DzPlatForm.Model; using DzPlatForm.BLL; namespace DzPlatForm.CRM { public partial class AddCustomerVisits : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request.QueryString["Id"] != null) { txtId.Text = Request.QueryString["Id"].ToString(); txtType.Text = "Edit"; FormPanel1.Title = "修改拜访记录"; DefaultValues(int.Parse(txtId.Text.Trim())); } else { txtType.Text = "Add"; FormPanel1.Title = "新增客户拜访记录"; } lblVisitor.Text = "屈文明"; lblVisitorCode.Text = "A328"; FormPanel1.SetValues(new { VisitDate = System.DateTime.Now.ToShortDateString() }); this.FieldSet3.Collapsed = true; } } /// <summary> /// 默认值 /// </summary> /// <param name="id"></param> private void DefaultValues(int id) { List<CustomerVisits> IList = new List<CustomerVisits>(); CustomerVisitsBLL cvbll = new CustomerVisitsBLL(); IList = cvbll.IList(id); foreach (var i in IList) { //基本信息资料 this.cbxCompany.SetValue(i.Company.ToString()); dfVisitDate.SetValue(i.VisitorDate.ToString()); txtCustomerCode.SetValue(i.CustomerCode.ToString()); txtCusomerName.SetValue(i.CustomerName.ToString()); lblVisitorCode.Text = i.VisitorCode.ToString(); lblVisitor.Text = i.Visitor.ToString(); txtVistorPurpose.SetValue(i.VisitPurpose.ToString()); txtVisitCotent.InnerText = i.VisitContent.ToString(); txtMetWith.SetValue(i.MetWith.ToString()); txtActionItem.InnerText = i.ActionItem.ToString(); } } /// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void SaveData(object sender, DirectEventArgs e) { if (this.dfVisitDate.Text.Trim() == "0001-1-1 0:00:00") { X.Msg.Notify("提示", "请选择访问日期"); return; } //var values = JSON.Deserialize<Dictionary<string, string>>(e.ExtraParams["values"]); //StringBuilder sb = new StringBuilder(); //foreach (var value in values) //{ // sb.AppendFormat("{0} = {1}<br />", value.Key, value.Value); //} //X.Msg.Alert("Values", sb.ToString()).Show(); DateTime VisitorDate; VisitorDate = Convert.ToDateTime(this.dfVisitDate.Text.Trim()); CustomerVisits cv = new CustomerVisits(); cv.Company = this.cbxCompany.SelectedItem.Value.ToString(); cv.VisitorDate = VisitorDate; cv.CustomerCode = txtCustomerCode.Text.Trim(); cv.CustomerName = txtCusomerName.Text.Trim(); cv.VisitorCode = lblVisitorCode.Text.Trim(); cv.Visitor = lblVisitor.Text.Trim(); cv.VisitPurpose = txtVistorPurpose.Text.Trim(); cv.VisitContent = txtVisitCotent.InnerText.Trim(); cv.MetWith = txtMetWith.Text.Trim(); cv.ActionItem = txtActionItem.InnerText.Trim(); CustomerVisitsBLL cvbll = new CustomerVisitsBLL(); if (txtType.Text == "Add") { if (cvbll.AddNewCustomerVisits(cv) > 0) { X.Msg.Notify("提示", "新增拜访记录成功").Show(); } else { X.Msg.Notify("提示", "发生数据库错误,新增拜访记录失败,请与管理员联系!").Show(); } } else { cv.Id = int.Parse(txtId.Text.Trim()); if (cvbll.EditCustomerVisits(cv) > 0) { X.Msg.Notify("提示", "修改拜访记录成功").Show(); } else { X.Msg.Notify("提示", "发生数据库错误,修改拜访记录失败,请与管理员联系!").Show(); } } } } }