Esempio n. 1
0
        public HttpResponseMessage GetContattiEntita(string idEntita, int start, int limit)
        {
            Response <Contatto> contatto = new api.Response <Contatto>();
            long idEnt = -1;

            if (start == 0)
            {
                start++;
            }
            if (!long.TryParse(idEntita, out idEnt))
            {
                return(null);
            }
            ContattoService cs   = new ContattoService();
            var             cont = cs.GetContattiByIdEntita(idEnt, true, true, false, false);

            contatto = new Response <Contatto>
            {
                Totale = cont.Count,
                Data   = cont.Select(rc =>
                {
                    Contatto c = new Contatto
                    {
                        Id   = -1,
                        Mail = rc.Mail
                    };
                    if (rc.IdContact.HasValue)
                    {
                        c.Id = (int)rc.IdContact.Value;
                    }
                    return(c);
                }).Skip(start - 1).Take(limit).ToList()
            };
            return(this.Request.CreateResponse <Response <Contatto> >(HttpStatusCode.OK, contatto));
        }
Esempio n. 2
0
        public static void InitializeTreeStore()
        {
            ContattoService contattoService            = new ContattoService();
            Dictionary <string, SimpleTreeItem> indice = (Dictionary <string, SimpleTreeItem>)contattoService.LoadRubricaIndex(IndexedCatalogs.ALL, 1);
            // get the current httpContext
            HttpContext context = HttpContext.Current;

            // get the current application object
            if (System.Web.HttpContext.Current.Application["tree"] != null)
            {
                HttpContext.Current.Application.Lock();
                // lock the current application object
                System.Web.HttpContext.Current.Application.Remove("tree");
                System.Web.HttpContext.Current.Application.Add("tree", indice);
                // unlock the application object
                HttpContext.Current.Application.UnLock();
            }
            else
            {
                System.Web.HttpContext.Current.Application.Add("tree", indice);
            }
        }
