CodeSmith系列(二)——使用CodeSmith生成ASP.NET后台代码

1
因为表单的后台代码都差不多,所以采用了CodeSmith生成。由于表单的控制是基于XML的,所以可以根据XML自定义生成。由于没时间,就不多写了,具体模板代码见最后。
1
在这里,先选择变量。如下:
1
<a href="http://images.cnblogs.com/cnblogs_com/codelove/201105/201105241711349447.png"><img style="display: inline; border: 0" title="image" src="https://images.cnblogs.com/cnblogs_com/codelove/201105/20110524171134527.png" alt="image" width="708" height="125" border="0"></a>
1
XMl文件内容如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?xml version="1.0" encoding="utf-8" ?>
<FieldConfig>
  <GlobalDefaultConfig>
    <Description>付款确认单</Description>
    <Width>360</Width>
  </GlobalDefaultConfig>
  <Fields>
    <Group Title="表单信息" Columns="2">
      <Field TextControlID="txtAreaName" Disabled="true">所属大区</Field>
      <Field TextControlID="txtBranchCompany" Disabled="true">所属分公司</Field>
      <Field TextControlID="txtProvince" Disabled="true">所属省份</Field>
      <Field TextControlID="txtCitys" Disabled="true">所属城市</Field>
      <Field TextControlID="txtShopName" Disabled="true" MaxLength="20">门店名称</Field>
      <Field TextControlID="txtName" Disabled="true">主持老师</Field>
      <Field TextControlID="txtOracleNO" Disabled="true">Oralce号</Field>
      <Field TextControlID="txtMarginNumber" Disabled="true">保证金号码号</Field>
      <Field TextControlID="txtPayTime" AllowBlank="false">付款时间</Field>
      <Field TextControlID="txtPayer" AllowBlank="false">付款人</Field>
      <Field TextControlID="tblPaymentAmount" AllowBlank="false">付款金额(元)</Field>
      <Field TextControlID="ddlCollectingCompany" AllowBlank="false">收款公司名称</Field>
      <Field TextControlID="ddlDueBank" AllowBlank="false">收款银行名称</Field>
      <Field TextControlID="ddlCollectingBankAccount" AllowBlank="false">收款银行帐号</Field>
      <Field TextControlID="txtBranchContacts">分公司联系人</Field>
      <Field TextControlID="txtContactPhoneNumber">联系电话</Field>
      <Field TextControlID="tblFinancialConfirm" Disabled="true">财务确认</Field>
      <!--<Field TextControlID="cblFinancialConfirm">财务确认</Field>-->
    </Group>
  </Fields>
  <Controls>
    <Control>
      <QueryStrings>
        <!--培训阶段-->
        <Query Name="DriverPhasesid">1E355FC6D4A744F4AF11BB0811E2A066</Query>
      </QueryStrings>
      <Disabled FieldsName="AttributeValue">
        <ControlField>加盟套餐费(元)</ControlField>
        <ControlField>改型套餐费(元)</ControlField>
        <ControlField>保证金(元)</ControlField>
        <ControlField>虹膜套餐款(元)</ControlField>
        <ControlField>虹膜续约款(元)</ControlField>
      </Disabled>
      <!--<ControlField Disabled="true">Cost1</ControlField>
      <ControlField Disabled="true">Cost2</ControlField>
      <ControlField Disabled="true">Cost3</ControlField>
      <ControlField Disabled="true">Cost4</ControlField>
      <ControlField Disabled="true">Cost5</ControlField>
      <ControlField Disabled="true">ddfBank1</ControlField>
      <ControlField Disabled="true">ddfBank2</ControlField>
      <ControlField Disabled="true">ddfBank3</ControlField>
      <ControlField Disabled="true">ddfBank4</ControlField>
      <ControlField Disabled="true">ddfBank5</ControlField>-->
    </Control>
    <Control>
      <QueryStrings>
        <!--签约阶段-->
        <Query Name="DriverPhasesid">72512CBA542E43029B91F9FB3155D4DD</Query>
      </QueryStrings>
      <!--<ControlField Disabled="true">Cost0</ControlField>
      <ControlField Disabled="true">Cost2</ControlField>
      <ControlField Disabled="true">Cost4</ControlField>
      <ControlField Disabled="true">Cost5</ControlField>-->
      <Disabled FieldsName="AttributeValue">
        <ControlField>培训费(元)</ControlField>
        <!--<ControlField>加盟套餐费</ControlField>-->
        <ControlField>改型套餐费(元)</ControlField>
        <!--<ControlField>保证金</ControlField>-->
        <ControlField>虹膜套餐款(元)</ControlField>
        <ControlField>虹膜续约款(元)</ControlField>
      </Disabled>
    </Control>
    <Control>
      <QueryStrings>
        <!--续约-->
        <Query Name="DriverPhasesid">BDA31689C7B54F4EAE925A5390F56C99</Query>
      </QueryStrings>
      <!--<ControlField Disabled="true">Cost0</ControlField>
      <ControlField Disabled="true">Cost1</ControlField>
      <ControlField Disabled="true">Cost2</ControlField>
      <ControlField Disabled="true">Cost4</ControlField>
      <ControlField Disabled="true">Cost5</ControlField>-->
      <Disabled FieldsName="AttributeValue">
        <ControlField>培训费(元)</ControlField>
        <ControlField>加盟套餐费(元)</ControlField>
        <ControlField>改型套餐费(元)</ControlField>
        <!--<ControlField>保证金</ControlField>-->
        <ControlField>虹膜套餐款(元)</ControlField>
        <ControlField>虹膜续约款(元)</ControlField>
      </Disabled>
    </Control>
    <Control>
      <QueryStrings>
        <!--改型-->
        <Query Name="DriverPhasesid">DEB4897EBD28440AB0C60F5D27ED677E</Query>
      </QueryStrings>
      <!--<ControlField Disabled="true">Cost0</ControlField>
      <ControlField Disabled="true">Cost1</ControlField>
      <ControlField Disabled="true">Cost4</ControlField>
      <ControlField Disabled="true">Cost5</ControlField>-->
      <Disabled FieldsName="AttributeValue">
        <ControlField>培训费(元)</ControlField>
        <ControlField>加盟套餐费(元)</ControlField>
        <!--<ControlField>改型套餐费</ControlField>-->
        <!--<ControlField>保证金</ControlField>-->
        <ControlField>虹膜套餐款(元)</ControlField>
        <ControlField>虹膜续约款(元)</ControlField>
      </Disabled>
    </Control>
    <Control>
      <QueryStrings>
        <!--转约-->
        <Query Name="DriverPhasesid">464BEE8157B943B1AC9C3930FD6D774C</Query>
      </QueryStrings>
      <!--<ControlField Disabled="true">Cost0</ControlField>
      <ControlField Disabled="true">Cost1</ControlField>
      <ControlField Disabled="true">Cost2</ControlField>
      <ControlField Disabled="true">Cost5</ControlField>-->
      <Disabled FieldsName="AttributeValue">
        <ControlField>培训费(元)</ControlField>
        <ControlField>加盟套餐费(元)</ControlField>
        <ControlField>改型套餐费(元)</ControlField>
        <!--<ControlField>保证金</ControlField>-->
        <!--<ControlField>虹膜套餐款</ControlField>-->
        <ControlField>虹膜续约款(元)</ControlField>
      </Disabled>
    </Control>
    <Control>
      <QueryStrings>
        <!--虹膜续约-->
        <Query Name="DriverPhasesid">6E022231D0AC41EFAD8E685D0B5FB768</Query>
        <Query Name="DriverPhasesid">60846B34E4F8482297192A2A0AE5D068</Query>
        <Query Name="DriverPhasesid">CFCFB79EA19F4B529819641E02EE8EE5</Query>
      </QueryStrings>
      <!--<ControlField Disabled="true">Cost0</ControlField>
      <ControlField Disabled="true">Cost1</ControlField>
      <ControlField Disabled="true">Cost2</ControlField>
      <ControlField Disabled="true">Cost3</ControlField>
      <ControlField Disabled="true">Cost4</ControlField>-->
      <Disabled FieldsName="AttributeValue">
        <ControlField>培训费(元)</ControlField>
        <ControlField>加盟套餐费(元)</ControlField>
        <ControlField>改型套餐费(元)</ControlField>
        <ControlField>保证金(元)</ControlField>
        <ControlField>虹膜套餐款(元)</ControlField>
        <!--<ControlField>虹膜续约款</ControlField>-->
      </Disabled>
    </Control>
  </Controls>
