Exemplo n.º 1
0
 public DataReturn GetData(SForceEdit.SObjectDef sobj)
 {
     return _sf.RunSOQL(sobj);
 }
Exemplo n.º 2
0
 public DataReturn Save(SForceEdit.SObjectDef sobj, DataRow r)
 {
     return _sf.Save(sobj, r);
 }
Exemplo n.º 3
0
        /* ---------------------------------------------------------Generic SForce Routines - need to clean up and merge with above */
        //Add Data to the Dataset - need to call recursilvely
        private void AddData(SForceEdit.SObjectDef sobj, DataRow rw, System.Xml.XmlElement x, string ParentName)
        {
            if (ParentName != "") ParentName += "_";

            if (x.HasAttributes && x.Attributes["xsi:type"] != null && x.Attributes["xsi:type"].Value == "sf:sObject")
            {
                string tempname = ParentName + x.LocalName;
                for (int k = 0; k < x.ChildNodes.Count; k++)
                {
                    System.Xml.XmlElement xchild = ((System.Xml.XmlElement)x.ChildNodes[k]);
                    if (xchild.HasAttributes && xchild.Attributes["xsi:type"] != null && xchild.Attributes["xsi:type"].Value == "sf:sObject")
                    {
                        AddData(sobj, rw, xchild, tempname);
                    }
                    else
                    {
                        //Check if the table contains the field if it does add it in
                        string fldname = tempname + "_" + xchild.LocalName;
                        if (rw.Table.Columns.Contains(fldname))
                        {
                            rw[fldname] = GetDataColumnData(fldname, xchild.InnerText);
                        }
                        else
                        {
                            //if the column is not there add it in if its in the columns objects
                            if (sobj.FieldExists(fldname))
                            {
                                string fldtype = sobj.GetField(fldname).DataType;
                                System.Data.DataColumn c = new DataColumn(fldname, GetDataColumnType(fldtype));
                                rw.Table.Columns.Add(c);
                                rw[fldname] = GetDataColumnData(fldname, xchild.InnerText);
                            }
                        }
                    }
                }
            }
            else
            {
                if (rw.Table.Columns.Contains(x.LocalName))
                {
                    string fldtype = sobj.GetField(x.LocalName).DataType;
                    rw[x.LocalName] = GetDataColumnData(fldtype, x.InnerText);
                }
                else
                {
                    //if the column is not there add it in if its in the columns objects
                    if (sobj.FieldExists(x.LocalName))
                    {
                        string fldtype = sobj.GetField(x.LocalName).DataType;
                        System.Data.DataColumn c = new DataColumn(x.LocalName, GetDataColumnType(fldtype));
                        rw.Table.Columns.Add(c);
                        rw[x.LocalName] = GetDataColumnData(fldtype, x.InnerText);
                    }
                }
            }
        }
