【無私分享:從入門到精通ASP.NET MVC】從0開始,一塊兒搭框架、作項目 (13)客戶管理

索引javascript

【無私分享:從入門到精通ASP.NET MVC】從0開始,一塊兒搭框架、作項目 目錄索引

簡述css

簡單的客戶管理html

項目準備java

咱們用的工具是:VS 2013 + SqlServer 2012 + IIS7.5ajax

但願你們對ASP.NET MVC有一個初步的理解,理論性的東西咱們不作過多解釋,有些地方不理解也不要緊,會用就好了,用的多了,用的久了,天然就理解了。spring

項目開始

1、數據庫設計

表名:SYS_BUSSINESSCUSTOMER
 
序號 列名 數據類型 長度 小數位 標識 主鍵 外鍵 容許空 默認值 說明
1 ID int 4 0      
2 Fk_DepartId nvarchar 36 0          
3 FK_RELATIONID nvarchar 72 0         公司介紹外鍵
4 CompanyName nvarchar 50 0         公司名稱
5 CompanyProvince nvarchar 10 0         公司所在省份
6 CompanyCity nvarchar 10 0         公司所在城市
7 CompanyArea nvarchar 10 0         公司所在縣區
8 CompanyAddress nvarchar 500 0         公司通信地址
9 CompanyTel nvarchar 50 0         公司辦公電話
10 CompanyWebSite nvarchar 100 0         公司網址
11 ChargePersionName nvarchar 50 0         負責人姓名
12 ChargePersionSex int 4 0         負責人性別
13 ChargePersionQQ nvarchar 20 0         負責人QQ
14 ChargePersionEmail nvarchar 50 0         負責人郵箱
15 ChargePersionPhone nvarchar 50 0         負責人電話
16 IsValidate bit 1 0         公司是否已驗證
17 CreateUser nvarchar 50 0         建立人
18 CreateDate datetime 8 3         建立時間
19 UpdateUser nvarchar 50 0         更新人
20 UpdateDate datetime 8 3         更新時間
21 CustomerStyle int 4 0         客戶類型

 

2、建立接口和實現類

一、咱們在Service類庫下IService文件夾的SysManage文件夾下新建一個接口 IBussinessCustomerManage

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace Service.IService
 8 {
 9     /// <summary>
10     /// 客戶管理接口
11     /// add yuangang by 2016-06-17
12     /// </summary>
13     public interface IBussinessCustomerManage:IRepository<Domain.SYS_BUSSINESSCUSTOMER>
14     {
15     }
16 }

 

二、咱們在ServiceImp文件夾的SysManage文件夾下面新建一個實現類 BussinessCustomerManage

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace Service.ServiceImp
 8 {
 9     public class BussinessCustomerManage:RepositoryBase<Domain.SYS_BUSSINESSCUSTOMER>,IService.IBussinessCustomerManage
10     {
11     }
12 }

 

三、而後呢?對了,千萬別忘記,咱們在Service類庫下面的Service.xml配置一下

 

3、控制器和視圖

一、咱們在/Areas/SysManage/Controllers 下新建一個控制器 BussinessCustomerController 繼承基礎控制器 BaseController

 

二、咱們配置一下/Config/Controllers.xml 實現spring的注入

 

三、咱們聲明一下這些容器

 1 #region 聲明容器
 2         /// <summary>
 3         /// 公司客戶管理
 4         /// </summary>
 5         IBussinessCustomerManage BussinessCustomerManage { get; set; }
 6         /// <summary>
 7         /// 省市區管理
 8         /// </summary>
 9         ICodeAreaManage CodeAreaManage { get; set; }
10         /// <summary>
11         /// 大數據字段管理
12         /// </summary>
13         IContentManage ContentManage { get; set; }
14         /// <summary>
15         /// 編碼管理
16         /// </summary>
17         ICodeManage CodeManage { get; set; }
18         #endregion

 

四、咱們爲Index添加視圖,而且加入驗證模塊 模塊別名爲 BussinessCustomer 操做驗證爲 View

1 /// <summary>
2         /// 客戶管理加載主頁
3         /// </summary>
4         /// <returns></returns>
5         [UserAuthorizeAttribute(ModuleAlias = "BussinessCustomer", OperaAction = "View")]
6         public ActionResult Index()
7         {
8             
9         }

 

五、咱們添加菜單鏈接