Esempio n. 3
0
        public void ProcessRequest(HttpContext context)
        {
            //  string nodeRaw = context.Request.Form["idNode"]; // IPA@123 RUBR@123 [1]IPA@123  [3]RUBR@435653
            string nodeRaw      = context.Request.Params["node"];
            string node         = nodeRaw;
            string catalog      = null;
            string virtualPager = null;
            bool   virtualNode  = false;

            if (nodeRaw.Contains(']'))
            {
                node         = nodeRaw.Substring(nodeRaw.LastIndexOf(']') + 1);
                virtualPager = nodeRaw.Substring(1, nodeRaw.LastIndexOf(']') - 1);
                virtualNode  = true;
            }
            Int64?nodeId = null;

            if (node.Contains('@'))
            {
                nodeId  = Int64.Parse(node.Split('@')[1]);
                catalog = node.Split('@')[0];
            }


            if (context.Application["tree"] == null)
            {
                InitializeTreeStore();
            }

            Dictionary <string, SimpleTreeItem> xDoc = (Dictionary <string, SimpleTreeItem>)context.Application["tree"];

            StringBuilder sb = null;

            if (node == null)
            {
                throw new ArgumentNullException("nodo richiesto non valido");
            }

            List <SimpleTreeItem> ll = null;

            try
            {
                //provo prima a prendere gli item dalla memoria

                if (virtualNode)
                {
                    ll = xDoc.Where(e => e.Value.ExtendedPadre.Equals(node)).Select(e => e.Value).ToList();
                    ll.Sort((x, y) => string.Compare(x.Text, y.Text));
                    if (ll.Count < int.Parse(virtualPager) + 100)
                    {
                        ll = ll.GetRange(int.Parse(virtualPager), ll.Count - int.Parse(virtualPager));
                    }
                    else
                    {
                        ll = ll.GetRange(int.Parse(virtualPager), 100);
                    }
                }
                else if (nodeId.HasValue)
                {
                    ll = xDoc.Where(e => e.Value.ExtendedPadre.Equals(node)).Select(e => e.Value).ToList();
                }
                else
                {
                    ll = xDoc.Where(e => string.IsNullOrEmpty(e.Value.Padre)).Select(e => e.Value).ToList();
                }

                //se non trova figli prova a caricarli dalla banca dati
                if (ll.Count() == 0)
                {
                    ContattoService contattoService = new ContattoService();
                    Dictionary <string, SimpleTreeItem> newChildren = (Dictionary <string, SimpleTreeItem>)contattoService.LoadRubricaIndex(nodeId.Value, (IndexedCatalogs)Enum.Parse(typeof(IndexedCatalogs), catalog), 2);
                    if (newChildren != null && newChildren.Count > 1)
                    {
                        AppendChildren(newChildren);
                        ll = xDoc.Where(e => e.Value.ExtendedPadre.Equals(node)).Select(e => e.Value).ToList();
                    }
                }

                if (ll.Count() > 100)
                {
                    ll.Sort((x, y) => string.Compare(x.Text, y.Text));
                    int nn     = ll.Count;
                    int gruppi = nn / 100;
                    for (int i = 0; i < nn - 1; i = i + 100)
                    {
                        if (sb == null)
                        {
                            sb = new StringBuilder();
                            sb.Append("[");
                            sb.Append(string.Format(JSON_ELEMENT_FIRST, "Da:" + ll[i].Text, "[" + i.ToString() + "]" + nodeRaw, "GRP"));
                        }
                        else
                        {
                            sb.Append(string.Format(JSON_ELEMENT, "Da:" + ll[i].Text, "[" + i.ToString() + "]" + nodeRaw, "GRP"));
                        }
                    }
                }
                else if (ll != null && ll.Count() > 0)
                {
                    ll.Sort((x, y) => string.Compare(x.Text, y.Text));
                    foreach (SimpleTreeItem xnode in ll)
                    {
                        if (sb == null)
                        {
                            sb = new StringBuilder();
                            sb.Append("[");
                            sb.Append(string.Format(JSON_ELEMENT_FIRST, xnode.Text, xnode.ExtendedValue, xnode.SubType));
                        }
                        else
                        {
                            sb.Append(string.Format(JSON_ELEMENT, xnode.Text, xnode.ExtendedValue, xnode.SubType));
                        }
                    }
                }

                if (sb != null)
                {
                    sb.Append("]");
                    context.Response.ContentType = "application/json";
                    context.Response.AppendHeader("Content-type", "text/json");
                    context.Response.Write(sb.ToString());
                }
            }
            catch { throw new Exception("Retry Please!!"); }
        }