</FieldConfig>
1
生成的代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Ext.Net;
using NBShopService;
using NBShopCommon;                     //辅助类库
using NBShopCommon.Ext;                 //Ext函数库以及扩展方法
using System.Collections.Generic;
namespace NBShop.UserControls.Form
{  
    /// <summary>
    /// 付款确认单
    /// </summary>
    public partial class ConfirmationForPayment : System.Web.UI.UserControl
    {
        #region 公共属性
        /// <summary>
        /// 店铺ID
        /// </summary>
        public string ShopID
        {
            get
            {
                return Request.QueryString["ObjectID"]??Request.QueryString["ShopID"];
            }
        }
        /// <summary>
        /// 表单类型
        /// </summary>
        public string FormType
        {
            get
            {
                return Request.QueryString["FormType"];
            }
 
        }
        /// <summary>
        /// 当前表单ID
        /// </summary>
        public string CurrentFormID
        {
            get
            {
                return (ViewState["CurrentFormID"] ?? string.Empty).ToString();
            }
            set
            {
                ViewState["CurrentFormID"] = value;
            }
        }
     #endregion
        protected void Page_Load(object sender, EventArgs e)
        {
            //在SharePoint中赋予权限加载Ext资源文件
            ResourceManager1.BuildAllPrivilegesForExtNET();
            //注册jquery脚本文件
            this.Page.ClientScript.RegisterClientScriptInclude("JQuery4.4", "/js/jquery-1.4.4.min.js");
            try
            {
                //绑定数据,设置界面逻辑
                Loading();
            }
            catch (Exception ex)
            {
                //记录错误日志
                LogManager.WriteErrorLog(ex);
            }
        }
         