Exemplo n.º 4
0
        public DataReturn RunSOQL(SForceEdit.SObjectDef sObj)
        {
            DataReturn dr = new DataReturn();

            //Build Query
            string soqlQuery = "select " + sObj.GetQueryList() + " from " + sObj.Name + "";

            //See if there is a fitler
            string filter = "";
            string filterdefaultsort = "";

            // see if we have defined filters
            if (sObj.GridFilters.Count > 0)
            {
                // defined filters
                // get the userid - check if there is an error, this could be the first thing to be called after a timeout
                string userid = "";
                try
                {
                    userid = GetUserId();
                }
                catch (Exception ex)
                {
                    dr.success = false;
                    dr.errormessage = ex.Message;
                    return dr;
                }

                if (sObj.Filter!=null && sObj.GridFilters.ContainsKey(sObj.Filter))
                {
                    AxiomIRISRibbon.SForceEdit.SObjectDef.FilterEntry f = sObj.GridFilters[sObj.Filter];
                    string soql = f.SOQL;
                    soql = soql.Replace("{UserId}", userid);

                    if(soql!="") filter = " where " + soql;
                    filterdefaultsort = f.OrderBy==""?"":" ORDER BY " + f.OrderBy;
                }

            }

            if (sObj.Search != "")
            {
                filter += (filter == "" ? " where " : " and ");
                filter += sObj.GetSearchClause();
            }

            if (sObj.Parent != "")
            {
                filter += (filter == "" ? " where " : " and ");
                string pclause = sObj.Parent;
                if (!pclause.EndsWith("__c"))
                {
                    pclause += "Id";
                }

                // if the parent id is blank we really want none - this is when we create a new parent and the
                // subtab is selected - can't just be parent='' cause there maybe children that have no parent and SOQL
                // returns them if you do ='' - so make it a dummy Id instead
                if (sObj.ParentId == "")
                {
                    filter += pclause + " = '123456789012345678'";
                }
                else
                {
                    filter += pclause + " = '" + sObj.ParentId + "'";
                }
            }

            if (sObj.Id != "")
            {
                filter += (filter == "" ? " where " : " and ");
                filter += "Id = '" + sObj.Id + "'";
            }

            soqlQuery += filter;

            if (sObj.Paging)
            {
                if (sObj.SortColumn != "")
                {
                    soqlQuery += " ORDER BY " + sObj.SortQueryField + " " + sObj.SortDir;
                }
                else
                {
                    soqlQuery += filterdefaultsort;
                }

                soqlQuery += " LIMIT " + sObj.RecordsPerPage.ToString() + " OFFSET " + (sObj.CurrnetPage * sObj.RecordsPerPage).ToString();

                try
                {
                    //Get total count
                    QueryResult qr = _binding.query("select count() from " + sObj.Name + filter);
                    Globals.Ribbons.Ribbon1.SFDebug("GetCount>" + sObj.Name, "select count() from " + sObj.Name + filter);
                    sObj.TotalRecords = qr.size;
                }
                catch (Exception ex)
                {
                    dr.success = false;
                    dr.errormessage = ex.Message;
                    return dr;
                }

            }
            else
            {
                if (sObj.SortColumn == null || sObj.SortColumn == "")
                {
                    soqlQuery += filterdefaultsort;
                }
            }

            //Create the DataTable from the Definition
            dr.dt = sObj.CreateDataTable();

            try
            {

                QueryResult qr = _binding.query(soqlQuery);
                Globals.Ribbons.Ribbon1.SFDebug("Get>" + sObj.Name, soqlQuery);
                bool done = false;

                if (qr.size > 0)
                {
                    while (!done)
                    {
                        sObject[] records = qr.records;
                        for (int i = 0; i < qr.records.Length; i++)
                        {

                            DataRow rw = dr.dt.NewRow();
                            for (int j = 0; j < records[i].Any.Length; j++)
                            {
                                AddData(sObj, rw, records[i].Any[j], "");
                            }

                            dr.dt.Rows.Add(rw);

                        }

                        if (qr.done)
                        {
                            done = true;
                        }
                        else
                        {
                            qr = _binding.queryMore(qr.queryLocator);
                            Globals.Ribbons.Ribbon1.SFDebug("GetMore>" + sObj.Name, "More>" + soqlQuery);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                dr.success = false;
                dr.errormessage = ex.Message;
            }

            return dr;
        }
Exemplo n.º 5
0
        //Given a DataRow, update or Create the SalesForce Object
        //Assuming that we have just one row, easy to change to handle multiples
        public DataReturn Save(SForceEdit.SObjectDef sObj, DataRow dRow)
        {
            DataReturn dr = new DataReturn();

            sObject s = new sObject();
            s.type = sObj.Name;
            string id = "";

            if (dRow["Id"] == null || dRow["Id"].ToString() == "")
            {
                //new
                int fldCount = dRow.Table.Columns.Count - 1;
                System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                System.Xml.XmlElement[] o = new System.Xml.XmlElement[fldCount];

                fldCount = 0;

                List<string> fieldsToNull = new List<string>();

                foreach (DataColumn dc in dRow.Table.Columns)
                {

                    //Get the field definition
                    SForceEdit.SObjectDef.FieldGridCol f = sObj.GetField(dc.ColumnName);

                    // this is a new record so do it even if it says its readonly but exclud any _Name or _Type
                    if (!f.Create)
                    {
                        //nada ...
                    }
                    else if (dc.ColumnName == "Id")
                    {
                        //Nothing!
                    }
                    else if (dc.ColumnName == "type")
                    {
                        //don't do anything - this happens when we have the type field from a join
                    }
                    else
                    {

                        object val = dRow[dc.ColumnName];
                        if (dRow[dc.ColumnName] == DBNull.Value)
                        {
                            fieldsToNull.Add(dc.ColumnName);
                        }
                        else
                        {
                            o[fldCount] = doc.CreateElement(dc.ColumnName);

                            string sval = "";
                            if (f.DataType == "datetime")
                            {
                                sval = ((DateTime)val).ToString("o");
                            }
                            else if (f.DataType == "date")
                            {
                                sval = ((DateTime)val).ToString("yyyy-MM-dd");
                            }
                            else
                            {
                                sval = CleanUpXML(val.ToString());
                            }

                            o[fldCount].InnerText = sval;
                            fldCount++;
                        }

                    }
                }

                try
                {
                    // dont need to set the values to Null! this is a create so just don't tell them
                    // s.fieldsToNull = fieldsToNull.ToArray();
                    s.Any = Utility.SubArray<System.Xml.XmlElement>(o, 0, fldCount);
                    sfPartner.SaveResult[] sr = _binding.create(new sObject[] { s });
                    Globals.Ribbons.Ribbon1.SFDebug("Save>" + s.type);

                    for (int j = 0; j < sr.Length; j++)
                    {
                        if (sr[j].success)
                        {
                            dr.id = sr[j].id;
                        }
                        else
                        {
                            dr.success = false;
                            for (int i = 0; i < sr[j].errors.Length; i++)
                            {
                                dr.errormessage += (dr.errormessage == "" ? "" : ",") + sr[j].errors[i].message;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    dr.success = false;
                    dr.errormessage = ex.Message;
                }
            }
            else
            {
                //update
                int fldCount = dRow.Table.Columns.Count;
                System.Xml.XmlDocument doc = new System.Xml.XmlDocument();

                System.Xml.XmlElement[] o = new System.Xml.XmlElement[fldCount];

                fldCount = 0;

                List<string> fieldsToNull = new List<string>();

                foreach (DataColumn dc in dRow.Table.Columns)
                {
                    //Get the field definition
                    SForceEdit.SObjectDef.FieldGridCol f = sObj.GetField(dc.ColumnName);

                    if (dc.ColumnName == "Id")
                    {
                        s.Id = dRow[dc.ColumnName].ToString();
                    }
                    else if (!f.Update)
                    {
                        //not on the list ...
                    }
                    else if (dc.ColumnName == "type")
                    {
                        //don't do anything - this happens when we have the type field from a join
                    }
                    else
                    {

                        object val = dRow[dc.ColumnName];
                        if (dRow[dc.ColumnName] == DBNull.Value ||
                            ((f.DataType != "string") && dRow[dc.ColumnName].ToString() == ""))
                        {
                            fieldsToNull.Add(dc.ColumnName);
                        }
                        else
                        {
                            o[fldCount] = doc.CreateElement(dc.ColumnName);

                            string sval = "";
                            if (f.DataType == "datetime")
                            {
                                sval = ((DateTime)val).ToString("o");
                            }
                            else if (f.DataType == "date")
                            {
                                sval = ((DateTime)val).ToString("yyyy-MM-dd");
                            }
                            else
                            {
                                sval = CleanUpXML(val.ToString());
                            }

                            o[fldCount].InnerText = sval;
                            fldCount++;
                        }
                    }
                }

                try
                {
                    s.fieldsToNull = fieldsToNull.ToArray();
                    s.Any = Utility.SubArray<System.Xml.XmlElement>(o, 0, fldCount);
                    sfPartner.SaveResult[] sr = _binding.update(new sObject[] { s });
                    Globals.Ribbons.Ribbon1.SFDebug("Update>" + s.type);
                    for (int j = 0; j < sr.Length; j++)
                    {
                        Console.WriteLine("\nItem: " + j);
                        if (sr[j].success)
                        {
                            dr.id = sr[j].id;
                        }
                        else
                        {
                            dr.success = false;
                            for (int i = 0; i < sr[j].errors.Length; i++)
                            {
                                dr.errormessage += (dr.errormessage == "" ? "" : ",") + sr[j].errors[i].message;
                            }
                        }
                    }

                }
                catch (Exception ex)
                {
                    dr.success = false;
                    dr.errormessage = ex.Message;
                }

            }
            return dr;
        }
        private void LoadData(string Id, SForceEdit.SObjectDef sObj)
        {
            sObj.Id = Id;
            DataReturn dr = _d.GetData(sObj);
            AxiomIRISRibbon.Utility.HandleData(dr);
            DataRow r = null;
            if (dr.dt.Rows.Count > 0)
            {
                r = dr.dt.Rows[0];
            }


            //WE ONLY LOAD the data once with the sidebar so just add the panels here to 
            //the main stack panel and then update the data
            if (r != null && r.Table.Columns.IndexOf("RecordTypeId") >= 0)
            {
                string rid = r["RecordTypeId"].ToString();
                sfPartner.RecordTypeMapping m = sObj.RecordTypeMapping[rid];
                StackPanel sp = sObj.SideBarLayouts[m.layoutId];
                Fields.Children.Add(sp);
                //FieldContent.Content = sp;
                UpdateTextWidth();
            }
            else
            {
                string rid = sObj.DefaultRecordType;
                // if the layout doesn't contain the default then just use the first one - this shouldn't happen
                if (!sObj.RecordTypeMapping.ContainsKey(sObj.DefaultRecordType)) rid = sObj.RecordTypeMapping.ElementAt(0).Key;
                sfPartner.RecordTypeMapping m = sObj.RecordTypeMapping[rid];
                StackPanel sp = sObj.SideBarLayouts[m.layoutId];
                Fields.Children.Add(sp);
                //FieldContent.Content = sp;
                UpdateTextWidth();
            }

            if (sObj.Name == "Version__c")
            {
                _DocumentRow = r;
                SForceEdit.Utility.UpdateForm(FindStackPanel("Version__c"), _DocumentRow);
            }
            else if (sObj.Name == "Matter__c")
            {
                _MatterRow = r;
                SForceEdit.Utility.UpdateForm(FindStackPanel("Matter__c"), _MatterRow);
            }
            else if (sObj.Name == "Request__c")
            {
                _RequestRow = r;
                SForceEdit.Utility.UpdateForm(FindStackPanel("Request__c"), _RequestRow);
            }
            else if (sObj.Name == "Document__c")
            {
                _RequestRow = r;
                SForceEdit.Utility.UpdateForm(FindStackPanel("Document__c"), _RequestRow);
            }

            btnSave.IsEnabled = false;
            btnCancel.IsEnabled = false;
        }
        private void AddGrid(SForceEdit.SObjectDef sObj)
        {

            //Create the Grid
            RadGridView radGridView1 = new RadGridView();
            radGridView1.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            radGridView1.IsFilteringAllowed = false;
            radGridView1.IsReadOnly = true;
            radGridView1.ShowGroupPanel = false;

            if (_setgbborder) sObj.SetGBBorder(_gbborder);
            if (StyleManager.ApplicationTheme.ToString() == "Windows8")
            {
                radGridView1.VerticalGridLinesBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFD1D1D1"));
                radGridView1.HorizontalGridLinesBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFD1D1D1"));
                radGridView1.GridLinesVisibility = Telerik.Windows.Controls.GridView.GridLinesVisibility.Both;
            }

            //TODO need to bind the events as well

            radGridView1.Columns.Clear();
            radGridView1.AutoGenerateColumns = false;
            sObj.AddColumns(radGridView1);

            StackPanel spAct1 = new StackPanel();
            spAct1.Tag = sObj.Name;
            spAct1.Children.Add(radGridView1);
            Fields.Children.Add(spAct1);

        }
        private void GenerateFields(SForceEdit.SObjectDef sObj)
        {

            sfPartner.DescribeSObjectResult dsr = _d.GetSObject(sObj.Name);
            sObj.Label = dsr.label;
            sObj.PluralLabel = dsr.labelPlural;
            if (_setgbborder) sObj.SetGBBorder(_gbborder);

            sObj.BuildCompactLayouts(_d, FieldChanged, SalesforcePressed, OpenPressed);

        }
Exemplo n.º 9
0
 public void setSettings(SForceEdit.Settings s)
 {
     _settings = s;
 }