Advertisement
Guest User

Untitled

a guest
Mar 30th, 2013
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.86 KB | None | 0 0
  1. //#define Release
  2.  
  3. #region Include Classes
  4. using System;
  5. using System.Threading;
  6. using System.Text;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Web;
  10. using System.Web.UI;
  11. using System.Web.UI.WebControls;
  12. using System.Data;
  13. using MySql;
  14. using MySql.Web;
  15. using MySql.Data;
  16. using MySql.Data.Common;
  17. using MySql.Data.Entity;
  18. using MySql.Data.Entity.Properties;
  19. using MySql.Data.MySqlClient;
  20. using MySql.Data.MySqlClient.Authentication;
  21. using MySql.Data.MySqlClient.Properties;
  22. using MySql.Data.Types;
  23. #endregion
  24.  
  25. namespace WebApplication1
  26. {
  27.     public partial class NewOffer : System.Web.UI.Page
  28.     {
  29.         private bool isCookiesEmpty = false;
  30.  
  31.         protected void Page_Load(object sender, EventArgs e)
  32.         {
  33.             this.btnQuit.Click += new ImageClickEventHandler(btnQuit_Click);
  34.             this.btnMakeNewOffer.Click += new EventHandler(btnMakeNewOffer_Click);
  35.  
  36.             try
  37.             {
  38.                 InitMe();
  39.             }
  40.             catch (Exception exc)
  41.             {
  42.                 exc.ToString();
  43.             }
  44.  
  45. #if Release
  46.             if (isCookiesEmpty) Response.Redirect("Default.aspx");
  47.             if (BankView.sentOffer) Response.Redirect("TradePlace.aspx?view=my");
  48. #endif
  49.         }
  50.  
  51.         void btnMakeNewOffer_Click(object sender, EventArgs e)
  52.         {
  53.             string valueSteps = Request.Form["valueSteps"];
  54.  
  55.             if (valueSteps != null && valueSteps != String.Empty)
  56.             {
  57.                 int stepsCount = Convert.ToInt32(valueSteps);
  58.                 List<string> arrayDocs = new List<string>();
  59.  
  60.                 foreach (var item in Page.Controls)
  61.                 {
  62.                     if (item.GetType().Name == "CheckBox")
  63.                     {
  64.                         CheckBox checkBox = item as CheckBox;
  65.                         if (checkBox.ID != null && checkBox.ID != String.Empty && checkBox.Checked)
  66.                         {
  67.                             arrayDocs.Add(checkBox.ID);
  68.                         }
  69.                     }
  70.                 }
  71.  
  72.                 StringBuilder queryBuilder = new StringBuilder();
  73.                 List<string>.Enumerator enumCheckedBoxes = arrayDocs.GetEnumerator();
  74.  
  75.                 queryBuilder.Append("NewOffer.aspx?step=2&checkedValues=[");
  76.  
  77.                 while (enumCheckedBoxes.MoveNext())
  78.                 {
  79.                     queryBuilder.Append(enumCheckedBoxes.Current);
  80.                     queryBuilder.Append(',');
  81.                 }
  82.  
  83.                 queryBuilder.Remove(queryBuilder.Length - 1, 1);
  84.                 queryBuilder.Append("]");
  85.                 Response.Redirect(queryBuilder.ToString());
  86.             }
  87.             else NewOfferStatus.showAlert = true;
  88.         }
  89.  
  90.         void btnQuit_Click(object sender, ImageClickEventArgs e)
  91.         {
  92.             string[] myCookies = Request.Cookies.AllKeys;
  93.  
  94.             foreach (string cookie in myCookies)
  95.             {
  96.                 Response.Cookies[cookie].Expires = DateTime.Now.AddDays(-1);
  97.             }
  98.  
  99.             Response.Redirect("Default.aspx");
  100.         }
  101.  
  102.         void CheckHttpMethod()
  103.         {
  104.             if (Request.HttpMethod == "POST")
  105.             {
  106.  
  107.             }
  108.             else if (Request.HttpMethod == "GET")
  109.             {
  110.                 string clientString = HttpUtility.UrlDecode(Request.QueryString.ToString());
  111.  
  112.                 if (clientString != String.Empty && clientString != null)
  113.                 {
  114.                     int indexStart = clientString.IndexOf('[');
  115.                     int indexEnd = clientString.IndexOf(']');
  116.                     string tmpParams = clientString.Substring(indexStart + 1, indexEnd - indexStart - 1);
  117.                     string[] clientDocuments = tmpParams.Split(',');
  118.  
  119.                     DocumentHandler objectDocumentHandler = new DocumentHandler(ref clientDocuments);
  120.                     int[] docsMapValues = objectDocumentHandler.GetMapCheckedDocuments();
  121.                     DocumentData.docsMap = new Dictionary<int, string>();
  122.  
  123.                     for (int i = 0; i < clientDocuments.Length; i++)
  124.                     {
  125.                         DocumentData.docsMap.Add(docsMapValues[i], clientDocuments[i]);
  126.                     }
  127.                 }
  128.             }
  129.         }
  130.  
  131.         void InitMe()
  132.         {
  133.             NewOfferStatus.showAlert = false;
  134.             BankView.sentOffer = false;
  135.             CheckHttpMethod();
  136.  
  137.             UserCookies dataUserCookies = new UserCookies();
  138.  
  139.             foreach (string item in Request.Cookies)
  140.             {
  141.                 switch (item)
  142.                 {
  143.                     case "sessionId":
  144.                         dataUserCookies.sessionGuid = Guid.Parse(Request.Cookies[item].Value);
  145.                         break;
  146.                     case "userName":
  147.                         dataUserCookies.userName = Request.Cookies[item].Value;
  148.                         break;
  149.                     case "userType":
  150.                         dataUserCookies.userType = Convert.ToInt32(Request.Cookies[item].Value);
  151.                         break;
  152.                     case "clientIp":
  153.                         dataUserCookies.clientIp = Request.Cookies[item].Value;
  154.                         break;
  155.                     case "timeAuth":
  156.                         dataUserCookies.timeAuth = DateTime.Parse(Request.Cookies[item].Value);
  157.                         break;
  158.                 }
  159.             }
  160.  
  161.             isCookiesEmpty = CheckUserCookiesObject(ref dataUserCookies);
  162.         }
  163.  
  164.         bool CheckUserCookiesObject(ref UserCookies objHanlder)
  165.         {
  166.             bool isEmpty = false;
  167.  
  168.             if (objHanlder.userName == String.Empty) isEmpty = true;
  169.             if (objHanlder.userType == -1) isEmpty = true;
  170.             if (objHanlder.clientIp == String.Empty) isEmpty = true;
  171.  
  172.             return isEmpty;
  173.         }
  174.     }
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement