Beispiel #1
0
        protected void GridView_Notes_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            String commId = ((Label)GridView_Notes.Rows[e.RowIndex].Cells[0].FindControl("Label_Hidden_Comm")).Text;

            Dictionary <String, String> whereCls   = new Dictionary <string, string>();
            Dictionary <String, String> targetVals = new Dictionary <string, string>();

            whereCls.Add(BackEndObjects.Communications.COMMUNICATIONS_COL_COMM_ID, commId);
            BackEndObjects.Communications.updateCommunicationDB(targetVals, whereCls, DBConn.Connections.OPERATION_DELETE);

            DataTable dt    = ((Dictionary <String, DataTable>)Session[SessionFactory.ALL_MSGS_DATAGRID])[Request.QueryString.GetValues("contextId")[0]];
            int       index = GridView_Notes.Rows[e.RowIndex].DataItemIndex;

            dt.Rows[index].Delete();


            GridView_Notes.DataSource = dt;
            GridView_Notes.DataBind();
        }
        protected void Button_Submit_Note_Click(object sender, EventArgs e)
        {
            String[] contextId = Request.QueryString.GetValues("contextId");

            BackEndObjects.Communications commObj = new BackEndObjects.Communications();
            commObj.setCommId(new Id().getNewId(Id.ID_TYPE_COMM_STRING));
            commObj.setContextId(contextId[0]);
            commObj.setDateCreated(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
            commObj.setFromEntityId(Session[SessionFactory.MAIN_BUSINESS_ENTITY_ID_STRING].ToString());
            commObj.setFromUserId(User.Identity.Name);
            commObj.setText(TextBox_Note.Text);
            commObj.setToEntityId("");
            commObj.setToUserId("");
            commObj.setContextType(Communications.COMMUNICATIONS_CONTEXT_TYPE_NOTE);

            if (FileUpload_Attachment != null && FileUpload_Attachment.HasFile)
            {
                if (FileUpload_Attachment.PostedFile.ContentLength == 0)
                {
                    Label_Insert_Stat.Text      = "Empty file will not be uploaded";
                    Label_Insert_Stat.Visible   = true;
                    Label_Insert_Stat.ForeColor = System.Drawing.Color.Red;
                }
                else
                {
                    Label_Insert_Stat.Visible = false;
                    commObj.setFileStream(FileUpload_Attachment);
                    commObj.setDocPathInFileStore(Session[SessionFactory.MAIN_BUSINESS_ENTITY_ID_STRING].ToString());
                }
            }


            try
            {
                BackEndObjects.Communications.insertCommunicationDB(commObj);
                Label_Insert_Stat.Visible   = true;
                Label_Insert_Stat.Text      = "Note Saved Successfully";
                Label_Insert_Stat.ForeColor = System.Drawing.Color.Green;

                Dictionary <String, DataTable> notesData = (Dictionary <String, DataTable>)Session[SessionFactory.ALL_NOTES_DATAGRID];

                DataTable dt = null;

                if (notesData != null)
                {
                    if (notesData.ContainsKey(contextId[0]))
                    {
                        dt = notesData[contextId[0]];
                    }
                    else
                    {
                        dt = new DataTable();
                        dt.Columns.Add("HiddenComm");
                        dt.Columns.Add("RespDateTime");
                        dt.Columns.Add("FromUsr");
                        dt.Columns.Add("docName");
                        dt.Columns.Add("Comments");
                    }
                }
                else
                {
                    dt = new DataTable();
                    dt.Columns.Add("HiddenComm");
                    dt.Columns.Add("RespDateTime");
                    dt.Columns.Add("FromUsr");
                    dt.Columns.Add("docName");
                    dt.Columns.Add("Comments");
                }

                int counter = 0;

                if (dt == null)
                {
                    dt = new DataTable();
                }
                else
                {
                    counter = dt.Rows.Count;
                }

                dt.Rows.Add();
                String docName = "";

                if (commObj.getDocPath() != null && !commObj.getDocPath().Equals(""))
                {
                    String[] docPathList = commObj.getDocPath().
                                           Split(new String[] { "\\" }, StringSplitOptions.RemoveEmptyEntries);
                    if (docPathList.Length > 0)
                    {
                        docName = docPathList[docPathList.Length - 1];
                    }
                }

                dt.Rows[counter]["HiddenComm"]   = commObj.getCommId();
                dt.Rows[counter]["RespDateTime"] = commObj.getDateCreated();
                dt.Rows[counter]["FromUsr"]      = commObj.getFromUserId();
                dt.Rows[counter]["docName"]      = (docName == null || docName.Equals("") ? "N/A" :
                                                    docName.Remove(0, (docName.IndexOf("_") + 1 + docName.Substring(docName.IndexOf("_") + 1).IndexOf("_") + 1)));
                dt.Rows[counter]["Comments"] = commObj.getText();

                dt.DefaultView.Sort = "RespDateTime" + " " + "DESC";
                DataTable sorteddt = dt.DefaultView.ToTable();

                GridView_Notes.DataSource = sorteddt;
                GridView_Notes.DataBind();
                GridView_Notes.Visible            = true;
                GridView_Notes.Columns[0].Visible = false;

                if (notesData == null)
                {
                    notesData = new Dictionary <string, DataTable>();
                }

                if (notesData.ContainsKey(contextId[0]))
                {
                    notesData[contextId[0]] = sorteddt;
                }
                else
                {
                    notesData.Add(contextId[0], sorteddt);
                }

                Session[SessionFactory.ALL_NOTES_DATAGRID] = notesData;
            }
            catch (Exception ex)
            {
                Label_Insert_Stat.Visible   = true;
                Label_Insert_Stat.Text      = "Note Could not be saved";
                Label_Insert_Stat.ForeColor = System.Drawing.Color.Red;
            }
        }
        protected void fillGrid()
        {
            String[] contextId = Request.QueryString.GetValues("contextId");

            Dictionary <String, BackEndObjects.Communications> allComm = Communications.
                                                                         getAllCommunicationsforContextIdAndContextTypeAndSourceIdDB(
                contextId[0],
                Communications.COMMUNICATIONS_CONTEXT_TYPE_NOTE,
                Session[SessionFactory.MAIN_BUSINESS_ENTITY_ID_STRING].ToString());



            DataTable dt = new DataTable();

            dt.Columns.Add("HiddenComm");
            dt.Columns.Add("RespDateTime");
            dt.Columns.Add("FromUsr");
            dt.Columns.Add("docName");
            dt.Columns.Add("Comments");


            int counter = 0;

            foreach (KeyValuePair <String, BackEndObjects.Communications> kvp in allComm)
            {
                BackEndObjects.Communications commObj = kvp.Value;
                dt.Rows.Add();

                String docName = "";
                if (commObj.getDocPath() != null && !commObj.getDocPath().Equals(""))
                {
                    String[] docPathList = commObj.getDocPath().
                                           Split(new String[] { "\\" }, StringSplitOptions.RemoveEmptyEntries);
                    if (docPathList.Length > 0)
                    {
                        docName = docPathList[docPathList.Length - 1];
                    }
                }

                dt.Rows[counter]["HiddenComm"]   = commObj.getCommId();
                dt.Rows[counter]["RespDateTime"] = commObj.getDateCreated();
                dt.Rows[counter]["FromUsr"]      = commObj.getFromUserId();
                dt.Rows[counter]["docName"]      = (docName == null || docName.Equals("") ? "N/A" :
                                                    docName.Remove(0, (docName.IndexOf("_") + 1 + docName.Substring(docName.IndexOf("_") + 1).IndexOf("_") + 1)));
                dt.Rows[counter]["Comments"] = commObj.getText();

                counter++;
            }

            if (dt.Rows.Count > 0)
            {
                dt.DefaultView.Sort = "RespDateTime" + " " + "DESC";
                DataTable sortedTable = dt.DefaultView.ToTable();

                GridView_Notes.DataSource = sortedTable;
                GridView_Notes.DataBind();
                GridView_Notes.Visible            = true;
                GridView_Notes.Columns[0].Visible = false;

                Dictionary <String, DataTable> notesData = new Dictionary <string, DataTable>();
                notesData.Add(contextId[0], sortedTable);

                Session[SessionFactory.ALL_NOTES_DATAGRID] = notesData;
            }
        }