5.1 咱們打開 系統管理中心 → 系統管理 → 模塊管理  添加一個頂部分類  【客戶管理中心】數據庫

 

5.2 咱們在【客戶管理中心】 下新建一個 右側頂級菜單 【客戶管理】json

 

5.3 咱們在【客戶管理】菜單下 新建一個菜單 【客戶中心】 模塊別名: BussinessCustomer  模塊類型: 列表頁   模塊路徑: /Sys/BussinessCustomer緩存

 

5.4 這樣咱們是否就有菜單了呢?答案是否認的。由於咱們爲Index添加了權限驗證 View 而咱們這個模塊尚未權限。因此咱們要建立權限app

爲了快速,咱們能夠直接選擇 【初始化權限】 會自動爲咱們添加 基本的操做權限 若是咱們須要其它權限 好比:審覈、發佈、下載、導出等,咱們能夠經過【建立新權限】 來添加自定義操做權限

 

OK,如今能夠打開頁面了。

 

六、修改Index 輸出客戶列表

 

6.1 輸出省份列表和客戶類型列表

1 ViewData["ProvinceList"] = CodeAreaManage.LoadListAll(p => p.LEVELS == 1);
2 ViewBag.KHLX = this.CodeManage.LoadAll(p => p.CODETYPE == "LXRLX").OrderBy(p => p.SHOWORDER).ToList();

 

6.2  處理查詢參數 輸出客戶列表

 1 /// <summary>
 2         /// 客戶管理加載主頁
 3         /// </summary>
 4         /// <returns></returns>
 5         [UserAuthorizeAttribute(ModuleAlias = "BussinessCustomer", OperaAction = "View")]
 6         public ActionResult Index()
 7         {
 8             try
 9             {
10 
11                 #region 處理查詢參數
12                 //接收省份
13                 string Province = Request.QueryString["Province"];
14                 ViewData["Province"] = Province;
15                 //接收客戶類型
16                 string CustomerStyle = Request.QueryString["CustomerStyle"];
17                 ViewData["CustomerStyle"] = CustomerStyle;
18                 //文本框輸入查詢關鍵字
19                 ViewBag.Search = base.keywords;                
20                 #endregion
21 
22                 ViewData["ProvinceList"] = CodeAreaManage.LoadListAll(p => p.LEVELS == 1);
23                 ViewBag.KHLX = this.CodeManage.LoadAll(p => p.CODETYPE == "LXRLX").OrderBy(p => p.SHOWORDER).ToList();
24 
25                 //輸出客戶分頁列表
26                 return View(BindList(Province, CustomerStyle));
27             }
28             catch (Exception e)
29             {
30                 WriteLog(Common.Enums.enumOperator.Select, "客戶管理加載主頁:", e);
31                 throw e.InnerException;
32             }
33         }

 

6.3 分頁查詢客戶列表方法

 1  #region 幫助方法及其餘控制器調用
 2         /// <summary>
 3         /// 分頁查詢公司客戶列表
 4         /// </summary>
 5         private Common.PageInfo BindList(string Province, string CustomerStyle)
 6         {
 7             //基礎數據(緩存)
 8             var query = this.BussinessCustomerManage.LoadAll(null);
 9 
10             //非超級管理員只容許查看用戶所在部門客戶
11             if(!CurrentUser.IsAdmin)
12             {
13                 query = query.Where(p => p.Fk_DepartId == CurrentUser.DptInfo.ID);
14             }
15 
16             //客戶所在省份
17             if (!string.IsNullOrEmpty(Province))
18             {               
19                 query = query.Where(p => p.CompanyProvince == Province);
20             }
21 
22             //客戶類型
23             if (!string.IsNullOrEmpty(CustomerStyle))
24             {
25                 int styleId = int.Parse(CustomerStyle);
26                 query = query.Where(p => p.CustomerStyle == styleId);
27             }
28 
29             //查詢關鍵字
30             if (!string.IsNullOrEmpty(keywords))
31             {
32                 keywords = keywords.ToLower();
33                 query = query.Where(p => p.CompanyName.Contains(keywords) || p.ChargePersionName.Contains(keywords));
34             }
35             //排序
36             query = query.OrderByDescending(p => p.UpdateDate).OrderByDescending(p => p.ID);
37             //分頁
38             var result = this.BussinessCustomerManage.Query(query, page, pagesize);
39 
40             var list = result.List.Select(p => new
41             {
42                 p.ID,
43                 p.CompanyName,
44                 p.IsValidate,
45                 CompanyProvince = this.CodeAreaManage.Get(m => m.ID == p.CompanyProvince).NAME,
46                 CompanyCity = this.CodeAreaManage.Get(m => m.ID == p.CompanyCity).NAME,
47                 CompanyArea = this.CodeAreaManage.Get(m => m.ID == p.CompanyArea).NAME,
48                 p.CompanyTel,
49                 p.ChargePersionName,
50                 p.CreateUser,
51                 CreateDate=p.CreateDate.ToString("yyyy-MM-dd"),
52                 p.CustomerStyle
53 
54 
55             }).ToList();
56 
57             return new Common.PageInfo(result.Index, result.PageSize, result.Count, Common.JsonConverter.JsonClass(list));
58         }59         #endregion

 

