2013-10-25 1 views
0

У меня есть приложение crm. У меня есть одна проблема, связанная с тем, как я связываю управление ретрансляторами как потоки сообщений. как первая нить как вопрос и вторая нить в качестве ответа на этот вопрос. если пользователь спросил вопрос с несколькими затем первым, вторым, .. тема, как вопрос and.as это как сообщение болтало ...Как связать управление ретранслятора как потоковое сообщение сообщений

для хранения данных из базы данных я использую эту хранимую процедуру:

set ANSI_NULLS ON 
set QUOTED_IDENTIFIER ON 
GO 
ALTER PROCEDURE [dbo].[ViewMessageThreads] (@inquiry_id varchar(50)) 
AS 
BEGIN 
    SET NOCOUNT ON; 
    select 
    i.body as master_body, 
    h.body as history_body, 
    q.body as question_body, 
    q.Created_date as question_timestamp, 
    a.body as answer_body, 
    a.Created_date as answer_timestamp, 
    t.Type_name as user_type 
from tbl_Inquiry_History i 
left join tbl_Inquiry_master h on h.Inquiry_id=i.Inquiry_id 
left join tbl_Question q on q.Inquiry_id=i.Inquiry_id 
left join tbl_Answer a on a.Question_id=q.Inquiry_id 
left join tbl_User_master u on u.Id=i.User_id 
left join tbl_Login_master l on l.Id=u.User_id 
left join tbl_Type t on t.Id = l.type_id 
where ([email protected]_id) 
END 

и это дает мне результат:

master_body history_body question_body question_t.. answer_body answer_t.. user_type 
__________________________________________________________________________________________ 
question 1 NULL  question 1 2005-03-14...  NULL NULL  User 
question 1 NULL  question 2 2005-03-14...  NULL NULL  User 

и я включить этот дизайн источник ретранслятора:

<asp:Repeater ID="Repeater_Inquiry_Messages" runat="server"> 
          <ItemTemplate> 
          <table id="ctl00_ContentPlaceHolder1_dl_ticketmsg" cellspacing="0" border="0" style="width:100%;border-collapse:collapse;"> 
    <tbody><tr> 
     <td style="background-color:#F5F5FF;"> 
            <table cellpadding="0" cellspacing="0" border="0"> 
             <tbody><tr> 
              <td class="header"> 
               <span id="ctl00_ContentPlaceHolder1_dl_ticketmsg_ctl00_lbl_msg_no"><%#Container.ItemIndex+1 %></span></td> 
              <td class="normaltext" valign="bottom"> 
               <span id="ctl00_ContentPlaceHolder1_dl_ticketmsg_ctl00_lbl_tagline">Message By <b><asp:Label ID="lbl_user_t" runat="server" Text='<%#Eval("user_type")%>'/></b> on <asp:Label ID="lbldatetime" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "question_timestamp","{0:ddd, dd MMMM yyyy}")%>'/></span></td> 
             </tr> 
             <tr> 
              <td class="header"> 
               &nbsp;</td> 
              <td class="normaltext" valign="bottom"> 
               <b>Message :</b><br> 
               <span id="ctl00_ContentPlaceHolder1_dl_ticketmsg_ctl00_Label1"><asp:Label ID="lbl_inquiry_desc" runat="server" Text='<%#Eval("question_body")%>'/></span></td> 
             </tr> 
            </tbody></table> 
           </td> 
    </tr> 
</tbody></table> 
          </ItemTemplate> 
          <SeparatorTemplate> 
          <table> 
          <tr> 
          <td style="height:3px"></td> 
          </tr> 
          </table> 
          </SeparatorTemplate> 
          <ItemTemplate> 
          <table id="ctl00_ContentPlaceHolder1_dl_ticketmsg1" cellspacing="0" border="0" style="width:100%;border-collapse:collapse;"> 
    <tbody><tr> 
     <td style="background-color:#F5F5FF;"> 
            <table cellpadding="0" cellspacing="0" border="0"> 
             <tbody><tr> 
              <td class="header"> 
               <span id="ctl00_ContentPlaceHolder1_dl_ticketmsg1_ctl00_lbl_msg_no"><%#Container.ItemIndex+1 %></span></td> 
              <td class="normaltext" valign="bottom"> 
               <span id="ctl00_ContentPlaceHolder1_dl_ticketmsg1_ctl00_lbl_tagline">Message By <b><asp:Label ID="Label1" runat="server" Text='<%#Eval("user_type")%>'/></b> on <asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "answer_timestamp","{0:ddd, dd MMMM yyyy}")%>'/></span></td> 
             </tr> 
             <tr> 
              <td class="header"> 
               &nbsp;</td> 
              <td class="normaltext" valign="bottom"> 
               <b>Message :</b><br> 
               <span id="ctl00_ContentPlaceHolder1_dl_ticketmsg1_ctl00_Label1"><asp:Label ID="Label3" runat="server" Text='<%#Eval("answer_body")%>'/></span></td> 
             </tr> 
             <tr> 
              <td class="header"> 
               &nbsp;</td> 
              <td class="normaltext" valign="bottom"> 
               <b></b> 
               </td> 
             </tr> 
            </tbody></table> 
           </td> 
    </tr> 
