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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CY.Model;
using CY.BLL;
using CY.Infrastructure.Common;
using System.Data;
using CY.BLL.Sys;
using System.Text;
 
namespace CY.WebForm.Pages.InfoManage
{
    //吴辉
    //添加/修改广告
    public partial class AdEdit : BasePage
    {
        Info_AdBLL bll_Info_AdBLL = null;
        Info_AdLoctionBLL bll_Info_AdLoctionBLL = null;
        Sys_DictionaryBLL bll_Sys_DictionaryBLL = null;
        EC_MemberBasicBLL bll_EC_MemberBasicBLL = null;
        EC_PaymentRecordBLL bll_EC_PaymentRecordBLL = null;
 
        //初始化
        public AdEdit()
        {
            bll_Info_AdBLL = new Info_AdBLL();
            bll_Info_AdLoctionBLL = new Info_AdLoctionBLL();
            bll_Sys_DictionaryBLL = new Sys_DictionaryBLL();
            bll_EC_MemberBasicBLL = new EC_MemberBasicBLL();
            bll_EC_PaymentRecordBLL = new EC_PaymentRecordBLL();
        }
 
        //页面加载
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
 
                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)
                        {
                            InitData();
                        }
                        return;
                }
            }
            catch (Exception ex)
            {
                PAGEHandleException(ex);
                Response.Clear();
                Response.Write("-1");
            }
            Response.End();
        }
 
        //页面加载
        public void InitData()
        {
            try
            {
                this.selRemark.DataSource = bll_Sys_DictionaryBLL.GetDataByType("网站广告位置版块");
                this.selRemark.DataValueField = "MeanValue";
                this.selRemark.DataTextField = "Name";
                this.selRemark.DataBind();
 
                Info_Ad m_Info_Ad = new Info_Ad();
                if (Request["Keyid"] != null && Request["Keyid"].ToInt32() > 0)
                {
                    m_Info_Ad = bll_Info_AdBLL.SelectModelByKeyId(Request["Keyid"].ToInt32());
                    EC_MemberBasic m_EC_MemberBasic = bll_EC_MemberBasicBLL.GetMemberByMemberId(m_Info_Ad.A_MemberId);
                    this.txtCompanyName.Text = m_EC_MemberBasic.Name;
                    this.selTimeChange.SelectedValue = ((m_Info_Ad.A_EndTime.Value.Year - m_Info_Ad.A_StartTime.Value.Year) * 12 + (m_Info_Ad.A_EndTime.Value.Month - m_Info_Ad.A_StartTime.Value.Month)).ToString2();
                    this.spanStartTime.InnerText = m_Info_Ad.A_StartTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                    this.spanEndTime.InnerText = m_Info_Ad.A_EndTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
 
                    this.txtAP_Title.Value = m_Info_Ad.A_Title.ToString2();
                    if (m_Info_Ad.A_Pic.ToString2() == "" || m_Info_Ad.A_Pic.ToString2() == "xx")
                    {
                        this.afileAP_DefaultImg.Visible = false;
                    }
                    else
                    {
                        this.afileAP_DefaultImg.HRef = m_Info_Ad.A_Pic.ToString2();
                    }
                    this.txtA_Url.Value = m_Info_Ad.A_Url.ToString2();
                    this.selA_IsTarget.Value = m_Info_Ad.A_IsTarget.ToString2();
                    this.txtHideMemberId.Value = m_Info_Ad.A_MemberId.ToString2();
 
 
                    Info_AdLoction m_Info_AdLoctionM = bll_Info_AdLoctionBLL.SelectModelByKeyId(m_Info_Ad.AdLocationId);
 
                    switch (this.selTimeChange.SelectedValue)
                    {
                        case "1":
                            this.txtPrice.Text = (m_Info_AdLoctionM.Price_Month ?? 0).ToString("0.00");
                            break;
                        case "3":
                            this.txtPrice.Text = (m_Info_AdLoctionM.Price_Season ?? 0).ToString("0.00");
                            break;
                        case "6":
                            this.txtPrice.Text = (m_Info_AdLoctionM.Price_Half ?? 0).ToString("0.00");
                            break;
                        case "12":
                            this.txtPrice.Text = (m_Info_AdLoctionM.Price_Year ?? 0).ToString("0.00");
                            break;
                        default:
                            break;
                    }
 
 
                    List<Info_AdLoction> m_Info_AdLoctionList = bll_Info_AdLoctionBLL.SelectListByMeanValue(m_Info_AdLoctionM.Remark.ToInt32()) as List<Info_AdLoction>;
                    this.selAdLocation.Items.Add(new ListItem("请选择", ""));
                    if (m_Info_AdLoctionList != null && m_Info_AdLoctionList.Count > 0)
                    {
                        foreach (var m_Info_AdLoction in m_Info_AdLoctionList)
                        {
                            this.selAdLocation.Items.Add(new ListItem(m_Info_AdLoction.AP_Title + "[W:" + m_Info_AdLoction.AP_WidePixels + ",H:" + m_Info_AdLoction.AP_HighPixels + "]", m_Info_AdLoction.Keyid.ToString2()));
                        }
                    }
                    this.selAdLocation.SelectedValue = m_Info_Ad.AdLocationId.ToString2();
 
                    this.selRemark.Enabled = false;
                    this.selAdLocation.Enabled = false;
                    this.txtCompanyName.Enabled = false;
                    this.txtReset.Visible = false;
                }
                else
                {
                    this.afileAP_DefaultImg.Visible = false;
                    this.selAdLocation.Items.Add(new ListItem("请选择", ""));
                }
            }
            catch (Exception ex)
            {
                PAGEHandleException(ex);
                JavaScript.MessageBox("加载失败", this);
            }
        }
 
        //提交事件
        protected void btn_Submit_form(object sender, EventArgs e)
        {
            Info_Ad m_Info_Ad = new Info_Ad();
            if (Request["Keyid"] != null && Request["Keyid"].ToInt32() > 0)
                m_Info_Ad = bll_Info_AdBLL.SelectModelByKeyId(Request["Keyid"].ToInt32());
 
            m_Info_Ad.A_Title = this.txtAP_Title.Value.ToString2();
 
            //图片上传
            CY.WebForm.cs.UploadCS.UpFileResult _UpFileResult2 = CY.WebForm.cs.UploadCS.Upload("fileAP_DefaultImg", m_Info_Ad.A_Pic);
            m_Info_Ad.A_Pic = m_Info_Ad.A_Pic ?? "";
            if (_UpFileResult2.returnerror.Count == 0)
            {
                if (_UpFileResult2.returnfilename.Count > 0)
                    m_Info_Ad.A_Pic = _UpFileResult2.returnfilename[0].ToString2();
            }
            else
            {
                JavaScript.MessageBox(string.Join("<br/>", (string[])_UpFileResult2.returnerror.ToArray(typeof(string))), this);
                return;
            }
 
            m_Info_Ad.A_Url = this.txtA_Url.Value.ToString2();
            m_Info_Ad.AdLocationId = this.selAdLocation.SelectedValue.ToInt32();
            m_Info_Ad.A_IsTarget = this.selA_IsTarget.Value.ToBoolean2();
            m_Info_Ad.A_StartTime = this.spanStartTime.InnerText.ToDateTime2();
            m_Info_Ad.A_EndTime = this.spanEndTime.InnerText.ToDateTime2();
            m_Info_Ad.A_MemberId = this.txtHideMemberId.Value.ToGuid2();
            m_Info_Ad.A_Remarks = m_Info_Ad.A_Remarks ?? "";
            m_Info_Ad.LastUpdateTime = DateTime.Now;
            m_Info_Ad.Operator = CurrentUser.ShortName;
 
            Info_AdLoction m_Info_AdLoction = bll_Info_AdLoctionBLL.SelectModelByKeyId(this.selAdLocation.SelectedValue.ToInt32());
            EC_MemberBasic m_EC_MemberBasic = bll_EC_MemberBasicBLL.GetMemberByMemberId(this.txtHideMemberId.Value.ToGuid2());
            EC_MemberExtend m_EC_MemberExtend = bll_EC_MemberBasicBLL.GetMemberExtendByMemberId(this.txtHideMemberId.Value.ToGuid2());
            m_Info_Ad.Remark = m_Info_AdLoction.AP_Title + " [宽:" + m_Info_AdLoction.AP_WidePixels + ",高:" + m_Info_AdLoction.AP_HighPixels + "]";
 
            bool result = false;
            if (Request["Keyid"] != null && Request["Keyid"].ToInt32() > 0)
            {
                result = bll_Info_AdBLL.UpdateModel(m_Info_Ad);
                if (result)
                {
                    JavaScript.MessageBox("更新成功", this, true, true);
                }
                else
                    JavaScript.MessageBox("更新失败", this);
            }
            else
            {
                result = bll_Info_AdBLL.InsertModel(m_Info_Ad);
                if (result)
                    JavaScript.MessageBox("添加成功", this, true, true);
                else
                    JavaScript.MessageBox("添加失败", this);
            }
            if (result && Request["type"] == "no" && !string.IsNullOrEmpty(m_Info_Ad.A_Pic) && m_Info_Ad.A_Pic != "xx")
            {
                EC_PaymentRecord m_EC_PaymentRecord = new EC_PaymentRecord();
                m_EC_PaymentRecord.BusinessManagerId = 0;
                m_EC_PaymentRecord.AccountManagerId = 0;
                m_EC_PaymentRecord.PayStartTime = this.spanStartTime.InnerText.ToDateTime2();
                m_EC_PaymentRecord.PayEndTime = this.spanEndTime.InnerText.ToDateTime2();
                m_EC_PaymentRecord.LastUpdateTime = DateTime.Now;
                m_EC_PaymentRecord.AdForum = this.selRemark.SelectedItem.Text;
                m_EC_PaymentRecord.AdImg = "<a target=\"_blank\" href=\"/Pages/InfoManage/AdDetail.aspx?Keyid=" + m_Info_Ad.Keyid + "\">点击查看</a>";
                m_EC_PaymentRecord.AdInstallments = "";
                m_EC_PaymentRecord.AdLocation = m_Info_AdLoction.AP_Title;
                m_EC_PaymentRecord.AdSize = m_Info_AdLoction.AP_WidePixels + " * " + m_Info_AdLoction.AP_HighPixels;
                m_EC_PaymentRecord.CompanyPhone = m_EC_MemberExtend.PhoneNum;
                m_EC_PaymentRecord.Contact = m_EC_MemberExtend.BusinessContacts;
                m_EC_PaymentRecord.Email = m_EC_MemberExtend.Email;
                m_EC_PaymentRecord.MemberId = this.txtHideMemberId.Value.ToGuid2();
                m_EC_PaymentRecord.MemberName = this.txtCompanyName.Text;
                m_EC_PaymentRecord.Operator = CurrentUser.ShortName;
                m_EC_PaymentRecord.PayAllMoney = this.txtPrice.Text.ToDecimal2();
                m_EC_PaymentRecord.PayMoney = this.txtPrice.Text.ToDecimal2();
                m_EC_PaymentRecord.PayRole = m_EC_MemberBasic.MemberType;
                m_EC_PaymentRecord.PayType = "网站广告费";
                m_EC_PaymentRecord.QQ = m_EC_MemberExtend.QQ;
                m_EC_PaymentRecord.Remark = bll_EC_PaymentRecordBLL.GetNewOrderId();
                m_EC_PaymentRecord.SoftwarePermissions = "";
 
                if (bll_EC_PaymentRecordBLL.InsertModel(m_EC_PaymentRecord))
                {
                    Pay_PaymentAccountBLL _pay_PaymentAccountBLL = new Pay_PaymentAccountBLL();
                    _pay_PaymentAccountBLL.SendPoOrMoToMember(m_EC_MemberBasic.MemberId, 392, m_EC_PaymentRecord.PayMoney);
                }
            }
        }
 
        //切换版块获取位置
        protected void changeRemarkGetLocation(object sender, EventArgs e)
        {
            this.selAdLocation.Items.Clear();
            List<Info_AdLoction> m_Info_AdLoctionList = bll_Info_AdLoctionBLL.SelectListByMeanValue(this.selRemark.SelectedValue.ToInt32()) as List<Info_AdLoction>;
            this.selAdLocation.Items.Add(new ListItem("请选择", ""));
            if (m_Info_AdLoctionList != null && m_Info_AdLoctionList.Count > 0)
            {
                foreach (var m_Info_AdLoction in m_Info_AdLoctionList)
                {
                    this.selAdLocation.Items.Add(new ListItem(m_Info_AdLoction.AP_Title + "[W:" + m_Info_AdLoction.AP_WidePixels + ",H:" + m_Info_AdLoction.AP_HighPixels + "]", m_Info_AdLoction.Keyid.ToString2()));
                }
            }
        }
 
        //切换位置获取开始时间和结束时间
        protected void changeLoctionGetTimeAndMoney(object sender, EventArgs e)
        {
            DateTime? LastedTime = DateTime.Now;
            Info_Ad m_Info_Ad = new Info_Ad();
            if (Request["Keyid"] != null && Request["Keyid"].ToInt32() > 0)
            {
                m_Info_Ad = bll_Info_AdBLL.SelectModelByKeyId(Request["Keyid"].ToInt32());
                if (m_Info_Ad != null)
                    LastedTime = m_Info_Ad.A_StartTime;
            }
            else
            {
                m_Info_Ad = bll_Info_AdBLL.SelectListByAdLocationId(this.selAdLocation.SelectedValue.ToInt32());
                if (m_Info_Ad != null)
                    LastedTime = m_Info_Ad.A_EndTime;
            }
 
            string startTimeString = LastedTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
            string endTimeString = LastedTime.Value.AddMonths(1).ToString("yyyy-MM-dd HH:mm:ss");
 
            this.spanStartTime.InnerText = startTimeString;
            this.spanEndTime.InnerText = endTimeString;
 
            this.selTimeChange.Items.Clear();
            this.selTimeChange.Items.Add(new ListItem("一个月", "1"));
            this.selTimeChange.Items.Add(new ListItem("一季度", "3"));
            this.selTimeChange.Items.Add(new ListItem("半年", "6"));
            this.selTimeChange.Items.Add(new ListItem("一年", "12"));
            Info_AdLoction m_Info_AdLoctionM = bll_Info_AdLoctionBLL.SelectModelByKeyId(this.selAdLocation.SelectedValue.ToInt32());
            this.txtPrice.Text = (m_Info_AdLoctionM.Price_Month ?? 0).ToString("0.00");
        }
 
        //切换时长更新
        protected void changeTimeGetStartAndEnd(object sender, EventArgs e)
        {
            DateTime? LastedTime = DateTime.Now;
            Info_Ad m_Info_Ad = new Info_Ad();
            if (Request["Keyid"] != null && Request["Keyid"].ToInt32() > 0)
            {
                m_Info_Ad = bll_Info_AdBLL.SelectModelByKeyId(Request["Keyid"].ToInt32());
                if (m_Info_Ad != null)
                    LastedTime = m_Info_Ad.A_StartTime;
            }
            else
            {
                m_Info_Ad = bll_Info_AdBLL.SelectListByAdLocationId(this.selAdLocation.SelectedValue.ToInt32());
                if (m_Info_Ad != null)
                    LastedTime = m_Info_Ad.A_EndTime;
            }
 
            int nowTime = this.selTimeChange.SelectedValue.ToInt32() ?? 1;
            string startTimeString = LastedTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
            string endTimeString = LastedTime.Value.AddMonths(nowTime).ToString("yyyy-MM-dd HH:mm:ss");
 
            this.spanStartTime.InnerText = startTimeString;
            this.spanEndTime.InnerText = endTimeString;
 
            Info_AdLoction m_Info_AdLoctionM = bll_Info_AdLoctionBLL.SelectModelByKeyId(this.selAdLocation.SelectedValue.ToInt32());
            switch (this.selTimeChange.SelectedValue)
            {
                case "1":
                    this.txtPrice.Text = (m_Info_AdLoctionM.Price_Month ?? 0).ToString("0.00");
                    break;
                case "3":
                    this.txtPrice.Text = (m_Info_AdLoctionM.Price_Season ?? 0).ToString("0.00");
                    break;
                case "6":
                    this.txtPrice.Text = (m_Info_AdLoctionM.Price_Half ?? 0).ToString("0.00");
                    break;
                case "12":
                    this.txtPrice.Text = (m_Info_AdLoctionM.Price_Year ?? 0).ToString("0.00");
                    break;
                default:
                    break;
            }
        }
 
        //绑定关联会员列表
        protected string BindCompanyList(string companyname)
        {
            List<EC_MemberExtend> m_EC_MemberExtendList = bll_EC_MemberBasicBLL.SelectExtendListByName(companyname) as List<EC_MemberExtend>;
 
            string[] modelArry = new string[m_EC_MemberExtendList.Count];
            int i = 0;
            foreach (var item in m_EC_MemberExtendList)
            {
                string result = "";
                StringBuilder sb_html = new StringBuilder();
 
                sb_html.AppendFormat("CustormKeyId:'{0}',", item.Keyid);
                sb_html.AppendFormat("CustormName:'{0}'", item.Name);
                result = "{" + sb_html.ToString() + "}";
                modelArry[i] = result;
                i++;
            }
            return ("[" + string.Join(",", modelArry) + "]");
        }
    }
}