首页 > silverlight数据库应用程序开发

silverlight数据库应用程序开发

该解决方案使用的是"silverlight导航应用程序+Oracle数据库+WebService服务”

新建silverlight项目GH,同时会自动添加一个GH.Web,在GH.Web中添加"web 服务",同时需要添加两个XML文件用于解决跨域问题:

第一个XML文件:clientaccesspolicy.xml:





 

   

     

       

     


     

       

     


   


 


第二个XML文件:crossdomain.xml:











在GH中添加一个文件夹:Model,用于存放实体类,然后添加"服务引用":GH_ServiceReference

web服务代码:

ExpandedBlockStart.gifView Code
  1 #region 用户管理

  2         [WebMethod]

  3         public string getUsers()

  4         {

  5             try

  6             {

  7                 OracleConnection orclConn = new OracleConnection(ConfigurationManager.ConnectionStrings["ConString"].ConnectionString);

  8                 orclConn.Open();

  9                 OracleDataAdapter orclAdapter = new OracleDataAdapter("select U.ID,U.XM,U.SSBMMC,ZD.MS,R.JSMC from SYS_USER U,SYS_ZD ZD,SYS_ROLE R WHERE U.SSQY=ZD.ID AND U.ROLEDM=R.ID AND ZD.LXID=1 order by U.ID ", orclConn);

 10                 DataSet ds = new DataSet();

 11                 orclAdapter.Fill(ds);

 12 

 13                 int num = 1;

 14                 StringBuilder builder = new StringBuilder();

 15                 builder.Append("");

 16                 builder.Append("");

 17                 foreach (DataRow row in ds.Tables[0].Rows)

 18                 {                    

 19                     builder.Append("");

 20                     builder.Append("");

 21                     builder.Append(num.ToString());

 22                     builder.Append("");

 23                     builder.Append("");

 24                     builder.Append(row[0].ToString());

 25                     builder.Append("");

 26                     builder.Append("");

 27                     builder.Append(row[1].ToString());

 28                     builder.Append("");

 29                     builder.Append("");

 30                     builder.Append(row[2].ToString());

 31                     builder.Append("");

 32                     builder.Append("");

 33                     builder.Append(row[3].ToString());

 34                     builder.Append("");

 35                     builder.Append("");

 36                     builder.Append(row[4].ToString());

 37                     builder.Append("");

 38                     builder.Append("");

 39                     num++;

 40                 }

 41                 builder.Append("");

 42                 orclConn.Close();

 43                 return builder.ToString();

 44             }

 45             catch (Exception ex)

 46             {

 47                 return string.Empty;

 48             }

 49         }

 50         //删除用户

 51         [WebMethod]

 52         public int DelUser(int uID)

 53         {

 54             string sql = "delete from SYS_USER where ID="+uID.ToString();

 55             return OperaData(sql);

 56         }

 57 

 58 

 59         [WebMethod]

 60         public int InsertUser(string uName,string dep,string areaid,string roleid)

 61         {

 62             string sql = "insert into SYS_USER(XM,SSBMMC,SSQY,ROLEDM) values('" + uName + "','" + dep + "','" + areaid + "','" + roleid + "')";

 63             return OperaData(sql);

 64         }

 65         [WebMethod]

 66         public int UptUser(string s)

 67         {

 68             string [] val=s.Split('|');

 69             string sql = "update SYS_USER set SSBMMC='" + val[0] + "',SSQY='" + val[1] + "',ROLEDM='" + val[2] + "' where ID='" + val[3] + "'";

 70             return OperaData(sql);

 71         }

 72 

 73         /// 

 74         /// 增、删、改

 75         /// 


 76         /// 

 77         /// 

 78         private int OperaData(string sql)

 79         {

 80             OracleConnection orclConn = new OracleConnection(ConfigurationManager.ConnectionStrings["ConString"].ConnectionString);

 81             orclConn.Open();

 82             OracleCommand orclCmd = new OracleCommand(sql, orclConn);

 83             int result = orclCmd.ExecuteNonQuery();

 84             orclConn.Close();

 85             return result;

 86         }

 87 

 88 

 89         /// 

 90         /// 获取所属区域

 91         /// 


 92         [WebMethod]

 93         public string GetArea()

 94         {

 95             try

 96             {

 97                 OracleConnection orclConn = new OracleConnection(ConfigurationManager.ConnectionStrings["ConString"].ConnectionString);

 98                 orclConn.Open();

 99                 OracleDataAdapter orclAdapter = new OracleDataAdapter("select ZD.ID,ZD.MS from SYS_ZD ZD WHERE ZD.LXID=1", orclConn);

100                 DataSet ds = new DataSet();

101                 orclAdapter.Fill(ds);

102 

103                 StringBuilder builder = new StringBuilder();

104                 builder.Append("");

105                 builder.Append("");

106                 foreach (DataRow row in ds.Tables[0].Rows)

107                 {

108                     builder.Append("");

109                     builder.Append("");

110                     builder.Append(row[0].ToString());

111                     builder.Append("");

112                     builder.Append("");

113                     builder.Append(row[1].ToString());

114                     builder.Append("");

115                     builder.Append("");

116                 }

117                 builder.Append("");

118                 orclConn.Close();

119                 return builder.ToString();

120             }

121             catch (Exception e)

122             {

123                 return string.Empty;

124             }

125         }

