private void GetServers()
 {
     //GetServersInvoke();
     imgProgress.Image     = global::SPSProfessional.ActionDataBase.Generator.Properties.Resources.progress;
     cbxServers.DataSource = SPSDbTools.GetActiveServers();
     cbxServers.Refresh();
     imgProgress.Image = null;
 }
Exemple #2
0
        private void FillTables()
        {
            try
            {
                lstTables.Sorting = SortOrder.Ascending;
                lstTables.Items.Clear();

                foreach (string table in SPSDbTools.GetTables(Generator.GetGenerator().Connection))
                {
                    lstTables.Items.Add(new ListViewItem(table, 5));
                }
                foreach (string table in SPSDbTools.GetViews(Generator.GetGenerator().Connection))
                {
                    lstTables.Items.Add(new ListViewItem(table, 6));
                }
            }
            catch (SqlException ex)
            {
                Error(ex.Message);
            }
        }
 private void btnTestConnection_Click(object sender, EventArgs e)
 {
     try
     {
         cbxDatabases.DataSource = SPSDbTools.GetDatabases(cbxServers.Text,
                                                           txtUser.Text,
                                                           txtPassword.Text,
                                                           chkSSPI.Checked);
         lblStatus.Text = "Test Sucessfully.";
         //MessageBox.Show("Sucessfully.",
         //                "Database Connection",
         //                MessageBoxButtons.OK,
         //                MessageBoxIcon.Information);
     }
     catch (SPSDbToolsException ex)
     {
         lblStatus.Text = "";
         MessageBox.Show(ex.Message,
                         "ERROR",
                         MessageBoxButtons.OKCancel,
                         MessageBoxIcon.Error);
     }
 }