        /// <summary>
        ///  绑定数据,设置界面逻辑
        /// </summary>
        private void Loading()
        {
          using (NBShopDataContext _db = new NBShopDataContext())
          {
            #region 设置参数
            if (!IsPostBack)
            {
               //设置审批列表的加载路径和参数
               pnlExamineList.AutoLoad.Url = "/FormServerTemplates/ExamineList.aspx?PTCode=" + Request.QueryString["PTCode"] + "&TaskId=" + Request.QueryString["TaskId"];
               ///加载配置(使用的是扩展方法,用于配置Ext控件)
               this.LoadConfigs("ConfirmationForPayment", Context);
               //TODO:设置参数
               #region 绑定下拉列表
                    #region 绑定收款公司名称
                    //TODO:请绑定下拉列表收款公司名称
                    //ExtControlHelper.BindComobox(this, _db.SelectGeneralFromTableINFO(ShopID, CurrentFormID,
                    //"CollectingCompany").ToList()
                    //, "ddlCollectingCompany", "AttributeValue", "AttributeID", "所选值");
                    #endregion
                    #region 绑定收款银行名称
                    //TODO:请绑定下拉列表收款银行名称
                    //ExtControlHelper.BindComobox(this, _db.SelectGeneralFromTableINFO(ShopID, CurrentFormID,
                    //"DueBank").ToList()
                    //, "ddlDueBank", "AttributeValue", "AttributeID", "所选值");
                    #endregion
                    #region 绑定收款银行帐号
                    //TODO:请绑定下拉列表收款银行帐号
                    //ExtControlHelper.BindComobox(this, _db.SelectGeneralFromTableINFO(ShopID, CurrentFormID,
                    //"CollectingBankAccount").ToList()
                    //, "ddlCollectingBankAccount", "AttributeValue", "AttributeID", "所选值");
                    #endregion
               #endregion
                var _context = _db.SelectConfirmationForPaymentINFO(ShopID).FirstOrDefault();
                    if (_context!=null)
                    {
                         //设置控件的值
                         this.SetControlValues(_context);
                         if (!string.IsNullOrEmpty(_context.ConfirmationForPaymentID))
                         {
                              CurrentFormID = _context.ConfirmationForPaymentID;
                         }
                         else
                         {
                              CurrentFormID = _db.GetNewGuid();
                         }
                    }
            }
            #endregion
                
                
             }
            GC.Collect();
        }
 
