Esempio n. 1
0
        internal bool Write2DB(Database_Upgrade_WindowsForm_Thread wfp_ui_thread,UpgradeDB_inThread.eUpgrade eUpgr,Old_tables_1_04_to_1_05 m_Old_tables_1_04_to_1_05)
        {
            string Err = null;
            foreach (TableDataItem xtdi in fkey_TableDataItem_List)
            {
                xtdi.Write2DB(wfp_ui_thread, eUpgr, m_Old_tables_1_04_to_1_05);
            }

            if (eUpgr == UpgradeDB_inThread.eUpgrade.from_1_04_to_105)
            {
                if (this.tbl.TableName.ToLower().Equals("pricelist"))
                {
                    if (GlobalData.Office_ID<0)
                    {
                        string sql = "insert into Office (myOrganisation_ID,Name)values(1,'P1')";
                        object oret = null;
                        if (DBSync.DBSync.ExecuteNonQuerySQLReturnID(sql,null,ref GlobalData.Office_ID,ref oret, ref Err,"Office"))
                        {
                            sql = "insert into myOrganisation_Person (UserName,Password,Job,Active,Description,Person_ID,Office_ID)values('marjetkah',null,'Direktor',1,'Direktorica in lastnica podjetja',1,1)";
                            long x_myOrganisation_Person_ID = -1;
                            if (DBSync.DBSync.ExecuteNonQuerySQLReturnID(sql, null, ref x_myOrganisation_Person_ID, ref oret, ref Err, "Office"))
                            {

                            }
                            else
                            {
                                LogFile.Error.Show("ERROR:usrc_Upgrade:Write2DB:sql=" + sql + "\r\nErr=" + Err);
                                return false;
                            }
                        }
                        else
                        {
                            LogFile.Error.Show("ERROR:usrc_Upgrade:Write2DB:sql=" + sql + "\r\nErr=" + Err);
                            return false;
                        }
                    }
                }
                else if (this.tbl.TableName.ToLower().Equals("atom_pricelist"))
                {
                    string sql = null;
                    object oret = null;
                    if (GlobalData.Atom_Office_ID < 0)
                    {
                        sql = "insert into Atom_Office (Atom_myOrganisation_ID,Name)values(1,'P1')";
                        if (!DBSync.DBSync.ExecuteNonQuerySQLReturnID(sql, null, ref GlobalData.Atom_Office_ID, ref oret, ref Err, "Atom_Office"))
                        {
                            LogFile.Error.Show("ERROR:usrc_Upgrade:Write2DB:sql=" + sql + "\r\nErr=" + Err);
                            return false;
                        }
                    }

                    DateTime dtStart = new DateTime(2015, 4, 29);
                    DateTime_v dtEnd_v = new DateTime_v();
                    dtEnd_v.v = DateTime.Now;
                    if (!GlobalData.GetWorkPeriodOld(f_Atom_WorkPeriod.sWorkPeriod_DB_ver_1_04,null,dtStart,dtEnd_v, ref Err))
                    {
                        return false;
                    }

                }
                else if (this.tbl.TableName.ToLower().Equals("docinvoice"))
                {
                    DateTime dtStart = new DateTime(2015, 4, 29);
                    DateTime_v dtEnd_v = new DateTime_v();
                    dtEnd_v.v = DateTime.Now;
                    GlobalData.GetWorkPeriodOld(f_Atom_WorkPeriod.sWorkPeriod_DB_ver_1_04, null, dtStart, dtEnd_v, ref Err);
                }
            }

            string tname = tbl.TableName;
            string sql_insert_columns = null;
            string sql_insert_values = null;
            List<SQL_Parameter> lpar = new List<SQL_Parameter>();
            bool bDocInvoiceTime = false;
            bool bFirstPrintTime = false;
            bool bPaid = false;
            bool bStorno = false;
            foreach (DataRow dr in dt.Rows)
            {
                if (dr["old_id"] is System.DBNull)
                {
                    wfp_ui_thread.Message(lngRPM.s_ImportData.s + ":" + tname);
                    sql_insert_columns = null;
                    sql_insert_values = null;
                    lpar.Clear();
                    long old_id = (long)dr["id"];
                    DateTime_v InvoiceTime_v = null;
                    DateTime_v PaidTime_v = null;
                    DateTime_v StornoTime_v = null;
                    foreach (DataColumn dcol in dt.Columns)
                    {
                        if (dcol.ColumnName.ToUpper().Equals("ID") || dcol.ColumnName.ToUpper().Equals("OLD_ID"))
                        {
                            continue;
                        }
                        else
                        {
                            if (eUpgr == UpgradeDB_inThread.eUpgrade.from_1_04_to_105)
                            {
                                if (dcol.ColumnName.ToLower().Equals("myorganisation_person_id"))
                                {
                                    continue;
                                }
                                if (this.tbl.TableName.ToLower().Equals("atom_pricelist"))
                                {
                                    if (dcol.ColumnName.ToLower().Equals("atom_myorganisation_person_id"))
                                    {
                                        continue;
                                    }
                                }
                                else
                                {
                                    if (this.tbl.TableName.ToLower().Equals("docinvoice"))
                                    {
                                        if (dcol.ColumnName.ToLower().Equals("atom_myorganisation_person_id"))
                                        {
                                            continue;
                                        }
                                    }

                                }
                            }
                        }
                        object o = dr[dcol];
                        string sparname = null;
                        SQL_Parameter par = null;
                        if (new_SQL_Parameter(this, dr, dcol, ref sparname, o, ref par))
                        {
                            if (dcol.ColumnName.ToLower().Equals("paid"))
                            {
                                bPaid = true;
                            }
                            if (dcol.ColumnName.ToLower().Equals("storno"))
                            {
                                bStorno = true;
                            }

                            if (dcol.ColumnName.ToLower().Equals("firstprinttime"))
                            {
                                bFirstPrintTime = true;
                            }
                            else if (dcol.ColumnName.ToLower().Equals("docinvoicetime"))
                            {
                                bDocInvoiceTime = true;
                            }
                            else
                            {
                                if (par != null)
                                {
                                    lpar.Add(par);
                                }
                                if (sql_insert_columns == null)
                                {
                                    sql_insert_columns = dcol.ColumnName;
                                }
                                else
                                {
                                    sql_insert_columns += "," + dcol.ColumnName;
                                }
                                if (sql_insert_values == null)
                                {
                                    sql_insert_values = sparname;
                                }
                                else
                                {
                                    sql_insert_values += "," + sparname;
                                }

                            }
                        }
                        else
                        {
                            return false;
                        }
                    }

                    if (bDocInvoiceTime)
                    {
                        if (dr["docinvoicetime"] is DateTime)
                        {
                            InvoiceTime_v = new DateTime_v();
                            InvoiceTime_v.v = (DateTime)dr["docinvoicetime"];
                        }
                    }

                    if (bPaid)
                    {
                        if (dr["Paid"] is bool)
                        {
                            PaidTime_v = new DateTime_v();
                            PaidTime_v.v = GetDocInvoiceTime(old_id,m_Old_tables_1_04_to_1_05);
                        }
                    }

                    if (bStorno)
                    {
                        if (dr["Storno"] is bool)
                        {
                            if ((bool)dr["Storno"])
                            {
                                StornoTime_v = new DateTime_v();
                                StornoTime_v.v = GetInvoiceStornoTime(old_id, m_Old_tables_1_04_to_1_05);
                            }
                            else
                            {
                                bStorno = false;
                            }
                        }
                    }

                    string sql_insert = " insert into " + tname + " (" + sql_insert_columns + ") values (" + sql_insert_values + ")";
                    long new_id = -1;
                    object ores = null;
                    if (DBSync.DBSync.ExecuteNonQuerySQLReturnID(sql_insert, lpar, ref new_id, ref ores, ref Err, tname))
                    {
                        dr["OLD_ID"] = old_id;
                        dr["id"] = new_id;
                        if (tname.ToLower().Equals("docinvoice"))
                        {
                            long Journal_DocInvoice_ID = -1;
                            f_Journal_DocInvoice.Write(new_id, GlobalData.Atom_WorkPeriod_ID, GlobalData.JOURNAL_DocInvoice_Type_definitions.InvoiceDraftTime.Name, GlobalData.JOURNAL_DocInvoice_Type_definitions.InvoiceDraftTime.Description, InvoiceTime_v, ref Journal_DocInvoice_ID);
                            if (dr["Draft"] is bool)
                            {
                                if (!(bool)dr["Draft"])
                                {
                                    f_Journal_DocInvoice.Write(new_id, GlobalData.Atom_WorkPeriod_ID, GlobalData.JOURNAL_DocInvoice_Type_definitions.InvoiceTime.Name, GlobalData.JOURNAL_DocInvoice_Type_definitions.InvoiceTime.Description ,InvoiceTime_v, ref Journal_DocInvoice_ID);
                                    f_Journal_DocInvoice.Write(new_id, GlobalData.Atom_WorkPeriod_ID, GlobalData.JOURNAL_DocInvoice_Type_definitions.InvoicePaidTime.Name, GlobalData.JOURNAL_DocInvoice_Type_definitions.InvoicePaidTime.Description, InvoiceTime_v, ref Journal_DocInvoice_ID);
                                }
                            }
                        }
                        else if (tname.ToLower().Equals("invoice"))
                        {
                            long Journal_Invoice_ID = -1;
                            f_Journal_DocInvoice.Write(new_id, GlobalData.Atom_WorkPeriod_ID, "Paid", "Plačano", PaidTime_v, ref Journal_Invoice_ID);
                            if (bStorno)
                            {
                                f_Journal_DocInvoice.Write(new_id, GlobalData.Atom_WorkPeriod_ID, "Storno*", "Napaka pri vnosu", StornoTime_v, ref Journal_Invoice_ID);
                            }
                        }
                    }
                    else
                    {
                        LogFile.Error.Show("ERROR:usrc_Upgrade:Write2DB:Err=" + Err);
                        return false;
                    }
                }
            }
            return true;
        }