Esempio n. 4
0
        //click sul bottone della formview dei contatti: gestisce update ed inserimento
        protected void ContactsFormView_ItemCommand(object sender, FormViewCommandEventArgs e)
        {
            RubricaEntita        rubEnt      = Session["EntSession"] as RubricaEntita;
            RubricaContatti      contact     = new RubricaContatti();
            RubricaEntitaService rubrService = new RubricaEntitaService();


            #region "Gestione Inseret/update contatto"
            if (e.CommandName.Equals("Update"))
            {
                int idCnt = Int32.Parse(((HiddenField)ContactsFormView.FindControl("hfIdContact")).Value);
                contact = rubEnt.Contatti.SingleOrDefault(x => x.IdContact == idCnt);
            }


            if ((e.CommandName.Equals("Insert") && hidInsertType.Value.Equals("Insert_c")) || e.CommandName.Equals("Update"))
            {
                if ((e.CommandName.Equals("Insert")))
                {
                    contact.RefIdReferral = rubEnt.IdReferral;
                }

                //funzione per il controllo di inserimento di contatti già inseriti
                if (contact != null && ContactControls(contact.IdContact) == false) //caso in cui non supera i controlli
                {
                    if (e.CommandName == "Update")                                  //ricarico i dati precedenti in caso di update
                    {
                        DataContactView(Int32.Parse(((HiddenField)ContactsFormView.FindControl("hfIdContact")).Value));
                    }
                    else //svuoto i campi in caso di insert
                    {
                        (ContactsFormView.FindControl("TextMail") as TextBox).Text     = "";
                        (ContactsFormView.FindControl("TextTelefono") as TextBox).Text = "";
                        (ContactsFormView.FindControl("TextFax") as TextBox).Text      = "";
                    }
                    return;
                }

                try
                {
                    contact.Telefono   = ((TextBox)ContactsFormView.FindControl("TextTelefono")).Text;
                    contact.Mail       = ((TextBox)ContactsFormView.FindControl("TextMail")).Text;
                    contact.Fax        = ((TextBox)ContactsFormView.FindControl("TextFax")).Text;
                    contact.ContactRef = ((TextBox)ContactsFormView.FindControl("TextRef")).Text;
                    contact.Note       = ((TextBox)ContactsFormView.FindControl("TextNote")).Text;
                    contact.IsPec      = ((CheckBox)ContactsFormView.FindControl("chkPec")).Checked;
                    contact.AffIPA     = 0;
                    if (contact.IsPec == false)
                    {
                        foreach (MailPecForCheck val in Enum.GetValues(typeof(MailPecForCheck)))
                        {
                            if (contact.Mail.Contains("@" + val.ToString() + "."))
                            {
                                contact.IsPec = true;
                            }
                        }
                    }
                }
                catch
                {
                    ((BasePage)this.Page).info.AddMessage("Attenzione: si è verificato un errore", Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR);
                    return;
                }

                if (contact.Telefono == "" && contact.Mail == "" && contact.Fax == "")
                {
                    ((BasePage)this.Page).info.AddMessage("Inserire almeno un parametro", Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR);
                    return;
                }

                if (contact.Mail == "" && contact.IsPec == true)
                {
                    ((BasePage)this.Page).info.AddMessage("Inserire indirizzo email valido", Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR);
                    contact.IsPec = false;
                    return;
                }

                if (contact.Telefono == "")
                {
                    contact.Telefono = null;
                }
                if (contact.Mail == "")
                {
                    contact.Mail = null;
                }
                if (contact.Fax == "")
                {
                    contact.Fax = null;
                }
                if (contact.ContactRef == "")
                {
                    contact.ContactRef = null;
                }
                if (contact.Note == "")
                {
                    contact.Note = null;
                }

                if (e.CommandName == "Update")
                {
                    try
                    {
                        //metodo per l'update
                        ContattoService contattoService = new ContattoService();
                        contattoService.UpdateRubrContatti(contact, false);
                    }
                    catch (Exception)
                    {
                        ((BasePage)this.Page).info.AddMessage("Aggiornamento non riuscito: Errore in banca dati", Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR);
                        return;
                    }
                    ((BasePage)this.Page).info.AddMessage("Contatto modificato", Com.Delta.Messaging.MapperMessages.LivelloMessaggio.INFO);
                }
                else if (e.CommandName == "Insert")
                {
                    try
                    {
                        //metodo per l'insert
                        ContattoService contattoService = new ContattoService();
                        contattoService.InsertRubrContatti(contact, false);
                    }
                    catch (Exception ex)
                    {
                        ((BasePage)this.Page).info.AddMessage("Inserimento non riuscito: Errore in banca dati dettagli: " + ex.Message, Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR);
                        return;
                    }
                    ((BasePage)this.Page).info.AddMessage("Contatto inserito", Com.Delta.Messaging.MapperMessages.LivelloMessaggio.INFO);
                }
            }
            #endregion


            #region "Insert di un nuovo gruppo o di un nuovo ufficio"

            if ((e.CommandName.Equals("Insert") && hidInsertType.Value.Equals("Insert_u")))
            {
                RubricaEntita newEnt = new RubricaEntita();
                newEnt.Ufficio = ((TextBox)ContactsFormView.FindControl("TextUfficio")).Text;
                newEnt.IdPadre = rubEnt.IdReferral;
                newEnt.RefOrg  = (rubEnt.RefOrg == null ? rubEnt.IdReferral : rubEnt.RefOrg);
                if (rubEnt.ReferralType.ToString().StartsWith("PA"))
                {
                    newEnt.ReferralType = EntitaType.PA_UFF;
                }
                else if (rubEnt.ReferralType.ToString().StartsWith("AZ"))
                {
                    newEnt.ReferralType = EntitaType.AZ_UFF;
                }
                try
                {
                    //metodo per l'insert
                    rubrService.Insert(newEnt);
                }
                catch (Exception e0)
                {
                    ((BasePage)this.Page).info.AddMessage("Inserimento non riuscito: " + e0.Message, Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR);
                    return;
                }
                ((BasePage)this.Page).info.AddMessage("Gruppo inserito", Com.Delta.Messaging.MapperMessages.LivelloMessaggio.INFO);
                ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "reload_local_tree", "ShowTree(config.tree);", true);
            }
            else if ((e.CommandName.Equals("Insert") && hidInsertType.Value.Equals("Insert_g")))
            {
                RubricaEntita newEnt = new RubricaEntita();

                newEnt.Ufficio = ((TextBox)ContactsFormView.FindControl("TextGruppo")).Text;
                newEnt.IdPadre = rubEnt.IdReferral;
                newEnt.RefOrg  = (rubEnt.RefOrg == null ? rubEnt.IdReferral : rubEnt.RefOrg);
                if (rubEnt.ReferralType.ToString().StartsWith("PA"))
                {
                    newEnt.ReferralType = EntitaType.PA_GRP;
                }
                else if (rubEnt.ReferralType.ToString().StartsWith("AZ"))
                {
                    newEnt.ReferralType = EntitaType.AZ_GRP;
                }
                try
                {
                    //metodo per l'insert
                    rubrService.Insert(newEnt);
                }
                catch (Exception e1)
                {
                    ((BasePage)this.Page).info.AddMessage("Inserimento non riuscito: " + e1.Message, Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR);
                    return;
                }
                ((BasePage)this.Page).info.AddMessage("Ufficio inserito", Com.Delta.Messaging.MapperMessages.LivelloMessaggio.INFO);
                ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "reload_local_tree", "ShowTree();", true);
            }


            #endregion
            hfCurrentID = contact.IdContact ?? -1;
            long idEntita = long.Parse((EntFormView.FindControl("hfIdEntita") as HiddenField).Value);
            EntFormViewDataSource = rubrService.GetRubricaEntitaCompleteById(idEntita);
            rubEnt = EntFormViewDataSource;
            switch (rubEnt.Contatti.Count)
            {
            case 0:
                gvContacts.Visible = true;
                gvContacts.DataBind();
                ContactsFormView.DataBind();
                break;

            default:
                if (hfCurrentID == -1)
                {
                    OnContactsPagerIndexChanged("", 0);
                }
                else
                {
                    int index = rubEnt.Contatti.IndexOf(rubEnt.Contatti.First(x => x.IdContact == hfCurrentID));
                    OnContactsPagerIndexChanged("", index / PagerSize);
                }
                if (rubEnt.Contatti.Count <= PagerSize)
                {
                    gvContacts.BottomPagerRow.Visible = false;
                }
                break;
            }
            ContactsFormView.Visible = false;
        }