        //保存
        protected void btnSave_Click(object sender, DirectEventArgs e)
        {
            try
            {
                //显示保存进度条
                X.Msg.Show(new MessageBoxConfig
                {
                    Message = "正在保存数据, 请稍后...",
                    ProgressText = "正在保存数据...",
                    Width = 300,
                    Wait = true,
                    WaitConfig = new WaitConfig { Interval = 200 },
                    IconCls = "ext-mb-download",
                    AnimEl = this.btnSave.ClientID
                });
                if (Save())
                {
                    //执行流程驱动
                    ResourceManager1.SetSubmitScript(ShopID, false);
                }
            }
            catch (Exception ex)
            {
                NBShopCommon.LogManager.WriteErrorLog(ex);
                ResourceManager1.AddScript(" setTimeout(function () { Ext.MessageBox.hide(); Ext.Msg.notify('完成', '保存失败!'); }, 1000);");
            }
 
        }
        //保存数据
        private bool Save()
        {
           //实例化LINQ To SQl类上下文对象
           NBShopDataContext _db = new NBShopDataContext();
           try
           {
               if (_db.Connection.State == ConnectionState.Closed)
                   _db.Connection.Open();
               //事务开始
               _db.Transaction = _db.Connection.BeginTransaction(System.Data.IsolationLevel.Serializable);
               //TODO:保存数据
                
               //提交事务
               _db.Transaction.Commit();
                
               //ObjectService _os = new ObjectService();
               //bool _bobjprc = _os.SaveObjectProcessInfo(Request.QueryString["ObjectID"] ?? string.Empty, Request.QueryString["PTCode"] ?? string.Empty);
               //bool _bobjnp = _os.SaveObjectPN(Request.QueryString["ObjectID"] ?? string.Empty, Request.QueryString["PhasesId"] ?? string.Empty);
               return true;
           }
           catch (Exception ex)
           {
               //回滚事务
               _db.Transaction.Rollback();
               LogManager.WriteErrorLog(ex);
               ResourceManager1.AddScript(" setTimeout(function () { Ext.MessageBox.hide(); Ext.Msg.notify('完成', '保存数据失败!');}, 3000);");
               return false;
           }
        }
        //提交
        protected void btnSubmit_Click(object sender, DirectEventArgs e)
        {
            try
            {
               //显示提交进度条
                X.Msg.Show(new MessageBoxConfig
                {
                    Message = "正在提交数据, 请稍后...",
                    ProgressText = "正在提交数据...",
                    Width = 300,
                    Wait = true,
                    WaitConfig = new WaitConfig { Interval = 200 },
                    IconCls = "ext-mb-download",
                    AnimEl = this.btnSumbit2.ClientID
                });
                if (Save())
                {
                    //流程操作并执行脚本
                    ResourceManager1.SetSubmitScript(ShopID, true);
                }
            }
            catch (Exception ex)
            {
                LogManager.WriteErrorLog(ex);
                ResourceManager1.AddScript(" setTimeout(function () { Ext.MessageBox.hide();Ext.Msg.notify('完成', '提交失败!'); }, 2000);");
            }
        }
    }
}

模板代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<%--
Name: 根据XML生成用户控件表单
Author: LWQ
--%>
<%@ CodeTemplate Language="C#" TargetLanguage="C#" ResponseEncoding="UTF-8" Description="生成Ext.NET用户控件处理代码" CompilerVersion="v3.5" %>
<%@ Property Name="ClassName" Type="System.String" Default="" Optional="True" Category="Optional" Description="用户控件名称。" %>
<%--加载使用访问数据库的组件SchemaExplorer,并声明其使用的命名空间。--%>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context"  Description="对应的数据主表" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Text.RegularExpressions" %>
<%@ Import Namespace="System.Windows.Forms.Design"%>
<%@ Assembly Name="System.Design" %>
<%@ Import Namespace="System.Xml.Linq" %>
<%@ Assembly Name="System.Xml.Linq" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.IO" %>
<script runat="template">
     ///配置文件路径
     private string _userFileName = string.Empty;
     [Editor(typeof(FileNameEditor), typeof(System.Drawing.Design.UITypeEditor)),Category("Custom"), Description("请选择配置XML文件。")]
     public string UserFileName
     {
          get {return _userFileName;}
          set {_userFileName= value;}
     }
     XElement elements =null;
     //返回XML的Key。
      public string GetFormKey()
     {
          return ClassName;
     }
</script>
<%
      if(File.Exists(_userFileName))
      {
          elements = XElement.Load(_userFileName);
      }