</tbody></table> 
          </ItemTemplate> 
          </asp:Repeater> 

как-то это дает мне только вопрос, пока я комментирую этот второй поток сообщений. ---------------------------------------- Обновлено -------- ------------------------------- enter image description here , пожалуйста, помогите мне ..

------- -------------------------------- Обновлено ----------------- -----------------------

Server Error in '/OmInvestmentStockMarketing_new' Application. 

Compilation Error 

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS1026:) expected 

Source Error: 


Line 162:            <span id="ctl00_ContentPlaceHolder1_dl_ticketmsg_ctl00_lbl_msg_no"><%#Container.ItemIndex+1 %></span></td> 
Line 163:           <td class="normaltext" valign="bottom"> 
Line 164:            <span id="ctl00_ContentPlaceHolder1_dl_ticketmsg_ctl00_lbl_tagline">Message By <b><asp:Label ID="lbl_user_t" runat="server" Text='<%# If(Eval("cargo2").ToString() Is "Admin", "You", Eval("cargo2"))%>'/></b> 
Line 165:            on <asp:Label ID="lbldatetime" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"cargo1","{0:ddd, dd MMMM yyyy}")%>'/></span></td> 
Line 166:          </tr> 

Source File: c:\Documents and Settings\Vishal\My Documents\Visual Studio 2005\WebSites\OmInvestmentStockMarketing_new\Admin\OWM_Inquiry.aspx Line: 164 


Show Detailed Compiler Output: 

Show Complete Compilation Source: 


Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053 

-------------------- ------- Обновлен ------------------------------------------ -

<asp:Repeater ID="Repeater_Inquiry_Messages" runat="server"> 
          <ItemTemplate> 
          <div style='display: <%# Container.ItemIndex == 0 ? "none" : "block" %>'> 
          <table id="ctl00_ContentPlaceHolder1_dl_ticketmsg" cellspacing="0" border="0" style="width:100%;border-collapse:collapse;"> 
          <tbody><tr> 
     <td style="background-color:#F5F5FF;"> 
      <table cellpadding="0" cellspacing="0" border="0"> 
             <tbody><tr> 
              <td class="header"> 
               <span id="ctl00_ContentPlaceHolder1_dl_ticketmsg_ctl00_lbl_msg_no"><%--<%#Container.ItemIndex+1 %>--%><%# Container.ItemIndex.ToString() == "0" ? int.Parse("1") : Container.ItemIndex %></span></td> 
              <td class="normaltext" valign="bottom"> 
               <span id="ctl00_ContentPlaceHolder1_dl_ticketmsg_ctl00_lbl_tagline">Message By <b><asp:Label ID="lbl_user_t" runat="server" Text='<%# Eval("cargo2").ToString()=="Admin" ? "You" : Eval("cargo2") %>'></asp:Label></b> 
               on <asp:Label ID="lbldatetime" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"cargo1","{0:ddd, dd MMMM yyyy}")%>'/></span></td> 
             </tr> 
             <tr> 
              <td class="header"> 
               &nbsp;</td> 
              <td class="normaltext" valign="bottom"> 
               <b>Message :</b><br> 
               <span id="ctl00_ContentPlaceHolder1_dl_ticketmsg_ctl00_Label1"><asp:Label ID="lbl_inquiry_desc" runat="server" Text='<%#Eval("body")%>'/></span></td> 
             </tr> 
             <tr> 
              <td class="header"> 
               &nbsp;</td> 
              <td class="normaltext" valign="bottom"> 
               </td> 

               </tr> 
               </tbody></table> 
     </td> 
    </tr> 
</tbody></table> 
          </div> 
          </ItemTemplate> 
          <SeparatorTemplate> 
          <table> 
          <tr> 
           <td style="background-color:White;width:5px;"> 
            <span id="Label2"></span> 
           </td></tr> 
           </table> 
          </SeparatorTemplate> 
          </asp:Repeater> 
+0

Довольно уверен, что вам нужно будет разобраться со всем в одном ItemTemplate (выработав то, что находится в каждой строке набора результатов и отображает содержимое для каждого - вот что я имел в виду в более раннем вопросе, когда я сказал «путем подавления повторный текст ") – dav1dsm1th

+0

, то что мы делаем, чтобы связать вопрос, чтобы ответить на повторитель ассоциации. –

+0

Это может быть проще для COALESCE запроса, истории, вопросов и ответов, чтобы упростить код вашего интерфейса. Но, поскольку вы имеете дело с иерархией, код должен быть где-то сложным. Это трудно объяснить, если у вас нет данных. – dav1dsm1th

ответ

1

Я собираюсь вернуться к своей схеме (related question)) - чисто потому, что для меня это быстрее, чем попытка воспроизвести ваши данные и т. д., но, надеюсь, это поможет (вам просто нужно будет отобразить его обратно на ваши структуры). Этот ответ может сильно проголосовать - поскольку он не отвечает на поставленный вопрос, но предлагает способ избежать сложной привязки, которая потребуется (теперь увидели, как будет использоваться выход хранимой процедуры).

