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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CY.BLL;
using CY.Model;
using CY.Infrastructure.Query;
using CY.Infrastructure.Common;
using CY.BLL.Sys;
using System.Text;
using CY.BLL.OA;
 
namespace CY.WebForm.Pages.adminclient
{
    //吴辉
    //新增/修改合作客户资料
    public partial class AddCorporateClients : BasePage
    {
        OA_CorporateClientsBLL bll_OA_CorporateClientsBLL = null;
        Sys_DictionaryBLL bll_Sys_DictionaryBLL = null;//字典业务逻辑操作类对象
        EC_MemberBasicBLL bll_EC_MemberBasicBLL = null;
        OA_IntentionCustomerBLL bll_OA_IntentionCustomerBLL = null;
        OA_StaffBLL bll_OA_StaffBLL = null;
        public string Province = ""; //接收值 Request["selectProvince"].ToString2();
        public string City = "";//接收值 Request["selectCity"].ToString2();
        public string County = "";//接收值 Request["selectCounty"].ToString2();
        public string Targetid = ""; //收货方式目标值
 
        //初始化
        public AddCorporateClients()
        {
            bll_OA_CorporateClientsBLL = new OA_CorporateClientsBLL();
            bll_Sys_DictionaryBLL = new Sys_DictionaryBLL();
            bll_EC_MemberBasicBLL = new EC_MemberBasicBLL();
            bll_OA_IntentionCustomerBLL = new OA_IntentionCustomerBLL();
            bll_OA_StaffBLL = new OA_StaffBLL();
        }
 
        //页面加载
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
 