Exemple #4
0
        private void DoFormXML()
        {
            if (_columnsTable != null)
            {
                StringWriter  sw = new StringWriter();
                XmlTextWriter w  = new XmlTextWriter(sw);

                w.WriteStartDocument();
                w.WriteStartElement("SPSActionEditConfig");

                w.WriteStartElement("DataBase");
                w.WriteAttributeString("ConnectionString", Generator.GetGenerator().ConnectionString);

                w.WriteStartElement("Table");
                w.WriteAttributeString("Name", _selectedTable);
                //w.WriteAttributeString("IdentityField", GetPrimaryKey());
                //w.WriteAttributeString("IdentityType", GetTypeForField(GetPrimaryKey()));

                // IdentityColumns
                foreach (DataRow row in _columnsTable.Rows)
                {
                    if ((bool)row["IsKey"])
                    {
                        SqlDbType sqlDbType =
                            (SqlDbType)Enum.Parse(typeof(SqlDbType), row["DataTypeName"].ToString(), true);
                        string datatype = sqlDbType.ToString();

                        w.WriteStartElement("IdentityColumn");
                        w.WriteAttributeString("Name", row["ColumnName"].ToString());
                        w.WriteAttributeString("Type", datatype);
                        w.WriteEndElement();
                    }
                }

                w.WriteEndElement();
                w.WriteEndElement();

                #region ActionToolBars Sample

                w.WriteStartElement("ActionToolBars");

                w.WriteStartElement("ActionToolBar");
                w.WriteAttributeString("Name", "View");

                w.WriteStartElement("Option");
                w.WriteAttributeString("Name", "Edit");
                w.WriteAttributeString("ImageUrl", "/_layouts/images/edit.gif");
                w.WriteAttributeString("Action", "Edit");
                w.WriteEndElement();

                w.WriteStartElement("Option");
                w.WriteAttributeString("Name", "Delete");
                w.WriteAttributeString("ImageUrl", "/_layouts/images/delete.gif");
                w.WriteAttributeString("Action", "Delete");
                w.WriteEndElement();

                w.WriteStartElement("Option");
                w.WriteAttributeString("Name", "New");
                w.WriteAttributeString("ImageUrl", "/_layouts/images/newrole.gif");
                w.WriteAttributeString("Action", "New");
                w.WriteEndElement();

                w.WriteEndElement();

                w.WriteStartElement("ActionToolBar");
                w.WriteAttributeString("Name", "Edit");

                w.WriteStartElement("Option");
                w.WriteAttributeString("Name", "Update");
                w.WriteAttributeString("ImageUrl", "/_layouts/images/save.gif");
                w.WriteAttributeString("Action", "Update");
                w.WriteEndElement();

                w.WriteStartElement("Option");
                w.WriteAttributeString("Name", "Back");
                w.WriteAttributeString("ImageUrl", "/_layouts/images/back.gif");
                w.WriteAttributeString("Action", "Back");
                w.WriteEndElement();

                w.WriteStartElement("Option");
                w.WriteAttributeString("Name", "Delete");
                w.WriteAttributeString("ImageUrl", "/_layouts/images/delete.gif");
                w.WriteAttributeString("Action", "Delete");
                w.WriteEndElement();

                w.WriteEndElement();

                w.WriteStartElement("ActionToolBar");
                w.WriteAttributeString("Name", "New");

                w.WriteStartElement("Option");
                w.WriteAttributeString("Name", "Save New");
                w.WriteAttributeString("ImageUrl", "/_layouts/images/save.gif");
                w.WriteAttributeString("Action", "Create");
                w.WriteEndElement();

                w.WriteStartElement("Option");
                w.WriteAttributeString("Name", "Back");
                w.WriteAttributeString("ImageUrl", "/_layouts/images/back.gif");
                w.WriteAttributeString("Action", "Back");
                w.WriteEndElement();

                w.WriteEndElement();
                w.WriteEndElement();

                #endregion

                w.WriteStartElement("Fields");

                foreach (DataRow row in _columnsTable.Rows)
                {
                    string columnName = row["ColumnName"].ToString();
                    string dataType   = row["DataType"].ToString();

                    bool isReadOnly      = (bool)row["IsReadOnly"];
                    bool isKey           = (bool)row["IsKey"];
                    bool isAutoIncrement = (bool)row["IsAutoIncrement"];
                    bool allowDbNull     = ((bool)row["AllowDBNull"]);

                    string newRecord  = (isReadOnly || isAutoIncrement ? "Disabled" : "Enabled");
                    string editRecord = newRecord;

                    int    maxLength = Int32.Parse(row["ColumnSize"].ToString());
                    int    columns   = maxLength > 40 ? 40 : maxLength;
                    string control   = ApropiatedControl(dataType, maxLength);

                    SqlFKPKInfo sqlFkPkInfo = SPSDbTools.GetFkPkInfoVersion(
                        Generator.GetGenerator().Connection,
                        columnName,
                        _selectedTable);

                    string required = (isAutoIncrement || !allowDbNull || sqlFkPkInfo != null).ToString().ToLower();

                    SqlDbType sqlDbType =
                        (SqlDbType)Enum.Parse(typeof(SqlDbType), row["DataTypeName"].ToString(), true);
                    string datatype = sqlDbType.ToString();

                    // Types not supported
                    if (datatype == "Xml")
                    {
                        w.WriteComment(string.Format("Field {0} type {1} is not supported by ActionDataBase",
                                                     columnName,
                                                     datatype));
                    }
                    else
                    {
                        Status(string.Format("Generating {0}", columnName));

                        w.WriteStartElement("Field");

                        w.WriteAttributeString("Name", columnName);
                        w.WriteAttributeString("Title", columnName);

                        w.WriteAttributeString("Type", datatype);
                        w.WriteAttributeString("Control", control);

                        w.WriteAttributeString("Required", required);
                        w.WriteAttributeString("DefaultValue", "");

                        if (dataType.Contains("Date"))
                        {
                            w.WriteAttributeString("DisplayFormat", "{0:d}");
                        }
                        else
                        {
                            w.WriteAttributeString("DisplayFormat", "");
                        }

                        w.WriteAttributeString("New", newRecord);
                        w.WriteAttributeString("Edit", editRecord);
                        w.WriteAttributeString("View", "Enabled");

                        if (control == "TextBox" && dataType.Contains("String") && maxLength <= 256)
                        {
                            w.WriteStartElement("TextBox");
                            w.WriteAttributeString("Columns", columns.ToString());
                            w.WriteAttributeString("MaxLength", maxLength.ToString());
                            w.WriteEndElement();
                        }

                        if (control == "CheckBox")
                        {
                            w.WriteStartElement("CheckBox");
                            w.WriteAttributeString("TextChecked", "Chekced");
                            w.WriteAttributeString("TextUnChecked", "UnChecked");
                            w.WriteEndElement();
                        }

                        if (control == "Memo")
                        {
                            w.WriteStartElement("Memo");
                            w.WriteAttributeString("Columns", "40");
                            w.WriteAttributeString("Rows", "15");
                            //w.WriteAttributeString("MaxLength", maxLength.ToString());
                            w.WriteEndElement();
                        }

                        if (control == "TextBox" &&
                            (!dataType.Contains("String") &&
                             !dataType.Contains("Date")))
                        {
                            w.WriteStartElement("TextBox");
                            w.WriteAttributeString("Columns", "20");
                            w.WriteAttributeString("RightToLeft", "true");
                            w.WriteEndElement();
                        }

                        if (sqlFkPkInfo != null)
                        {
                            // TextField="CompanyName" ValueField="CustomerID" Table="TabelName"
                            w.WriteStartElement("Lookup");
                            w.WriteAttributeString("ControlEditor", "DropDownList");
                            w.WriteAttributeString("TextField", sqlFkPkInfo.PKColumnName);
                            w.WriteAttributeString("ValueField", sqlFkPkInfo.PKColumnName);
                            w.WriteAttributeString("ValueFieldType", datatype);
                            w.WriteAttributeString("Table", sqlFkPkInfo.PKTable);
                            w.WriteEndElement();
                        }

                        w.WriteEndElement();
                    }
                }
                w.WriteEndElement();

                w.WriteEndElement();
                w.WriteEndDocument();

                txtFormXML.Text = FormatXML(sw.ToString());
                LoadXMLFormEditor();
                Status("ActionBase XML Form generated.");
            }
            else
            {
                Error("Run column info, prior to generate a form.");
            }
        }
 private void DoWork(object sender, DoWorkEventArgs e)
 {
     imgProgress.Image = global::SPSProfessional.ActionDataBase.Generator.Properties.Resources.progress;
     servers           = SPSDbTools.GetActiveServers();
 }