Beispiel #1
0
        private bool sendDataToCabangMultipleFiles(int branchID, string ipServerBranch = "")
        {
            Data_Access DS_BRANCH = new Data_Access();
            bool        result    = false;

            // CONNECT TO BRANCH

            if (DS_BRANCH.Branch_mySQLConnect(branchID, ipServerBranch))
            {
                result = syncLocalDataToServerMultipleFiles(DS_BRANCH, Data_Access.BRANCH_SERVER);

                // CLOSE BRANCH CONNECTION
                DS_BRANCH.Branch_mySqlClose();
            }

            return(result);
        }
Beispiel #2
0
        private bool clearDataCabang(string tableName, int branchID, string ipServerBranch = "")
        {
            Data_Access    DS_BRANCH  = new Data_Access();
            bool           result     = false;
            string         sqlCommand = "";
            MySqlException internalEX = null;

            // CONNECT TO BRANCH
            if (DS_BRANCH.Branch_mySQLConnect(branchID, ipServerBranch))
            {
                DS_BRANCH.beginTransaction(Data_Access.BRANCH_SERVER);

                try
                {
                    sqlCommand = "DELETE FROM " + tableName;

                    if (!DS_BRANCH.executeNonQueryCommand(sqlCommand))
                    {
                        throw internalEX;
                    }

                    DS_BRANCH.commit();
                    result = true;
                }
                catch (Exception ex)
                {
                    gUtil.saveSystemDebugLog(0, "[SYNC CABANG] FAILED TO CLEAR DATA CABANG [" + ex.Message + "]");
                }

                // CLOSE BRANCH CONNECTION
                DS_BRANCH.Branch_mySqlClose();
            }
            else
            {
                gUtil.saveSystemDebugLog(0, "[SYNC CABANG] FAILED TO CONNECT TO CABANG");
            }

            return(result);
        }
Beispiel #3
0
        private string createUpdateQueryDataCabang(int branchID, string tableName, string PKField, List <string> fieldToBackup, string ipServerBranch = "")
        {
            Data_Access DS_BRANCH = new Data_Access();
            //bool result = false;
            string sqlCommand = "";

            MySqlDataReader rdr;
            string          fieldName;
            object          DBValue          = null;
            int             rdrFieldIndex    = 0;
            int             startIndex       = 0;
            StreamWriter    sw               = null;
            string          fileName         = "";
            string          commandStatement = "";
            string          valueStatement   = "";
            string          fieldValueForPK  = "";

            fileName = "EXPORT_" + branchID + "_DATA_" + tableName + ".sql";

            if (!File.Exists(fileName))
            {
                sw = File.CreateText(fileName);
            }
            else
            {
                File.Delete(fileName);
                sw = File.CreateText(fileName);
            }

            // CONNECT TO BRANCH
            if (DS_BRANCH.Branch_mySQLConnect(branchID, ipServerBranch))
            {
                sqlCommand = "SELECT * FROM " + tableName;

                using (rdr = DS_BRANCH.getData(sqlCommand, false, true))
                {
                    if (rdr.HasRows)
                    {
                        while (rdr.Read())
                        {
                            commandStatement = "UPDATE " + tableName + " SET ";
                            valueStatement   = "";
                            for (rdrFieldIndex = startIndex; rdrFieldIndex < rdr.FieldCount; rdrFieldIndex++)
                            {
                                DBValue = rdr.GetValue(rdrFieldIndex);

                                if (DBValue.ToString().Length > 0)
                                {
                                    fieldName = rdr.GetName(rdrFieldIndex);

                                    if (!fieldToSkip.Contains(fieldName) && fieldName != PKField)
                                    {
                                        continue;
                                    }

                                    if (fieldName != PKField)
                                    {
                                        valueStatement = valueStatement + fieldName + " = " + "'" + Convert.ToString(rdr.GetValue(rdrFieldIndex)) + "', ";
                                    }
                                    else
                                    {
                                        fieldValueForPK = Convert.ToString(rdr.GetValue(rdrFieldIndex));
                                    }
                                }
                            }

                            valueStatement   = valueStatement.Substring(0, valueStatement.Length - 2);
                            commandStatement = commandStatement + valueStatement;
                            commandStatement = commandStatement + " WHERE " + PKField + " = '" + fieldValueForPK + "';";

                            sw.WriteLine(commandStatement);
                        }
                    }
                }
                rdr.Close();

                // CLOSE BRANCH CONNECTION
                DS_BRANCH.Branch_mySqlClose();

                //result = true;
            }
            else
            {
                gUtil.saveSystemDebugLog(0, "[SYNC CABANG] FAILED TO CONNECT TO CABANG");
            }

            sw.Close();
            return(fileName);
        }