                Targetid = Request["Keyid"].ToString2();
                switch (Request["datatype"].ToString2())
                {
                    case "check":
                        if (Request["companyName"] != null && Request["datatype"].ToString2() == "check")
                            Response.Write(BindCompanyList(Request["companyName"].ToString2().Trim()));
                        break;
                    default:
                        if (!IsPostBack)
                        {
                            Province = CurrentUser.Province;
                            City = CurrentUser.City;
                            //County = CurrentUser.County;
                            BindData();
                        }
                        return;
                }
            }
            catch (Exception ex)
            {
                PAGEHandleException(ex);
                Response.Clear();
                Response.Write("-1");
            }
            Response.End();
        }
 
        //绑定数据
        protected void BindData()
        {
            #region 初始字典表数据
 
            this.selSourcesInfoId.DataSource = bll_Sys_DictionaryBLL.GetDataByType("软件客户来源");
            this.selSourcesInfoId.DataValueField = "Keyid";
            this.selSourcesInfoId.DataTextField = "Name";
            this.selSourcesInfoId.DataBind();
 
            this.selCustomerIndustriesId.DataSource = bll_Sys_DictionaryBLL.GetDataByType("软件所属行业");
            this.selCustomerIndustriesId.DataValueField = "Keyid";
            this.selCustomerIndustriesId.DataTextField = "Name";
            this.selCustomerIndustriesId.DataBind();
            this.selCustomerIndustriesId.Value = "435";
 
            this.selCustomerTypeId.DataSource = bll_Sys_DictionaryBLL.GetDataByType("软件客户类型");
            this.selCustomerTypeId.DataValueField = "Keyid";
            this.selCustomerTypeId.DataTextField = "Name";
            this.selCustomerTypeId.DataBind();
 
            this.selBusinessManagerId.DataSource = bll_OA_StaffBLL.SelectListByFirmId(CurrentUser.MemberId, true, false);
            this.selBusinessManagerId.DataTextField = "Name";
            this.selBusinessManagerId.DataValueField = "Keyid";
            this.selBusinessManagerId.DataBind();
            this.selBusinessManagerId.Items.Insert(0, new ListItem("请选择", ""));
 
            this.selAccountManagerId.DataSource = bll_OA_StaffBLL.SelectListByFirmId(CurrentUser.MemberId, false, true);
            this.selAccountManagerId.DataTextField = "Name";
            this.selAccountManagerId.DataValueField = "Keyid";
            this.selAccountManagerId.DataBind();
            this.selAccountManagerId.Items.Insert(0, new ListItem("请选择", ""));
 
            this.selCreditId.DataSource = bll_Sys_DictionaryBLL.GetDataByType("客户信誉");
            this.selCreditId.DataValueField = "Keyid";
            this.selCreditId.DataTextField = "Name";
            this.selCreditId.DataBind();
            this.selCreditId.Value = "76";
 
            this.selDegreeImportanId.DataSource = bll_Sys_DictionaryBLL.GetDataByType("客户重要程度");
            this.selDegreeImportanId.DataValueField = "Keyid";
            this.selDegreeImportanId.DataTextField = "Name";
            this.selDegreeImportanId.DataBind();
 
            this.selBusinessAnalysisId.DataSource = bll_Sys_DictionaryBLL.GetDataByType("客户业务分析量");
            this.selBusinessAnalysisId.DataValueField = "Keyid";
            this.selBusinessAnalysisId.DataTextField = "Name";
            this.selBusinessAnalysisId.DataBind();
            this.selBusinessAnalysisId.Value = "83";
            #endregion
 
            if (Request["Keyid"] != null)
            {
                OA_CorporateClients m_OA_CorporateClients = bll_OA_CorporateClientsBLL.GetModel(Request["Keyid"].ToGuid2());
                OA_CustomerCommunications m_OA_CustomerCommunications = bll_OA_CorporateClientsBLL.GetModel_CustomerCommunications(Request["Keyid"].ToGuid2());
                EC_AcceptWayByCustomers m_EC_AcceptWayByCustomers = bll_OA_CorporateClientsBLL.GetModel_AcceptWayByCustomers(Request["Keyid"].ToGuid2());
 
                #region 页面初始合作客户基础信息
 
                this.selSourcesInfoId.Value = m_OA_CorporateClients.SourcesInfoId.ToString2();
                this.selCustomerIndustriesId.Value = m_OA_CorporateClients.CustomerIndustriesId.ToString2();
                this.selCustomerTypeId.Value = m_OA_CorporateClients.CustomerTypeId.ToString2();
                this.selBusinessManagerId.Value = m_OA_CorporateClients.BusinessManagerId.ToString2();
                this.selAccountManagerId.Value = m_OA_CorporateClients.AccountManagerId.ToString2();
                this.selDegreeImportanId.Value = m_OA_CorporateClients.DegreeImportanId.ToString2();
                this.selBusinessAnalysisId.Value = m_OA_CorporateClients.BusinessAnalysisId.ToString2();
                //this.selIsLoginCorporateWeb.Value = m_OA_CorporateClients.IsLoginCorporateWeb.ToString2();
                this.selCreditId.Value = m_OA_CorporateClients.CreditId.ToString2();
                this.txtCompanyName.Value = m_OA_CorporateClients.CompanyName.ToString2();
                //this.txtCorporateWebsite.Value = m_OA_CorporateClients.CorporateWebsite.ToString2();
                //this.txtCredit.Value = m_OA_CorporateClients.Credit.ToString2().ToDecimal2Yen();
                //this.txtLoginPhone.Value = m_OA_CorporateClients.LoginPhone.ToString2();
                this.txtBank.Value = m_OA_CorporateClients.Bank.ToString2();
                this.txtTaxID.Value = m_OA_CorporateClients.TaxID.ToString2();
                this.txtAccountID.Value = m_OA_CorporateClients.AccountID.ToString2();
                this.txtRemark.InnerText = m_OA_CorporateClients.Remark.ToString2();
                // this.txtPassWord.Value = m_OA_CorporateClients.LoginPwd.ToString2();
                #endregion
 
                #region 页面初始合作客户通讯信息
 
                this.txtDetailedAddress.Value = m_OA_CustomerCommunications.DetailedAddress.ToString2();
                this.txtCompanyPhone.Value = m_OA_CustomerCommunications.CompanyPhone.ToString2();
                this.txtPostcode.Value = m_OA_CustomerCommunications.Postcode.ToString2();
                this.txtMobile.Value = m_OA_CustomerCommunications.Mobile.ToString2();
                this.txtFax.Value = m_OA_CustomerCommunications.Fax.ToString2();
                this.txtEmail.Value = m_OA_CustomerCommunications.Email.ToString2();
                this.txtQQ.Value = m_OA_CustomerCommunications.QQ.ToString2();
                this.txtLegalRepresentative.Value = m_OA_CustomerCommunications.LegalRepresentative.ToString2();
                this.txtLegalMobile.Value = m_OA_CustomerCommunications.LegalMobile.ToString2();
                this.txtLegalQQ.Value = m_OA_CustomerCommunications.LegalQQ.ToString2();
                this.txtBusinessManagers.Value = m_OA_CustomerCommunications.BusinessManagers.ToString2();
                this.txtManagersMobile.Value = m_OA_CustomerCommunications.ManagersMobile.ToString2();
                this.txtManagersQQ.Value = m_OA_CustomerCommunications.ManagersQQ.ToString2();
                this.txtFinancialOfficers.Value = m_OA_CustomerCommunications.FinancialOfficers.ToString2();
                this.txtOfficersMobile.Value = m_OA_CustomerCommunications.OfficersMobile.ToString2();
                this.txtOfficersQQ.Value = m_OA_CustomerCommunications.OfficersQQ.ToString2();
 
                Province = m_OA_CustomerCommunications.Province.ToString2();
                City = m_OA_CustomerCommunications.City.ToString2();
                County = m_OA_CustomerCommunications.County.ToString2();
 
                #endregion
 
            }
            else
            {
                #region 页面初始合作客户基础信息
 
                this.txtCompanyName.Value = "";
                this.txtBank.Value = "";
                this.txtTaxID.Value = "";
                this.txtAccountID.Value = "";
                this.txtRemark.InnerText = "";
                #endregion
 
                #region 页面初始合作客户通讯信息
 
                this.txtDetailedAddress.Value = "";
                this.txtCompanyPhone.Value = "";
                this.txtPostcode.Value = "";
                this.txtMobile.Value = "";
                this.txtFax.Value = "";
                this.txtEmail.Value = "";
                this.txtQQ.Value = "";
                this.txtLegalRepresentative.Value = "";
                this.txtLegalMobile.Value = "";
                this.txtLegalQQ.Value = "";
                this.txtBusinessManagers.Value = "";
                this.txtManagersMobile.Value = "";
                this.txtManagersQQ.Value = "";
                this.txtFinancialOfficers.Value = "";
                this.txtOfficersMobile.Value = "";
                this.txtOfficersQQ.Value = "";
 
                #endregion
            }
        }
 
        //绑定关联会员列表以及意向客户列表
        protected string BindCompanyList(string companyname)
        {
            Guid Keyid = Request["Keyid"].ToGuid2();
 
            bool isExit = bll_OA_CorporateClientsBLL.isExistCompanyName(companyname, CurrentUser.MemberId, Keyid);
            if (isExit)
                return "0";
 
            if (Request["xs"].ToString2() == "blur")
            {
                bool resultxs = bll_OA_IntentionCustomerBLL.isExistCompanyName(Request["companyname"].ToString2(), CurrentUser.MemberId, 0);
                if (resultxs)
                    return "1";
                else
                    return "2";
            }
            else
            {
 
                List<OA_IntentionCustomer> m_OA_IntentionCustomerList = bll_OA_IntentionCustomerBLL.SelectListByName(companyname, CurrentUser.MemberId) as List<OA_IntentionCustomer>;
 
                string[] modelArry = new string[m_OA_IntentionCustomerList.Count];
                int i = 0;
 
                foreach (var item in m_OA_IntentionCustomerList)
                {
                    string result = "";
                    StringBuilder sb_html = new StringBuilder();
 
                    sb_html.AppendFormat("CustormType:'{0}',", "意向客户");
                    sb_html.AppendFormat("CustormKeyId:'{0}',", item.Keyid);
                    sb_html.AppendFormat("CustormName:'{0}',", item.CompanyName);
                    sb_html.AppendFormat("CustormAddress:'{0}',", item.DetailedAddress);
                    sb_html.AppendFormat("CustormPhone:'{0}',", item.PhoneNum);
                    sb_html.AppendFormat("CustormMobile:'{0}',", item.MobileNum);
                    sb_html.AppendFormat("CustormFax:'{0}',", "");
                    sb_html.AppendFormat("CustormQQ:'{0}',", item.QQ);
                    sb_html.AppendFormat("CustormEmail:'{0}',", item.Email);
                    sb_html.AppendFormat("CustormPostCode:'{0}',", item.Postcode);
                    sb_html.AppendFormat("CustormWeb:'{0}'", "");
 
                    result = "{" + sb_html.ToString() + "}";
                    modelArry[i] = result;
                    i++;
                }
                return ("[" + string.Join(",", modelArry) + "]");
            }
        }
 
        //提交事件
        protected void btn_Submit_Config(object sender, EventArgs e)
        {
            OA_CorporateClients m_OA_CorporateClients = new OA_CorporateClients();
            OA_CustomerCommunications m_OA_CustomerCommunications = new OA_CustomerCommunications();
            EC_AcceptWayByCustomers m_EC_AcceptWayByCustomers = new EC_AcceptWayByCustomers();
 
            try
            {
                Guid Keyid = Request["Keyid"].ToGuid2();
                bool isExit = bll_OA_CorporateClientsBLL.isExistCompanyName(this.txtCompanyName.Value.ToString2(), CurrentUser.MemberId, Keyid);
                if (!isExit)
                {
                    bool resultxs = bll_OA_IntentionCustomerBLL.isExistCompanyName(this.txtCompanyName.Value.ToString2(), CurrentUser.MemberId, 0);
                    if (resultxs)
                    {
                        JavaScript.MessageBox("此客户已存在于意向客户中,请勿重复添加", this);
                    }
                    else
                    {
 
                        if (Request["Keyid"] != null)
                        {
                            m_OA_CorporateClients = bll_OA_CorporateClientsBLL.GetModel(Request["Keyid"].ToGuid2());
                            m_OA_CustomerCommunications = bll_OA_CorporateClientsBLL.GetModel_CustomerCommunications(Request["Keyid"].ToGuid2());
                            m_EC_AcceptWayByCustomers = bll_OA_CorporateClientsBLL.GetModel_AcceptWayByCustomers(Request["Keyid"].ToGuid2());
                            if (m_EC_AcceptWayByCustomers == null)
                            {
                                m_EC_AcceptWayByCustomers = new EC_AcceptWayByCustomers();
                            }
                        }
 
                        #region 初始合作客户基础信息
 
                        m_OA_CorporateClients.CompanyName = this.txtCompanyName.Value.ToString2();
                        m_OA_CorporateClients.CustomerIndustriesId = this.selCustomerIndustriesId.Value.ToInt32() ?? 0;
                        m_OA_CorporateClients.CustomerTypeId = this.selCustomerTypeId.Value.ToInt32() ?? 0;
                        m_OA_CorporateClients.SourcesInfoId = this.selSourcesInfoId.Value.ToInt32() ?? 0;
                        m_OA_CorporateClients.DegreeImportanId = this.selDegreeImportanId.Value.ToInt32() ?? 0;
                        m_OA_CorporateClients.AccountManagerId = this.selAccountManagerId.Value.ToInt32() ?? 0;
                        m_OA_CorporateClients.BusinessManagerId = this.selBusinessManagerId.Value.ToInt32() ?? 0;
 
                        m_OA_CorporateClients.CreditId = this.selCreditId.Value.ToInt32() ?? 0;
                        m_OA_CorporateClients.LoginPhone = "";
                        m_OA_CorporateClients.LoginPwd = "";
                        m_OA_CorporateClients.CorporateWebsite = "";
                        m_OA_CorporateClients.BusinessAnalysisId = this.selBusinessAnalysisId.Value.ToInt32() ?? 0;
                        m_OA_CorporateClients.IsLoginCorporateWeb = false;
                        m_OA_CorporateClients.Credit =0;
                        m_OA_CorporateClients.Bank = this.txtBank.Value.ToString2();
                        m_OA_CorporateClients.TaxID = this.txtTaxID.Value.ToString2();
                        m_OA_CorporateClients.AccountID = this.txtAccountID.Value.ToString2();
                        m_OA_CorporateClients.OutVendorName = CurrentUser.Name;
                        m_OA_CorporateClients.LastUpdateTime = DateTime.Now;
                        m_OA_CorporateClients.Operator = CurrentUser.ShortName;
                        m_OA_CorporateClients.Remark = this.txtRemark.InnerText.ToString2();
                        m_OA_CorporateClients.OutRate =1;
 
                        #endregion
 
                        #region 初始合作客户通讯信息
 
                        m_OA_CustomerCommunications.Province = Request["selectProvince"].ToString2();
                        m_OA_CustomerCommunications.City = Request["selectCity"].ToString2();
                        m_OA_CustomerCommunications.County = Request["selectCounty"].ToString2();
                        m_OA_CustomerCommunications.DetailedAddress = this.txtDetailedAddress.Value.ToString2();
                        m_OA_CustomerCommunications.CompanyPhone = this.txtCompanyPhone.Value.ToString2();
                        m_OA_CustomerCommunications.Postcode = this.txtPostcode.Value.ToString2();
                        m_OA_CustomerCommunications.Mobile = this.txtMobile.Value.ToString2();
                        m_OA_CustomerCommunications.Fax = this.txtFax.Value.ToString2();
                        m_OA_CustomerCommunications.Email = this.txtEmail.Value.ToString2();
                        m_OA_CustomerCommunications.QQ = this.txtQQ.Value.ToString2();
                        m_OA_CustomerCommunications.LegalRepresentative = this.txtLegalRepresentative.Value.ToString2();
                        m_OA_CustomerCommunications.LegalMobile = this.txtLegalMobile.Value.ToString2();
                        m_OA_CustomerCommunications.LegalQQ = this.txtLegalQQ.Value.ToString2();
                        m_OA_CustomerCommunications.BusinessManagers = this.txtBusinessManagers.Value.ToString2();
                        m_OA_CustomerCommunications.ManagersMobile = this.txtManagersMobile.Value.ToString2();
                        m_OA_CustomerCommunications.ManagersQQ = this.txtManagersQQ.Value.ToString2();
                        m_OA_CustomerCommunications.FinancialOfficers = this.txtFinancialOfficers.Value.ToString2();
                        m_OA_CustomerCommunications.OfficersMobile = this.txtOfficersMobile.Value.ToString2();
                        m_OA_CustomerCommunications.OfficersQQ = this.txtOfficersQQ.Value.ToString2();
                        m_OA_CustomerCommunications.Remark = "";
                        m_OA_CustomerCommunications.LastUpdateTime = DateTime.Now;
                        m_OA_CustomerCommunications.Operator = CurrentUser.ShortName;
 
                        #endregion
 
                        #region 初始合作客户收货地址
 
                        m_EC_AcceptWayByCustomers.AcceptTypeId = Request["AcceptTypeId"].ToInt32() ?? 0;
                        m_EC_AcceptWayByCustomers.InvoiceDemand = Request["InvoiceId"].ToString2();
                        m_EC_AcceptWayByCustomers.Remark = Request["Remark"].ToString2();
                        m_EC_AcceptWayByCustomers.LastUpdateTime = DateTime.Now;
                        m_EC_AcceptWayByCustomers.Operator = CurrentUser.ShortName;
 
                        m_EC_AcceptWayByCustomers.City = "";
                        m_EC_AcceptWayByCustomers.Accepter = "";
                        m_EC_AcceptWayByCustomers.AccepterPhone = "";
                        m_EC_AcceptWayByCustomers.AppointCourierCompany = "";
                        m_EC_AcceptWayByCustomers.AccepterAddress = "";
                        m_EC_AcceptWayByCustomers.AccepterPhoneNum = "";
                        m_EC_AcceptWayByCustomers.AcceptContacts = "";
                        m_EC_AcceptWayByCustomers.FetchAddress = "";
                        m_EC_AcceptWayByCustomers.FetchPhoneNum = "";
                        m_EC_AcceptWayByCustomers.FetchContacts = "";
                        m_EC_AcceptWayByCustomers.AppointCourierCompany = "";
 
                        #endregion
 
                        #region 添加或编辑
 
                        if (Request["Keyid"] != null)
                        {
                            bool result = bll_OA_CorporateClientsBLL.UpdateModel(m_OA_CorporateClients, m_OA_CustomerCommunications, m_EC_AcceptWayByCustomers);//更新信息
                            if (result)
                                JavaScript.MessageBox("更新成功", this, true, true);
                            else
                                JavaScript.MessageBox("更新失败", this);
                        }
                        else
                        {
                            m_OA_CorporateClients.OrderCount = 0;
                            m_OA_CorporateClients.OrderMoney = 0;
                            m_OA_CorporateClients.Prepayments = 0;
                            m_OA_CorporateClients.IsOutsourcing = false;
                            m_OA_CorporateClients.IsPriority = false;
                            m_OA_CorporateClients.CumulativePrepayments = 0;
 
                            m_OA_CorporateClients.Keyid = Guid.NewGuid();
                            m_OA_CorporateClients.CreateTime = DateTime.Now;
                            m_OA_CorporateClients.CustomerId = bll_OA_CorporateClientsBLL.GetLastIdByFirmId(CurrentUser.MemberId) + 1;
                            m_OA_CorporateClients.FirmId = CurrentUser.MemberId;
                            m_OA_CorporateClients.InquiryId = CurrentUser.InquiryId;
                            if (this.txtHideMemberType.Value == "网站会员")
                            {
                                m_OA_CorporateClients.MemberId = this.txtHideMemberId.Value.ToGuid2();
                            }
                            else
                            {
                                m_OA_CorporateClients.MemberId = m_OA_CorporateClients.Keyid;
                            }
                            m_OA_CustomerCommunications.Keyid = m_OA_CorporateClients.Keyid;
                            m_EC_AcceptWayByCustomers.TargetId = m_OA_CorporateClients.Keyid;
 
                            bool result = bll_OA_CorporateClientsBLL.InsertModel(m_OA_CorporateClients, m_OA_CustomerCommunications, m_EC_AcceptWayByCustomers);//添加信息
                            if (result)
                            {
                                Province = CurrentUser.Province;
                                City = CurrentUser.City;
                                County = CurrentUser.County;
                                JavaScript.MessageBox("添加成功", this,false,true);
                                BindData();
                            }
                            else
                                JavaScript.MessageBox("添加失败", this);
                        }
                        #endregion
                    }
                }
                else
                {
                    JavaScript.MessageBox("此客户已存在,请勿重复添加", this);
                }
            }
            catch (Exception ex)
            {
                PAGEHandleException(ex);
                JavaScript.MessageBox("操作失败", this);
            }
        }
    }
}