6.4 頁面輸出

 

 

七、添加、修改、刪除客戶

7.1  加載客戶詳情 生成表單

 1  /// <summary>
 2         /// 加載詳情
 3         /// </summary>
 4         /// <param name="id"></param>
 5         /// <returns></returns>
 6         [UserAuthorizeAttribute(ModuleAlias = "BussinessCustomer", OperaAction = "Detail")]
 7         public ActionResult Detail(int? id)
 8         {
 9             //初始化客戶
10             var entity = new Domain.SYS_BUSSINESSCUSTOMER() { ChargePersionSex = 1 };
11 
12             if(id!=null && id>0)
13             {
14                 //客戶實體
15                 entity = BussinessCustomerManage.Get(p => p.ID == id);
16                 //公司介紹
17                 ViewData["CompanyInstroduce"] = ContentManage.Get(p => p.FK_RELATIONID == entity.FK_RELATIONID && p.FK_TABLE == "SYS_BUSSINESSCUSTOMER") ?? new Domain.COM_CONTENT();
18             }
19 
20             //客戶類型
21             ViewBag.KHLX = this.CodeManage.LoadAll(p => p.CODETYPE == "LXRLX").OrderBy(p=>p.SHOWORDER).ToList();
22 
23             return View(entity);
24         }

 

