#region Included Namespaces
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using SelfMobile.EnumerationTable;
#endregion
namespace SelfMobile
{
public partial class PersonalCabinet : System.Web.UI.Page
{
static bool postbackUserInfo = false;
protected void Page_Load(object sender, EventArgs e)
{
CheckCookies();
SetCurrentPageEvents();
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (IsPostBack)
{
RefreshTableContent();
if (postbackUserInfo) SetSceneMyProfile();
}
}
void CheckCookies()
{
if (!AuthProtection.CheckCookiesExist(this.Request)) Response.Redirect("Default.aspx");
}
void SetCurrentPageEvents()
{
SetHeadPanel();
SetTabsEvents();
SetDockEvents();
SetSubpanelEvents();
}
void SetHeadPanel()
{
this.buttonProfile.Click += new EventHandler(buttonViewMyProfile_Click);
this.buttonViewMyProfile.Click += new EventHandler(buttonViewMyProfile_Click);
this.buttonChangeMyPassword.Click += new EventHandler(buttonChangeMyPassword_Click);
this.buttonMessages.Click += new EventHandler(buttonMessages_Click);
this.buttonExit.Click += new EventHandler(buttonExit_Click);
}
void SetDockEvents()
{
this.dockIconMyProfile.Click += new EventHandler(dockIconMyProfile_Click);
this.dockIconMarket.Click += new EventHandler(dockIconMarket_Click);
}
void SetTabsEvents()
{
this.tabDashboard.Click += new EventHandler(tabDashboard_Click);
this.tabFirst.Click += new EventHandler(tabFirst_Click);
this.tabSecond.Click += new EventHandler(tabSecond_Click);
}
void SetSubpanelEvents()
{
this.buttonChangeCurrentPassword.Click += new EventHandler(buttonChangeCurrentPassword_Click);
}
void dockIconMarket_Click(object sender, EventArgs e)
{
SetSceneMarket();
}
void dockIconMyProfile_Click(object sender, EventArgs e)
{
SetSceneMyProfile();
}
void tabDashboard_Click(object sender, EventArgs e)
{
SetSceneDashboard();
}
void tabFirst_Click(object sender, EventArgs e)
{
LinkButton control = (LinkButton)sender;
switch (control.Text)
{
case "Мои данные":
SetSceneMyProfile();
break;
case "":
break;
}
}
void tabSecond_Click(object sender, EventArgs e)
{
LinkButton control = (LinkButton)sender;
switch (control.Text)
{
case "Копия данных с ЭЦП":
SetSceneMyProfileTabTokenData();
break;
case "":
break;
}
}
void buttonViewMyProfile_Click(object sender, EventArgs e)
{
SetSceneMyProfile();
}
void buttonChangeMyPassword_Click(object sender, EventArgs e)
{
SetSceneChangePassword();
}
void buttonChangeCurrentPassword_Click(object sender, EventArgs e)
{
if (CheckFieldsOfPasswordChange())
{
}
else
{
SetPanelAlertText(AlertBoxStyle.Error,
"Поля <b>не должны</b> быть пустыми!",
"boxPasswordChange",
"statePasswordChange");
boxPasswordChange.Visible = true;
}
}
bool CheckFieldsOfPasswordChange()
{
if (this.fieldOldPass.Text == String.Empty) return false;
if (this.fieldNewPass.Text == String.Empty) return false;
if (this.fieldNewRepass.Text == String.Empty) return false;
return true;
}
void buttonMessages_Click(object sender, EventArgs e)
{
}
void buttonExit_Click(object sender, EventArgs e)
{
AuthProtection.TruncateCookies(this.Request, this.Response);
}
void AddDynamicallyTokenData()
{
InternalApi api = new InternalApi();
Literal tokenData = new Literal();
tokenData.ID = "fullTokenData";
string[] dataToWrite = api.GetTokenInfoByUsername(Request.Cookies["userName"].Value).Split(',');
StringBuilder output = new StringBuilder();
for (int i = 0; i < dataToWrite.Length; i++)
{
output.Append(dataToWrite[i]);
output.Append("<br />");
}
tokenData.Text = output.ToString();
this.contentViewTokendata.Controls.Add(tokenData);
}
void AddDynamicallyFullUserInfo()
{
InternalApi api = new InternalApi();
// fetching Web Data from DB
Literal webData = new Literal();
webData.ID = "fullUserInfo";
webData.Text = "<p>" + api.GetFullUserInfo(Request.Cookies["userName"].Value) + "</p>";
// init controls
LinkButton buttonEditData = new LinkButton();
buttonEditData.ID = "buttonEditUserInfo";
buttonEditData.CssClass = "button round blue image-right ic-edit text-upper";
buttonEditData.Click += new EventHandler(buttonEditData_Click);
buttonEditData.Text = "Изменить личные данные";
// adding controls to User Info panel
this.contentViewWebdata.Controls.Add(webData);
this.contentViewWebdata.Controls.Add(buttonEditData);
postbackUserInfo = true;
}
void buttonEditData_Click(object sender, EventArgs e)
{
this.contentViewWebdata.Controls.Clear();
SetSceneEditableUserInfo();
}
void SetSceneEditableUserInfo()
{
// init objects
InternalApi api = new InternalApi();
var serializedData = api.GetSerializedUserInfo(Request.Cookies["userName"].Value);
Literal paragraphBegin = new Literal();
paragraphBegin.Text = "<p>";
Literal paragraphEnd = new Literal();
paragraphEnd.Text = "</p>";
Literal breakLine = new Literal();
breakLine.Text = "<br />";
// <p> start
this.contentViewWebdata.Controls.Add(paragraphBegin);
// set User GUID editable field
Label labelUserGuid = new Label();
labelUserGuid.ID = "editableLabelUserGuid";
labelUserGuid.Text = "GUID-идентификатор пользователя: ";
TextBox editableUserGuid = new TextBox();
editableUserGuid.ID = "editableTextBoxUserGuid";
editableUserGuid.CssClass = "round default-width-input";
editableUserGuid.Text = serializedData.guid.ToString();
editableUserGuid.Enabled = false;
this.contentViewWebdata.Controls.Add(labelUserGuid);
this.contentViewWebdata.Controls.Add(editableUserGuid);
this.contentViewWebdata.Controls.Add(breakLine);
// set Username editable field
Label labelUserName = new Label();
labelUserName.ID = "editableLabelUserName";
labelUserName.Text = "Логин: ";
TextBox editableUserName = new TextBox();
editableUserName.ID = "editableTextBoxUserName";
editableUserName.CssClass = "round default-width-input";
editableUserName.Text = serializedData.login;
editableUserName.Enabled = false;
this.contentViewWebdata.Controls.Add(labelUserName);
this.contentViewWebdata.Controls.Add(editableUserName);
this.contentViewWebdata.Controls.Add(breakLine);
// set User E-mail editable field
Label labelUserEmail = new Label();
labelUserEmail.ID = "editableLabelUserEmail";
labelUserEmail.Text = "E-mail: ";
TextBox editableUserEmail = new TextBox();
editableUserEmail.ID = "editableTextBoxUserEmail";
editableUserEmail.CssClass = "round default-width-input";
editableUserEmail.Text = serializedData.email;
this.contentViewWebdata.Controls.Add(labelUserEmail);
this.contentViewWebdata.Controls.Add(editableUserEmail);
this.contentViewWebdata.Controls.Add(breakLine);
// </p> end
this.contentViewWebdata.Controls.Add(paragraphEnd);
}
void SetSceneDashboard()
{
// Dock
this.dock.Visible = true;
// CSS
this.tabDashboard.CssClass = "active-tab dashboard-tab";
this.tabFirst.CssClass = String.Empty;
this.tabSecond.CssClass = String.Empty;
this.tabThird.CssClass = String.Empty;
this.tabFourth.CssClass = String.Empty;
// Text
this.tabFirst.Text = String.Empty;
this.tabSecond.Text = String.Empty;
this.tabThird.Text = String.Empty;
this.tabFourth.Text = String.Empty;
// Visible
this.tabFirst.Visible = false;
this.tabSecond.Visible = false;
this.tabThird.Visible = false;
this.tabFourth.Visible = false;
// Content panel head
this.contentTitle.Text = String.Empty;
this.contentHeader.Visible = false;
// Content panel views
this.contentMarket.Visible = false;
this.contentViewWebdata.Visible = false;
this.contentViewTokendata.Visible = false;
this.contentСhangePassword.Visible = false;
// Subpanels controls
this.tableMarket.Visible = false;
this.boxPasswordChange.Visible = false;
this.statePasswordChange.Visible = false;
}
void SetSceneMarket()
{
// Dock
this.dock.Visible = false;
// CSS
this.tabDashboard.CssClass = "dashboard-tab";
this.tabFirst.CssClass = "active-tab";
this.tabSecond.CssClass = String.Empty;
this.tabThird.CssClass = String.Empty;
this.tabFourth.CssClass = String.Empty;
// Text
this.tabFirst.Text = "Все предложения";
this.tabSecond.Text = "Мои избранные заявки";
this.tabThird.Text = "Мои текущие заявки на кредит";
this.tabFourth.Text = "История моих заявок";
// Visible
this.tabFirst.Visible = true;
this.tabSecond.Visible = true;
this.tabThird.Visible = true;
this.tabFourth.Visible = true;
// Content panel head
this.contentTitle.Text = "Cписок всех предложений";
this.contentHeader.Visible = true;
// Free panel controls
this.contentViewWebdata.Controls.Clear();
this.contentViewTokendata.Controls.Clear();
// Content panel views
this.contentMarket.Visible = true;
this.contentViewWebdata.Visible = true;
this.contentViewTokendata.Visible = false;
this.contentСhangePassword.Visible = false;
// Subpanels controls
this.tableMarket.Visible = true;
this.boxPasswordChange.Visible = false;
this.statePasswordChange.Visible = false;
RefreshTableContent();
}
void RefreshTableContent()
{
ClearOldContentFromTable();
SetTableHeadForSceneMarket();
SetTableBodyForSceneMarket();
}
void ClearOldContentFromTable()
{
this.tableMarket = new Table();
this.tableHeader = new TableHeaderRow();
this.tableMarket.Controls.Add(tableHeader);
this.contentMarket.Controls.Clear();
this.contentMarket.Controls.Add(tableMarket);
}
void SetTableHeadForSceneMarket()
{
/* Set header of current table */
// First cell
TableHeaderCell cellFirst = new TableHeaderCell();
cellFirst.ID = "cellCheckBoxSelectAll";
CheckBox checkBoxSelectAll = new CheckBox();
checkBoxSelectAll.ID = "checkBoxSelectAll";
cellFirst.Controls.Add(checkBoxSelectAll);
// Second cell
TableHeaderCell cellSecond = new TableHeaderCell();
cellSecond.ID = "cellBankNames";
cellSecond.Text = "Наименование банка";
// Third cell
TableHeaderCell cellThird = new TableHeaderCell();
cellThird.ID = "cellCreditSum";
cellThird.Text = "Сумма кредита";
// Fourth cell
TableHeaderCell cellFourth = new TableHeaderCell();
cellFourth.ID = "cellPercentage";
cellFourth.Text = "Процент";
// Fifth cell
TableHeaderCell cellFifth = new TableHeaderCell();
cellFifth.ID = "cellCredittime";
cellFifth.Text = "Срок кредита";
// Sixth cell
TableHeaderCell cellSixth = new TableHeaderCell();
cellSixth.ID = "cellActions";
cellSixth.Text = "Действия";
// Add cells to current header
tableHeader.Controls.Add(cellFirst);
tableHeader.Controls.Add(cellSecond);
tableHeader.Controls.Add(cellThird);
tableHeader.Controls.Add(cellFourth);
tableHeader.Controls.Add(cellFifth);
tableHeader.Controls.Add(cellSixth);
// Finally
this.tableMarket.Controls.Add(tableHeader);
}
void SetTableBodyForSceneMarket()
{
InternalApi api = new InternalApi();
var offers = api.GetAllOffersStandardInfo();
var enumerator = offers.GetEnumerator();
int rowCounter = 0;
while (enumerator.MoveNext())
{
TableRow row = new TableRow();
row.ID = "rowData" + rowCounter.ToString();
// init CheckBox for row
TableCell cellSelectButton = new TableCell();
CheckBox checkBox = new CheckBox();
checkBox.ID = "checkBoxRow" + "offerId" + enumerator.Current.offerId + "rowNumber" + rowCounter.ToString();
cellSelectButton.Controls.Add(checkBox);
// init Bank Name for row
TableCell cellBank = new TableCell();
cellBank.ID = "bankId" + enumerator.Current.bankId + "rowNumber" + rowCounter.ToString();
cellBank.Text = enumerator.Current.bankName;
// init Offer Sum for row
TableCell cellOfferSum = new TableCell();
cellOfferSum.ID = "offerSumOfferId" + enumerator.Current.offerId + "rowNumber" + rowCounter.ToString();
cellOfferSum.Text = enumerator.Current.offerSum.ToString();
// init Offer Percentage for row
TableCell cellOfferPercentage = new TableCell();
cellOfferPercentage.ID = "offerPercentageOfferId" + enumerator.Current.offerId + "rowNumber" + rowCounter.ToString();
cellOfferPercentage.Text = enumerator.Current.offerPercentage.ToString() + " %";
// init Offer Credit Time for row
TableCell cellOfferCreditTime = new TableCell();
cellOfferCreditTime.ID = "offerCreditTimeOfferId" + enumerator.Current.offerId + "rowNumber" + rowCounter.ToString();
cellOfferCreditTime.Text = enumerator.Current.offerCreditTime;
/* init Action Buttons for row */
TableCell cellActions = new TableCell();
cellActions.ID = "offerActionsOfferId" + enumerator.Current.offerId;
// button View More for cell
LinkButton buttonViewExpanded = new LinkButton();
buttonViewExpanded.ID = "buttonViewExpandedOfferId" + enumerator.Current.offerId + "rowNumber" + rowCounter.ToString();
buttonViewExpanded.CssClass = "table-actions-button ic-table-info";
buttonViewExpanded.Click += new EventHandler(buttonViewExpanded_Click);
buttonViewExpanded.ToolTip = "посмотреть расширенное описание предложения";
cellActions.Controls.Add(buttonViewExpanded);
// add space between actions icons
Literal spaceControl = new Literal();
spaceControl.ID = "spaceLiteral" + rowCounter.ToString() + Guid.NewGuid().ToString();
spaceControl.Text = " ";
cellActions.Controls.Add(spaceControl);
// button Add to Favourites for cell
LinkButton buttonAddToFavourites = new LinkButton();
buttonAddToFavourites.ID = "buttonAddToFavouritesOfferId" + enumerator.Current.offerId + "rowNumber" + rowCounter.ToString();
buttonAddToFavourites.CssClass = "table-actions-button ic-table-favourite";
buttonAddToFavourites.Click += new EventHandler(buttonAddToFavourites_Click);
buttonAddToFavourites.ToolTip = "добавить в избранное";
cellActions.Controls.Add(buttonAddToFavourites);
/* end of Action Buttons */
// add Cells to Rows
row.Cells.Add(cellSelectButton);
row.Cells.Add(cellBank);
row.Cells.Add(cellOfferSum);
row.Cells.Add(cellOfferPercentage);
row.Cells.Add(cellOfferCreditTime);
row.Cells.Add(cellActions);
// add Row to Main Table
this.tableMarket.Controls.Add(row);
rowCounter++;
}
}
void buttonViewExpanded_Click(object sender, EventArgs e)
{
}
void buttonAddToFavourites_Click(object sender, EventArgs e)
{
}
void SetSceneMyProfile()
{
// Dock
this.dock.Visible = false;
// CSS
this.tabDashboard.CssClass = "dashboard-tab";
this.tabFirst.CssClass = "active-tab";
this.tabSecond.CssClass = String.Empty;
this.tabThird.CssClass = String.Empty;
this.tabFourth.CssClass = String.Empty;
// Text
this.tabFirst.Text = "Мои данные";
this.tabSecond.Text = "Копия данных с ЭЦП";
this.tabThird.Text = String.Empty;
this.tabFourth.Text = String.Empty;
// Visible
this.tabFirst.Visible = true;
this.tabSecond.Visible = true;
this.tabThird.Visible = false;
this.tabFourth.Visible = false;
// Content panel head
this.contentTitle.Text = "Просмотр регистрационных данных";
this.contentHeader.Visible = true;
// Content panel views
this.contentMarket.Visible = false;
this.contentViewWebdata.Visible = true;
this.contentViewTokendata.Visible = false;
this.contentСhangePassword.Visible = false;
// Subpanels controls
this.tableMarket.Visible = false;
this.boxPasswordChange.Visible = false;
this.statePasswordChange.Visible = false;
// Update current subpanel data
var control = FindControl("fullUserInfo");
if (control == null) AddDynamicallyFullUserInfo();
}
void SetSceneMyProfileTabTokenData()
{
// Dock
this.dock.Visible = false;
// CSS
this.tabDashboard.CssClass = "dashboard-tab";
this.tabFirst.CssClass = String.Empty;
this.tabSecond.CssClass = "active-tab";
this.tabThird.CssClass = String.Empty;
this.tabFourth.CssClass = String.Empty;
// Text
this.tabFirst.Text = "Мои данные";
this.tabSecond.Text = "Копия данных с ЭЦП";
this.tabThird.Text = String.Empty;
this.tabFourth.Text = String.Empty;
// Visible
this.tabFirst.Visible = true;
this.tabSecond.Visible = true;
this.tabThird.Visible = false;
this.tabFourth.Visible = false;
// Content panel head
this.contentTitle.Text = "Просмотр резервной копии данных с ЭЦП";
this.contentHeader.Visible = true;
// Content panel views
this.contentMarket.Visible = false;
this.contentViewWebdata.Visible = false;
this.contentViewTokendata.Visible = true;
this.contentСhangePassword.Visible = false;
// Subpanels controls
this.tableMarket.Visible = false;
this.boxPasswordChange.Visible = false;
this.statePasswordChange.Visible = false;
// Update current subpanel data
var control = FindControl("fullTokenData");
if (control == null) AddDynamicallyTokenData();
}
void SetSceneChangePassword()
{
// Dock
this.dock.Visible = false;
// CSS
this.tabDashboard.CssClass = "dashboard-tab";
this.tabFirst.CssClass = "active-tab";
this.tabSecond.CssClass = String.Empty;
this.tabThird.CssClass = String.Empty;
this.tabFourth.CssClass = String.Empty;
// Text
this.tabFirst.Text = "Смена пароля";
this.tabSecond.Text = String.Empty;
this.tabThird.Text = String.Empty;
this.tabFourth.Text = String.Empty;
// Visible
this.tabFirst.Visible = true;
this.tabSecond.Visible = false;
this.tabThird.Visible = false;
this.tabFourth.Visible = false;
// Content panel head
this.contentTitle.Text = "Обновление пароля для пользователя <b>"
+ Request.Cookies["userName"].Value + "</b>";
this.contentHeader.Visible = true;
// Content panel views
this.contentMarket.Visible = false;
this.contentViewWebdata.Visible = false;
this.contentViewTokendata.Visible = false;
this.contentСhangePassword.Visible = true;
// Subpanels controls
this.tableMarket.Visible = false;
this.boxPasswordChange.Visible = false;
this.statePasswordChange.Visible = false;
}
void SetPanelAlertText(AlertBoxStyle boxStyle, string inputText, string panelId, string labelId)
{
Panel box = (Panel)FindControl(panelId);
Label state = (Label)FindControl(labelId);
if (box != null && state != null)
{
switch (boxStyle)
{
case AlertBoxStyle.Error:
box.CssClass = "error-box round";
state.Text = inputText;
break;
case AlertBoxStyle.Information:
box.CssClass = "information-box round";
state.Text = inputText;
break;
case AlertBoxStyle.OK:
box.CssClass = "confirmation-box round";
state.Text = inputText;
break;
case AlertBoxStyle.Warning:
box.CssClass = "warning-box round";
state.Text = inputText;
break;
}
box.Visible = true;
state.Visible = true;
}
}
}
}