コード例 #1
0
        protected void lbAdd_Click(object sender, EventArgs e)
        {
            DataTable dt = ((DataTable)ViewState["Resources"]).Copy();

            if (!String.IsNullOrEmpty(txtEMail.Text.Trim()))
            {
                DataRow[] rows = dt.Select(String.Format("Id='{0}'", String.Format("{0}::0", txtEMail.Text.Trim())));
                if (rows.Length == 0)
                {
                    DataRow dr = dt.NewRow();
                    dr["Id"]   = String.Format("{0}::0", txtEMail.Text.Trim());
                    dr["Name"] = txtEMail.Text.Trim();
                    dt.Rows.Add(dr);
                }
                txtEMail.Text = String.Empty;
            }
            else
            {
                string[] mas = EntityGrid.GetCheckedCollection(this.Page, grdMain.ID);
                if (mas.Length == 0)
                {
                    mas = hdnValue.Value.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                }
                foreach (string s in mas)
                {
                    DataRow[] rows = dt.Select(String.Format("Id='{0}'", s));
                    if (rows.Length > 0)
                    {
                        continue;
                    }
                    DataRow dr = dt.NewRow();
                    if (ddFilter.SelectedValue == ContactEntity.GetAssignedMetaClassName())
                    {
                        dr["Id"]   = s;
                        dr["Name"] = CHelper.GetEntityTitle(ContactEntity.GetAssignedMetaClassName(), PrimaryKeyId.Parse(s.Split(new string[] { "::" }, StringSplitOptions.RemoveEmptyEntries)[0]));
                    }
                    else if (ddFilter.SelectedValue == OrganizationEntity.GetAssignedMetaClassName())
                    {
                        dr["Id"]   = s;
                        dr["Name"] = CHelper.GetEntityTitle(OrganizationEntity.GetAssignedMetaClassName(), PrimaryKeyId.Parse(s.Split(new string[] { "::" }, StringSplitOptions.RemoveEmptyEntries)[0]));
                    }
                    else if (ddFilter.SelectedValue == Principal.GetAssignedMetaClass().Name)
                    {
                        dr["Id"]   = s;
                        dr["Name"] = CHelper.GetEntityTitle(Principal.GetAssignedMetaClass().Name, PrimaryKeyId.Parse(s.Split(new string[] { "::" }, StringSplitOptions.RemoveEmptyEntries)[0]));
                    }
                    dt.Rows.Add(dr);
                }
            }
            ViewState["Resources"] = dt;

            grdMainSelectedPanel.Update();
            CommonEventPart();
            hdnValue.Value = String.Empty;
        }