7.2 Detail.cshtml

  1 @{
  2     ViewBag.Title = "Detail";
  3     Layout = "~/Views/Shared/_Layout.cshtml";
  4     var content = ViewData["CompanyInstroduce"] == null ? new Domain.COM_CONTENT() : ViewData["CompanyInstroduce"] as Domain.COM_CONTENT;
  5 }
  6 @model Domain.SYS_BUSSINESSCUSTOMER
  7 <style type="text/css">
  8     .gray-bg {
  9         background-color: white;
 10     }
 11 </style>
 12 @using (Ajax.BeginForm("Save", null, new AjaxOptions()
 13                            {
 14                                HttpMethod = "Post",
 15                                OnBegin = "SubAjax.Loading",
 16                                OnComplete = "SubAjax.Complate",
 17                                OnFailure = "SubAjax.Failure",
 18                                OnSuccess = "SubAjax.Success"
 19                            },
 20                                new { @class = "form-horizontal dig-from", @role = "form" }))
 21 {
 22     @Html.HiddenFor(p => p.ID)
 23     @Html.HiddenFor(p=>p.FK_RELATIONID)
 24     @Html.HiddenFor(p=>p.Fk_DepartId)
 25     @Html.HiddenFor(p => p.CreateUser)
 26     @Html.HiddenFor(p => p.CreateDate)
 27     @Html.Hidden("ContentId", content.ID)
 28     <div class="wrapper wrapper-content animated fadeInUp">
 29         <div class="row">
 30             <div class="ibox-detail-title">
 31                 <i class="fa fa-pencil-square-o"></i>添加/修改客戶
 32             </div>
 33             <div class="ibox-content">
 34                 <div class="row">
 35                     <div class="col-xs-6">
 36                         <div class="form-group">
 37                             <label class="col-xs-4 control-label">客戶名稱:</label>
 38                             <div class="col-xs-8">
 39                                 @Html.TextBoxFor(p => p.CompanyName, new { @class = "form-control", @placeholder = "請輸入客戶名稱", @datatype = "*", @nullmsg = "請輸入客戶名稱!", @errormsg = "請輸入客戶名稱!" })
 40                             </div>
 41                         </div>
 42                     </div>
 43                     <div class="col-xs-6">
 44                         <div class="form-group">
 45                             <label class="col-xs-4 control-label">客戶類型:</label>
 46                             <div class="col-xs-8">
 47                                 <select name="CustomerStyle" class="form-control input-sm  input-s-sm inline">
 48                                     @{
 49     foreach (var item in ViewBag.KHLX)
 50     {
 51                             <option value="@item.CODEVALUE" @(Model.CustomerStyle!=null&&Model.CustomerStyle.ToString() == @item.CODEVALUE ? "selected" : "")>@item.NAMETEXT</option>
 52     }
 53                                     }
 54                                 </select>
 55 
 56                             </div>
 57                         </div>
 58                     </div>
 59                 </div>
 60                 <div class="hr-line-dashed"></div>
 61                 <div class="row">
 62                     <div class="col-xs-6">
 63                         <div class="form-group">
 64                             <label class="col-xs-4 control-label">公司電話:</label>
 65                             <div class="col-xs-8">
 66                                 @Html.TextBoxFor(p => p.CompanyTel, new { @class = "form-control", @placeholder = "請輸入公司電話" })
 67                             </div>
 68                         </div>
 69                     </div>
 70                     <div class="col-xs-6">
 71                         <div class="form-group">
 72                             <label class="col-xs-4 control-label">公司網址:</label>
 73                             <div class="col-xs-8">
 74                                 @Html.TextBoxFor(p => p.CompanyWebSite, new { @class = "form-control", @placeholder = "請輸入公司網址" })
 75                             </div>
 76                         </div>
 77                     </div>
 78                 </div>
 79                 <div class="hr-line-dashed"></div>
 80                         <div class="form-group">
 81                             <label class="col-xs-2 control-label">所在地:</label>
 82                             <div class="col-xs-10">
 83                                 @Html.HiddenFor(p => p.CompanyProvince)
 84                                 @Html.HiddenFor(p => p.CompanyCity)
 85                                 @Html.HiddenFor(p => p.CompanyArea)
 86                                 <select name="Province" id="Province" onchange="SelectCity('Province', 'City')" class="form-control input-sm  input-s-sm inline">
 87                                     <option value="-1">--請選擇--</option>
 88                                 </select>
 89                                 <select name="City" id="City" onchange="SelectCountry('City', 'Area')" class="form-control input-sm  input-s-sm inline">
 90                                     <option value="-1">--請選擇--</option>
 91                                 </select>
 92                                 <select name="Area" id="Area" onchange="SelectAreas('Area')" class="form-control input-sm  input-s-sm inline">
 93                                     <option value="-1">--請選擇--</option>
 94                                 </select>
 95                             </div>
 96                         </div>
 97                 <div class="hr-line-dashed"></div>
 98                 <div class="form-group">
 99                     <label class="col-xs-2 control-label">通信地址:</label>
100                     <div class="col-xs-10">
101                         @Html.TextBoxFor(p => p.CompanyAddress, new { @class = "form-control", @placeholder = "請輸入通信地址" })
102                     </div>
103                 </div>
104                 <div class="hr-line-dashed"></div>
105                 <div class="row">
106                     <div class="col-xs-6">
107                         <div class="form-group">
108                             <label class="col-xs-4 control-label">負責人:</label>
109                             <div class="col-xs-8">
110                                 @Html.TextBoxFor(p => p.ChargePersionName, new { @class = "form-control", @placeholder = "請輸入負責人姓名", @datatype = "*", @nullmsg = "請輸入負責人姓名!", @errormsg = "請輸入負責人姓名!" })
111                             </div>
112                         </div>
113                     </div>
114                     <div class="col-xs-6">
115                         <div class="form-group">
116                             <label class="col-xs-4 control-label">性別:</label>
117                             <div class="col-xs-8">
118                                 <label class="icheck_line">
119                                     <input type="radio" name="ChargePersionSex" value="1" @(Model.ChargePersionSex != null && Model.ChargePersionSex == 1 ? "checked" : "") class="icheck_box">120                                 </label>
121                                 <label class="icheck_line">
122                                     <input type="radio" name="ChargePersionSex" value="2" @(Model.ChargePersionSex != null && Model.ChargePersionSex == 2 ? "checked" : "") class="icheck_box">123                                 </label>
124                             </div>
125                         </div>
126                     </div>
127                 </div>
128                 <div class="hr-line-dashed"></div>
129                 <div class="row">
130                     <div class="col-xs-6">
131                         <div class="form-group">
132                             <label class="col-xs-4 control-label">聯繫電話:</label>
133                             <div class="col-xs-8">
134                                 @Html.TextBoxFor(p => p.ChargePersionPhone, new { @class = "form-control", @placeholder = "請輸入負責人電話" })
135                             </div>
136                         </div>
137                     </div>
138                     <div class="col-xs-6">
139                         <div class="form-group">
140                             <label class="col-xs-4 control-label">QQ:</label>
141                             <div class="col-xs-8">
142                                @Html.TextBoxFor(p => p.ChargePersionQQ, new { @class = "form-control", @placeholder = "請輸入負責人QQ" })
143                             </div>
144                         </div>
145                     </div>
146                 </div>
147                 <div class="hr-line-dashed"></div>
148                 <div class="row">
149                     <div class="col-xs-6">
150                         <div class="form-group">
151                             <label class="col-xs-4 control-label">Email:</label>
152                             <div class="col-xs-8">
153                                 @Html.TextBoxFor(p => p.ChargePersionEmail, new { @class = "form-control", @placeholder = "請輸入負責人郵箱" })
154                             </div>
155                         </div>
156                     </div>
157                     <div class="col-xs-6">
158                         <div class="form-group">
159                             <label class="col-xs-4 control-label">驗證狀態:</label>
160                             <div class="col-xs-8">
161                                 <label class="jswitch_line">
162                                     @Html.CheckBoxFor(p => p.IsValidate, new { @class = "js-switch" })
163                                 </label>
164                             </div>
165                         </div>
166                     </div>
167                 </div>
168                 <div class="hr-line-dashed"></div>
169                 <div class="form-group">
170                     <label class="col-xs-2 control-label">公司簡介:</label>
171                     <div class="col-xs-10">
172                         <script id="Content" name="Content" type="text/plain" style="width:100%;height:200px;">
173                             @Html.Raw(content.CONTENT)
174                         </script>
175                     </div>
176                 </div>
177                 <div class="hr-line-dashed"></div>
178                 <div class="text-center">
179                     <button class="btn btn-primary btn-save" type="submit"><i class="fa fa-check"></i> <span>肯定保存</span></button>
180                     <button class="btn btn-warning" id="btn-dig-close" type="button"><i class="fa fa-reply-all"></i> 取消返回</button>
181                 </div>
182             </div>
183         </div>
184     </div>
185 }
186 @section scripts{
187 <script type="text/javascript" src="/Content/ueditor/ueditor.config.js"></script>
188 <script type="text/javascript" src="/Content/ueditor/ueditor.all.min.js"></script>
189 <script type="text/javascript" src="/Content/ueditor/lang/zh-cn/zh-cn.js"></script>
190     <script type="text/javascript">
191         $(function () {
192             $('.form-horizontal').initValidform();
193             UE.getEditor('Content');
194             r.Initial();
195         });
196         var r = {
197             Initial: function () {
198                 $.ajax({
199                     url: '/Sys/CodeArea/prov',
200                     data: null,
201                     type: 'post',
202                     dataType: 'json',
203                     cache: false,
204                     success: function (res) {
205                         if (res.Status == 'y') {
206                             var option = '';
207                             var data = eval(res.Data);
208                             for (var i = 0; i < data.length; i++) {
209                                 var jsonH = data[i];
210                                 if (jsonH.ID == $("#CompanyProvince").val()) {
211                                     option += '<option value="' + jsonH.ID + '" selected="selected">' + jsonH.NAME + '</option>';
212                                 }
213                                 else {
214                                     option += '<option value="' + jsonH.ID + '">' + jsonH.NAME + '</option>';
215                                 }
216                             }
217                             $('#Province').html(option);
218                             SelectCity('Province', 'City');
219                         }
220                     }
221                 });
222             }
223         };
224         //加載城市
225         function SelectCity(t, n) {
226             var prov = $('#' + t).val();
227             $("#CompanyProvince").val(prov);
228             var city = $('#' + n);
229             var option = '';
230             if (prov == '') {
231                 city.html(option);
232             } else {
233                 $.ajax({
234                     url: '/Sys/CodeArea/City/' + prov,
235                     data: null,
236                     type: 'post',
237                     dataType: 'json',
238                     async: false,
239                     cache: false,
240                     success: function (res) {
241                         if (res.Status == 'y') {
242                             var data = eval(res.Data);
243                             for (var i = 0; i < data.length; i++) {
244                                 var jsonH = data[i];
245                                 if (jsonH.ID == $("#CompanyCity").val()) {
246                                     option += '<option value="' + jsonH.ID + '" selected="selected">' + jsonH.NAME + '</option>';
247                                 }
248                                 else {
249                                     option += '<option value="' + jsonH.ID + '">' + jsonH.NAME + '</option>';
250                                 }
251                             }
252                         }
253                         city.html(option);
254                         SelectCountry('City', 'Area')
255                     }
256                 });
257             }
258         }
259         //加載縣級市
260         function SelectCountry(t, n) {
261             var city = $('#' + t).val();
262             $("#CompanyCity").val(city);
263             var country = $('#' + n);
264             var option = '';
265             if (city == '') {
266                 country.html(option);
267             } else {
268                 $.ajax({
269                     url: '/Sys/CodeArea/Country/' + city,
270                     data: null,
271                     type: 'post',
272                     dataType: 'json',
273                     async: false,
274                     cache: false,
275                     success: function (res) {
276                         if (res.Status == 'y') {
277                             var data = eval(res.Data);
278                             for (var i = 0; i < data.length; i++) {
279                                 var jsonH = data[i];
280                                 if (jsonH.ID == $("#CompanyArea").val()) {
281                                     option += '<option value="' + jsonH.ID + '" selected="selected">' + jsonH.NAME + '</option>';
282                                 }
283                                 else {
284                                     option += '<option value="' + jsonH.ID + '">' + jsonH.NAME + '</option>';
285                                 }
286                             }
287                         }
288                         country.html(option);
289                         SelectAreas('Area')
290                     }
291                 });
292             }
293         }
294         function SelectAreas(t) {
295             var area = $('#' + t).val();
296             $("#CompanyArea").val(area);
297         }
298     </script>
299 }
View Code

 

 

