예제 #1
0
    protected void Page_Init(object sender, EventArgs e)
    {
        if (Request.QueryString["IdLead"] != null)
        {
            IdLead = Convert.ToInt32(Request.QueryString["IdLead"]);
        }
        //Создаем наш класс, при этом срабатывает конструктор, который сразу авторизируется в Битрикс24
        BX24 = new Bitrix24(HttpContext.Current);

        // IdLead = 66816;


        if (!IsPostBack)
        {
            Session.Contents["productrows"]   = null;
            Session.Contents["productsearch"] = null;
            if (Request.QueryString["Phone"] != null)
            {
                TextBoxLeadPHONE_1.Text = Request.QueryString["Phone"].ToString();
            }
        }


        string LeadStatusListByJSON = BX24.SendCommand("crm.status.list", "FILTER[ENTITY_ID]=STATUS", "", "GET");
        var    StatusList           = JsonConvert.DeserializeObject <dynamic>(LeadStatusListByJSON);

        foreach (var status in StatusList.result)
        {
            DropDownListLeadSTATUS_ID.Items.Add(new ListItem(status.NAME.ToString(), status.STATUS_ID.ToString()));
        }


        DropDownListLeadPHONE_1.Items.AddRange(
            BX24.PhoneTypes.Select(r => new ListItem(r.Value, r.Key)).ToArray());

        string LeadSourceListByJSON = BX24.SendCommand("crm.status.list", "FILTER[ENTITY_ID]=SOURCE", "", "GET");
        var    SourceList           = JsonConvert.DeserializeObject <dynamic>(LeadSourceListByJSON);

        foreach (var source in SourceList.result)
        {
            DropDownListLeadSOURCE_ID.Items.Add(new ListItem(source.NAME.ToString(), source.STATUS_ID.ToString()));
        }

        var dataListUsers = new
        {
            sort = "LAST_NAME"
        };

        var userSearchListJson = BX24.SendCommand("user.search", "", JsonConvert.SerializeObject(dataListUsers), "POST");
        var UserSearchList     = JsonConvert.DeserializeObject <dynamic>(userSearchListJson);
        var users = new List <KeyValuePair <string, string> >();

        foreach (var user in UserSearchList.result)
        {
            users.Add(new KeyValuePair <string, string>(user.LAST_NAME.ToString() + " " + user.NAME.ToString(), user.ID.ToString()));
        }
        DropDownListLeadASSIGNED_BY_ID.Items.Add(new ListItem("-----", ""));
        foreach (var user in users.OrderBy(r => r.Key))
        {
            DropDownListLeadASSIGNED_BY_ID.Items.Add(new ListItem(user.Key, user.Value));
        }

        foreach (var uf in BX24.Userfields)
        {
            var tr = new TableRow()
            {
                ID = "TableRow" + uf.ID
            };
            var tc1 = new TableCell()
            {
                ID = "TableCellLabel" + uf.ID, Text = uf.NAME
            };
            var tc2 = new TableCell()
            {
                ID = "TableCellUserfield" + uf.ID
            };
            if (uf.USER_TYPE_ID == Bitrix24.USER_TYPE_ID.enumeration)
            {
                var ddl = new DropDownList()
                {
                    ID = "DropDownListUserfield" + uf.ID, CssClass = "form-control"
                };
                ddl.Items.Add(new ListItem("-----", ""));
                foreach (var item in uf.LIST)
                {
                    ddl.Items.Add(new ListItem()
                    {
                        Text = item.VALUE, Value = item.ID.ToString()
                    });
                }
                tc2.Controls.Add(ddl);
            }
            tr.Cells.Add(tc1);
            tr.Cells.Add(tc2);
            TableLead.Rows.Add(tr);
        }


        if (IdLead > 0 && !IsPostBack)
        {
            string Lead       = BX24.SendCommand("crm.lead.get", "ID=" + IdLead, "", "GET");
            var    LeadByJSON = JsonConvert.DeserializeObject <dynamic>(Lead);
            LabelNameLead.Text                           = LeadByJSON.result.TITLE;
            TextBoxLeadTITLE.Text                        = LeadByJSON.result.TITLE;
            TextBoxLeadNAME.Text                         = LeadByJSON.result.NAME;
            TextBoxLeadSECOND_NAME.Text                  = LeadByJSON.result.SECOND_NAME;
            TextBoxLeadLAST_NAME.Text                    = LeadByJSON.result.LAST_NAME;
            DropDownListLeadSTATUS_ID.SelectedValue      = LeadByJSON.result.STATUS_ID;
            TextBoxLeadPHONE_1.Text                      = LeadByJSON.result.PHONE[0].VALUE;
            DropDownListLeadPHONE_1.SelectedValue        = LeadByJSON.result.PHONE[0].VALUE_TYPE;
            DropDownListLeadSOURCE_ID.SelectedValue      = LeadByJSON.result.SOURCE_ID;
            CheckBoxLeadOPENED.Checked                   = LeadByJSON.result.OPENED == "1";
            DropDownListLeadASSIGNED_BY_ID.SelectedValue = LeadByJSON.result.ASSIGNED_BY_ID;
            Type t = LeadByJSON.result.GetType();
            foreach (var uf in BX24.Userfields)
            {
                if (uf.USER_TYPE_ID == Bitrix24.USER_TYPE_ID.enumeration)
                {
                    var DropDownListUF = FindControl("DropDownListUserfield" + uf.ID) as DropDownList;
                    foreach (Newtonsoft.Json.Linq.JProperty item in LeadByJSON.result)
                    {
                        if (item.Name == uf.FIELD_NAME)//property name
                        {
                            DropDownListUF.SelectedValue = item.Value.ToString();
                        }
                    }
                }
            }


            var    Result                = new List <Bitrix24.PRODUCT>();
            string LeadProductList       = BX24.SendCommand("crm.lead.productrows.get", "ID=" + IdLead, "", "GET");
            var    LeadProductListByJSON = JsonConvert.DeserializeObject <dynamic>(LeadProductList);
            foreach (var item in LeadProductListByJSON.result)
            {
                Result.Add(new Bitrix24.PRODUCT()
                {
                    ID = item.ID, NAME = BX24.GetNameProduct(item.PRODUCT_ID.ToString()), PRODUCT_PRICE = item.PRICE, PRODUCT_QUANTITY = item.QUANTITY
                });
            }
            Session.Contents["productrows"] = Result;
            //   LeadByJSON.result.ID
            HiddenFieldIdLead.Value = IdLead.ToString();
            ButtonSaveLead.Text     = "Обновить лид";
        }

        //string LeadListByJSON = BX24.SendCommand("crm.lead.list", "", "", "GET");
        //string LeadListByJSON = BX24.SendCommand("crm.lead.add", "", contentText, "POST");

        // string UFListByJSON = BX24.SendCommand("crm.lead.userfield.list", "", "", "POST");
        //string LeadProductListByJSON = BX24.SendCommand("crm.lead.productrows.get", "id=", "", "GET");
    }