Esempio n. 5
0
        public HttpResponseMessage GetTree(string node)
        {
            //  string nodeRaw = context.Request.Form["idNode"]; // IPA@123 RUBR@123 [1]IPA@123  [3]RUBR@435653
            //   string nodeRaw = context.Request.Params["node"];
            string nodeP = node;

            Models.TreeModel       model = new Models.TreeModel();
            List <Models.TreeNode> list  = new List <Models.TreeNode>();
            string catalog      = null;
            string virtualPager = null;
            bool   virtualNode  = false;

            if (node.Contains(']'))
            {
                nodeP        = node.Substring(node.LastIndexOf(']') + 1);
                virtualPager = node.Substring(1, node.LastIndexOf(']') - 1);
                virtualNode  = true;
            }
            Int64?nodeId = null;

            if (nodeP.Contains('@'))
            {
                nodeId  = Int64.Parse(nodeP.Split('@')[1]);
                catalog = nodeP.Split('@')[0];
            }


            if (HttpContext.Current.Application["tree"] == null)
            {
                InitializeTreeStore();
            }

            Dictionary <string, SimpleTreeItem> xDoc = (Dictionary <string, SimpleTreeItem>)HttpContext.Current.Application["tree"];

            // StringBuilder sb = null;

            if (nodeP == null)
            {
                throw new ArgumentNullException("nodo richiesto non valido");
            }

            List <SimpleTreeItem> ll = null;

            try
            {
                //provo prima a prendere gli item dalla memoria

                if (virtualNode)
                {
                    ll = xDoc.Where(e => e.Value.ExtendedPadre.Equals(nodeP)).Select(e => e.Value).ToList();
                    ll.Sort((x, y) => string.Compare(x.Text, y.Text));
                    if (ll.Count < int.Parse(virtualPager) + 100)
                    {
                        ll = ll.GetRange(int.Parse(virtualPager), ll.Count - int.Parse(virtualPager));
                    }
                    else
                    {
                        ll = ll.GetRange(int.Parse(virtualPager), 100);
                    }
                }
                else if (nodeId.HasValue)
                {
                    ll = xDoc.Where(e => e.Value.ExtendedPadre.Equals(nodeP)).Select(e => e.Value).ToList();
                }
                else
                {
                    ll = xDoc.Where(e => string.IsNullOrEmpty(e.Value.Padre)).Select(e => e.Value).ToList();
                }

                //se non trova figli prova a caricarli dalla banca dati
                if (ll.Count() == 0)
                {
                    ContattoService contattoService = new ContattoService();
                    Dictionary <string, SimpleTreeItem> newChildren = (Dictionary <string, SimpleTreeItem>)contattoService.LoadRubricaIndex(nodeId.Value, (IndexedCatalogs)Enum.Parse(typeof(IndexedCatalogs), catalog), 2);
                    if (newChildren != null && newChildren.Count > 1)
                    {
                        AppendChildren(newChildren);
                        ll = xDoc.Where(e => e.Value.ExtendedPadre.Equals(nodeP)).Select(e => e.Value).ToList();
                    }
                }

                if (ll.Count() > 100)
                {
                    ll.Sort((x, y) => string.Compare(x.Text, y.Text));
                    int nn     = ll.Count;
                    int gruppi = nn / 100;
                    model.totale = (nn - 1).ToString();
                    for (int i = 0; i < nn - 1; i = i + 100)
                    {
                        Models.TreeNode nodeTree = new Models.TreeNode()
                        {
                            itemId = ll[i].ExtendedValue,
                            text   = ll[i].Text,
                            cls    = ll[i].SubType
                        };
                        list.Add(nodeTree);
                        //if (sb == null)
                        //{
                        //    sb = new StringBuilder();
                        //    sb.Append("{\"Items\":[");
                        //    sb.Append(string.Format(JSON_ELEMENT_FIRST, "Da:" + ll[i].Text, "[" + i.ToString() + "]" + node, "GRP"));
                        //}
                        //else
                        //    sb.Append(string.Format(JSON_ELEMENT, "Da:" + ll[i].Text, "[" + i.ToString() + "]" + node, "GRP"));
                    }
                }
                else if (ll != null && ll.Count() > 0)
                {
                    ll.Sort((x, y) => string.Compare(x.Text, y.Text));
                    model.totale = ll.Count.ToString();
                    foreach (SimpleTreeItem xnode in ll)
                    {
                        Models.TreeNode nodeTree = new Models.TreeNode()
                        {
                            itemId = xnode.ExtendedValue,
                            text   = xnode.Text,
                            cls    = xnode.SubType
                        };
                        list.Add(nodeTree);
                        //if (sb == null)
                        //{
                        //    sb = new StringBuilder();
                        //    sb.Append("{\"Items\":[");
                        //    sb.Append(string.Format(JSON_ELEMENT_FIRST, xnode.Text, xnode.ExtendedValue, xnode.SubType));
                        //}
                        //else
                        //    sb.Append(string.Format(JSON_ELEMENT, xnode.Text, xnode.ExtendedValue, xnode.SubType));
                    }
                }

                //if (sb != null)
                //{
                //    sb.Append("]}");
                model.Items = list;
                return(this.Request.CreateResponse <Models.TreeModel>(HttpStatusCode.OK, model));
                //}
                //else
                //{
                //    return this.Request.CreateResponse<string>(HttpStatusCode.OK, string.Empty);
                //}
            }
            catch { throw new Exception("Retry Please!!"); }
        }
