Files
ayanova7/source/MBI/memoedit.aspx.cs
2018-06-29 19:47:36 +00:00

259 lines
8.2 KiB
C#

using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using GZTW.AyaNova.BLL;
using System.Text;
namespace AyaNovaMBI
{
public partial class memoedit : System.Web.UI.Page
{
#region BizObject
public GZTW.AyaNova.BLL.Memo mMemo;
protected GZTW.AyaNova.BLL.Memo CurrentMemo
{
get
{
if (mMemo != null) return mMemo;
//The current memo is in the session or not put there yet
//if it's in the session then Bob's your Lobster.
if (Session["memo"] != null)
{
mMemo = (Memo)Session["memo"];
return mMemo;
}
//We're here because there is no memo in the session cache so this is the first time visit
//and memo needs to be created and put in the session cache
//The idstring represents either a new memo
//or the memo being replied to / (forwarded in future)
//so get the ID...
string idstring = Request.QueryString["id"];
if (util.mt(idstring))
throw new ApplicationException("MemoComposer - Memo id specified");
Guid oID = new Guid(idstring);
//completely new memo?
if (oID == AyaBizUtils.NewObjectGuid)
{
mMemo = Memo.NewItem();
Session["memo"] = mMemo;
return mMemo;
}
//Reply (forward in future) to existing memo
MemoFetcher mf = MemoFetcher.GetItem(oID, util.CurrentUser.DefaultLanguage);
mMemo = mf.ReplyForward(false);//true if forwarding
Session["memo"] = mMemo;
return mMemo;
}
}
#endregion
#region Recipient list DataTable
private DataTable dtRecipients = null;
protected DataTable Recipients
{
get
{
if (dtRecipients != null) return dtRecipients;
if (Session["memoto"] != null)
{
dtRecipients = (DataTable)Session["memoto"];
return dtRecipients;
}
//not in session cache, create, put in cache and return
InitializeRecipientTable();
Session.Add("memoto", dtRecipients);
return dtRecipients;
}
}
private void InitializeRecipientTable()
{
dtRecipients = new DataTable("RECIPIENTS");
Dictionary<UserTypes, string> ut = new Dictionary<UserTypes, string>();
ut.Add(UserTypes.Administrator, util.LocaleText("UserTypes.Label.Administrator"));
ut.Add(UserTypes.Schedulable, util.LocaleText("UserTypes.Label.Schedulable"));
ut.Add(UserTypes.NonSchedulable, util.LocaleText("UserTypes.Label.NonSchedulable"));
ut.Add(UserTypes.Client, util.LocaleText("UserTypes.Label.Client"));
ut.Add(UserTypes.HeadOffice, util.LocaleText("UserTypes.Label.HeadOffice"));
ut.Add(UserTypes.Utility, util.LocaleText("UserTypes.Label.UTILITY"));
dtRecipients.Columns.Add("RECIPIENT", typeof(System.String));
dtRecipients.Columns.Add("RECIPIENTTYPE", typeof(System.String));
dtRecipients.Columns.Add("SUBCONTRACTOR", typeof(bool));
dtRecipients.Columns.Add("RECIPIENTID", typeof(System.Guid));
dtRecipients.Columns.Add("SELECTED", typeof(bool));
//case 2000
//UserPickList UList = UserPickList.GetList(false);
UserPickList UList = UserPickList.GetInternalStaffOnlyList(false);
foreach (UserPickList.UserPickListInfo ui in UList)
{
DataRow dr = dtRecipients.NewRow();
dr["RECIPIENT"] = ui.Name;
dr["RECIPIENTTYPE"] = ut[ui.Type];
dr["SUBCONTRACTOR"] = ui.SubContractor;
dr["RECIPIENTID"] = ui.ID;
//In case of reply:
if (CurrentMemo.ToID == ui.ID)
dr["SELECTED"] = true;
else
dr["SELECTED"] = false;
dtRecipients.Rows.Add(dr);
}
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
//Get data logic
if (this.IsPostBack )//Only on a postback and not a callback
{
GetData();
}
}
protected void Page_LoadComplete(object sender, EventArgs e)
{
//Load and set data in initial form load
//and in all postbacks that are not a result of a rad
//manager callback
//Localize the page
util.Localize(this.Page);
SetData();
Page.Title = "*" + util.LocaleText("O.Memo");
btnto.Text = util.LocaleText("Memo.Label.ToID");
}
/// <summary>
/// Update user viewed display of recipients selected
/// called after coming back from MemoToSelector form
/// </summary>
private void DisplayTo()
{
bool bAtLeastOne = false;
this.lblRequired.Visible = false;
this.lblRecipients.Text = "";
StringBuilder sb = new StringBuilder();
foreach (DataRow dr in Recipients.Rows)
{
if ((bool)dr["SELECTED"] == true)
{
bAtLeastOne = true;
sb.Append((string)dr["RECIPIENT"] + "; ");
}
}
this.lblRecipients.Text = sb.ToString();
if (!bAtLeastOne)
lblRequired.Visible = true;
}
private void SetData()
{
edSubject.Text = CurrentMemo.Subject;
edMessage.Text = CurrentMemo.Message;
DisplayTo();
}
private void GetData()
{
CurrentMemo.Subject = edSubject.Text;
CurrentMemo.Message = edMessage.Text;
}
protected void btnOK_Click(object sender, EventArgs e)
{
//populate to collection first
bool bAtLeastOne = false;
foreach (DataRow dr in Recipients.Rows)
{
if ((bool)dr["SELECTED"] == true)
{
bAtLeastOne = true;
break;
}
}
if (!bAtLeastOne)
return;
string subject = edSubject.Text;
if (string.IsNullOrEmpty(subject))
subject = "NO SUBJECT";
//we have a recipient, we can send
foreach (DataRow dr in this.dtRecipients.Rows)
{
if ((bool)dr["SELECTED"] == true)
{
GZTW.AyaNova.BLL.Memo m = GZTW.AyaNova.BLL.Memo.NewItem();
m.ToID = (Guid)dr["RECIPIENTID"];
m.Subject = subject;
m.Message = edMessage.Text;
m.Save();
}
}
Session.Remove("memo");
Session.Remove("memoto");
util.Redirect(Session, Response, "ro.aspx?cmd=memos");
}
protected void btnCancel_Click(object sender, EventArgs e)
{
Session.Remove("memo");
Session.Remove("memoto");
util.Redirect(Session, Response, "ro.aspx?cmd=memos");
}
protected void btnto_Click(object sender, EventArgs e)
{
Response.Redirect("memoto.aspx");
}
//-----------------
}
}