Пример #1
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            if (txtFolder.Text.Trim().Length == 0)
            {
                General.Mes("please type a folder");
                return;
            }

            //create export folder
            string exportDIR = Application.StartupPath + "\\" + txtFolder.Text + "\\";

            if (Directory.Exists(exportDIR))
            {
                General.Mes("Folder already exists!");
                return;
            }
            else
            {
                Directory.CreateDirectory(exportDIR);
            }

            if (cmbTemplate.SelectedIndex == 0)
            {
                do_template_adminLTE();
            }
            else
            {
                do_template_bootstraptable();
            }

            Process.Start(exportDIR);
        }
Пример #2
0
        private void btnRefresh_Click(object sender, EventArgs e)
        {
            try
            {
                DataTable dT_Fields;

                DG.Rows.Clear();
                string tmp1, tmp2;

                dT_Fields = sourceDB.ExecuteSQL(txtCustomSQL.Text, out tmp1, out tmp2);

                if (tmp2.Length > 0)
                {
                    General.Mes(tmp2);
                }

                if (dT_Fields == null)
                {
                    return;
                }

                foreach (DataColumn column in dT_Fields.Columns)
                {
                    DG.Rows.Add(column.ColumnName, "");
                }
            }
            catch (Exception ex)
            {
                General.Mes(ex.Message);
            }
        }
        void c_isConnected(bool isSuccess)
        {
            if (txtURL.InvokeRequired)
            {
                txtURL.BeginInvoke(new c_isConnectedCallback(this.c_isConnected), new object[] { isSuccess });
                return;
            }

            Cursor = System.Windows.Forms.Cursors.Default;

            if (isSuccess)
            {
                General.Connections.Add(new dbConnection
                {
                    dbaseName  = "",
                    filename   = "",
                    password   = txtPassword.Text,
                    port       = "",
                    serverName = txtURL.Text,
                    TYPE       = (int)General.dbTypes.MySQLtunnel,
                    user       = ""
                });


                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            else
            {
                General.Mes("Could not connect!");
            }
        }
Пример #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (txtServer.Text.Trim().Length > 0 && txtUser.Text.Trim().Length > 0 && txtPassword.Text.Trim().Length > 0)
            {
                //   General.ConneADO = new ADOnet("Provider=SQLOLEDB;Data Source=" + txtServer.Text + ";Initial Catalog=" + txtDBASE.Text + ";User ID=" + txtUser.Text + ";Password="******"Please fill all infos required!", General.apTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            MySqlConnection objConn      = null;
            bool            errorOccured = false;

            try
            {
                Cursor = System.Windows.Forms.Cursors.WaitCursor;

                objConn = new MySqlConnection("server=" + txtServer.Text + ";" +
                                              "database=" + txtDBASE.Text + ";" +
                                              "user id=" + txtUser.Text + ";" +
                                              "password="******";" +
                                              "Port=" + txtPort.Text + ";");
                objConn.Open();
            }
            catch (Exception ex)
            {
                General.Mes(ex.Message);
                errorOccured = true;
            }
            finally
            {
                if (objConn != null)
                {
                    objConn.Close();
                    objConn.Dispose();
                    objConn = null;
                }

                Cursor = System.Windows.Forms.Cursors.Default;
            }

            if (!errorOccured)
            {
                General.Connections.Add(new dbConnection
                {
                    dbaseName  = txtDBASE.Text,
                    filename   = "",
                    password   = txtPassword.Text,
                    port       = txtPort.Text,
                    serverName = txtServer.Text,
                    TYPE       = (int)General.dbTypes.MySQL,
                    user       = txtUser.Text
                });


                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (txtURL.Text.Trim().Length == 0 || txtPassword.Text.Trim().Length == 0)
            {
                MessageBox.Show("Please fill all infos!", General.apTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            else
            {
                if (txtPassword.Text.Contains("$"))
                {
                    MessageBox.Show("The symbol '$' forbidden!", General.apTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                if (!txtURL.Text.ToLower().StartsWith("https"))
                {
                    if (MessageBox.Show("Server must be https enabled, are you sure you want to continue ?", General.apTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == System.Windows.Forms.DialogResult.No)
                    {
                        return;
                    }
                }
            }


            if (txtURL.Text.ToLower().StartsWith("https"))
            {
                ServicePointManager.SecurityProtocol = (SecurityProtocolType)(0xc0 | 0x300 | 0xc00);
            }
            else
            {
                ServicePointManager.SecurityProtocol = (SecurityProtocolType)(48 | 192);
            }


            Cursor = System.Windows.Forms.Cursors.WaitCursor;
            //MySqlConnection objConn = null;
            //bool errorOccured = false;
            c              = new MySQLTunnel();
            c.isConnected += new MySQLTunnel.IsConnected(c_isConnected);
            try
            {
                Cursor = System.Windows.Forms.Cursors.WaitCursor;

                c.testConnection(txtURL.Text.Trim(), txtPassword.Text.Trim());
            }
            catch (Exception ex)
            {
                General.Mes(ex.Message);
            }
            finally
            {
                Cursor = System.Windows.Forms.Cursors.Default;
            }
        }
Пример #6
0
 private void button4_Click(object sender, EventArgs e)
 {
     try
     {
         File.WriteAllBytes("c:\\PHPtemplate.zip", DBManager.Properties.Resources.PHPtemplate);
         General.Mes(@"Successfully extracted to 'c:\PHPtemplate.zip'");
     }
     catch (Exception ex) {
         General.Mes(ex.Message, MessageBoxIcon.Error);
     }
 }
Пример #7
0
 static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
 {
     if (e.Exception is NotImplementedException)
     {
         General.Mes("This functionality not supported on this database type", MessageBoxIcon.Exclamation);
     }
     else
     {
         ErrorReporter reporter = new ErrorReporter(e.Exception);
         reporter.ShowDialog();
     }
 }
Пример #8
0
 private void button4_Click(object sender, EventArgs e)
 {
     try
     {
         if (cmbTemplate.SelectedIndex == 0)
         {
             File.WriteAllBytes("c:\\PHPtemplateCRUD.zip", DBManager.Properties.Resources.PHPtemplateCRUD);
             General.Mes(@"Successfully extracted to 'c:\PHPtemplateCRUD.zip'");
         }
         else if (cmbTemplate.SelectedIndex == 1)
         {
             File.WriteAllBytes("c:\\PHPtemplateCRUDbootstraptable.zip", DBManager.Properties.Resources.PHPtemplateCRUDbootstraptable);
             General.Mes(@"Successfully extracted to 'c:\PHPtemplateCRUDbootstraptable.zip'");
         }
     }
     catch (Exception ex)
     {
         General.Mes(ex.Message, MessageBoxIcon.Error);
     }
 }
Пример #9
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            if (txtFolder.Text.Trim().Length == 0)
            {
                General.Mes("please type a folder");
                return;
            }

            //create export folder
            string exportDIR = Application.StartupPath + "\\" + txtFolder.Text + "\\";

            if (Directory.Exists(exportDIR))
            {
                General.Mes("Folder already exists!");
                return;
            }
            else
            {
                Directory.CreateDirectory(exportDIR);
            }


            List <TBLStructure> cols = new List <TBLStructure>();
            treeItem            itemTR;

            //grab all fields to our list of
            foreach (var nodeR in TR.Root.Children)
            {
                foreach (var node in nodeR.Children)
                {
                    itemTR = (node.Tag as treeItem);

                    cols.Add(new TBLStructure(itemTR.nodeText, itemTR.fieldType, itemTR.fieldSize, itemTR.imageIndex == 2, itemTR.imageIndex == 1, (nodeR.Tag as treeItem).nodeText));
                }
            }

            //page_template***********
            string pageTemplate         = ReadASCIIfromResources("DBManager.ResourcesPHPexport.page_template.txt");
            string pageTemplateAppender = "";


            //modal element
            string modalElementTemplate         = ReadASCIIfromResources("DBManager.ResourcesPHPexport.page_template_modal_element.txt");
            string modalElementTemplateAppender = "";

            //modal elements Edit button get from DB to modal
            string modalElementEDITtemplate         = "							$('[name={{field}}]').val(data.{{field}});\r\n";
            string modalElementEDITtemplateAppender = "";

            //table element
            string tableColTemplate         = "					<th tabindex=\"0\" rowspan=\"1\" colspan=\"1\">{{field}}</th>\r\n";
            string tableColTemplateAppender = "";


            //validator Declaration***********
            string validateDeclareAppender             = "";
            string validateErrMessagesTemplateAppender = "";

            //validator String Declare
            string validateDeclareStringTemplate = "				{{field}} : {\r\n					required : true,\r\n					minlength : 1,\r\n					maxlength : {{size}}\r\n				},\r\n";

            //validator String Error Messages
            string validateErrMessagesStringTemplate = "				{{field}} : 'Please enter a value up to {{size}} characters',\r\n";

            //validator Decimal Declare
            string validateDeclareDecimalTemplate = "				{{field}} : {\r\n					required : true,\r\n					currency : true\r\n				},\r\n";

            //validator Decimal Error Messages
            string validateErrMessagesDecimalTemplate = "				{{field}} : 'Please enter a decimal value',\r\n";


            //page_pagination template***********
            string pagePaginationTemplate         = ReadASCIIfromResources("DBManager.ResourcesPHPexport.table_pagination.txt");
            string pagePaginationTemplateAppender = "";

            //page_pagination table item
            string pagePaginationColTemplate         = "							    	<td>{{{{field}}}}</td>\r\n";
            string pagePaginationColTemplateAppender = "";

            //page_pagination while
            string pagePaginationWhileTemplateOnlyFirstField = "	$rowTBL = str_replace('{{{{field}}}}', $row['{{field}}'], $RowTemplate);\r\n";
            string pagePaginationWhileTemplate         = "	$rowTBL = str_replace('{{{{field}}}}', $row['{{field}}'], $rowTBL);\r\n";
            string pagePaginationWhileTemplateAppender = "";


            //table_save template***********
            string tableSaveTemplate         = ReadASCIIfromResources("DBManager.ResourcesPHPexport.page_save_template.txt");
            string tableSaveTemplateAppender = "";

            string ID              = "";
            string secondField     = "";
            string insFields       = "";
            string qmarks          = "";
            string updFields       = "";
            string post2vars       = "";
            string paramFields     = "";
            string paramFieldsType = "";


            //table_fetch template***********
            string tableFetchTemplate         = ReadASCIIfromResources("DBManager.ResourcesPHPexport.page_fetch_template.txt");
            string tableFetchTemplateAppender = "";

            //table_delete template***********
            string tableDeleteTemplate         = ReadASCIIfromResources("DBManager.ResourcesPHPexport.page_delete_template.txt");
            string tableDeleteTemplateAppender = "";

            //table_export template***********
            string tableExportTemplate         = ReadASCIIfromResources("DBManager.ResourcesPHPexport.page_export_template.txt");
            string tableExportTemplateAppender = "";

            bool isFirst = true;

            foreach (TBLStructure item in cols)
            {
                if (item.fieldPK)
                {
                    ID = item.fieldName;
                }

                //for TABLE.php
                modalElementTemplateAppender     += modalElementTemplate.Replace("{{field}}", item.fieldName);
                tableColTemplateAppender         += tableColTemplate.Replace("{{field}}", item.fieldName);
                modalElementEDITtemplateAppender += modalElementEDITtemplate.Replace("{{field}}", item.fieldName);

                //for TABLE_pagination.php
                pagePaginationColTemplateAppender += pagePaginationColTemplate.Replace("{{field}}", item.fieldName);

                if (isFirst)
                {
                    pagePaginationWhileTemplateAppender += pagePaginationWhileTemplateOnlyFirstField.Replace("{{field}}", item.fieldName);
                    isFirst = false;
                }
                else
                {
                    pagePaginationWhileTemplateAppender += pagePaginationWhileTemplate.Replace("{{field}}", item.fieldName);
                    if (secondField.Length == 0)
                    {
                        secondField = item.fieldName;
                    }
                }

                //table_save.php
                insFields       += "                                " + item.fieldName + ",\r\n";
                qmarks          += "?,";
                updFields       += "                                " + item.fieldName + " = ?,\r\n";
                post2vars       += "	$"+ item.fieldName + " = $_POST['" + item.fieldName + "'];\r\n";
                paramFields     += " $" + item.fieldName + ",";
                paramFieldsType += (item.fieldType == "decimal" ? "d" : "s");

                if (item.fieldType == "decimal")
                {
                    validateDeclareAppender             += validateDeclareDecimalTemplate.Replace("{{field}}", item.fieldName);
                    validateErrMessagesTemplateAppender += validateErrMessagesDecimalTemplate.Replace("{{field}}", item.fieldName);
                }
                else
                {
                    validateDeclareAppender             += validateDeclareStringTemplate.Replace("{{field}}", item.fieldName).Replace("{{size}}", item.fieldSize);
                    validateErrMessagesTemplateAppender += validateErrMessagesStringTemplate.Replace("{{field}}", item.fieldName).Replace("{{size}}", item.fieldSize);
                }
            }

            //replace validation delcaration
            pageTemplateAppender = pageTemplate.Replace("{{validationDECLARATION}}", validateDeclareAppender);

            //replace validation Error messages
            pageTemplateAppender = pageTemplateAppender.Replace("{{validationErrMessages}}", validateErrMessagesTemplateAppender);

            //replace EDIT elements (fill modal form with data from server)
            pageTemplateAppender = pageTemplateAppender.Replace("{{elementsEDIT}}", modalElementEDITtemplateAppender);

            //replace modal elements
            pageTemplateAppender = pageTemplateAppender.Replace("{{modalElements}}", modalElementTemplateAppender);

            //replace table cols
            pageTemplateAppender = pageTemplateAppender.Replace("{{tableCOLS}}", tableColTemplateAppender);

            var    tblName   = TR.Root.Children.FirstOrDefault();
            string tableName = (tblName.Tag as treeItem).nodeText;

            pageTemplateAppender = pageTemplateAppender.Replace("{{Ufield}}", tableName.ToUpper())
                                   .Replace("{{Lfield}}", tableName.ToLower())
                                   .Replace("{{Cfield}}", General.UppercaseFirst(tableName.ToLower().Substring(0, tableName.Length - 1)));

            //table.php - export page
            File.WriteAllText(exportDIR + tableName.ToLower() + ".php", pageTemplateAppender, Encoding.ASCII);

            //table_pagination.php
            pagePaginationTemplateAppender = pagePaginationTemplate.Replace("{{table}}", tableName)
                                             .Replace("{{Ctable}}", General.UppercaseFirst(tableName.ToLower()))
                                             .Replace("{{tableCol}}", pagePaginationColTemplateAppender)
                                             .Replace("{{while}}", pagePaginationWhileTemplateAppender);

            File.WriteAllText(exportDIR + tableName.ToLower() + "_pagination.php", pagePaginationTemplateAppender, Encoding.ASCII);

            //table_save.php
            tableSaveTemplateAppender = tableSaveTemplate.Replace("{{2ndfield}}", secondField)
                                        .Replace("{{Utable}}", tableName.ToUpper())
                                        .Replace("{{table}}", tableName)
                                        .Replace("{{insFields}}", insFields.Substring(0, insFields.Length - 3))
                                        .Replace("{{qmarks}}", qmarks.Substring(0, qmarks.Length - 3))
                                        .Replace("{{updFields}}", updFields.Substring(0, updFields.Length - 3) + " ")
                                        .Replace("{{id}}", ID)
                                        .Replace("{{post2vars}}", post2vars)
                                        .Replace("{{parameterFields}}", paramFields.Substring(0, paramFields.Length - 1))
                                        .Replace("{{parameterFieldsType}}", paramFieldsType);

            File.WriteAllText(exportDIR + tableName.ToLower() + "_save.php", tableSaveTemplateAppender, Encoding.ASCII);

            //table_fetch.php
            tableFetchTemplateAppender = tableFetchTemplate.Replace("{{Utable}}", tableName.ToUpper())
                                         .Replace("{{table}}", tableName)
                                         .Replace("{{id}}", ID);

            File.WriteAllText(exportDIR + tableName.ToLower() + "_fetch.php", tableFetchTemplateAppender, Encoding.ASCII);


            //table_delete.php
            tableDeleteTemplateAppender = tableDeleteTemplate.Replace("{{Utable}}", tableName.ToUpper())
                                          .Replace("{{table}}", tableName)
                                          .Replace("{{id}}", ID);

            File.WriteAllText(exportDIR + tableName.ToLower() + "_delete.php", tableDeleteTemplateAppender, Encoding.ASCII);

            //table_export.php
            tableExportTemplateAppender = tableExportTemplate.Replace("{{Utable}}", tableName.ToUpper())
                                          .Replace("{{table}}", tableName);

            File.WriteAllText(exportDIR + tableName.ToLower() + "_export.php", tableExportTemplateAppender, Encoding.ASCII);

            //config.php - mysql
            File.WriteAllText(exportDIR + "config.php", ReadASCIIfromResources("DBManager.ResourcesPHPexport.config.txt"), Encoding.ASCII);

            //EXCEL export REQ files
            File.WriteAllText(exportDIR + "ExcelWriterXML.php", ReadASCIIfromResources("DBManager.ResourcesPHPexport.ExcelWriterXML.txt"), Encoding.ASCII);
            File.WriteAllText(exportDIR + "ExcelWriterXML_Sheet.php", ReadASCIIfromResources("DBManager.ResourcesPHPexport.ExcelWriterXML_Sheet.txt"), Encoding.ASCII);
            File.WriteAllText(exportDIR + "ExcelWriterXML_Style.php", ReadASCIIfromResources("DBManager.ResourcesPHPexport.ExcelWriterXML_Style.txt"), Encoding.ASCII);

            //login+authorization
            File.WriteAllText(exportDIR + "admin.php", ReadASCIIfromResources("DBManager.ResourcesPHPexport.auth_admin.txt"), Encoding.ASCII);
            File.WriteAllText(exportDIR + "login.php", ReadASCIIfromResources("DBManager.ResourcesPHPexport.auth_login.txt"), Encoding.ASCII);
            File.WriteAllText(exportDIR + "portal.php", ReadASCIIfromResources("DBManager.ResourcesPHPexport.portal_template.txt").Replace("{{Ltable}}", tableName.ToLower()), Encoding.ASCII);

            //bootstrap+jquery
            Directory.CreateDirectory(exportDIR + "js");
            Directory.CreateDirectory(exportDIR + "css");
            File.WriteAllText(exportDIR + "css\\bootstrap.min.css", ReadASCIIfromResources("DBManager.ResourcesPHPexport.bootstrap.min.css"), Encoding.ASCII);
            File.WriteAllText(exportDIR + "css\\signin.css", ReadASCIIfromResources("DBManager.ResourcesPHPexport.signin.css"), Encoding.ASCII);
            File.WriteAllText(exportDIR + "js\\bootstrap.min.js", ReadASCIIfromResources("DBManager.ResourcesPHPexport.bootstrap.min.js"), Encoding.ASCII);
            File.WriteAllText(exportDIR + "js\\jquery-1.10.2.min.js", ReadASCIIfromResources("DBManager.ResourcesPHPexport.jquery-1.10.2.min.js"), Encoding.ASCII);
            File.WriteAllText(exportDIR + "js\\jquery.validate.min.js", ReadASCIIfromResources("DBManager.ResourcesPHPexport.jquery.validate.min.js"), Encoding.ASCII);
        }
Пример #10
0
        private void do_template_bootstraptable()
        {
            string table_name;

            string top_item_template = DBManager.Properties.Resources.CRUD2template_main;
            string top_item          = "";

            //table cols
            string CRUD2template_main_TABLE_Item_template = DBManager.Properties.Resources.CRUD2template_main_TABLE_Item;
            string CRUD2template_main_TABLE_Item          = DBManager.Properties.Resources.CRUD2template_main_TABLE_Item;

            //pagination
            string CRUD2template_pagination_template = DBManager.Properties.Resources.CRUD2template_pagination;
            string CRUD2template_pagination          = "";

            //fetch record for edit
            string CRUD2template_fetch_template = DBManager.Properties.Resources.CRUD2template_fetch;
            string CRUD2template_fetch          = "";

            //delete record
            string CRUD2template_delete_template = DBManager.Properties.Resources.CRUD2template_delete;
            string CRUD2template_delete          = "";

            string apppath = Application.StartupPath + "\\" + txtFolder.Text + "\\";

            string select_fields          = "";
            string select_fields_wo_joins = "";
            string PK = "";

            //templates
            string PHPSelectDetailTemplateDB2FORM      = "		$('[name=*field*]').val(data.*field*);";
            string PHPSelectDetailTemplateDB2FORMcheck = "		$('[name=*field*]').bootstrapSwitch('state',parseInt(data.*field*));";

            string jsonValidator_template = "				             *field* : { required : true },";
            string jsonValidator          = "";

            string jsonValidator_message_template = "				            *field* : 'Required Field',";
            string jsonValidator_message          = "";

            //classic control (aka input)
            string PHPSelectDetailTemplateCOL = DBManager.Properties.Resources.PHPpagesSELECTdetailCOL;

            //PHP read recordset for combo
            string CRUDtemplate_FK_Control_FILL_template = DBManager.Properties.Resources.CRUDtemplate_FK_Control_FILL;
            string CRUDtemplate_FK_Control_FILL          = "";

            //JS fill combo  from PHP variable
            string CRUDtemplate_FK_Control_FILL_COMBO_template = DBManager.Properties.Resources.CRUDtemplate_FK_Control_FILL_COMBO;
            string CRUDtemplate_FK_Control_FILL_COMBO          = "";

            //switch initialization
            string CRUDtemplate_FK_Control_FILL_CHECKinit_template = "	$(\"[name='*field*']\").bootstrapSwitch();\r\n";
            string CRUDtemplate_FK_Control_FILL_CHECKinit          = "";

            //DTP initialization
            string CRUDtemplate_FK_Control_FILL_DTPinit_template = DBManager.Properties.Resources.CRUDtemplate_Control_DTP_init;
            string CRUDtemplate_FK_Control_FILL_DTPinit          = "";

            //DTPtime initialization
            string CRUDtemplate_Control_DTPtime_init_template = DBManager.Properties.Resources.CRUDtemplate_Control_DTPtime_init;
            string CRUDtemplate_Control_DTPtime_init          = "";

            string CRUDtemplate_Control_DTPmalot_init_template = DBManager.Properties.Resources.CRUDtemplate_Control_DTPmalot;
            //string CRUDtemplate_Control_DTPmalot_init = "";



            //form-control templates
            string PHPSelectDetailTemplateCOL_COMBO    = DBManager.Properties.Resources.PHPpagesSELECTdetailCOL_COMBO;
            string PHPSelectDetailTemplateCOL_CHECK    = DBManager.Properties.Resources.PHPpagesSELECTdetailCOL_CHECK;
            string PHPSelectDetailTemplateCOL_DTP      = DBManager.Properties.Resources.PHPpagesSELECTdetailCOL_DTP;
            string PHPSelectDetailTemplateCOL_DTPtime  = DBManager.Properties.Resources.PHPpagesSELECTdetailCOL_DTPtime;
            string PHPSelectDetailTemplateCOL_DTPmalot = DBManager.Properties.Resources.PHPpagesSELECTdetailCOL_DTPmalot;

            //php_save templates
            string CRUDtemplate_SAVE_CHECK_validation_template = DBManager.Properties.Resources.CRUDtemplate_save_checkbox_validation;
            string CRUDtemplate_SAVE_CHECK_validation          = "";

            string CRUDtemplate_SAVE_DTPTime_validation_template = DBManager.Properties.Resources.CRUDtemplate_save_dtptime_validation;
            string CRUDtemplate_SAVE_DTPTime_validation          = "";

            string CRUDtemplate_SAVE_DTPmalot_validation_template = DBManager.Properties.Resources.CRUDtemplate_save_dtpmalot_validation;
            //string CRUDtemplate_SAVE_DTPmalot_validation = "";



            string col_names = "";

            //save vars
            string insertFields    = "";
            string insertVAL       = "";
            string updateVAL       = "";
            string save_prepared   = "";
            string dbase2form      = "";
            string post_validation = "";
            string joins           = "";
            string rows            = "";
            string fieldnames      = "";
            string first_field     = "";

            foreach (treeItem2 tbl in tables)
            {
                table_name = tbl.table_name;

                joins = select_fields = select_fields_wo_joins = fieldnames = PK = dbase2form = rows = insertFields = insertVAL = updateVAL = post_validation = save_prepared =
                    CRUDtemplate_FK_Control_FILL           = CRUDtemplate_FK_Control_FILL_COMBO = CRUDtemplate_FK_Control_FILL_CHECKinit = CRUDtemplate_SAVE_CHECK_validation =
                        CRUDtemplate_SAVE_CHECK_validation = CRUDtemplate_FK_Control_FILL_DTPinit = col_names = CRUD2template_main_TABLE_Item = CRUD2template_delete = CRUD2template_fetch =
                            jsonValidator = CRUD2template_pagination = jsonValidator_message = first_field = CRUDtemplate_Control_DTPtime_init = CRUDtemplate_SAVE_DTPTime_validation = "";
                //CRUDtemplate_SAVE_DTPmalot_validation=CRUDtemplate_Control_DTPmalot_init

                foreach (treeItem2fields fields in tbl.table_fields)
                {
                    col_names += "'" + fields.field_name + "',\r\n";

                    if (fields.field_PK)
                    {
                        PK                      = fields.field_name;
                        select_fields          += PK + ", ";
                        select_fields_wo_joins += PK + ", ";

                        //when is PK, turn the visibility OFF
                        CRUD2template_main_TABLE_Item += CRUD2template_main_TABLE_Item_template.Replace("*field*", fields.field_name).Replace("*fieldv*", "false");
                    }
                    else
                    {
                        //when is PK, turn the visibility ON
                        CRUD2template_main_TABLE_Item += CRUD2template_main_TABLE_Item_template.Replace("*field*", fields.field_name).Replace("data-visible=\"*fieldv*\"", "data-sortable=\"true\""); //.Replace("*fieldv*", "true");

                        insertFields += fields.field_name + ", ";
                        insertVAL    += ":" + fields.field_name + ", ";

                        updateVAL += fields.field_name + "=:" + fields.field_name + ", ";

                        //details.php
                        if (fields.field_type.ToLower() == "bit" && chkBIT.Checked)
                        {
                            save_prepared += "$stmt->bindValue(':" + fields.field_name + "' , $" + fields.field_name + ", PDO::PARAM_INT);\r\n";
                            dbase2form    += PHPSelectDetailTemplateDB2FORMcheck.Replace("*field*", fields.field_name) + "\r\n";
                        }
                        else if (fields.field_type.ToLower() == "tinyint" && chkTINYINT.Checked)
                        {
                            save_prepared += "$stmt->bindValue(':" + fields.field_name + "' , $" + fields.field_name + ", PDO::PARAM_INT);\r\n";
                            dbase2form    += PHPSelectDetailTemplateDB2FORMcheck.Replace("*field*", fields.field_name) + "\r\n";
                        }
                        else
                        {
                            post_validation += "!isset($_POST['" + fields.field_name + "']) || ";

                            //on datetime make custom save_prepared
                            if ((chkDATETIME.Checked && fields.field_type.ToLower() == "datetime") || (chkDATEmalot.Checked && fields.field_type.ToLower() == "date"))
                            {
                                Console.WriteLine("");
                            }
                            else
                            {
                                save_prepared += "$stmt->bindValue(':" + fields.field_name + "' , $_POST['" + fields.field_name + "']);\r\n";
                            }

                            dbase2form += PHPSelectDetailTemplateDB2FORM.Replace("*field*", fields.field_name) + "\r\n";
                        }

                        string[] returnVAL = check4tie(fields.field_name);
                        //0 - ID // 1 - TXT // 2 - TABLE

                        if (returnVAL[0] != null && returnVAL[1] != null && returnVAL[2] != null)
                        {
                            //PHP - read values from original tables (aka FOREIGN)
                            CRUDtemplate_FK_Control_FILL += CRUDtemplate_FK_Control_FILL_template.Replace("#table#", returnVAL[2]).Replace("#txt#", returnVAL[1]);
                            //CRUDtemplate_FK_Control_FILL += CRUDtemplate_FK_Control_FILL.Replace("#txt#", returnVAL[1]);

                            //JS - store it to COMBO
                            CRUDtemplate_FK_Control_FILL_COMBO += CRUDtemplate_FK_Control_FILL_COMBO_template.Replace("#table#", returnVAL[2]).Replace("#TXT#", returnVAL[1]).Replace("#PK#", returnVAL[0]).Replace("#FK_NAME#", fields.field_name);

                            joins += "\r\n LEFT JOIN " + returnVAL[2] + " ON " + returnVAL[2] + "." + returnVAL[0] + " = " + table_name + "." + fields.field_name;

                            //add select element when foreign key found!
                            rows += PHPSelectDetailTemplateCOL_COMBO.Replace("*field*", fields.field_name) + "\r\n";

                            select_fields          += returnVAL[2] + "." + returnVAL[1] + " as " + fields.field_name + ", ";
                            select_fields_wo_joins += fields.field_name + ", ";
                        }
                        else if (fields.field_type.ToLower() == "bit" && chkBIT.Checked)
                        {
                            rows                   += PHPSelectDetailTemplateCOL_CHECK.Replace("*field*", fields.field_name) + "\r\n";
                            select_fields          += fields.field_name + ", ";
                            select_fields_wo_joins += fields.field_name + ", ";

                            CRUDtemplate_FK_Control_FILL_CHECKinit += CRUDtemplate_FK_Control_FILL_CHECKinit_template.Replace("*field*", fields.field_name);


                            CRUDtemplate_SAVE_CHECK_validation += CRUDtemplate_SAVE_CHECK_validation_template.Replace("*field*", fields.field_name).Replace("*0var*", "0");
                        }
                        else if (fields.field_type.ToLower() == "tinyint" && chkTINYINT.Checked)
                        {
                            rows                   += PHPSelectDetailTemplateCOL_CHECK.Replace("*field*", fields.field_name) + "\r\n";
                            select_fields          += fields.field_name + ", ";
                            select_fields_wo_joins += fields.field_name + ", ";

                            CRUDtemplate_FK_Control_FILL_CHECKinit += CRUDtemplate_FK_Control_FILL_CHECKinit_template.Replace("*field*", fields.field_name);

                            CRUDtemplate_SAVE_CHECK_validation += CRUDtemplate_SAVE_CHECK_validation_template.Replace("*field*", fields.field_name).Replace("*0var*", "\"0\"");
                        }
                        else if (chkDATE.Checked && fields.field_type.ToLower() == "date")
                        {
                            rows                   += PHPSelectDetailTemplateCOL_DTP.Replace("*field*", fields.field_name) + "\r\n";
                            select_fields          += fields.field_name + ", ";
                            select_fields_wo_joins += fields.field_name + ", ";

                            CRUDtemplate_FK_Control_FILL_DTPinit += CRUDtemplate_FK_Control_FILL_DTPinit_template.Replace("*field*", fields.field_name);
                        }
                        else if (chkDATEmalot.Checked && fields.field_type.ToLower() == "date")
                        {
                            rows                   += PHPSelectDetailTemplateCOL_DTPmalot.Replace("*field*", fields.field_name) + "\r\n";
                            select_fields          += "DATE_FORMAT(" + fields.field_name + ",'%d-%m-%Y') as " + fields.field_name + ", ";
                            select_fields_wo_joins += "DATE_FORMAT(" + fields.field_name + ",'%d-%m-%Y') as " + fields.field_name + ", ";

                            CRUDtemplate_Control_DTPtime_init += CRUDtemplate_Control_DTPmalot_init_template.Replace("*field*", fields.field_name);

                            CRUDtemplate_SAVE_DTPTime_validation += CRUDtemplate_SAVE_DTPmalot_validation_template.Replace("*field*", fields.field_name);

                            save_prepared += "$stmt->bindValue(':" + fields.field_name + "' , $" + fields.field_name + ");\r\n";
                        }
                        else if (chkDATETIME.Checked && fields.field_type.ToLower() == "datetime")
                        {
                            rows                   += PHPSelectDetailTemplateCOL_DTPtime.Replace("*field*", fields.field_name) + "\r\n";
                            select_fields          += "DATE_FORMAT(" + fields.field_name + ",'%d-%m-%Y %H:%i') as " + fields.field_name + ", ";
                            select_fields_wo_joins += "DATE_FORMAT(" + fields.field_name + ",'%d-%m-%Y %H:%i') as " + fields.field_name + ", ";

                            CRUDtemplate_Control_DTPtime_init += CRUDtemplate_Control_DTPtime_init_template.Replace("*field*", fields.field_name);

                            CRUDtemplate_SAVE_DTPTime_validation += CRUDtemplate_SAVE_DTPTime_validation_template.Replace("*field*", fields.field_name);

                            //if (chkDATETIME.Checked && fields.field_type.ToLower() == "datetime")
                            save_prepared += "$stmt->bindValue(':" + fields.field_name + "' , $" + fields.field_name + ");\r\n";
                        }
                        else
                        {
                            if (first_field.Length == 0)
                            {
                                first_field = fields.field_name;
                            }


                            rows                   += PHPSelectDetailTemplateCOL.Replace("*field*", fields.field_name).Replace("*fieldsize*", fields.field_size) + "\r\n";
                            select_fields          += fields.field_name + ", ";
                            select_fields_wo_joins += fields.field_name + ", ";

                            jsonValidator         += jsonValidator_template.Replace("*field*", fields.field_name) + "\r\n";
                            jsonValidator_message += jsonValidator_message_template.Replace("*field*", fields.field_name) + "\r\n";
                        }

                        //countDetail += 1;
                    }


                    //tab_customers.php
                    fieldnames += "	'" + fields.field_name + "',\r\n";
                }//table fields end

                //.php
                top_item = top_item_template.Replace("#utable#", table_name.ToUpper());
                top_item = top_item.Replace("#ltable#", table_name.ToLower());
                top_item = top_item.Replace("#PK#", PK.ToLower());
                top_item = top_item.Replace("#table_cols#", CRUD2template_main_TABLE_Item);
                top_item = top_item.Replace("#controls#", rows.Replace("<div class=\"col-xs-6 col-md-4\">", "").Replace("</div>\r\n			</div>", "</div>"));
                top_item = top_item.Replace("#first_field#", first_field);
                top_item = top_item.Replace("#dbase2form#", dbase2form);
                top_item = top_item.Replace("#jsonValidator_template#", jsonValidator);
                top_item = top_item.Replace("#jsonValidator_message#", jsonValidator_message);
                top_item = top_item.Replace("#FKs#", CRUDtemplate_FK_Control_FILL);
                top_item = top_item.Replace("#FKs_JS#", CRUDtemplate_FK_Control_FILL_COMBO + "\r\n" + CRUDtemplate_FK_Control_FILL_CHECKinit + CRUDtemplate_FK_Control_FILL_DTPinit + CRUDtemplate_Control_DTPtime_init);

                File.WriteAllText(apppath + "tab_" + table_name + ".php", top_item, outputEnc);


                //_pagination.php
                if (select_fields.Length > 2)
                {
                    select_fields          = select_fields.Substring(0, select_fields.Length - 2);
                    select_fields_wo_joins = select_fields_wo_joins.Substring(0, select_fields_wo_joins.Length - 2);
                }

                CRUD2template_pagination = CRUD2template_pagination_template.Replace("#cols#", col_names);
                CRUD2template_pagination = CRUD2template_pagination.Replace("#select_cols#", select_fields);
                CRUD2template_pagination = CRUD2template_pagination.Replace("#table#", table_name);
                CRUD2template_pagination = CRUD2template_pagination.Replace("#joins#", joins);
                File.WriteAllText(apppath + "tab_" + table_name + "_pagination.php", CRUD2template_pagination, outputEnc);


                //_fetch.php
                CRUD2template_fetch = CRUD2template_fetch_template.Replace("*table*", table_name).Replace("*PK*", PK).Replace("*select*", select_fields_wo_joins);//select_fields);
                File.WriteAllText(apppath + "tab_" + table_name + "_fetch.php", CRUD2template_fetch, outputEnc);

                //_delete.php
                CRUD2template_delete = CRUD2template_delete_template.Replace("*table*", table_name).Replace("*PK*", PK);
                File.WriteAllText(apppath + "tab_" + table_name + "_delete.php", CRUD2template_delete, outputEnc);

                //_save.php
                //tab_customers_details_save
                if (insertFields.Length > 0)
                {
                    insertFields = insertFields.Substring(0, insertFields.Length - 2);
                    insertVAL    = insertVAL.Substring(0, insertVAL.Length - 2);
                    updateVAL    = updateVAL.Substring(0, updateVAL.Length - 2);

                    if (post_validation.Length > 4)
                    {
                        post_validation = post_validation.Substring(0, post_validation.Length - 4);
                    }


                    string template = DBManager.Properties.Resources.CRUD2template_save;

                    template = template.Replace("#validation#", post_validation);
                    template = template.Replace("#updateWhere#", PK);
                    template = template.Replace("#tblname#", table_name);
                    template = template.Replace("#updateVAL#", updateVAL);
                    template = template.Replace("#insertFields#", insertFields);
                    template = template.Replace("#insertVAL#", insertVAL);
                    template = template.Replace("#stmt#", save_prepared);
                    template = template.Replace("#checkboxes#", CRUDtemplate_SAVE_CHECK_validation);
                    template = template.Replace("#dtptimes#", CRUDtemplate_SAVE_DTPTime_validation);

                    File.WriteAllText(apppath + "tab_" + table_name + "_save.php", template, outputEnc);
                }
                else
                {
                    General.Mes("Error on " + table_name + "_save.php", MessageBoxIcon.Exclamation);
                }
            }//tables loop
        }
Пример #11
0
        private void do_template_adminLTE()
        {
            string table_name;

            string top_item_template = DBManager.Properties.Resources.CRUDtemplate_top_item;
            string top_item          = "";

            string table_template = DBManager.Properties.Resources.CRUDtemplate_table;
            string table_item     = "";
            string fieldnames     = "";
            string PK             = "";

            string table_delete_template = DBManager.Properties.Resources.CRUDtemplate_delete;
            string table_delete          = "";

            //DETAILS
            string table_detail_template              = DBManager.Properties.Resources.CRUDtemplate_detail;
            string table_detail                       = "";
            string PHPSelectDetailTemplateCOL         = DBManager.Properties.Resources.PHPpagesSELECTdetailCOL;
            string PHPSelectDetailTemplateCOL_COMBO   = DBManager.Properties.Resources.PHPpagesSELECTdetailCOL_COMBO;
            string PHPSelectDetailTemplateCOL_CHECK   = DBManager.Properties.Resources.PHPpagesSELECTdetailCOL_CHECK;
            string PHPSelectDetailTemplateCOL_DTP     = DBManager.Properties.Resources.PHPpagesSELECTdetailCOL_DTP;
            string PHPSelectDetailTemplateCOL_DTPtime = DBManager.Properties.Resources.PHPpagesSELECTdetailCOL_DTPtime;

            string CRUDtemplate_FK_Control_FILL_template           = DBManager.Properties.Resources.CRUDtemplate_FK_Control_FILL;
            string CRUDtemplate_FK_Control_FILL                    = "";
            string CRUDtemplate_FK_Control_FILL_COMBO_template     = DBManager.Properties.Resources.CRUDtemplate_FK_Control_FILL_COMBO;
            string CRUDtemplate_FK_Control_FILL_COMBO              = "";
            string CRUDtemplate_FK_Control_FILL_CHECKinit_template = "	$(\"[name='*field*']\").bootstrapSwitch();\r\n";
            string CRUDtemplate_FK_Control_FILL_CHECKinit          = "";
            string CRUDtemplate_FK_Control_FILL_DTPinit_template   = DBManager.Properties.Resources.CRUDtemplate_Control_DTP_init;
            string CRUDtemplate_FK_Control_FILL_DTPinit            = "";
            string CRUDtemplate_Control_DTPtime_init_template      = DBManager.Properties.Resources.CRUDtemplate_Control_DTPtime_init;
            string CRUDtemplate_Control_DTPtime_init               = "";
            string joins = "";

            string CRUDtemplate_SAVE_CHECK_validation_template = DBManager.Properties.Resources.CRUDtemplate_save_checkbox_validation;
            string CRUDtemplate_SAVE_CHECK_validation          = "";

            string CRUDtemplate_SAVE_DTPTime_validation_template = DBManager.Properties.Resources.CRUDtemplate_save_dtptime_validation;
            string CRUDtemplate_SAVE_DTPTime_validation          = "";

            string CRUDtemplate_Control_DTPmalot_init_template    = DBManager.Properties.Resources.CRUDtemplate_Control_DTPmalot;
            string PHPSelectDetailTemplateCOL_DTPmalot            = DBManager.Properties.Resources.PHPpagesSELECTdetailCOL_DTPmalot;
            string CRUDtemplate_SAVE_DTPmalot_validation_template = DBManager.Properties.Resources.CRUDtemplate_save_dtpmalot_validation;

            string PHPSelectDetailTemplateDB2FORM      = "		$('[name=*field*]').val(jArray[0][\"*field*\"]);";
            string PHPSelectDetailTemplateDB2FORMcheck = "		$('[name=*field*]').bootstrapSwitch('state',parseInt(jArray[0][\"*field*\"]));";
            string tmp8 = "";
            string rows = "";
            //int count = 0;
            int countDetail = 0;


            //save vars
            string insertFields    = "";
            string insertVAL       = "";
            string updateVAL       = "";
            string bind            = "";
            string post_validation = "";

            string apppath = Application.StartupPath + "\\" + txtFolder.Text + "\\";

            string select_fields = "";


            foreach (treeItem2 tbl in tables)
            {
                table_name = tbl.table_name;

                joins = select_fields = fieldnames = PK = table_item = tmp8 = rows = insertFields = insertVAL = updateVAL = post_validation = bind =
                    CRUDtemplate_FK_Control_FILL           = CRUDtemplate_FK_Control_FILL_COMBO = CRUDtemplate_FK_Control_FILL_CHECKinit = CRUDtemplate_SAVE_CHECK_validation =
                        CRUDtemplate_SAVE_CHECK_validation = CRUDtemplate_FK_Control_FILL_DTPinit = CRUDtemplate_Control_DTPtime_init = CRUDtemplate_SAVE_DTPTime_validation = "";

                countDetail = 0;
                //table name - generic use


                //template_top.php
                top_item += top_item_template.Replace("#table#", table_name);

                foreach (treeItem2fields fields in tbl.table_fields)
                {
                    if (fields.field_PK)
                    {
                        PK             = fields.field_name;
                        select_fields += PK + ", ";
                    }
                    else
                    {
                        insertFields += fields.field_name + ", ";
                        insertVAL    += ":" + fields.field_name + ", ";

                        updateVAL += fields.field_name + "=:" + fields.field_name + ", ";



                        //details.php
                        if (fields.field_type.ToLower() == "bit" && chkBIT.Checked)
                        {
                            bind += "$stmt->bindValue(':" + fields.field_name + "' , $" + fields.field_name + ", PDO::PARAM_INT);\r\n";
                            tmp8 += PHPSelectDetailTemplateDB2FORMcheck.Replace("*field*", fields.field_name) + "\r\n";
                        }
                        else if (fields.field_type.ToLower() == "tinyint" && chkTINYINT.Checked)
                        {
                            bind += "$stmt->bindValue(':" + fields.field_name + "' , $" + fields.field_name + ", PDO::PARAM_INT);\r\n";
                            tmp8 += PHPSelectDetailTemplateDB2FORMcheck.Replace("*field*", fields.field_name) + "\r\n";
                        }
                        else
                        {
                            post_validation += "!isset($_POST['" + fields.field_name + "']) || ";

                            bind += "$stmt->bindValue(':" + fields.field_name + "' , $_POST['" + fields.field_name + "']);\r\n";
                            tmp8 += PHPSelectDetailTemplateDB2FORM.Replace("*field*", fields.field_name) + "\r\n";
                        }


                        if (countDetail % 3 == 0)
                        {
                            if (countDetail > 0)
                            {
                                rows += "		</div>\r\n\r\n";
                            }


                            rows += "		<div class=\"row\">\r\n";
                        }

                        string[] returnVAL = check4tie(fields.field_name);
                        //0 - ID // 1 - TXT // 2 - TABLE

                        if (returnVAL[0] != null && returnVAL[1] != null && returnVAL[2] != null)
                        {
                            //PHP - read values from original tables (aka FOREIGN)
                            CRUDtemplate_FK_Control_FILL += CRUDtemplate_FK_Control_FILL_template.Replace("#table#", returnVAL[2]).Replace("#txt#", returnVAL[1]);
                            //CRUDtemplate_FK_Control_FILL += CRUDtemplate_FK_Control_FILL.Replace("#txt#", returnVAL[1]);

                            //JS - store it to COMBO
                            CRUDtemplate_FK_Control_FILL_COMBO += CRUDtemplate_FK_Control_FILL_COMBO_template.Replace("#table#", returnVAL[2]).Replace("#TXT#", returnVAL[1]).Replace("#PK#", returnVAL[0]).Replace("#FK_NAME#", fields.field_name);

                            joins += "\r\n LEFT JOIN " + returnVAL[2] + " ON " + returnVAL[2] + "." + returnVAL[0] + " = " + table_name + "." + fields.field_name;

                            //add select element when foreign key found!
                            rows += PHPSelectDetailTemplateCOL_COMBO.Replace("*field*", fields.field_name) + "\r\n";

                            select_fields += returnVAL[2] + "." + returnVAL[1] + " as " + fields.field_name + ", ";
                        }
                        else if (fields.field_type.ToLower() == "bit" && chkBIT.Checked)
                        {
                            rows          += PHPSelectDetailTemplateCOL_CHECK.Replace("*field*", fields.field_name) + "\r\n";
                            select_fields += fields.field_name + ", ";

                            CRUDtemplate_FK_Control_FILL_CHECKinit += CRUDtemplate_FK_Control_FILL_CHECKinit_template.Replace("*field*", fields.field_name);


                            CRUDtemplate_SAVE_CHECK_validation += CRUDtemplate_SAVE_CHECK_validation_template.Replace("*field*", fields.field_name).Replace("*0var*", "0");
                        }
                        else if (fields.field_type.ToLower() == "tinyint" && chkTINYINT.Checked)
                        {
                            rows          += PHPSelectDetailTemplateCOL_CHECK.Replace("*field*", fields.field_name) + "\r\n";
                            select_fields += fields.field_name + ", ";

                            CRUDtemplate_FK_Control_FILL_CHECKinit += CRUDtemplate_FK_Control_FILL_CHECKinit_template.Replace("*field*", fields.field_name);

                            CRUDtemplate_SAVE_CHECK_validation += CRUDtemplate_SAVE_CHECK_validation_template.Replace("*field*", fields.field_name).Replace("*0var*", "\"0\"");
                        }
                        else if (chkDATE.Checked && fields.field_type.ToLower() == "date")
                        {
                            rows          += PHPSelectDetailTemplateCOL_DTP.Replace("*field*", fields.field_name) + "\r\n";
                            select_fields += fields.field_name + ", ";

                            CRUDtemplate_FK_Control_FILL_DTPinit += CRUDtemplate_FK_Control_FILL_DTPinit_template.Replace("*field*", fields.field_name);
                        }
                        else if (chkDATEmalot.Checked && fields.field_type.ToLower() == "date")
                        {
                            rows          += PHPSelectDetailTemplateCOL_DTPmalot.Replace("*field*", fields.field_name) + "\r\n";
                            select_fields += "DATE_FORMAT(" + fields.field_name + ",'%d-%m-%Y') as " + fields.field_name + ", ";

                            CRUDtemplate_Control_DTPtime_init += CRUDtemplate_Control_DTPmalot_init_template.Replace("*field*", fields.field_name);

                            CRUDtemplate_SAVE_DTPTime_validation += CRUDtemplate_SAVE_DTPmalot_validation_template.Replace("*field*", fields.field_name);
                        }
                        else if (chkDATETIME.Checked && fields.field_type.ToLower() == "datetime")
                        {
                            rows          += PHPSelectDetailTemplateCOL_DTPtime.Replace("*field*", fields.field_name) + "\r\n";
                            select_fields += "DATE_FORMAT(" + fields.field_name + ",'%d-%m-%Y %H:%i') as " + fields.field_name + ", ";

                            CRUDtemplate_Control_DTPtime_init += CRUDtemplate_Control_DTPtime_init_template.Replace("*field*", fields.field_name);

                            CRUDtemplate_SAVE_DTPTime_validation += CRUDtemplate_SAVE_DTPTime_validation_template.Replace("*field*", fields.field_name);
                        }
                        else
                        {
                            rows          += PHPSelectDetailTemplateCOL.Replace("*field*", fields.field_name) + "\r\n";
                            select_fields += fields.field_name + ", ";
                        }

                        countDetail += 1;
                    }

                    //tab_customers.php
                    fieldnames += "	'" + fields.field_name + "',\r\n";
                }//table fields end

                rows += "		</div>\r\n\r\n";

                //tab_customers.php
                table_item += table_template.Replace("#table#", table_name);
                table_item  = table_item.Replace("#fields#", fieldnames);
                table_item  = table_item.Replace("#PK#", PK);
                table_item  = table_item.Replace("#joins#", joins);

                if (select_fields.Length > 2)
                {
                    select_fields = select_fields.Substring(0, select_fields.Length - 2);
                    table_item    = table_item.Replace("#select#", select_fields);
                }
                else
                {
                    General.Mes("Error on " + table_name + "tab_table.php", MessageBoxIcon.Exclamation);
                }


                File.WriteAllText(apppath + "tab_" + table_name + ".php", table_item, outputEnc);

                //tab_customers_delete.php
                table_delete = table_delete_template.Replace("#table#", table_name);
                table_delete = table_delete.Replace("#PK#", PK);
                File.WriteAllText(apppath + "tab_" + table_name + "_delete.php", table_delete, outputEnc);

                //tab_customers_details_save
                if (insertFields.Length > 0)
                {
                    insertFields    = insertFields.Substring(0, insertFields.Length - 2);
                    insertVAL       = insertVAL.Substring(0, insertVAL.Length - 2);
                    updateVAL       = updateVAL.Substring(0, updateVAL.Length - 2);
                    post_validation = post_validation.Substring(0, post_validation.Length - 4);


                    string template = DBManager.Properties.Resources.CRUDtemplate_save;

                    template = template.Replace("#validation#", post_validation);
                    template = template.Replace("#updateWhere#", PK);
                    template = template.Replace("#tblname#", table_name);
                    template = template.Replace("#updateVAL#", updateVAL);
                    template = template.Replace("#insertFields#", insertFields);
                    template = template.Replace("#insertVAL#", insertVAL);
                    template = template.Replace("#stmt#", bind);
                    template = template.Replace("#checkboxes#", CRUDtemplate_SAVE_CHECK_validation);
                    template = template.Replace("#dtptimes#", CRUDtemplate_SAVE_DTPTime_validation);

                    File.WriteAllText(apppath + "tab_" + table_name + "_details_save.php", template, outputEnc);
                }
                else
                {
                    General.Mes("Error on " + table_name + "_save.php", MessageBoxIcon.Exclamation);
                }


                //details.php
                table_detail = table_detail_template.Replace("#table#", table_name);
                table_detail = table_detail.Replace("#PK#", PK);
                table_detail = table_detail.Replace("#db2form#", tmp8);
                table_detail = table_detail.Replace("#rows#", rows);
                table_detail = table_detail.Replace("#FKs#", CRUDtemplate_FK_Control_FILL);
                table_detail = table_detail.Replace("#FKs_JS#", CRUDtemplate_FK_Control_FILL_COMBO + "\r\n" + CRUDtemplate_FK_Control_FILL_CHECKinit + CRUDtemplate_FK_Control_FILL_DTPinit + CRUDtemplate_Control_DTPtime_init);


                File.WriteAllText(apppath + "tab_" + table_name + "_details.php", table_detail, outputEnc);
            }//table loop

            //DONT WRITE UTF8 MARGIN TOP+DOWN appear! LOL
            File.WriteAllText(apppath + "template_top.php", DBManager.Properties.Resources.CRUDtemplate_top.Replace("#tables#", top_item));

            if (General.DB is SQLite)
            {
                File.WriteAllText(apppath + "config.php", DBManager.Properties.Resources.CRUDtemplate_config_sqlite.Replace("#filename#", Path.GetFileName(General.Connections[General.activeConnection].filename)), outputEnc);
            }
            else
            {
                File.WriteAllText(apppath + "config.php", DBManager.Properties.Resources.CRUDtemplate_config_mysql, outputEnc);
            }
        }
Пример #12
0
        private void cmbSourceServer_SelectedIndexChanged(object sender, EventArgs e)
        {
            cmbSourceServer.Enabled = false;
            Cursor = System.Windows.Forms.Cursors.WaitCursor;

            if (cmbSourceServer.Text.Length == 0)
            {
                return;
            }
            else
            {
                btnHelp.Visible = false;
            }

            try
            {
                if ((General.dbTypes)General.Connections[cmbSourceServer.SelectedIndex].TYPE == General.dbTypes.SQLSERVER)
                {
                    sourceDB = new SQLServer(cmbSourceServer.SelectedIndex, null);
                }
                else if ((General.dbTypes)General.Connections[cmbSourceServer.SelectedIndex].TYPE == General.dbTypes.MySQL)
                {
                    sourceDB = new MySQL(cmbSourceServer.SelectedIndex, null);
                }
                else if ((General.dbTypes)General.Connections[cmbSourceServer.SelectedIndex].TYPE == General.dbTypes.SQLite)
                {
                    sourceDB = new SQLite(cmbSourceServer.SelectedIndex, null);
                }
                else if ((General.dbTypes)General.Connections[cmbSourceServer.SelectedIndex].TYPE == General.dbTypes.MySQLtunnel)
                {
                    sourceDB = new MySQLTunnel(cmbSourceServer.SelectedIndex, null);
                }
                else if ((General.dbTypes)General.Connections[cmbSourceServer.SelectedIndex].TYPE == General.dbTypes.Access)
                {
                    sourceDB        = new ADOnet(cmbSourceServer.SelectedIndex, null);
                    btnHelp.Visible = true;
                    btnHelp.Tag     = DBManager.Properties.Resources.helpEXCEL;
                }
                else if ((General.dbTypes)General.Connections[cmbSourceServer.SelectedIndex].TYPE == General.dbTypes.SQLSERVERtunnel)
                {
                    sourceDB = new SQLServerTunnel(cmbSourceServer.SelectedIndex, null);
                }

                //   sourceDB.Connect();

                General.Mes(sourceDB.Connect(), MessageBoxIcon.Exclamation); //IF ERROR occured in class


                List <String> tblsFROM = sourceDB.getTables();
                if (tblsFROM.Count == 0)
                {
                    return;
                }

                cmbFROM.Items.Add("[-Custom Query-]");

                foreach (string item in tblsFROM)
                {
                    cmbFROM.Items.Add(item);
                }

                List <String> tblsTO = General.DB.getTables();
                foreach (string item in tblsTO)
                {
                    cmbTO.Items.Add(item);
                }

                cmbFROM.DroppedDown = true;
            }
            catch (Exception ex)
            {
                cmbFROM.Items.Clear();
                General.Mes(ex.Message, MessageBoxIcon.Exclamation);
            }
            finally
            {
                //cmbSourceServer.Enabled = true;
                Cursor = System.Windows.Forms.Cursors.Default;
            }
        }
Пример #13
0
        //List<string> sourceFields4mySQLtunnel = new List<string>();
        //List<string> destFieldsT4mySQLtunnel = new List<string>();
        //DataTable sourceDT4mySQLtunnel=null;
        //int sourceDT4mySQLtunnel_counter = 0;
        //private void mySQLtunnel_CopyRows(object sender, WaitWindowEventArgs e)
        //{
        //    sourceDT4mySQLtunnel_counter = -1;
        //    mySQLtunnel_CopyRows2();
        //}

        //private void mySQLtunnel_CopyRows2()
        //{
        //    sourceDT4mySQLtunnel_counter += 1;

        //    if (sourceDT4mySQLtunnel_counter < sourceDT4mySQLtunnel.Rows.Count)
        //    {
        //        //WebPostRequest myPost = new WebPostRequest("http://localhost/sensor.php");
        //        //myPost.Add("keyword", "void");
        //        //myPost.Add("data", "hello&+-[]");
        //        //Console.WriteLine(myPost.GetResponse());
        //        //Console.ReadLine();
        //        string result = null;
        //        using (var wb = new WebClient())
        //        {
        //            var parameters = new NameValueCollection();
        //            parameters["sql"] = "{\"q\": \"" + General.SafeJSON(sql) + "\"}";
        //            parameters["p"] = General.Connections[ConnIndex].password;

        //            var response = wb.UploadValues(General.Connections[ConnIndex].serverName, "POST", parameters);
        //            result=Encoding.UTF8.GetString(response);
        //        }
        //    }

        //}



        private void CopyRows(object sender, WaitWindowEventArgs e)
        {
            string        INSsql       = (string)e.Arguments[0];
            DataTable     sourceDT     = (DataTable)e.Arguments[1];
            List <string> sourceFields = (List <string>)e.Arguments[2];
            List <string> destFields   = (List <string>)e.Arguments[3];
            string        toTable      = (string)e.Arguments[4];

            General.dbTypes destDBtype = (General.dbTypes)e.Arguments[5];

            if (chkIDENTITY.Checked)
            {
                INSsql = "SET IDENTITY_INSERT " + toTable + " ON; " + INSsql;
            }

            IDbCommand command = null;

            if (destDBtype == General.dbTypes.SQLSERVER)
            {
                command = new SqlCommand(INSsql);
            }
            else if (destDBtype == General.dbTypes.MySQL)
            {
                command = new MySqlCommand(INSsql);
            }
            else if (destDBtype == General.dbTypes.SQLite)
            {
                command = new SQLiteCommand(INSsql);
            }
            else if (destDBtype == General.dbTypes.Access)
            {
                command = new OleDbCommand(INSsql);
            }


            //transaction
            //http://msdn.microsoft.com/en-us/library/system.data.idbtransaction.aspx
            //http://msdn.microsoft.com/en-us/library/86773566.aspx
            IDbTransaction transaction = null;

            transaction = General.DB.getConnection().BeginTransaction();

            //command
            command.Connection  = General.DB.getConnection();
            command.Transaction = transaction;

            //for all records
            int Count = sourceDT.Rows.Count;
            IDbDataParameter parameter = null;



            try
            {
                for (int i = 0; i < sourceDT.Rows.Count; i++)
                {
                    e.Window.Message = "Copying " + i.ToString() + " of " + Count.ToString();

                    command.Parameters.Clear();
                    command.CommandText = INSsql;

                    //for all columns
                    for (int x = 0; x < sourceFields.Count; x++)
                    {
                        //create new parameter
                        parameter = command.CreateParameter();
                        parameter.ParameterName = "@" + destFields[x];
                        parameter.Value         = sourceDT.Rows[i][sourceFields[x]];

                        //sqlserver get from accdb works without this
                        //if (sourceDT.Rows[i][sourceFields[x]].GetType() == typeof(System.Byte[]))
                        //    parameter.DbType = DbType.Binary;

                        //add to command
                        command.Parameters.Add(parameter);

                        //command.Parameters.Add( AddWithValue("@" + destFields[x], sourceDT.Rows[i][sourceFields[x]]);
                    }

                    command.ExecuteNonQuery();
                }

                e.Result = "ok";

                transaction.Commit();
                transaction.Dispose();
            }
            catch (Exception ex)
            {
                // Attempt to roll back the transaction.
                try
                {
                    transaction.Rollback();
                }
                catch (Exception ex2)
                {
                    // This catch block will handle any errors that may have occurred
                    // on the server that would cause the rollback to fail, such as
                    // a closed connection.
                    General.Mes("Rollback Exception Type: " + ex2.GetType() + "\r\nMessage: " + ex2.Message);
                }

                e.Result = ex.Message;
            }
            finally
            {
                if (command != null)
                {
                    command.Dispose();
                }

                if (sourceDT != null)
                {
                    sourceDT.Dispose();
                }
            }
        }