|
Hi DNA Developer!
i'm a newbier for DNA and MVC. Few day ago i saw the DNA and want to using it. I'm learn to write the widget, but demo to build widget it too few and too simple. Now i stuck with my idea widget : i want to build a support Online widget: This is Model file: 1:
2: using System; 3: using System.Collections.Generic; 4: using System.Linq; 5: using System.Web; 6: using System.Net; 7: using System.IO; 8: using System.Text; 9:
10: namespace DNACreateWidget.Models 11: {
12: public class SupportOnline 13: {
14: //private string _yahoo = string.Empty; 15: //public string Yahoo 16: //{ 17: // get 18: // { 19: // return _yahoo; 20: // } 21: // set 22: // { 23: // _yahoo = value; 24: // } 25: //} 26: private string Yahoo = ""; 27:
28: public string _Yahoo { 29: get {
30: return Yahoo; 31: }
32: set {
33: Yahoo = _Yahoo;
34: }
35: }
36:
37:
38: private string PostData(string url) // Nick yahoo can check 39: {
40: HttpWebRequest request = null; 41: Uri uri = new Uri(url); 42: request = (HttpWebRequest)WebRequest.Create(uri);
43: request.Method = "POST"; 44: request.ContentType = "application/x-www-form-urlencoded"; 45: string result = ""; 46:
47: using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) 48: {
49: using (Stream responseStream = response.GetResponseStream()) 50: {
51: using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8)) 52: {
53: result = readStream.ReadToEnd();
54: }
55: }
56: }
57: return result; 58: }
59:
60: private bool isOnline(string Username) // Yahoo can hien 61: {
62: string isonval = PostData("http://mail.opi.yahoo.com/online?u=" + Username.Trim() + "&m=t&t=1"); -- day la phan chinh 63: //string isonval = "01"; // demo 64: if (isonval == "00") return false; 65: else if (isonval == "01") return true; 66: else return false; 67: }
68:
69: public string SupportOnlines() 70: {
71: bool KetQua = isOnline(Yahoo); 72: if (KetQua == true) // neu bang true thi dang online, neu ko thi dang offline 73: {
74: return "Online"; 75: }
76: else 77: {
78: return "Offline"; 79: }
80: }
81: }
82:
83: }
This is Controller File: 1:
2: using System; 3: using System.Collections.Generic; 4: using System.Linq; 5: using System.Web; 6: using System.Web.Mvc; 7: using DNA.Mvc.UI; 8:
9: using DNACreateWidget.Models; 10:
11: namespace DNACreateWidget.Controllers 12: {
13: public class SupportOnlineController : Controller 14: {
15: // 16: // GET: /SupportOnline/ 17:
18:
19:
20: [Widget(
21: Title="SupportOnline", 22: Description="Support online for checking status YM! , Comming soon for view info contact.", 23: Category="Misc", 24: IsClosable=false 25: )]
26:
27: [Property("Nick", 28: DisplayName="Nick of people", 29: PropertyControl=ControlTypes.TextBox,
30: ValueType=typeof(string), 31: DefaultValue="kleonnova" 32: )]
33:
34:
35: public ActionResult SupportOnline(string nick) 36: {
37: SupportOnline sP = new SupportOnline(); 38:
39: return PartialView("Online", sP); 40: }
41: }
42: }
This is CsHTML file 1:
2: @model DNACreateWidget.Models.SupportOnline
3:
4:
5: @{
6: Ajax.Dna().Widget()
7: .UserPreferences(@<text> 8: <span> title: @item.GetString("Nick")span> 9: <br> 10:
11: text>) 12: .Content(@<text> 13: @{
14: var nickCheck = item.GetString("Nick");
15: Model._Yahoo = nickCheck;
16: var f = Model.SupportOnlines();
17: }
18: <div class="check_acc"> 19: <label> :label> 20: <span>@fspan> 21: div> 22: text>).Render(); 23: }
24:
I made it show full info but now i need custom the edit display in form UserPreference to show full user parameter, but i don't know to it. pls, can you show me the solution to solve it, or demo for me a widget with a custom Userpreference form in csHtml? Sorry for my bad Eng Thanks! |