%>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Ext.Net;
using NBShopService;
using NBShopCommon;                     //辅助类库
using NBShopCommon.Ext;                 //Ext函数库以及扩展方法
using System.Collections.Generic;
namespace NBShop.UserControls.Form
{  
    <% if(elements.Element("GlobalDefaultConfig").Element("Description")!=null) {%>
    /// <summary>
    /// <%=elements.Element("GlobalDefaultConfig").Element("Description").Value %>
    /// </summary>
    <% } %>
    public partial class <%=ClassName%> : System.Web.UI.UserControl
    {
        #region 公共属性
        /// <summary>
        /// 店铺ID
        /// </summary>
        public string ShopID
        {
            get
            {
                return Request.QueryString["ObjectID"]??Request.QueryString["ShopID"];
            }
        }
        /// <summary>
        /// 表单类型
        /// </summary>
        public string FormType
        {
            get
            {
                return Request.QueryString["FormType"];
            }
 
        }
        /// <summary>
        /// 当前表单ID
        /// </summary>
        public string CurrentFormID
        {
            get
            {
                return (ViewState["CurrentFormID"] ?? string.Empty).ToString();
            }
            set
            {
                ViewState["CurrentFormID"] = value;
            }
        }
     #endregion
        protected void Page_Load(object sender, EventArgs e)
        {
            //在SharePoint中赋予权限加载Ext资源文件
            ResourceManager1.BuildAllPrivilegesForExtNET();
            //注册jquery脚本文件
            this.Page.ClientScript.RegisterClientScriptInclude("JQuery4.4", "/js/jquery-1.4.4.min.js");
            try
            {
                //绑定数据,设置界面逻辑
                Loading();
            }
            catch (Exception ex)
            {
                //记录错误日志
                LogManager.WriteErrorLog(ex);
            }
        }
         
        /// <summary>
        ///  绑定数据,设置界面逻辑
        /// </summary>
        private void Loading()
        {
          using (NBShopDataContext _db = new NBShopDataContext())
          {
            #region 设置参数
            if (!IsPostBack)
            {
               //设置审批列表的加载路径和参数
               pnlExamineList.AutoLoad.Url = "/FormServerTemplates/ExamineList.aspx?PTCode=" + Request.QueryString["PTCode"] + "&TaskId=" + Request.QueryString["TaskId"];
               ///加载配置(使用的是扩展方法,用于配置Ext控件)
               this.LoadConfigs("<%=ClassName%>", Context);
               //TODO:设置参数
                 <%
                    if(elements.Descendants("Field").Where(p=>p.Attribute("TextControlID").Value.Substring(0,3)=="ddl").Count()>0){
                 %>
               #region 绑定下拉列表
               <%
                    var ddls = elements.Descendants("Field").Where(p => p.Attribute("TextControlID").Value.Substring(0, 3) == "ddl");
                    foreach (var item in ddls){
               %>
                    #region 绑定<%=item.Value%>
                    //TODO:请绑定下拉列表<%=item.Value%>
                    //ExtControlHelper.BindComobox(this, _db.SelectGeneralFromTableINFO(ShopID, CurrentFormID,
                    //"<%=item.Attribute("AttributeTypeCode")==null?item.Attribute("TextControlID").Value.Substring(3):item.Attribute("AttributeTypeCode").Value %>").ToList()
                    //, "<%=item.Attribute("TextControlID").Value %>", "AttributeValue", "AttributeID", "所选值");
                    #endregion
               <% }%>
               #endregion
               <%} %>
                var _context = _db.Select<%=ClassName%>INFO(ShopID).FirstOrDefault();
                    if (_context!=null)
                    {
                         //设置控件的值
                         this.SetControlValues(_context);
                         if (!string.IsNullOrEmpty(_context.<%=ClassName%>ID))
                         {
                              CurrentFormID = _context.<%=ClassName%>ID;
                         }
                         else
                         {
                              CurrentFormID = _db.GetNewGuid();
                         }
                    }
            }
            #endregion
               <%
               if(elements.Descendants("Field").Where(p=>p.Attribute("TextControlID").Value.Substring(0,3)=="cbl").Count()>0){
               %>
                    #region 绑定复选框组
                    <%
                         var cbos = elements.Descendants("Field").Where(p => p.Attribute("TextControlID").Value.Substring(0, 3) == "cbl");
                         foreach (var item in cbos){
                    %>
                         #region 绑定<%=item.Value%>
                         //TODO:请绑定复选框组<%=item.Value%>
                         //ExtControlHelper.BindCheckGroup(this, _db.SelectGeneralFromTableINFO(ShopID, CurrentFormID,
                         //"<%=item.Attribute("AttributeTypeCode")==null?item.Attribute("TextControlID").Value.Substring(3):item.Attribute("AttributeTypeCode").Value %>").ToList()
                         //, "<%=item.Attribute("TextControlID").Value %>", "AttributeValue", "AttributeID", "CheckValue",4);
                         #endregion
                    <% }%>
                    #endregion
               <%} %>
                
                
               <%
               if(elements.Descendants("Field").Where(p=>p.Attribute("TextControlID").Value.Substring(0,3)=="rbl").Count()>0){
               %>
                    #region 绑定单选框组
                    <%
                         var rdos = elements.Descendants("Field").Where(p => p.Attribute("TextControlID").Value.Substring(0, 3) == "rbl");
                         foreach (var item in rdos){
                    %>
                         #region 绑定<%=item.Value%>
                         //TODO:请绑定单选框组<%=item.Value%>
                         //ExtControlHelper.BindRadioGroup(this, _db.SelectGeneralFromTableINFO(ShopID, CurrentFormID,
                         //"<%=item.Attribute("AttributeTypeCode")==null?item.Attribute("TextControlID").Value.Substring(3):item.Attribute("AttributeTypeCode").Value %>").ToList()
                         //, "<%=item.Attribute("TextControlID").Value %>", "AttributeValue", "AttributeID", "CheckValue",true,4);
                         #endregion
                    <% }%>
                    #endregion
               <%} %>
             }
            GC.Collect();
        }
 
        //保存
        protected void btnSave_Click(object sender, DirectEventArgs e)
        {
            try
            {
                //显示保存进度条
                X.Msg.Show(new MessageBoxConfig
                {
                    Message = "正在保存数据, 请稍后...",
                    ProgressText = "正在保存数据...",
                    Width = 300,
                    Wait = true,
                    WaitConfig = new WaitConfig { Interval = 200 },
                    IconCls = "ext-mb-download",
                    AnimEl = this.btnSave.ClientID
                });
                if (Save())
                {
                    //执行流程驱动
                    ResourceManager1.SetSubmitScript(ShopID, false);
                }
            }
            catch (Exception ex)
            {
                NBShopCommon.LogManager.WriteErrorLog(ex);
                ResourceManager1.AddScript(" setTimeout(function () { Ext.MessageBox.hide(); Ext.Msg.notify('完成', '保存失败!'); }, 1000);");
            }
 
        }
        //保存数据
        private bool Save()
        {
           //实例化LINQ To SQl类上下文对象
           NBShopDataContext _db = new NBShopDataContext();
           try
           {
               if (_db.Connection.State == ConnectionState.Closed)
                   _db.Connection.Open();
               //事务开始
               _db.Transaction = _db.Connection.BeginTransaction(System.Data.IsolationLevel.Serializable);
               //TODO:保存数据
                
               //提交事务
               _db.Transaction.Commit();
                
               //ObjectService _os = new ObjectService();
               //bool _bobjprc = _os.SaveObjectProcessInfo(Request.QueryString["ObjectID"] ?? string.Empty, Request.QueryString["PTCode"] ?? string.Empty);
               //bool _bobjnp = _os.SaveObjectPN(Request.QueryString["ObjectID"] ?? string.Empty, Request.QueryString["PhasesId"] ?? string.Empty);
               return true;
           }
           catch (Exception ex)
           {
               //回滚事务
               _db.Transaction.Rollback();
               LogManager.WriteErrorLog(ex);
               ResourceManager1.AddScript(" setTimeout(function () { Ext.MessageBox.hide(); Ext.Msg.notify('完成', '保存数据失败!');}, 3000);");
               return false;
           }
        }
        //提交
        protected void btnSubmit_Click(object sender, DirectEventArgs e)
        {
            try
            {
               //显示提交进度条
                X.Msg.Show(new MessageBoxConfig
                {
                    Message = "正在提交数据, 请稍后...",
                    ProgressText = "正在提交数据...",
                    Width = 300,
                    Wait = true,
                    WaitConfig = new WaitConfig { Interval = 200 },
                    IconCls = "ext-mb-download",
                    AnimEl = this.btnSumbit2.ClientID
                });
                if (Save())
                {
                    //流程操作并执行脚本
                    ResourceManager1.SetSubmitScript(ShopID, true);
                }
            }
            catch (Exception ex)
            {
                LogManager.WriteErrorLog(ex);
                ResourceManager1.AddScript(" setTimeout(function () { Ext.MessageBox.hide();Ext.Msg.notify('完成', '提交失败!'); }, 2000);");
            }
        }
    }
}
posted @   雪雁  阅读(1379)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示