126 

127         /// 

128         /// 获取角色

129         /// 


130         [WebMethod]

131         public string GetRole()

132         {

133             try

134             {

135                 OracleConnection orclConn = new OracleConnection(ConfigurationManager.ConnectionStrings["ConString"].ConnectionString);

136                 orclConn.Open();

137                 OracleDataAdapter orclAdapter = new OracleDataAdapter("select ROLE.ID,ROLE.JSMC from SYS_ROLE ROLE", orclConn);

138                 DataSet ds = new DataSet();

139                 orclAdapter.Fill(ds);

140 

141                 StringBuilder builder = new StringBuilder();

142                 builder.Append("");

143                 builder.Append("");

144                 foreach (DataRow row in ds.Tables[0].Rows)

145                 {

146                     builder.Append("");

147                     builder.Append("");

148                     builder.Append(row[0].ToString());

149                     builder.Append("");

150                     builder.Append("");

151                     builder.Append(row[1].ToString());

152                     builder.Append("");

153                     builder.Append("");

154                 }

155                 builder.Append("");

156                 orclConn.Close();

157                 return builder.ToString();

158             }

159             catch (Exception e)

160             {

161                 return string.Empty;

162             }

163         }

164         #endregion

主页面视图:

主页面xmal代码:

ExpandedBlockStart.gifView Code
  1 public partial class GH_User : Page

  2     {

  3         GH_ServiceReference.GH_serviceSoapClient client = new GH.GH_ServiceReference.GH_serviceSoapClient();

  4         public GH_User()

  5         {

  6             InitializeComponent();

  7             GH_ServiceReference.GH_serviceSoapClient client = new GH.GH_ServiceReference.GH_serviceSoapClient();

  8             client.getUsersCompleted += new EventHandler(OnGetUsersCompleted);

  9             client.getUsersAsync();            

 10         }

 11        

 12         /// 

 13         /// 获取用户信息

 14         /// 


 15         private void OnGetUsersCompleted(object sender, GH.GH_ServiceReference.getUsersCompletedEventArgs e)

 16         {

 17             if (e.Error != null)

 18             {

 19                 return;

 20             }

 21             XmlReader reader = XmlReader.Create(new StringReader(e.Result.ToString()));

 22             XDocument doc = XDocument.Load(reader);

 23             var info = from items in doc.Descendants("user")

 24                        select new gh_UserModel()

 25                        {

 26                            Num = (int)items.Element("number"),

 27                            ID = (string)items.Element("userID"),

 28                            Name = (string)items.Element("userName"),

 29                            DepName = (string)items.Element("userDep"),

 30                            Area = (string)items.Element("userArea"),

 31                            RoleID = (string)items.Element("userRole")

 32                        };

 33             //分页

 34             PagedCollectionView view = new PagedCollectionView(info.ToList());

 35             dataGrid1.ItemsSource = view;

 36             dataPager1.Source = view;

 37             dataPager1.PageSize = 5;

 38         }

 39 

 40         //删除用户

 41         private void bt_del_Click(object sender, RoutedEventArgs e)

 42         {

 43             client.DelUserCompleted += new EventHandler(client_DelUserCompleted);

 44             client.DelUserAsync(Convert.ToInt32((sender as Button).Tag.ToString()));

 45         }

 46         void client_DelUserCompleted(object sender, GH_ServiceReference.DelUserCompletedEventArgs e)

 47         {

 48             if (e.Error == null)

 49             {

 50                 MessageBox.Show("删除成功!");

 51                 //重新绑定

 52                 client.getUsersCompleted += new EventHandler(OnGetUsersCompleted);

 53                 client.getUsersAsync();

 54             }

 55             else

 56             {

 57                 MessageBox.Show(e.Error.ToString());

 58             }

 59         }

 60 

 61         private void Page_Loaded(object sender, RoutedEventArgs e)

 62         {

 63             client.GetAreaCompleted += new EventHandler(client_GetAreaCompleted);

 64             client.GetAreaAsync();

 65             client.GetRoleCompleted += new EventHandler(client_GetRoleCompleted);

 66             client.GetRoleAsync();

 67         }

 68 

 69         void client_GetRoleCompleted(object sender, GH_ServiceReference.GetRoleCompletedEventArgs e)

 70         {

 71             if (e.Error == null)

 72             {

 73                 XmlReader reader = XmlReader.Create(new StringReader(e.Result.ToString()));

 74                 XDocument doc = XDocument.Load(reader);

 75                 var role = from items in doc.Descendants("role")

 76                            select new gh_RoleModel()

 77                            {

 78                                RoleID=(string)items.Element("id"),

 79                                RoleName = (string)items.Element("roleName")

 80                            };

 81 

 82                 comboBox_role.ItemsSource = role.ToList();

 83                 comboBox_role.DisplayMemberPath = "RoleName";

 84                 comboBox_role.UpdateLayout();

 85                 comboBox_role.SelectedIndex = 0;

 86             }

 87         }

 88 

 89         void client_GetAreaCompleted(object sender, GH_ServiceReference.GetAreaCompletedEventArgs e)

 90         {

 91             if (e.Error == null)

 92             {

 93                 XmlReader reader = XmlReader.Create(new StringReader(e.Result.ToString()));

 94                 XDocument xdoc = XDocument.Load(reader);

 95                 var area = from items in xdoc.Descendants("area")

 96                            select new gb_ZDModel()

 97                            {

 98                                ID = (string)items.Element("id"),

 99                                Des = (string)items.Element("ms")

100                            };

101                 comboBox_area.ItemsSource = area.ToList();

102                 comboBox_area.DisplayMemberPath = "Des";

103                 comboBox_area.UpdateLayout();

104                 comboBox_area.SelectedIndex = 0;

105             }

106         }

107         //保存用户

108         private void btn_Sava_Click(object sender, RoutedEventArgs e)

109         {

110             if (string.IsNullOrEmpty(textBox1.Text))

111             {

112                 MessageBox.Show("请输入用户名");

113                 return;

114             }

115             if (string.IsNullOrEmpty(textBox2.Text))

116             {

117                 MessageBox.Show("请输入所属部门");

118                 return;

119             }

120             var areaname = comboBox_area.SelectedItem;

121             string areaid = ((gb_ZDModel)areaname).ID;

122 

123             var rolename = comboBox_role.SelectedItem;

124             string roleid = ((gh_RoleModel)rolename).RoleID;

125 

126             client.InsertUserCompleted += new EventHandler(client_InsertUserCompleted);

127             client.InsertUserAsync(textBox1.Text, textBox2.Text, areaid, roleid);

128         }

129 

130         void client_InsertUserCompleted(object sender, GH_ServiceReference.InsertUserCompletedEventArgs e)

131         {

132             if (e.Error == null)

133             {

134                 client.getUsersCompleted += new EventHandler(OnGetUsersCompleted);

135                 client.getUsersAsync();

136                 MessageBox.Show("用户添加完毕.");

137                 textBox1.Text = "";

138                 textBox2.Text = "";

139                 comboBox_area.SelectedIndex = 0;

140                 comboBox_role.SelectedIndex = 0;

141             }

142             else

143             {

144                 MessageBox.Show(e.Error.ToString());

145             }

146         }

147 

148         gh_User_Child user_child;

149         //修改

150         private void btn_upt_Click(object sender, RoutedEventArgs e)

151         {

152             gh_UserModel row = (gh_UserModel)dataGrid1.SelectedItem;

153 

154             user_child = new gh_User_Child(row.ID, row.Name, row.DepName, row.Area, row.RoleID);

155             user_child.Title = "用户信息";            

156             user_child.Show();

157             user_child.Closed += new EventHandler(user_child_Closed);

158         }

159 

160         void user_child_Closed(object sender, EventArgs e)

161         {

162             if (user_child.DialogResult == true)

163             {

164                 string dep = user_child.textBox2.Text;

165                 string area = ((gb_ZDModel)user_child.comboBox_area.SelectedItem).ID;

166                 string role = ((gh_RoleModel)user_child.comboBox_role.SelectedItem).RoleID;

167                 string uID=user_child.OKButton.Tag.ToString();

168                 client.UptUserCompleted += new EventHandler(client_UptUserCompleted);

169                 string s = dep +"|"+ area+"|" + role +"|"+ uID;

170                 client.UptUserAsync(s);

171             }

172         }

173 

174         void client_UptUserCompleted(object sender, GH_ServiceReference.UptUserCompletedEventArgs e)

175         {

176             if (e.Error == null)

177             {

178                 MessageBox.Show("更新成功");

179                 client.getUsersCompleted += new EventHandler(OnGetUsersCompleted);

180                 client.getUsersAsync();

181             }

182         }

子窗体视图:

子窗体代码:

ExpandedBlockStart.gifView Code
 1 GH_ServiceReference.GH_serviceSoapClient client = new GH.GH_ServiceReference.GH_serviceSoapClient();

 2         public gh_User_Child()

 3         {

 4             InitializeComponent();

 5         }

 6         

 7         public gh_User_Child(string id, string name, string dep, string area, string role)

 8         {

 9             InitializeComponent();

10             

11             client.GetAreaCompleted += new EventHandler(client_GetAreaCompleted);

12             client.GetAreaAsync();

13             client.GetRoleCompleted += new EventHandler(client_GetRoleCompleted);

14             client.GetRoleAsync();

15 

16             this.OKButton.Tag = id;

17             textBox1.Text = name;

18             textBox2.Text = dep;

19             comboBox_area.SelectedValue = area;  //无效

20             comboBox_area.SelectedValue = role;

21         }

22 

23         void client_GetRoleCompleted(object sender, GH_ServiceReference.GetRoleCompletedEventArgs e)

24         {

25             if (e.Error == null)

26             {

27                 XmlReader reader = XmlReader.Create(new StringReader(e.Result.ToString()));

28                 XDocument doc = XDocument.Load(reader);

29                 var role = from items in doc.Descendants("role")

30                            select new gh_RoleModel()

31                            {

32                                RoleID = (string)items.Element("id"),

33                                RoleName = (string)items.Element("roleName")

34                            };

35 

36                 comboBox_role.ItemsSource = role.ToList();

37                 comboBox_role.DisplayMemberPath = "RoleName";

38                 comboBox_role.UpdateLayout();

39                 comboBox_role.SelectedIndex = 0;

40             }

41         }

42 

43         void client_GetAreaCompleted(object sender, GH_ServiceReference.GetAreaCompletedEventArgs e)

44         {

45             if (e.Error == null)

46             {

47                 XmlReader reader = XmlReader.Create(new StringReader(e.Result.ToString()));

48                 XDocument xdoc = XDocument.Load(reader);

49                 var area = from items in xdoc.Descendants("area")

50                            select new gb_ZDModel()

51                            {

52                                ID = (string)items.Element("id"),

53                                Des = (string)items.Element("ms")

54                            };

55                 comboBox_area.ItemsSource = area.ToList();

56                 comboBox_area.DisplayMemberPath = "Des";

57                 comboBox_area.UpdateLayout();

58                 comboBox_area.SelectedIndex = 0;

59             }

60         }

61 

62         private void OKButton_Click(object sender, RoutedEventArgs e)

63         {

64             this.DialogResult = true;

65         }

66         private void CancelButton_Click(object sender, RoutedEventArgs e)

67         {

68             this.DialogResult = false;

69         }

 

转载于:https://www.cnblogs.com/jsping/archive/2012/09/21/2697063.html

更多相关:

  • 菜鸟一枚,正在学习C++ Gui Qt4,整理很零碎,欢迎批评指正   1.窗口标题: QWidget *window = new QWidget; window->setWindowTitle("Enter Your Age"); **************************************** 关于标题...

  • 将两个有序链表合并为一个新的有序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 示例: 输入:1->2->4, 1->3->4 输出:1->1->2->3->4->4 总体思路是: 比较两个链表头节点,较小的插入新链表指针之后,同时较小链表指针向后移动一位 实现如下: ListNode* mergeTwo...

  • 1.直接调用微软socket对象处理 static void Main(string[] args){try{IPAddress ip = new IPAddress(new byte[] { 127, 0, 0, 1 });//在3721端口新建一个TcpListener对象TcpListener listener = new...

  •   现在很多地方都会用到zookeeper, 用到它的地方就是为了实现分布式。用到的场景就是服务注册,比如一个集群服务器,需要知道哪些服务器在线,哪些服务器不在线。   ZK有一个功能,就是创建临时节点,当机器启动应用的时候就会连接到一个ZK节点,然后创建一个临时节点,那么通过获取监听该路径,并且获取该路径下的节点数量就知道有哪些服务...

  • 前台到后台java时data日期类型的转化 在实体类中用@DataTimeFormat,这样设置即使传过来是空的字符串也是可以转的,要和前面传过来的格式一致,如 @XmlElement(name="BeginDate") @DateTimeFormat(pattern="yyyy-MM-dd") private Date begin...

  • importjava.security.SecureRandom;importjavax.crypto.Cipher;importjavax.crypto.SecretKey;importjavax.crypto.SecretKeyFactory;importjavax.crypto.spec.DESKeySpec;//结果与DES算...

  • 题目:替换空格 请实现一个函数,把字符串 s 中的每个空格替换成"%20"。 输入:s = "We are happy." 输出:"We%20are%20happy." 限制: 0 <= s 的长度 <= 10000 解题: 时间复杂度:O(n) 空间复杂度:O(n) class Solution { public:s...

  • 在C++11标准库中,string.h已经添加了to_string方法,方便从其他类型(如整形)快速转换成字面值。 例如: for (size_t i = 0; i < texArrSize; i++)RTX_Shader.SetInt(string("TexArr[") + to_string(i) + "]", 7 + i);...

  • Ubuntu 14.04安装并升级之后,变成楷体字体非常难看,我昨天搞了一晚上,终于理了个头绪,这里整理一下。 经过网上调研,大家的一致看法是,使用开源字体库文泉驿的微黑字体效果比较理想,甚至效果不输windows平台的雅黑字体。下面我打算微黑来美化Ubuntu 14.04. 1.安装文泉驿微黑字体库 sudo aptitude...

  • 使用string时发现了一些坑。 我们知道stl 容器并不是线程安全的,所以在使用它们的过程中往往需要一些同步机制来保证并发场景下的同步更新。 应该踩的坑还是一个不拉的踩了进去,所以还是记录一下吧。 string作为一个容器,随着我们的append 或者 针对string的+ 操作都会让string内部的数据域动态增加,而动态增加的...