예제 #2
0
    protected void Page_Init(object sender, EventArgs e)
    {
        if (Request.QueryString["IdLead"] != null)
        {
            IdLead = Convert.ToInt32(Request.QueryString["IdLead"]);
        }

        BX24 = new Bitrix24(HttpContext.Current, "local.5d9dbbaf8a3075.94895012", "nu67ZnsK1SxXlrD9C5xChsq2LZJzPafKJy60Q6AkbvwHqrGP1U", "https://borond.bitrix24.ru", "https://oauth.bitrix.info", "*****@*****.**", "Vika15986");



        if (!IsPostBack)
        {
            Session.Contents["productrows"]   = null;
            Session.Contents["productsearch"] = null;
            if (Request.QueryString["Phone"] != null)
            {
                TextBoxLeadPHONE_1.Text = Request.QueryString["Phone"].ToString();
            }
        }


        string LeadStatusListByJSON = BX24.SendCommand("crm.status.list", "FILTER[ENTITY_ID]=STATUS", "", "GET");
        var    StatusList           = JsonConvert.DeserializeObject <dynamic>(LeadStatusListByJSON);

        foreach (var status in StatusList.result)
        {
            DropDownListLeadSTATUS_ID.Items.Add(new ListItem(status.NAME.ToString(), status.STATUS_ID.ToString()));
        }


        DropDownListLeadPHONE_1.Items.AddRange(
            BX24.PhoneTypes.Select(r => new ListItem(r.Value, r.Key)).ToArray());

        string LeadSourceListByJSON = BX24.SendCommand("crm.status.list", "FILTER[ENTITY_ID]=SOURCE", "", "GET");
        var    SourceList           = JsonConvert.DeserializeObject <dynamic>(LeadSourceListByJSON);

        foreach (var source in SourceList.result)
        {
            DropDownListLeadSOURCE_ID.Items.Add(new ListItem(source.NAME.ToString(), source.STATUS_ID.ToString()));
        }

        var li = DropDownListLeadSOURCE_ID.Items.FindByValue("CALL");

        if (li != null)
        {
            li.Selected = true;
        }

        var dataListUsers = new
        {
            sort = "LAST_NAME"
        };
        //&FILTER[ID][0]=15938&FILTER[ID][1]=174&FILTER[ID][2]=8170&FILTER[ID][3]=22&FILTER[ID][4]=15934&FILTER[ID][5]=15908
        var userSearchListJson = BX24.SendCommand("user.search", "FILTER[ACTIVE]=TRUE", JsonConvert.SerializeObject(dataListUsers), "POST");
        var UserSearchList     = JsonConvert.DeserializeObject <dynamic>(userSearchListJson);
        var users = new List <KeyValuePair <string, string> >();

        foreach (var user in UserSearchList.result)
        {
            users.Add(new KeyValuePair <string, string>(user.LAST_NAME.ToString() + " " + user.NAME.ToString(), user.ID.ToString()));
        }
        DropDownListLeadASSIGNED_BY_ID.Items.Add(new ListItem("-----", ""));
        foreach (var user in users.OrderBy(r => r.Key))
        {
            DropDownListLeadASSIGNED_BY_ID.Items.Add(new ListItem(user.Key, user.Value));
        }


        foreach (var uf in BX24.Userfields)
        {
            var tr = new TableRow()
            {
                ID = "TableRow" + uf.ID
            };
            var tc1 = new TableCell()
            {
                ID = "TableCellLabel" + uf.ID, Text = uf.NAME
            };
            var tc2 = new TableCell()
            {
                ID = "TableCellUserfield" + uf.ID
            };
            if (uf.USER_TYPE_ID == Bitrix24.USER_TYPE_ID.enumeration)
            {
                var ddl = new DropDownList()
                {
                    ID = "DropDownListUserfield" + uf.ID, CssClass = "form-control"
                };
                ddl.Items.Add(new ListItem("-----", ""));
                foreach (var item in uf.LIST)
                {
                    ddl.Items.Add(new ListItem()
                    {
                        Text = item.VALUE, Value = item.ID.ToString()
                    });
                }
                tc2.Controls.Add(ddl);

                tr.Cells.Add(tc1);
                tr.Cells.Add(tc2);
                TableLead.Rows.Add(tr);
            }
            else if (uf.USER_TYPE_ID == Bitrix24.USER_TYPE_ID.@string)
            {
                var ddl = new TextBox()
                {
                    ID = "TextBoxUserfield" + uf.ID, CssClass = "form-control"
                };
                tc2.Controls.Add(ddl);

                tr.Cells.Add(tc1);
                tr.Cells.Add(tc2);
                TableLead.Rows.Add(tr);
            }
        }


        if (IdLead > 0 && !IsPostBack)
        {
            string Lead       = BX24.SendCommand("crm.lead.get", "ID=" + IdLead, "", "GET");
            var    LeadByJSON = JsonConvert.DeserializeObject <dynamic>(Lead);
            LabelNameLead.Text                           = LeadByJSON.result.TITLE;
            TextBoxLeadTITLE.Text                        = LeadByJSON.result.TITLE;
            TextBoxLeadNAME.Text                         = LeadByJSON.result.NAME;
            TextBoxLeadSECOND_NAME.Text                  = LeadByJSON.result.SECOND_NAME;
            TextBoxLeadADDRESS_CITY.Text                 = LeadByJSON.result.ADDRESS_CITY;
            TextBoxLeadLAST_NAME.Text                    = LeadByJSON.result.LAST_NAME;
            DropDownListLeadSTATUS_ID.SelectedValue      = LeadByJSON.result.STATUS_ID;
            TextBoxLeadPHONE_1.Text                      = LeadByJSON.result.PHONE[0].VALUE;
            DropDownListLeadPHONE_1.SelectedValue        = LeadByJSON.result.PHONE[0].VALUE_TYPE;
            DropDownListLeadSOURCE_ID.SelectedValue      = LeadByJSON.result.SOURCE_ID;
            CheckBoxLeadOPENED.Checked                   = LeadByJSON.result.OPENED == "1";
            TextBoxLeadCOMMENTS.Text                     = LeadByJSON.result.COMMENTS;
            DropDownListLeadASSIGNED_BY_ID.SelectedValue = LeadByJSON.result.ASSIGNED_BY_ID;
            Type t = LeadByJSON.result.GetType();
            foreach (var uf in BX24.Userfields)
            {
                if (uf.USER_TYPE_ID == Bitrix24.USER_TYPE_ID.enumeration)
                {
                    var DropDownListUF = FindControl("DropDownListUserfield" + uf.ID) as DropDownList;
                    foreach (Newtonsoft.Json.Linq.JProperty item in LeadByJSON.result)
                    {
                        if (item.Name == uf.FIELD_NAME)//property name
                        {
                            DropDownListUF.SelectedValue = item.Value.ToString();
                        }
                    }
                }
            }


            var    Result                = new List <Bitrix24.PRODUCT>();
            string LeadProductList       = BX24.SendCommand("crm.lead.productrows.get", "ID=" + IdLead, "", "GET");
            var    LeadProductListByJSON = JsonConvert.DeserializeObject <dynamic>(LeadProductList);
            foreach (var item in LeadProductListByJSON.result)
            {
                Result.Add(new Bitrix24.PRODUCT()
                {
                    ID = item.ID, NAME = BX24.GetNameProduct(item.PRODUCT_ID.ToString()), PRODUCT_PRICE = item.PRICE, PRODUCT_QUANTITY = item.QUANTITY
                });
            }
            Session.Contents["productrows"] = Result;
            //   LeadByJSON.result.ID
            HiddenFieldIdLead.Value = IdLead.ToString();
            ButtonSaveLead.Text     = "Обновить лид";
        }

        //string LeadListByJSON = BX24.SendCommand("crm.lead.list", "", "", "GET");
        //string LeadListByJSON = BX24.SendCommand("crm.lead.add", "", contentText, "POST");

        // string UFListByJSON = BX24.SendCommand("crm.lead.userfield.list", "", "", "POST");
        //string LeadProductListByJSON = BX24.SendCommand("crm.lead.productrows.get", "id=", "", "GET");
    }