Esempio n. 6
0
        public HttpResponseMessage GetEntitaByPartialName(string text, string type, int start, int limit)
        {
            ResponseType <Item> response = new ResponseType <Item>();

            if (String.IsNullOrEmpty(text) || string.IsNullOrEmpty(type))
            {
                this.Request.CreateResponse <ResponseType <Item> >(HttpStatusCode.OK, response);
            }
            start = (start == 0) ? ++start : start;
            IList <EntitaType> filtro = new List <EntitaType>();
            KeyValuePair <FastIndexedAttributes, string> matchingString = new KeyValuePair <FastIndexedAttributes, string>();
            IndexedCatalogs catalogo;

            try
            {
                List <string> types       = type.Split(':').ToList();
                string        tipoRicerca = types.First();
                catalogo = (IndexedCatalogs)Enum.Parse(typeof(IndexedCatalogs), types.Last());

                var f = from t in types
                        where types.IndexOf(t) != 0 &&
                        types.IndexOf(t) != (types.Count - 1)
                        select(EntitaType) Enum.Parse(typeof(EntitaType), t);
                if (f.Count() != 0)
                {
                    filtro = f.ToList();
                }
                matchingString = new KeyValuePair <FastIndexedAttributes, string>(
                    (FastIndexedAttributes)Enum.Parse(typeof(FastIndexedAttributes),
                                                      tipoRicerca), text);
            }
            catch
            {
                response.message = "Errore: la stringa di ricerca è mal formata";
                response.totale  = 0;
                response.Items   = null;
                return(this.Request.CreateResponse <ResponseType <Item> >(HttpStatusCode.OK, response));
            }

            ResultList <SimpleResultItem> res = null;

            try
            {
                ContattoService service = new ContattoService();
                res = service.GetFieldsByParams(catalogo, filtro, matchingString, start, limit);
                if (res == null || res.List.Count == 0)
                {
                    response.message = "la ricerca non ha prodotto risultati";
                    response.totale  = 0;
                    response.Items   = null;
                    return(this.Request.CreateResponse <ResponseType <Item> >(HttpStatusCode.OK, response));
                }
                response.totale = res.Totale;
                response.Items  = (from i in res.List
                                   select new SendMail.Model.WebserviceMappings.Item
                {
                    Id = string.Format("{0}#{1}", i.Value, (res.List as List <SimpleResultItem>).IndexOf(i)),
                    Title = i.Text,
                    Text = i.Description,
                    Subtype = i.SubType
                }).ToList();
                response.success = bool.TrueString;
                response.message = "";
            }
            catch (Exception e)
            {
                response.message = "Errore: " + e.Message;
            }
            return(this.Request.CreateResponse <ResponseType <Item> >(HttpStatusCode.OK, response));
        }