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
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 CY.BLL.OA;
using System.Collections;
using System.Data;
 
namespace CY.WebForm.Pages.procurement
{
    public partial class SuppliersEdit : BasePage
    {
 
        Sys_DictionaryBLL _Sys_DictionaryBLL = null;
        OA_Suppliers supplier = null;
        OA_SuppliersBLL _OA_SuppliersBLL = null;
        OA_BrandBLL _OA_BrandBLL = null;
        OA_SuppliersOtherQualificationBLL _OA_SuppliersOtherQualificationBLL = null;
        OA_CorporateClientsBLL bll_OA_CorporateClientsBLL = null;
        public string[] Fileds;
 
        public SuppliersEdit()
        {
            _OA_SuppliersOtherQualificationBLL = new OA_SuppliersOtherQualificationBLL();
            _OA_BrandBLL = new OA_BrandBLL();
            _Sys_DictionaryBLL = new Sys_DictionaryBLL();
            supplier = new OA_Suppliers();
            _OA_SuppliersBLL = new OA_SuppliersBLL();
            bll_OA_CorporateClientsBLL = new OA_CorporateClientsBLL();
 
        }
 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitialSelData();
                if (Request["Keyid"].ToInt32() > 0)
                    InitialSuplier();
            }
 
        }
 
        //初始化下拉列表中的值   
        protected void InitialSelData()
        {
            this.txtOrderNum.Value = _OA_BrandBLL.GetMaxOrderNum(CurrentUser.MemberId, "OA_Suppliers");
            selCooperativeStateId.DataSource = _Sys_DictionaryBLL.GetDataByType("供应商合作状态");
            selCooperativeStateId.DataBind();
            selSuppliersLevelId.DataSource = _Sys_DictionaryBLL.GetDataByType("供应商级别");
            selSuppliersLevelId.DataBind();
            selSuppliersTypeId.DataSource = _Sys_DictionaryBLL.GetDataByType("供应商类别 ").OrderBy(x=>x.LastUpdateTime);
            selSuppliersTypeId.DataBind();
        }
 
        /// <summary>
        /// 如果是修改/则加载要修改的数据
        /// </summary>
        protected void InitialSuplier()
        {
            supplier = _OA_SuppliersBLL.getSingleSupplier(Request["Keyid"].ToString2());
            this.selCooperativeStateId.Value = supplier.CooperativeStateId.ToString2();
            this.selSuppliersLevelId.Value = supplier.SuppliersLevelId.ToString2();
            this.selSuppliersTypeId.Value = supplier.SuppliersTypeId.ToString2();
            this.txtBusinessLicenseNum.Value = supplier.BusinessLicenseNum;
            this.txtBusinessManagers.Value = supplier.BusinessManagers;
            this.txtBusinessScope.Value = supplier.BusinessScope;
            this.txtCompanyPhone.Value = supplier.CompanyPhone;
            this.txtDetailedAddress.Value = supplier.DetailedAddress;
            this.txtFax.Value = supplier.Fax;
            this.txtFinancialOfficers.Value = supplier.FinancialOfficers;
            this.txtLegalMobile.Value = supplier.LegalMobile;
            this.txtLegalQQ.Value = supplier.LegalQQ;
            this.txtLegalRepresentative.Value = supplier.LegalRepresentative;
            this.txtManagersMobile.Value = supplier.ManagersMobile;
            this.txtManagersQQ.Value = supplier.ManagersQQ;
            this.txtName.Value = supplier.Name;
            this.txtOfficersMobile.Value = supplier.OfficersMobile;
            this.txtOfficersQQ.Value = supplier.OfficersQQ;
            this.txtBank.Value = supplier.Bank;
            this.txtHuming.Value = supplier.Huming;
            this.txtAccountID.Value = supplier.AccountID;
            this.txtPostcode.Value = supplier.Postcode;
            this.txtQQ.Value = supplier.QQ;
            this.txtRegisterCapital.Value = supplier.RegisterCapital.ToString2();
            this.txtWebSite.Value = supplier.WebSite;
            this.txtOrderNum.Value = (this.supplier.OrderNum ?? 0).ToString();
            if (!string.IsNullOrEmpty(supplier.OrganizationCodeFileId))
            {
                this.div_Organization.Visible = true;
                this.OrganizationCodeFileImg.Src = supplier.OrganizationCodeFileId;
                this.aOrganizationCodeFileImg.HRef = supplier.OrganizationCodeFileId;
            }
            if (!string.IsNullOrEmpty(supplier.BusinessLicenseFileId))
            {
                this.div_Business.Visible = true;
                this.BusinessLicenseFilePic.Src = supplier.BusinessLicenseFileId;
                this.aBusinessLicenseFilePic.HRef = supplier.BusinessLicenseFileId;
            }
            if (!string.IsNullOrEmpty(supplier.TaxRegistrationFileId))
            {
                this.div_Tax.Visible = true;
                this.TaxRegistrationFileImg.Src = supplier.TaxRegistrationFileId;
                this.aTaxRegistrationFileImg.HRef = supplier.TaxRegistrationFileId;
            }
 
            DataTable ds = _OA_SuppliersOtherQualificationBLL.selectOtherQuBySuppliersId(supplier.Keyid.ToString2());
            if (ds != null && ds.Rows.Count > 0)
            {
                Fileds = new string[ds.Rows.Count];
                for (int i = 0; i < ds.Rows.Count; i++)
                {
                    Fileds[i] = ds.Rows[i]["FileId"].ToString2();
                }
 
            }
 
        }
 
        protected void btn_Submit_Click(object sender, EventArgs e)
        {
 
            if (Request["Keyid"].ToInt32() > 0)
            {
                supplier = _OA_SuppliersBLL.getSingleSupplier(Request["Keyid"].ToString2());
 
                var sss = _OA_SuppliersBLL.getSupplierByFirmId(CurrentUser.MemberId, this.txtName.Value.Trim()).ToList();
                if (sss.Count > 0)
                {
                    if(sss.Count(x => x.Keyid != supplier.Keyid) > 0)
                    {
                        JavaScript.MessageBox("已有同名供应商!", this);
                        return;
                    }
                }
            }
            else
            {
                var sss = _OA_SuppliersBLL.getSupplierByFirmId(CurrentUser.MemberId, this.txtName.Value.Trim()).ToList();
                if (sss.Count > 0)
                {
                    JavaScript.MessageBox("已有同名供应商!", this);
                    return;
                }
                var suptypeid = this.selSuppliersTypeId.Value.ToInt32();
               var sys_Dictionary  = _Sys_DictionaryBLL.GetDataByType("供应商类别 ").Where(x=>x.Keyid == suptypeid).FirstOrDefault();
                if (sys_Dictionary!=null && sys_Dictionary.Name == "外协加工")
                {
                    Pagination pa = new Pagination();
                    pa.PageSize = 500;
                    pa.PageIndex = 1;
                    //查询是否有同名的外协
                    var ss = bll_OA_CorporateClientsBLL.SelectModelPage(pa, CurrentUser.MemberId, "").Where(x=>x.OutVendorName == this.txtName.Value.Trim()).ToList();
                    if (ss.Count == 0)
                    {
                        //新增外协厂商
                        OA_CorporateClients m_OA_CorporateClients = new OA_CorporateClients();
                        OA_CustomerCommunications m_OA_CustomerCommunications = new OA_CustomerCommunications();
                        EC_AcceptWayByCustomers m_EC_AcceptWayByCustomers = new EC_AcceptWayByCustomers();
                        EC_MemberBasic m_EC_MemberBasic = new EC_MemberBasic();
                        Guid NewGuid = Guid.NewGuid();
                        #region 初始合作客户基础信息
                        m_OA_CorporateClients.CompanyName = CurrentUser.Name;
                        m_OA_CorporateClients.CustomerIndustriesId = 0;
                        m_OA_CorporateClients.CustomerTypeId = 0;
                        m_OA_CorporateClients.SourcesInfoId = 0;
                        m_OA_CorporateClients.DegreeImportanId = 0;
                        m_OA_CorporateClients.AccountManagerId = 0;
                        m_OA_CorporateClients.BusinessManagerId = 0;
 
                        m_OA_CorporateClients.CreditId = 0;
                        m_OA_CorporateClients.LoginPhone = "";
                        m_OA_CorporateClients.CorporateWebsite = "";
                        m_OA_CorporateClients.BusinessAnalysisId = 0;
                        m_OA_CorporateClients.IsLoginCorporateWeb = false;
                        m_OA_CorporateClients.Credit = 0;
                        m_OA_CorporateClients.Bank = "";
                        m_OA_CorporateClients.TaxID = "";
                        m_OA_CorporateClients.AccountID = "";
                        m_OA_CorporateClients.OrderCount = 0;
                        m_OA_CorporateClients.OrderMoney = 0;
 
                        m_OA_CorporateClients.Prepayments = 0;
                        m_OA_CorporateClients.IsOutsourcing = true;
                        m_OA_CorporateClients.OutVendorName = this.txtName.Value.Trim();
                        m_OA_CorporateClients.IsPriority = false;
                        m_OA_CorporateClients.CumulativePrepayments = 0;
                        m_OA_CorporateClients.LastUpdateTime = DateTime.Now;
                        m_OA_CorporateClients.Operator = CurrentUser.ShortName;
                        m_OA_CorporateClients.Remark = "";
                        m_OA_CorporateClients.OutRate = 1;
                        m_OA_CorporateClients.LoginPwd = "";
 
                        #endregion
 
                        #region 初始合作客户通讯信息
                        m_OA_CustomerCommunications.Province = CurrentUser.Province;
                        m_OA_CustomerCommunications.City = CurrentUser.City;
                        m_OA_CustomerCommunications.County = CurrentUser.County;
                        m_OA_CustomerCommunications.DetailedAddress = CurrentMemberExtend.DetailedAddress;
                        m_OA_CustomerCommunications.CompanyPhone = CurrentMemberExtend.PhoneNum;
                        m_OA_CustomerCommunications.Postcode = CurrentMemberExtend.Postcode;
                        m_OA_CustomerCommunications.Mobile = CurrentMemberExtend.MobileNum;
                        m_OA_CustomerCommunications.Fax = CurrentMemberExtend.Fax;
                        m_OA_CustomerCommunications.Email = CurrentMemberExtend.Email;
                        m_OA_CustomerCommunications.QQ = CurrentMemberExtend.QQ;
                        m_OA_CustomerCommunications.LegalRepresentative = "";
                        m_OA_CustomerCommunications.LegalMobile = "";
                        m_OA_CustomerCommunications.LegalQQ = "";
                        m_OA_CustomerCommunications.BusinessManagers = "";
                        m_OA_CustomerCommunications.ManagersMobile = "";
                        m_OA_CustomerCommunications.ManagersQQ = "";
                        m_OA_CustomerCommunications.FinancialOfficers = "";
                        m_OA_CustomerCommunications.OfficersMobile = "";
                        m_OA_CustomerCommunications.OfficersQQ = "";
                        m_OA_CustomerCommunications.Remark = "";
                        m_OA_CustomerCommunications.LastUpdateTime = DateTime.Now;
                        m_OA_CustomerCommunications.Operator = CurrentUser.ShortName;
                        #endregion
 
                        #region 初始合作客户收货地址
                        m_EC_AcceptWayByCustomers.AcceptTypeId = 0;
                        m_EC_AcceptWayByCustomers.InvoiceDemand = "";
                        m_EC_AcceptWayByCustomers.Remark = "";
                        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 = "";
 
                        #endregion
 
                        m_OA_CorporateClients.Keyid = NewGuid;
                        m_OA_CorporateClients.CreateTime = DateTime.Now;
                        m_OA_CorporateClients.MemberId = CurrentUser.MemberId;
                        m_OA_CorporateClients.FirmId = NewGuid;
                        m_OA_CorporateClients.InquiryId = AdminAccount.MemberId;
                        m_OA_CorporateClients.CustomerId = bll_OA_CorporateClientsBLL.GetLastIdByFirmId(m_OA_CorporateClients.FirmId) + 1;
 
                        m_OA_CustomerCommunications.Keyid = NewGuid;
                        m_EC_AcceptWayByCustomers.TargetId = NewGuid;
                        m_OA_CorporateClients.Paytime = 0;
                        m_OA_CorporateClients.Paydays = 0;
                        m_OA_CorporateClients.Biddingcompany = 0;
                        m_OA_CorporateClients.Contracttype = 0;
                        m_OA_CorporateClients.Contractmoney = 0;
                        m_OA_CorporateClients.Jigoudaima = "";
                        m_OA_CorporateClients.Piaoju = 0;
                        m_OA_CorporateClients.Kaipiaoziliao = "";
                        m_OA_CorporateClients.Expiretype = 0;
                        m_OA_CorporateClients.Shifouwanjie = 2;
                        m_OA_CorporateClients.Note = "";
                        bool result = bll_OA_CorporateClientsBLL.InsertModel(m_OA_CorporateClients, m_OA_CustomerCommunications, m_EC_AcceptWayByCustomers);//添加信息
                        if (!result)
                        {
                            JavaScript.MessageBox("添加失败", this);
                            return;
                        }
                         
                            
                    }
                }
            }
 
 
            //营业执照上传
            CY.WebForm.cs.UploadCS.UpFileResult _UpFileResult0 = CY.WebForm.cs.UploadCS.Upload("BusinessLicenseFileId", supplier.BusinessLicenseFileId);
            supplier.BusinessLicenseFileId = supplier.BusinessLicenseFileId ?? "";
            if (_UpFileResult0.returnerror.Count == 0)
            {
                if (_UpFileResult0.returnfilename.Count > 0)
                    supplier.BusinessLicenseFileId = _UpFileResult0.returnfilename[0].ToString2();
            }
            else
            {
                JavaScript.MessageBox(string.Join("<br/>", (string[])_UpFileResult0.returnerror.ToArray(typeof(string))), this);
                return;
            }
 
            //组织机构代码上传
            CY.WebForm.cs.UploadCS.UpFileResult _UpFileResult1 = CY.WebForm.cs.UploadCS.Upload("OrganizationCodeFileId", supplier.OrganizationCodeFileId);
            supplier.OrganizationCodeFileId = supplier.OrganizationCodeFileId ?? "";
            if (_UpFileResult1.returnerror.Count == 0)
            {
                if (_UpFileResult1.returnfilename.Count > 0)
                    supplier.OrganizationCodeFileId = _UpFileResult1.returnfilename[0].ToString2();
            }
            else
            {
                JavaScript.MessageBox(string.Join("<br/>", (string[])_UpFileResult1.returnerror.ToArray(typeof(string))), this);
                return;
            }
 
 
            ///税务登记证上传
            CY.WebForm.cs.UploadCS.UpFileResult _UpFileResult2 = CY.WebForm.cs.UploadCS.Upload("TaxRegistrationFileId", supplier.TaxRegistrationFileId);
            supplier.TaxRegistrationFileId = supplier.TaxRegistrationFileId ?? "";
            if (_UpFileResult2.returnerror.Count == 0)
            {
                if (_UpFileResult2.returnfilename.Count > 0)
                    supplier.TaxRegistrationFileId = _UpFileResult2.returnfilename[0].ToString2();
            }
            else
            {
                JavaScript.MessageBox(string.Join("<br/>", (string[])_UpFileResult2.returnerror.ToArray(typeof(string))), this);
                return;
            }
 
            #region
            //其它资质文件
            OA_SuppliersOtherQualification model = new OA_SuppliersOtherQualification();
            CY.WebForm.cs.UploadCS.UpFileResult _UpFileResult3 = CY.WebForm.cs.UploadCS.Upload("ProductPics", model.FileId);
 
            if (_UpFileResult3.returnerror.Count == 0)
            {
                ArrayList NameList = new ArrayList();
                for (int i = 0; i < _UpFileResult3.returnfilename.Count; i++)
                {
                    OA_SuppliersOtherQualification model1 = new OA_SuppliersOtherQualification();
                    model1.FileId = _UpFileResult3.returnfilename[i].ToString();
                    model1.SuppliersId = Request["Keyid"].ToInt32();
                    NameList.Add(model1);
                }
                string[] aaa = (Request.Form["OldProductPics"]??"").Split(',');
                for (int i = 0; i < aaa.Length; i++)
                {
                    if (!string.IsNullOrEmpty(aaa[i].ToString2()))
                    {
                        OA_SuppliersOtherQualification newmodel = new OA_SuppliersOtherQualification();
                        newmodel.FileId = aaa[i].ToString2();
                        newmodel.SuppliersId = Request["Keyid"].ToInt32();
                        NameList.Add(newmodel);
                    }
                }
                _OA_SuppliersOtherQualificationBLL.DeleteAllModel(supplier.Keyid.ToString());
                _OA_SuppliersOtherQualificationBLL.InsertModelList(NameList, supplier.Keyid.ToString());
            }
 
            #endregion
 
            supplier.CooperativeStateId = this.selCooperativeStateId.Value.ToInt32();
            supplier.SuppliersLevelId = this.selSuppliersLevelId.Value.ToInt32();
            supplier.SuppliersTypeId = this.selSuppliersTypeId.Value.ToInt32();
            supplier.BusinessLicenseNum = this.txtBusinessLicenseNum.Value;
            supplier.BusinessManagers = this.txtBusinessManagers.Value;
            supplier.BusinessScope = this.txtBusinessScope.Value;
            supplier.CompanyPhone = this.txtCompanyPhone.Value;
            supplier.DetailedAddress = this.txtDetailedAddress.Value;
            supplier.Fax = this.txtFax.Value;
            supplier.FinancialOfficers = this.txtFinancialOfficers.Value;
            supplier.LegalMobile = this.txtLegalMobile.Value;
            supplier.LegalQQ = this.txtLegalQQ.Value;
            supplier.LegalRepresentative = this.txtLegalRepresentative.Value;
            supplier.ManagersMobile = this.txtManagersMobile.Value;
            supplier.ManagersQQ = this.txtManagersQQ.Value;
            supplier.Name = this.txtName.Value.Trim();
            supplier.OfficersMobile = this.txtOfficersMobile.Value;
            supplier.OfficersQQ = this.txtOfficersQQ.Value;
            if (!string.IsNullOrEmpty(this.txtHuming.Value))
            {
                supplier.Huming = this.txtHuming.Value;
            }
            else
            {
                supplier.Huming = this.txtName.Value;
            }
           
            supplier.Bank = this.txtBank.Value;
            supplier.AccountID = this.txtAccountID.Value;
            supplier.Postcode = this.txtPostcode.Value;
            supplier.QQ = this.txtQQ.Value;
            supplier.RegisterCapital = (string.IsNullOrEmpty(this.txtRegisterCapital.Value) ? "0" : this.txtRegisterCapital.Value).ToInt32();
            supplier.Remark = "";
            supplier.WebSite = this.txtWebSite.Value;
            supplier.OrderNum = this.txtOrderNum.Value.ToInt32();
            if ((Request["Keyid"].ToInt32() > 0))
            {
                if (_OA_SuppliersBLL.UpdateModel(supplier))
                {
                    JavaScript.MessageBox("更新成功", this, true, true);
                }
                else
                    JavaScript.MessageBox("更新失败", this);
            }
            else
            {
                supplier.FirmId = CurrentUser.MemberId;
                supplier.Operator = CurrentUser.ShortName;
                supplier.LastUpdateTime = System.DateTime.Now;
                if (_OA_SuppliersBLL.InsertModel(supplier))
                {
                    if (!string.IsNullOrEmpty(Request["flasss"]))
                    {
                        JavaScript.MessageBoxCloseAndRefreshparent("新增成功", this);
                    }
                    else
                    {
                        JavaScript.MessageBox("新增成功", this, true, true);
                    }
                    
                }
                else
                    JavaScript.MessageBox("添加失败", this);
            }
        }
    }
}