Если ваша схема была такой: -

create table tbl_Inquiry_master (
    id int, 
    body varchar(1024) 
); 
create table tbl_Inquiry_history (
    id int, 
    inquiry_id int, 
    body varchar(1024) 
); 
create table tbl_question (
    id int, 
    inquiry_id int, 
    body varchar(1024) 
); 
create table tbl_answer (
    id int, 
    question_id int, 
    body varchar(1024) 
); 
insert into tbl_Inquiry_master values (1, 'inquiry one'); 
insert into tbl_Inquiry_master values (2, 'inquiry two'); 
insert into tbl_Inquiry_master values (3, 'inquiry three'); 
insert into tbl_Inquiry_master values (4, 'inquiry four'); 
insert into tbl_Inquiry_history values (1, 1,'history 1 (relates to inquiry 1)'); 
insert into tbl_Inquiry_history values (2, 3,'history 2 (relates to inquiry 3)'); 
insert into tbl_question values (1,1,'inquiry one question one') 
insert into tbl_question values (2,1,'inquiry one question two') 
insert into tbl_question values (3,2,'inquiry two question one') 
insert into tbl_question values (4,4,'inquiry four question one') 
insert into tbl_answer values (1,1,'answer 1 to question 1') 
insert into tbl_answer values (2,1,'answer 2 to question 1') 
insert into tbl_answer values (3,2,'answer 1 to question 2') 
insert into tbl_answer values (4,4,'answer 1 to question 4') 
insert into tbl_answer values (5,4,'answer 2 to question 4') 
insert into tbl_answer values (6,4,'answer 3 to question 4') 

Вы могли бы хранимую процедуру так: -

create procedure [dbo].[ViewMessageThreads] (
    @inquiry_id int) 
AS 
BEGIN 

    create table #return (
     FromTable varchar(10), 
     sort1 int, 
     sort2 int, 
     sort3 int, 
     body varchar(1024), 
     cargo1 datetime, 
     cargo2 varchar(50) 
    ) 

    insert into #return 
    select 'master', 1, 0, 0, m.body , null, null 
    from tbl_Inquiry_master m 
    where [email protected]_id 

    insert into #return 
    select 'history', 2, 0, 0, h.body , null, null 
    from tbl_Inquiry_history h 
    where [email protected]_id 

    insert into #return 
    select 'question', 3, q.id, 0, q.body , GETDATE(), 'user' 
    from tbl_question q 
    where [email protected]_id 

    insert into #return 
    select 'answer', 3, q.id, a.id, a.body , GETDATE(), 'staff' 
    from tbl_answer a 
    join tbl_question q on q.id=a.question_id 
    where [email protected]_id 

    /* 
    -- uncomment this block to update the type in the way you appear 
    -- to want it set, I'm leaving it commented in my answer as I 
    -- cannot confirm the logic works - as I don't have your schema/data 
    -- and the code is, therefore, untested. 

    -- this logic could be moved to the top of the SP and the variable could be 
    -- substituted into each SELECT, so that the UPDATE would then not be required 

    declare @Type_name = @varchar(50) -- I don't know the dimensions of this type 

    select top 1 @Type_name=t.Type_name 
    from tbl_Type t 
    join tbl_Login_master l on l.Id=t.Id 
    join tbl_User_master u on u.Id=l.Id 
    join tbl_Inquiry_History h on h.User_id=u.Id 
    where ([email protected]_id))  

    update #return set [email protected]_name 

    */ 

    select * 
    from #return 
    order by sort1, sort2, sort3 

end 

и называя это нравится: -

exec [dbo].[ViewMessageThreads] 1 
exec [dbo].[ViewMessageThreads] 2 
exec [dbo].[ViewMessageThreads] 3 
exec [dbo].[ViewMessageThreads] 4 

который будет производить: -

out from call to SP , который будет выдавать выходные данные, которые должны быть проще для вас привязаны, а не выход SP в вашем вопросе.

Вы можете использовать значения в столбцах таблицы и сортировки, чтобы принимать решения в вашем повторителе о том, как отформатировать другие столбцы.

Вам придется поиграть с заполнением грузовых слотов (вам может потребоваться больше) и порядка сортировки - поскольку я не уверен, где вы хотите получать данные из таблиц History/Master. Надеюсь, это направит вас в правильном направлении.

+0

для типа - какой тип пользователя здесь я должен использовать три таблицы сначала tbl_User_master, который связывает Id с user_id (как уникальный ref_no) в tbl_Inquiry_History, второй tbl_Login_master, который связывает Id с user_id (как уникальное имя пользователя) в tbl_User_master и последний tbl_Type, который связывает Id с type_id (тип пользователя: EndUser/Staff/Admin) , –

+0

здесь использование отображаемого типа сообщение от пользователя (User/Admin). –

+0

, обновите хранимую процедуру, чтобы заполнить грузовой отсек значением, которое вы просматриваете, используя любую логику, которую вы выбрали. – dav1dsm1th

Смежные вопросы