Esempio n. 2
0
        private object UpgradeDB_1_04_to_1_05(object obj, ref string Err)
        {
            Check_DB_1_04();
            m_Old_tables_1_04_to_1_05 = new Old_tables_1_04_to_1_05();
            if (m_Old_tables_1_04_to_1_05.Read())
            {
                m_eUpgrade = eUpgrade.from_1_04_to_105;
                wfp_ui_thread = new Database_Upgrade_WindowsForm_Thread();
                wfp_ui_thread.Start();

                List<DataTable> dt_List = new List<DataTable>();
                string Message_Title = " 1.04 -> 1.05";

                SQLTable tbl = DBSync.DBSync.DB_for_Tangenta.m_DBTables.GetTable(typeof(PersonData));
                wfp_ui_thread.Message("$$$" + lngRPM.s_UpgradeDatabase.s + Message_Title);
                wfp_ui_thread.Message(lngRPM.s_ReadTable.s + tbl.TableName);
                SQLTable xtbl = new SQLTable(tbl);
                xtbl.CreateTableTree(DBSync.DBSync.DB_for_Tangenta.m_DBTables.items);
                TableDataItem dt_PersonData = new TableDataItem(xtbl, ref dt_List, null, ref Err);
                if (Err != null)
                {

                    wfp_ui_thread.End();
                    LogFile.Error.Show("ERROR:usrc_Upgrade:UpgradeDB_1_04_to_1_05:TableName=" + tbl.TableName + ";Err=" + Err);
                    return false;
                }

                TableDataItem_List.Add(dt_PersonData);

                Err = null;
                Message_Title = " 1.04 -> 1.05";
                tbl = DBSync.DBSync.DB_for_Tangenta.m_DBTables.GetTable(typeof(myOrganisation));
                wfp_ui_thread.Message("$$$" + lngRPM.s_UpgradeDatabase.s + Message_Title);
                wfp_ui_thread.Message(lngRPM.s_ReadTable.s + tbl.TableName);
                xtbl = new SQLTable(tbl);
                xtbl.CreateTableTree(DBSync.DBSync.DB_for_Tangenta.m_DBTables.items);
                TableDataItem dt_myOrganisation = new TableDataItem(xtbl, ref dt_List, null, ref Err);
                if (Err != null)
                {

                    wfp_ui_thread.End();
                    LogFile.Error.Show("ERROR:usrc_Upgrade:UpgradeDB_1_04_to_1_05:TableName=" + tbl.TableName + ";Err=" + Err);
                    return false;
                }
                TableDataItem_List.Add(dt_myOrganisation);

                tbl = DBSync.DBSync.DB_for_Tangenta.m_DBTables.GetTable(typeof(Atom_myOrganisation));
                wfp_ui_thread.Message("$$$" + lngRPM.s_UpgradeDatabase.s + Message_Title);
                wfp_ui_thread.Message(lngRPM.s_ReadTable.s + tbl.TableName);
                xtbl = new SQLTable(tbl);
                xtbl.CreateTableTree(DBSync.DBSync.DB_for_Tangenta.m_DBTables.items);
                TableDataItem dt_Atom_myOrganisation = new TableDataItem(xtbl, ref dt_List, null, ref Err);
                if (Err != null)
                {

                    wfp_ui_thread.End();
                    LogFile.Error.Show("ERROR:usrc_Upgrade:UpgradeDB_1_04_to_1_05:TableName=" + tbl.TableName + ";Err=" + Err);
                    return false;
                }
                TableDataItem_List.Add(dt_Atom_myOrganisation);

                tbl = DBSync.DBSync.DB_for_Tangenta.m_DBTables.GetTable(typeof(Price_Item));
                wfp_ui_thread.Message("$$$" + lngRPM.s_UpgradeDatabase.s + Message_Title);
                wfp_ui_thread.Message(lngRPM.s_ReadTable.s + tbl.TableName);
                xtbl = new SQLTable(tbl);
                xtbl.CreateTableTree(DBSync.DBSync.DB_for_Tangenta.m_DBTables.items);
                TableDataItem dt_Price_Item = new TableDataItem(xtbl, ref dt_List, null, ref Err);
                if (Err != null)
                {

                    wfp_ui_thread.End();
                    LogFile.Error.Show("ERROR:usrc_Upgrade:UpgradeDB_1_04_to_1_05:TableName=" + tbl.TableName + ";Err=" + Err);
                    return false;
                }
                TableDataItem_List.Add(dt_Price_Item);

                tbl = DBSync.DBSync.DB_for_Tangenta.m_DBTables.GetTable(typeof(Price_SimpleItem));
                wfp_ui_thread.Message(lngRPM.s_ReadTable.s + tbl.TableName);
                xtbl = new SQLTable(tbl);
                xtbl.CreateTableTree(DBSync.DBSync.DB_for_Tangenta.m_DBTables.items);
                TableDataItem dt_Price_SimpleItem = new TableDataItem(xtbl, ref dt_List, null, ref Err);
                if (Err != null)
                {
                    wfp_ui_thread.End();
                    LogFile.Error.Show("ERROR:usrc_Upgrade:UpgradeDB_1_04_to_1_05:TableName=" + tbl.TableName + ";Err=" + Err);
                    return false;
                }
                TableDataItem_List.Add(dt_Price_SimpleItem);

                tbl = DBSync.DBSync.DB_for_Tangenta.m_DBTables.GetTable(typeof(OrganisationAccount));
                wfp_ui_thread.Message(lngRPM.s_ReadTable.s + tbl.TableName);
                xtbl = new SQLTable(tbl);
                xtbl.CreateTableTree(DBSync.DBSync.DB_for_Tangenta.m_DBTables.items);
                TableDataItem dt_OrganisationAccount = new TableDataItem(xtbl, ref dt_List, null, ref Err);
                if (Err != null)
                {
                    wfp_ui_thread.End();
                    LogFile.Error.Show("ERROR:usrc_Upgrade:UpgradeDB_1_04_to_1_05:TableName=" + tbl.TableName + ";Err=" + Err);
                    return false;
                }
                TableDataItem_List.Add(dt_OrganisationAccount);

                tbl = DBSync.DBSync.DB_for_Tangenta.m_DBTables.GetTable(typeof(DocInvoice_ShopB_Item));
                wfp_ui_thread.Message(lngRPM.s_ReadTable.s + tbl.TableName);
                xtbl = new SQLTable(tbl);
                xtbl.CreateTableTree(DBSync.DBSync.DB_for_Tangenta.m_DBTables.items);
                TableDataItem dt_DocInvoice_ShopB_Item = new TableDataItem(xtbl, ref dt_List, null, ref Err);
                if (Err != null)
                {
                    wfp_ui_thread.End();
                    LogFile.Error.Show("ERROR:usrc_Upgrade:UpgradeDB_1_04_to_1_05:TableName=" + tbl.TableName + ";Err=" + Err);
                    return false;
                }
                TableDataItem_List.Add(dt_DocInvoice_ShopB_Item);

                tbl = DBSync.DBSync.DB_for_Tangenta.m_DBTables.GetTable(typeof(DocInvoice_ShopC_Item));
                wfp_ui_thread.Message(lngRPM.s_ReadTable.s + tbl.TableName);
                xtbl = new SQLTable(tbl);
                xtbl.CreateTableTree(DBSync.DBSync.DB_for_Tangenta.m_DBTables.items);
                TableDataItem dt_DocInvoice_ShopC_Item = new TableDataItem(xtbl, ref dt_List, null, ref Err);
                if (Err != null)
                {
                    wfp_ui_thread.End();
                    LogFile.Error.Show("ERROR:usrc_Upgrade:UpgradeDB_1_04_to_1_05:TableName=" + tbl.TableName + ";Err=" + Err);
                    return false;
                }
                TableDataItem_List.Add(dt_DocInvoice_ShopC_Item);

                Err = null;
                tbl = DBSync.DBSync.DB_for_Tangenta.m_DBTables.GetTable(typeof(TangentaTableClass.DBSettings));
                wfp_ui_thread.Message("$$$" + lngRPM.s_UpgradeDatabase.s + Message_Title);
                wfp_ui_thread.Message(lngRPM.s_ReadTable.s + tbl.TableName);
                xtbl = new SQLTable(tbl);
                xtbl.CreateTableTree(DBSync.DBSync.DB_for_Tangenta.m_DBTables.items);
                TableDataItem dt_DBSettings = new TableDataItem(xtbl, ref dt_List, null, ref Err);
                if (Err != null)
                {

                    wfp_ui_thread.End();
                    LogFile.Error.Show("ERROR:usrc_Upgrade:UpgradeDB_1_04_to_1_05:TableName=" + tbl.TableName + ";Err=" + Err);
                    return false;
                }
                TableDataItem_List.Add(dt_DBSettings);

                Err = null;
                tbl = DBSync.DBSync.DB_for_Tangenta.m_DBTables.GetTable(typeof(TangentaTableClass.BaseCurrency));
                wfp_ui_thread.Message("$$$" + lngRPM.s_UpgradeDatabase.s + Message_Title);
                wfp_ui_thread.Message(lngRPM.s_ReadTable.s + tbl.TableName);
                xtbl = new SQLTable(tbl);
                xtbl.CreateTableTree(DBSync.DBSync.DB_for_Tangenta.m_DBTables.items);
                TableDataItem dt_BaseCurrency = new TableDataItem(xtbl, ref dt_List, null, ref Err);
                if (Err != null)
                {

                    wfp_ui_thread.End();
                    LogFile.Error.Show("ERROR:usrc_Upgrade:UpgradeDB_1_04_to_1_05:TableName=" + tbl.TableName + ";Err=" + Err);
                    return false;
                }
                TableDataItem_List.Add(dt_BaseCurrency);

                wfp_ui_thread.Message(lngRPM.s_BackupOfExistingDatabase.s + DBSync.DBSync.DataBase + " -> " + DBSync.DBSync.DataBase_BackupTemp);

                if (DBSync.DBSync.DB_for_Tangenta.DataBase_Make_BackupTemp())
                {
                    if (DBSync.DBSync.DB_for_Tangenta.DataBase_Delete())
                    {
                        if (DBSync.DBSync.DB_for_Tangenta.DataBase_Create())
                        {
                            wfp_ui_thread.Message(lngRPM.s_ImportData.s);
                            if (Write_TableDataItem_List(m_eUpgrade, m_Old_tables_1_04_to_1_05))
                            {
                                // Correct Item's Units
                                Set_DatBase_Version("1.05");
                                string sql = "update item set Unit_ID=1";
                                object ores = null;
                                if (DBSync.DBSync.ExecuteNonQuerySQL(sql, null, ref ores, ref Err))
                                {
                                    wfp_ui_thread.End();
                                    return true;
                                }
                                else
                                {
                                    wfp_ui_thread.End();
                                    LogFile.Error.Show("ERROR:usrc_Upgrade:UpgradeDB_1_04_to_1_05:TableName=" + tbl.TableName + ";Err=" + Err);
                                    return false;
                                }

                            }
                        }
                    }
                }
                wfp_ui_thread.End();
                return true;
            }
            else
            {
                return false;
            }
        }
