码迷,mamicode.com
首页 > Web开发 > 详细

CRM2011弹出asp.net模态窗口关闭的问题

时间:2014-10-28 11:43:33      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   io   color   os   ar   java   for   

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="batchassign.aspx.cs" Inherits="Demo.batchassign" %>

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Xrm.Sdk.Client;
using UploadFiles;
using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk;
using System.Data.SqlClient;
using System.Data;

namespace Demo
{
    public partial class batchassign : System.Web.UI.Page
    {
        private IOrganizationService orgService;
        string ownerid = string.Empty;
        private static string strConnectionString = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                orgService = GetCrmService();
                BindGridView();
            }
        }

        public void BindGridView() 
        {
            string strOwnerId=Request.QueryString["ownerid"].ToString();
            if (!string.IsNullOrEmpty(strOwnerId))
            {
                Guid OwnerId = new Guid(strOwnerId);
                gvInfo.DataSource = GetSettingsByProcedure(orgService, OwnerId);
                gvInfo.DataBind();
            }
        }

        protected void gvInfo_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            try
            {
                //单选
                CheckBox cb = (CheckBox)e.Row.FindControl("chkSelected");
                if (cb != null)
                    cb.Attributes.Add("onclick", "signcheck(" + cb.ClientID + ")");

                //如果是绑定数据行 
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    //鼠标经过时,行背景色变 
                    e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor=‘#E6F5FA‘");
                    //鼠标移出时,行背景色变 
                    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=‘#FFFFFF‘");
                }
            }
            catch
            {
                
            }

        }

        private OrganizationServiceProxy GetCrmService()
        {
            string filePath = MapPath(@"/ISV/Config.txt");
            FileConfig config = new FileConfig(filePath);
            string crmUrl;
            string orgName = config.GetValue("orgName").ToLower();
            if (Request.Url.Host.ToLower().StartsWith(orgName, StringComparison.CurrentCultureIgnoreCase))
            {
                crmUrl = Request.Url.Scheme + "://" + Request.Url.Host + ":" + Request.Url.Port + "/XRMServices/2011/Organization.svc";
            }
            else
            {
                crmUrl = Request.Url.Scheme + "://" + Request.Url.Host + ":" + Request.Url.Port + "/" + orgName + "/XRMServices/2011/Organization.svc";
            }
            ClientCredentials credentials = new ClientCredentials();
            credentials.UserName.UserName = config.GetValue("UserName");
            credentials.UserName.Password = config.GetValue("Password");

            OrganizationServiceProxy crmServiceProxy = new OrganizationServiceProxy(new Uri(crmUrl), null, credentials, null);
            return crmServiceProxy;
        }

        /// <summary>
        /// 依据指定的CRM服务,指定的OwnerId,获取销售顾问
        /// </summary>
        /// <param name="service">指定的CRM服务</param>
        /// <param name="entityName">指定的OwnerId</param>
        /// <returns>流水号管理类</returns>
        public  DataSet GetSettingsByProcedure(IOrganizationService service, Guid OwnerId)
        {
            DataSet ds = new DataSet();

            if (string.IsNullOrEmpty(strConnectionString))
            {
                SystemConfig config = new SystemConfig(service, "IDOSSales_ReadOnly");
                strConnectionString = config.GetValue();
            }

            using (SqlConnection sqlconn = new SqlConnection(strConnectionString))
            {
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = sqlconn;
                cmd.CommandText = "[dbo].[GetSalesConsultant]";
                cmd.CommandType = CommandType.StoredProcedure;
                sqlconn.Open();
                IDataParameter[] parameters = { 
                                       
                                        new SqlParameter("@ownerid", SqlDbType.UniqueIdentifier)};
                parameters[0].Value = OwnerId;
                cmd.Parameters.Add(parameters[0]);
                SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                adapter.Fill(ds);
                sqlconn.Close();
            }

            return ds;
        }

        protected void chkSelected_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox chk = sender as CheckBox;

            int index = ((GridViewRow)(chk.NamingContainer)).RowIndex;

            if (chk.Checked)
            {
                ownerid = gvInfo.Rows[index].Cells[3].Text.Trim();
            }
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            if (ownerid != null && ownerid != "")
            {
                Response.Write("<script>window.returnValue=‘" + ownerid + "‘;window.opener = \"\"; window.open(\"\", \"_self\"); window.close();</script>");
                //Response.Write("<script>window.returnValue=‘" + ownerid + "‘;window.close();</script>");
            }   
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            //Response.Write("<script>window.returnValue=‘1‘;</script>");
            Response.Write("<script>window.returnValue=‘" + ownerid + "‘;window.opener = \"\"; window.open(\"\", \"_self\"); window.close();</script>");
        }
    }
}


这是模态窗口的代码,通过Response.Write始终关闭不了模态窗口,具体原因不明觉厉,希望大家各抒己见探讨探讨,请各位高手多多指教。。。。。。

CRM2011弹出asp.net模态窗口关闭的问题

标签:des   style   blog   io   color   os   ar   java   for   

原文地址:http://www.cnblogs.com/gaohao/p/4056176.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!