PageRenderTime 20ms CodeModel.GetById 11ms app.highlight 7ms RepoModel.GetById 0ms app.codeStats 0ms

/EQT_V1/EQTWebApp/CreateNotice.aspx.cs

http://sgsoft-las.googlecode.com/
C# | 230 lines | 206 code | 22 blank | 2 comment | 36 complexity | 729c8e43044000e25bbfec9f84cde970 MD5 | raw file
Possible License(s): LGPL-2.1
  1using System;
  2using System.Data;
  3using System.Configuration;
  4using System.Collections;
  5using System.Web;
  6using System.Web.Security;
  7using System.Web.UI;
  8using System.Web.UI.WebControls;
  9using System.Web.UI.WebControls.WebParts;
 10using System.Web.UI.HtmlControls;
 11using EQT.Model;
 12using EQT.Dal;
 13using System.Collections.Generic;
 14
 15public partial class CreateNotice : System.Web.UI.Page
 16{
 17    private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
 18    private DaNotice dalNotice = new DaNotice();
 19    private DaTfile dalTfile = new DaTfile();
 20    private UserContext context;
 21
 22    protected void Page_Load(object sender, EventArgs e)
 23    {
 24        Response.Expires = -1;
 25
 26        context = Session["USER_CONTEXT"] as UserContext;
 27        OperationResult.Text = "";
 28        divResult.Visible = true;
 29
 30        if (!IsPostBack)
 31        {
 32            if (Request.QueryString["type"] == null) Response.End();
 33            if(Request.QueryString["type"]=="one")
 34            {
 35                DaTuser dal = new DaTuser();
 36                CheckUsers.DataSource = dal.Query(" where status=2");
 37                CheckUsers.DataBind();
 38                user.Visible = true;
 39                ViewState.Add("TYPE",1);
 40                labType.Text = "????";
 41                CreateSave.Visible = true;
 42                EditSave.Visible = false;
 43            }
 44            else if (Request.QueryString["type"] == "all")
 45            {
 46                labType.Text = "????";
 47                user.Visible = false;
 48                ViewState.Add("TYPE", 0);
 49                CreateSave.Visible =true ;
 50                EditSave.Visible = false;
 51            }
 52            else
 53            { 
 54            //??
 55                if (Request.QueryString["noticeid"] != null)
 56                {
 57                    ViewState["NOTICEID"] = Request.QueryString["noticeid"];
 58                    CreateSave.Visible = false;
 59                    EditSave.Visible = true;
 60                    MoNotice mod = dalNotice.GetEntity(Request.QueryString["noticeid"].ToString());
 61                    if (mod != null)
 62                    {
 63                        labType.Text = mod.Publish_Type == 0 ? "????" : "????";
 64                        user.Visible = mod.Publish_Type == 0 ? false : true;
 65                        CreateNotice_Title.Text = mod.Title;
 66
 67                        if (mod.Publish_Type == 1)
 68                        {
 69                            DaTuser dal = new DaTuser();
 70                            CheckUsers.DataSource = dal.Query(" where status=2");
 71                            CheckUsers.DataBind();
 72                            
 73                            DaNoticeReceiver darec = new DaNoticeReceiver();
 74                            IList<MoNoticeReceiver> lists= darec.GetEntities(" where notice_id='"+mod.Notice_Id+"'");
 75                            if(lists!=null)
 76                            {
 77                                foreach(MoNoticeReceiver modr in lists)
 78                                {
 79                                    ListItem item=CheckUsers.Items.FindByValue(modr.Uid);
 80                                    if (item!=null)
 81                                    {
 82                                        item.Selected = true;
 83                                    }
 84                                }
 85                            }
 86                        }
 87                        string filename="NoticeFile//" + mod.Notice_Id + ".htm";
 88
 89                        filename = Server.MapPath(filename);
 90                        if (!string.IsNullOrEmpty(filename))
 91                        {
 92                            FCKeditorContent.Value = System.IO.File.ReadAllText(filename);
 93                        }
 94                    }
 95                }
 96            }
 97
 98            FCKeditorContent.FormatOutput = true;
 99            FCKeditorContent.FormatSource = true;
100        }
101    }
102
103    protected void CreateSave_Click(object sender, EventArgs e)
104    {
105        //???????
106
107        if (CreateNotice_Title.Text.Trim() == "")
108        {
109            OperationResult.Text = "???????!"; divResult.Visible = true;
110            return;
111        }
112
113        MoNotice mod = new MoNotice();
114
115        try
116        {
117            mod.Notice_Id = SequenceKeys.GenerateNoticeID();
118            ViewState["NOTICE_ID"] = mod.Notice_Id;
119            mod.Uid = context.UserID;
120            mod.Publish_Type = int.Parse(ViewState["TYPE"].ToString());
121            mod.Notice_Content = mod.Notice_Id;
122            mod.Create_Time = DateTime.Now;
123            mod.Title = CreateNotice_Title.Text.Trim();
124
125            List<string> users = new List<string>();
126
127            if (mod.Publish_Type == 0)
128            {
129                DaTuser daluser = new DaTuser();
130                DataSet ds = daluser.GetAllAvailableUsers();
131                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
132                {
133                    users.Add(ds.Tables[0].Rows[i]["UID"].ToString());
134                }
135            }
136            else
137            {
138                for (int i = 0; i < CheckUsers.Items.Count; i++)
139                {
140                    if (CheckUsers.Items[i].Selected)
141                    {
142                        users.Add(CheckUsers.Items[i].Value);
143                    }
144                }
145
146                if (users.Count < 1)
147                {
148                    OperationResult.Text = "??????????"; divResult.Visible = true;
149                    return;
150                }
151            }
152            if (dalNotice.CreateNotice(mod, users))
153            {
154                Utility.SaveNoticeContent(mod.Notice_Id, FCKeditorContent.Value);
155                OperationResult.Text = "???????!"; divResult.Visible = true;
156                CreateSave.Enabled = false;
157            }
158            else
159            {
160                OperationResult.Text = "???????!"; divResult.Visible = true;
161            }
162        }
163        catch (Exception ex)
164        {
165            log.Error(ex);
166            OperationResult.Text = "???????!"; divResult.Visible = true;
167        }
168    }
169
170    protected void EditSave_Click(object sender, EventArgs e)
171    {
172        if (CreateNotice_Title.Text.Trim() == "")
173        {
174            OperationResult.Text = "???????!"; divResult.Visible = true;
175            return;
176        }
177
178        MoNotice mod = dalNotice.GetEntity(ViewState["NOTICEID"].ToString());
179
180        try
181        {
182            mod.Create_Time = DateTime.Now;
183            mod.Title = CreateNotice_Title.Text.Trim();
184
185            List<string> users = new List<string>();
186
187            if (mod.Publish_Type == 0)
188            {
189                DaTuser daluser = new DaTuser();
190                DataSet ds = daluser.GetAllAvailableUsers();
191                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
192                {
193                    users.Add(ds.Tables[0].Rows[i]["UID"].ToString());
194                }
195            }
196            else
197            {
198                for (int i = 0; i < CheckUsers.Items.Count; i++)
199                {
200                    if (CheckUsers.Items[i].Selected)
201                    {
202                        users.Add(CheckUsers.Items[i].Value);
203                    }
204                }
205
206                if (users.Count < 1)
207                {
208                    OperationResult.Text = "??????????"; divResult.Visible = true;
209                    return;
210                }
211            }
212            if (dalNotice.EditNoticeSave(mod, users))
213            {
214                Utility.SaveNoticeContent(mod.Notice_Id, FCKeditorContent.Value);
215                OperationResult.Text = "??????!"; divResult.Visible = true;
216                EditSave.Enabled = false;
217            }
218            else
219            {
220                OperationResult.Text = "??????!"; divResult.Visible = true;
221            }
222        }
223        catch (Exception ex)
224        {
225            log.Error(ex);
226            OperationResult.Text = "??????!"; divResult.Visible = true;
227        }
228    }
229
230}