Esempio n. 3
0
        private object UpgradeDB_1_01_to_1_02(object obj, ref string Err)
        {
            wfp_ui_thread = new Database_Upgrade_WindowsForm_Thread();
            wfp_ui_thread.Start();

            List<DataTable> dt_List = new List<DataTable>();
            SQLTable tbl = DBSync.DBSync.DB_for_Tangenta.m_DBTables.GetTable(typeof(Price_Item));
            wfp_ui_thread.Message("$$$" + lngRPM.s_UpgradeDatabase.s + " 1.01 -> 1.02");
            wfp_ui_thread.Message(lngRPM.s_ReadTable.s + tbl.TableName);
            SQLTable xtbl = new SQLTable(tbl);
            xtbl.CreateTableTree(DBSync.DBSync.DB_for_Tangenta.m_DBTables.items);
            TableDataItem dt_Price_Item = new TableDataItem(xtbl, ref dt_List, null, ref Err);
            if (Err != null)
            {

                wfp_ui_thread.End();
                LogFile.Error.Show("ERROR:usrc_Upgrade:UpgradeDB_1_01_to_1_02:TableName=" + tbl.TableName + ";Err=" + Err);
                return false;
            }
            TableDataItem_List.Add(dt_Price_Item);

            tbl = DBSync.DBSync.DB_for_Tangenta.m_DBTables.GetTable(typeof(Price_SimpleItem));
            wfp_ui_thread.Message(lngRPM.s_ReadTable.s + tbl.TableName);
            xtbl = new SQLTable(tbl);
            xtbl.CreateTableTree(DBSync.DBSync.DB_for_Tangenta.m_DBTables.items);
            TableDataItem dt_Price_SimpleItem = new TableDataItem(xtbl, ref dt_List, null, ref Err);
            if (Err != null)
            {
                wfp_ui_thread.End();
                LogFile.Error.Show("ERROR:usrc_Upgrade:UpgradeDB_1_01_to_1_02:TableName=" + tbl.TableName + ";Err=" + Err);
                return false;
            }
            TableDataItem_List.Add(dt_Price_SimpleItem);

            tbl = DBSync.DBSync.DB_for_Tangenta.m_DBTables.GetTable(typeof(OrganisationAccount));
            wfp_ui_thread.Message(lngRPM.s_ReadTable.s + tbl.TableName);
            xtbl = new SQLTable(tbl);
            xtbl.CreateTableTree(DBSync.DBSync.DB_for_Tangenta.m_DBTables.items);
            TableDataItem dt_OrganisationAccount = new TableDataItem(xtbl, ref dt_List, null, ref Err);
            if (Err != null)
            {
                wfp_ui_thread.End();
                LogFile.Error.Show("ERROR:usrc_Upgrade:UpgradeDB_1_01_to_1_02:TableName=" + tbl.TableName + ";Err=" + Err);
                return false;
            }
            TableDataItem_List.Add(dt_OrganisationAccount);

            wfp_ui_thread.Message(lngRPM.s_BackupOfExistingDatabase.s + DBSync.DBSync.DataBase + " -> " + DBSync.DBSync.DataBase_BackupTemp);

            if (DBSync.DBSync.DB_for_Tangenta.DataBase_Make_BackupTemp())
            {
                if (DBSync.DBSync.DB_for_Tangenta.DataBase_Delete())
                {
                    if (DBSync.DBSync.DB_for_Tangenta.DataBase_Create())
                    {
                        wfp_ui_thread.Message(lngRPM.s_ImportData.s);
                        if (Write_TableDataItem_List(m_eUpgrade, m_Old_tables_1_04_to_1_05))
                        {
                            Set_DatBase_Version("1.02");
                        }
                    }
                }
            }
            wfp_ui_thread.End();
            return true;
        }