Пример #1
0
 public Form_Upgrade_inThread(UpgradeDB_inThread xUpgrade_inThread, UpgradeDB_inThread.Upgrade[] upgradeArray, int j, string xBackupFileName)
 {
     InitializeComponent();
     m_Upgrade_inThread = xUpgrade_inThread;
     this.upgradeArray = upgradeArray;
     this.m_j = j;
     m_BackupFileName = xBackupFileName;
     thread = new ThreadProcessor.ThreadP();
 }
Пример #2
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;
        }
Пример #3
0
 public usrc_Document()
 {
     InitializeComponent();
     Program.usrc_TangentaPrint1 = this.usrc_TangentaPrint1;
     m_UpgradeDB = new UpgradeDB_inThread(this);
 }