7.3 保存客戶

  1 /// <summary>
  2         /// 保存客戶信息
  3         /// </summary>
  4         [ValidateInput(false)]
  5         [UserAuthorizeAttribute(ModuleAlias = "BussinessCustomer", OperaAction = "Add,Edit")]
  6         public ActionResult Save(Domain.SYS_BUSSINESSCUSTOMER entity)
  7         {
  8             bool isEdit = false;
  9             var FK_RELATIONID = "";
 10             var json = new JsonHelper() { Msg = "保存成功", Status = "n" };
 11             try
 12             {
 13                 if (entity != null)
 14                 {
 15                     //公司簡介數據ID
 16                     var contentId = Request["ContentId"] == null ? 0 : Int32.Parse(Request["ContentId"].ToString());
 17 
 18                     if (entity.ID <= 0) //添加
 19                     {
 20                         FK_RELATIONID = Guid.NewGuid().ToString();
 21                         entity.FK_RELATIONID = FK_RELATIONID;
 22                         entity.Fk_DepartId = this.CurrentUser.DptInfo == null ? "" : this.CurrentUser.DptInfo.ID;
 23                         entity.CreateUser = CurrentUser.Name;
 24                         entity.CreateDate = DateTime.Now;
 25                         entity.UpdateUser = CurrentUser.Name;
 26                         entity.UpdateDate = DateTime.Now;
 27 
 28                     }
 29                     else //修改
 30                     {
 31                         FK_RELATIONID = entity.FK_RELATIONID;
 32                         entity.UpdateUser = CurrentUser.Name;
 33                         entity.UpdateDate = DateTime.Now;
 34                         isEdit = true;
 35                     }
 36                     //同部門下 客戶名稱不能重複
 37                     if (!this.BussinessCustomerManage.IsExist(p => p.CompanyName.Equals(entity.CompanyName) && p.ID != entity.ID && p.Fk_DepartId == entity.Fk_DepartId))
 38                     {
 39                         using (TransactionScope ts = new TransactionScope())
 40                         {
 41                             try
 42                             {
 43                                 if (this.BussinessCustomerManage.SaveOrUpdate(entity, isEdit))
 44                                 {
 45                                     if (contentId <= 0)
 46                                     {
 47                                         this.ContentManage.Save(new Domain.COM_CONTENT()
 48                                         {
 49                                             CONTENT = Request["Content"],
 50                                             FK_RELATIONID = FK_RELATIONID,
 51                                             FK_TABLE = "SYS_BUSSINESSCUSTOMER",
 52                                             CREATEDATE = DateTime.Now
 53                                         });
 54                                     }
 55                                     else
 56                                     {
 57                                         this.ContentManage.Update(new Domain.COM_CONTENT()
 58                                         {
 59                                             ID = contentId,
 60                                             CONTENT = Request["Content"],
 61                                             FK_RELATIONID = FK_RELATIONID,
 62                                             FK_TABLE = "SYS_BUSSINESSCUSTOMER",
 63                                             CREATEDATE = DateTime.Now
 64                                         });
 65                                     }
 66                                     json.Status = "y";
 67 
 68                                 }
 69 
 70                                 ts.Complete();
 71                                 
 72                             }
 73                             catch(Exception e)
 74                             {
 75                                 json.Msg = "保存客戶信息發生內部錯誤!";
 76                                 WriteLog(Common.Enums.enumOperator.None, "保存客戶錯誤:", e);
 77                             }
 78                             
 79                         }                                                
 80                     }
 81                     else
 82                     {
 83                         json.Msg = "客戶已經存在,請不要重複添加!";
 84                     }
 85                 }
 86                 else
 87                 {
 88                     json.Msg = "未找到要操做的客戶記錄";
 89                 }
 90                 if (isEdit)
 91                 {
 92                     WriteLog(Common.Enums.enumOperator.Edit, "修改客戶[" + entity.CompanyName + "],結果:" + json.Msg, Common.Enums.enumLog4net.INFO);
 93                 }
 94                 else
 95                 {
 96                     WriteLog(Common.Enums.enumOperator.Add, "添加客戶[" + entity.CompanyName + "],結果:" + json.Msg, Common.Enums.enumLog4net.INFO);
 97                 }
 98             }
 99             catch (Exception e)
100             {
101                 json.Msg = "保存客戶信息發生內部錯誤!";
102                 WriteLog(Common.Enums.enumOperator.None, "保存客戶錯誤:", e);
103             }
104             return Json(json);
105 
106         }

 

7.3 刪除客戶

 1 /// <summary>
 2         /// 刪除客戶
 3         /// 刪除原則:一、刪除客戶信息
 4         ///           二、刪除客戶公司簡介數據
 5         /// </summary>
 6         [UserAuthorizeAttribute(ModuleAlias = "User", OperaAction = "Remove")]
 7         public ActionResult Delete(string idList)
 8         {
 9             var json = new JsonHelper() { Status = "n", Msg = "刪除客戶成功" };
10             try
11             {
12                 //是否爲空
13                 if (string.IsNullOrEmpty(idList)) { json.Msg = "未找到要刪除的客戶"; return Json(json); }
14 
15                 var id = idList.Trim(',').Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(p => int.Parse(p)).ToList();
16 
17                 using (TransactionScope ts = new TransactionScope())
18                 {
19                     try
20                     {
21                         foreach(var item in id)
22                         {
23                             //刪除客戶公司簡介
24                             var entity = BussinessCustomerManage.Get(p => p.ID == item);
25                             ContentManage.Delete(p => p.FK_RELATIONID == entity.FK_RELATIONID && p.FK_TABLE == "SYS_BUSSINESSCUSTOMER");
26                         }
27                         //刪除客戶信息
28                         BussinessCustomerManage.Delete(p => id.Contains(p.ID));
29 
30                         WriteLog(Common.Enums.enumOperator.Remove, "刪除客戶:" + json.Msg, Common.Enums.enumLog4net.WARN);                
31 
32                         ts.Complete();
33 
34                     }
35                     catch (Exception e)
36                     {
37                         json.Msg = "刪除客戶發生內部錯誤!";
38                         WriteLog(Common.Enums.enumOperator.Remove, "刪除客戶:", e);
39                     }
40 
41                 }                                                        
42             }
43             catch (Exception e)
44             {
45                 json.Msg = "刪除客戶發生內部錯誤!";
46                 WriteLog(Common.Enums.enumOperator.Remove, "刪除客戶:", e);
47             }
48             return Json(json);
49         }

 

 

 

原創文章 轉載請尊重勞動成果 http://yuangang.cnblogs.com

相關文章
相關標籤/搜索
本站公眾號
   歡迎關注本站公眾號,獲取更多信息