public Price_Undefined_Window(string sTitle,DataTable xdt_price_Item_view,CodeTables.DBTableControl xdbTables)
 {
     InitializeComponent();
     this.Title = sTitle;
     this.btn_Edit.Content = lngRPM.s_EditPriceList.s;
     this.btn_Cancel.Content = lngRPM.s_Cancel.s;
     dt_price_Item_view = xdt_price_Item_view;
     dbTables = xdbTables;
     this.dgvx_PriceUndefinedItem.ItemsSource = dt_price_Item_view.AsDataView();
     tbl = new SQLTable(dbTables.GetTable(typeof(Atom_cAddress_Org)));
     tbl.CreateTableTree(dbTables.items);
     this.dgvx_PriceUndefinedItem.AutoGeneratedColumns +=dgvx_PriceUndefinedItem_AutoGeneratedColumns;
     //this.dgvx_PriceUndefinedItem.Columns[0].Header =
 }
 public bool Init(CodeTables.DBTableControl dbTables,SQLTable tbl,ref string Err, NavigationButtons.Navigation xnav)
 {
     nav = xnav;
     tbl.CreateTableTree(dbTables.items);
     string selection = @"ID,
                          PurchasePrice_$$CreationDate,
                          PurchasePrice_$$Description,
                          PurchasePrice_$_Cur_$$Name,
                          PurchasePrice_$_Cur_$$Abbreviation,
                          PurchasePrice_$_Cur_$$Symbol,
                          PurchasePrice_$$Valid,
                          PurchasePrice_$$ValidFrom,
                          PurchasePrice_$$ValidTo
     ";
     return usrc_EditTable_PurchasePriceList.Init(DBSync.DBSync.DB_for_Tangenta.m_DBTables, tbl,selection, "ID asc",false,null,null,false,nav);
 }
 public Form_PriceList_Edit(bool xbEditUndefined,usrc_PriceList_Edit.eShopType xeShopType,NavigationButtons.Navigation xnav)
 {
     InitializeComponent();
     if (xnav != null)
     {
         nav = xnav;
     }
     else
     {
         nav = new NavigationButtons.Navigation();
         nav.bDoModal = true;
         nav.m_eButtons = NavigationButtons.Navigation.eButtons.OkCancel;
     }
     m_eShopType = xeShopType;
     bEditUndefined = xbEditUndefined;
     m_tbl_PriceList = new SQLTable(DBSync.DBSync.DB_for_Tangenta.m_DBTables.GetTable(typeof(PriceList)));
     m_tbl_PriceList.CreateTableTree(DBSync.DBSync.DB_for_Tangenta.m_DBTables.items);
     this.Text = lngRPM.s_PriceListType.s;
 }
Beispiel #4
0
        public bool SQLcmd_ImportFile(Form mMainForm, string FileName, ref List<SQLTable> lTable)
        {
            List<SQL_Parameter> lsqlPar = new List<SQL_Parameter>();

            SQLTable sqlTbl = null;
            SQLTable refsqlTbl = null;
            int iTableNameStart;
            int iTableNameEnd;
            Globals.MainWindow = mMainForm;
            StringBuilder sbSQLInsert = new StringBuilder(m_strSQLUseDatabase.ToString());
            string sPrevVar = "";
            SourceText Source_Txt = new SourceText(FileName);

            char[] trimChars = new char[] { ' ', '\t' };
            if (Source_Txt.OpenText())
            {
                while (Source_Txt.ReadLine())
                {
                    if (sqlTbl != null)
                    {
                        iTableNameStart = Source_Txt.sLine.IndexOf('<');
                        if (iTableNameStart != -1)
                        {
                            iTableNameStart++;
                            if (Source_Txt.sLine[iTableNameStart].Equals('/'))
                            {
                                iTableNameStart++;
                                iTableNameEnd = Source_Txt.sLine.IndexOf('>');
                                string sTblName = Source_Txt.sLine.Substring(iTableNameStart, iTableNameEnd - iTableNameStart);
                                if (sqlTbl.TableName.Equals(sTblName))
                                {
                                    string sVarID = Globals.sVar + "_" + sqlTbl.TableName;
                                    sPrevVar = Globals.sVar;
                                    string ErrorMsg = "";
                                    Int64 newID = -1;
                                    if (sqlTbl.SQLcmd_InsertInto(m_con,lTable, ref ErrorMsg, m_strSQLUseDatabase, ref newID))
                                    {
                                        sqlTbl = null;
                                    }
                                    else
                                    {
                                        return false;
                                    }
                                }
                                else
                                {
                                    Source_Txt.ShowParseError(lngRPM.s_Illegal_end_table_XML_command_expected.s + ": </" + sqlTbl.TableName + ">\n", lngRPM.s_Error.s, MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    Source_Txt.CloseText();
                                }
                            }
                            else
                            {
                                Source_Txt.ShowParseError(lngRPM.s_Illegal_end_table_XML_command_expected.s + ": </" + sqlTbl.TableName + ">\n", lngRPM.s_Error.s, MessageBoxButtons.OK, MessageBoxIcon.Error);
                                Source_Txt.CloseText();
                            }
                        }
                        else
                        {
                            string[] column = Source_Txt.sLine.Split(',');
                            int iCount = column.Length;
                            string s1;
                            string s2 = "";
                            if (iCount >= 2)
                            {
                                s1 = column[0];
                                int i;
                                for (i = 1; i < iCount; i++)
                                {
                                    s2 += column[i];
                                }
                                string Value = "";
                                GetValue_FromSourceText(Source_Txt, s2, ref Value);
                                if (sqlTbl.SetColumnValue(s1, Value))
                                {
                                    continue;
                                }
                                else
                                {
                                    Source_Txt.CloseText();
                                    return false;
                                }
                            }
                            else
                            {
                                Source_Txt.ShowParseError(lngRPM.s_File.s + ":" + FileName + "\n" + lngRPM.s_Comma_is_missing_to_separate_cells_column_name_from_cell_value_in_line.s + ":" + Source_Txt.iLine.ToString(), lngRPM.s_Error.s, MessageBoxButtons.OK, MessageBoxIcon.Error);
                                Source_Txt.CloseText();
                                return false;
                            }
                        }
                    }
                    else
                    {
                        iTableNameStart = Source_Txt.sLine.IndexOf('<');
                        iTableNameEnd = Source_Txt.sLine.IndexOf('>');
                        if ((iTableNameStart != -1) && (iTableNameEnd != -1) && (iTableNameEnd > iTableNameStart))
                        {
                            string sTableName = Source_Txt.sLine.Substring(iTableNameStart + 1, iTableNameEnd - iTableNameStart - 1);
                            sTableName = sTableName.TrimStart(trimChars);
                            sTableName = sTableName.TrimEnd(trimChars);
                            if (Globals.FindTable(out refsqlTbl, sTableName, items))
                            {
                                sqlTbl = new SQLTable(refsqlTbl);
                                sqlTbl.CreateTableTree(lTable);
                                continue;
                            }
                            else
                            {
                                Source_Txt.ShowParseError(lngRPM.s_TableNameIsExpectedToBeBeforeDataLines.s, lngRPM.s_Error.s, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                return false;
                            }

                        }
                        else
                        {
                            Source_Txt.ShowParseError(lngRPM.s_TableNameIsExpectedToBeBeforeDataLines.s, lngRPM.s_Error.s, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return false;
                        }
                    }
                }
                Source_Txt.CloseText();

                //  Structures are filled now create SQL statements

                return true;

            }
            else
            {
                return false;
            }
        }
        private void usrc_EditTable_PriceList_SelectedIndexChanged(SQLTable m_tbl, long ID, int index)
        {
            string Err = null;
            if (SetPriceListName(ID,ref Err))
            {
                string sOrder_by_UndefinedFirst = null;

                string where_condition = null;
                string selection = null;
                if (m_eShopType == eShopType.ShopB)
                {
                    if (usrc_EditTable_Shop_Prices != null)
                    {
                        if (tbl_Price_SimpleItem == null)
                        {
                            tbl_Price_SimpleItem = new SQLTable(DBSync.DBSync.DB_for_Tangenta.m_DBTables.GetTable(typeof(Price_SimpleItem)));
                            tbl_Price_SimpleItem.CreateTableTree(DBSync.DBSync.DB_for_Tangenta.m_DBTables.items);
                        }
                        else
                        {
                            tbl_Price_SimpleItem.DeleteInputControls();
                        }

                        where_condition = " where Price_SimpleItem_$_pl_$$ID = " + ID.ToString() + " ";

                        selection = @"             Price_SimpleItem_$_si_$$Name,
                                                      Price_SimpleItem_$$RetailSimpleItemPrice,
                                                      Price_SimpleItem_$_si_$_sipg1_$$Name,
                                                      Price_SimpleItem_$_si_$_sipg1_$_sipg2_$$Name,
                                                      Price_SimpleItem_$_si_$_sipg1_$_sipg2_$_sipg3_$$Name,
                                                      Price_SimpleItem_$_si_$_siimg_$$Image_Data,
                                                      Price_SimpleItem_$$Discount,
                                                      Price_SimpleItem_$_tax_$$Name,
                                                      Price_SimpleItem_$_tax_$$Rate,
                                                      Price_SimpleItem_$_pl_$_Cur_$$Symbol,
                                                      Price_SimpleItem_$_pl_$_Cur_$$Abbreviation,
                                                      Price_SimpleItem_$_pl_$$Name,
                                                      Price_SimpleItem_$_si_$$Code,
                                                      ID
                                                      ";
                        sOrder_by_UndefinedFirst = "";
                        if (bEditUndefined)
                        {
                            sOrder_by_UndefinedFirst = " Price_SimpleItem_$$RetailSimpleItemPrice asc, ";
                        }
                        else
                        {
                            sOrder_by_UndefinedFirst = " Price_SimpleItem_$_si_$_sipg1_$$Name,Price_SimpleItem_$_si_$_sipg1_$_sipg2_$$Name,Price_SimpleItem_$_si_$_sipg1_$_sipg2_$_sipg3_$$Name, Price_SimpleItem_$$RetailSimpleItemPrice asc, ";
                        }

                        if (usrc_EditTable_Shop_Prices.Init(DBSync.DBSync.DB_for_Tangenta.m_DBTables, tbl_Price_SimpleItem, selection, sOrder_by_UndefinedFirst + " Price_SimpleItem_$_si_$$Code desc", false, where_condition, null, false,nav))
                        {

                        }
                    }
                }
                else
                {
                    if (usrc_EditTable_Shop_Prices != null)
                    {
                        if (tbl_Price_Item == null)
                        {
                            tbl_Price_Item = new SQLTable(DBSync.DBSync.DB_for_Tangenta.m_DBTables.GetTable(typeof(Price_Item)));
                            tbl_Price_Item.CreateTableTree(DBSync.DBSync.DB_for_Tangenta.m_DBTables.items);
                        }
                        else
                        {
                            tbl_Price_Item.DeleteInputControls();
                        }
                        where_condition = " where Price_Item_$_pl_$$ID = " + ID.ToString() + " ";
                        selection = @"                Price_Item_$_i_$$UniqueName,
                                                      Price_Item_$$RetailPricePerUnit,
                                                      Price_Item_$_i_$_ipg1_$$Name,
                                                      Price_Item_$_i_$_ipg1_$_ipg2_$$Name,
                                                      Price_Item_$_i_$_ipg1_$_ipg2_$_ipg3_$$Name,
                                                      Price_Item_$_i_$$Name,
                                                      Price_Item_$_i_$_iimg_$$Image_Data,
                                                      Price_Item_$$Discount,
                                                      Price_Item_$_tax_$$Rate,
                                                      Price_Item_$_i_$_exp_$$ExpectedShelfLifeInDays,
                                                      Price_Item_$_i_$_exp_$$SaleBeforeExpiryDateInDays,
                                                      Price_Item_$_pl_$_Cur_$$Symbol,
                                                      Price_Item_$_pl_$_Cur_$$Abbreviation,
                                                      Price_Item_$_i_$$Code,
                                                      Price_Item_$_pl_$$Name,
                                                      ID
                                                      ";
                        sOrder_by_UndefinedFirst = "";
                        if (bEditUndefined)
                        {
                            sOrder_by_UndefinedFirst = " Price_Item_$$RetailPricePerUnit asc, ";
                        }
                        else
                        {
                            sOrder_by_UndefinedFirst = " Price_Item_$_i_$_ipg1_$$Name, Price_Item_$_i_$_ipg1_$_ipg2_$$Name, Price_Item_$_i_$_ipg1_$_ipg2_$_ipg3_$$Name, Price_Item_$$RetailPricePerUnit asc, ";
                        }
                        if (usrc_EditTable_Shop_Prices.Init(DBSync.DBSync.DB_for_Tangenta.m_DBTables, tbl_Price_Item, selection, sOrder_by_UndefinedFirst + " Price_Item_$_i_$$Code desc", false, where_condition, null, false,nav))
                        {

                        }
                    }
                }
            }
            else
            {
                LogFile.Error.Show("ERROR:usrc_PriceList_Edit:usrc_EditTable_PriceList_SelectedIndexChanged:Err=" + Err);
            }
        }
        private void usrc_EditTable_PriceList_after_InsertInDataBase(SQLTable m_tbl, long ID, bool bRes)
        {
            // Now create price lists
            if (bRes)
            {
                if (nav.m_eButtons == Navigation.eButtons.OkCancel)
                {
                    SQLTable tbl_Taxation = new SQLTable(DBSync.DBSync.DB_for_Tangenta.m_DBTables.GetTable(typeof(Taxation)));
                    tbl_Taxation.CreateTableTree(DBSync.DBSync.DB_for_Tangenta.m_DBTables.items);
                    SelectID_Table_Assistant_Form SelectID_Table_dlg = new SelectID_Table_Assistant_Form(tbl_Taxation, DBSync.DBSync.DB_for_Tangenta.m_DBTables, null);
                    SelectID_Table_dlg.ShowDialog();
                    long id_Taxation = SelectID_Table_dlg.ID;
                    if (id_Taxation >= 0)
                    {
                        string sql = null;
                        object ores = null;
                        string Err = null;
                        if (m_eShopType == eShopType.ShopB)
                        {

                            sql = @" insert into Price_SimpleItem (SimpleItem_ID,PriceList_ID,Taxation_ID,RetailSimpleItemPrice,Discount)
                                    select id," + ID.ToString() + "," + id_Taxation.ToString() + ",-1,0 from SimpleItem where ToOffer = 1";
                            if (DBSync.DBSync.ExecuteNonQuerySQL(sql, null, ref ores, ref Err))
                            {
                                if (tbl_Price_SimpleItem == null)
                                {
                                    tbl_Price_SimpleItem = new SQLTable(DBSync.DBSync.DB_for_Tangenta.m_DBTables.GetTable(typeof(Price_SimpleItem)));
                                    tbl_Price_SimpleItem.CreateTableTree(DBSync.DBSync.DB_for_Tangenta.m_DBTables.items);
                                }
                                else
                                {
                                    tbl_Price_SimpleItem.DeleteInputControls();
                                }
                                string where_condition = " where Price_SimpleItem_$_pl_$$ID = " + ID.ToString() + " ";
                                string selection = @" ID,
                                                  Price_SimpleItem_$$RetailSimpleItemPrice,
                                                  Price_SimpleItem_$$Discount,
                                                  Price_SimpleItem_$_si_$$Name,
                                                  Price_SimpleItem_$_si_$_siimg_$$Image_Data,
                                                  Price_SimpleItem_$_tax_$$Name,
                                                  Price_SimpleItem_$_tax_$$Rate,
                                                  Price_SimpleItem_$_pl_$_Cur_$$Symbol,
                                                  Price_SimpleItem_$_pl_$_Cur_$$Abbreviation,
                                                  Price_SimpleItem_$_si_$$Code,
                                                  Price_SimpleItem_$_pl_$$Name
                                                  ";
                                if (usrc_EditTable_Shop_Prices != null)
                                {
                                    if (this.usrc_EditTable_Shop_Prices.Init(DBSync.DBSync.DB_for_Tangenta.m_DBTables, tbl_Price_SimpleItem, selection, "Price_SimpleItem_$_si_$$Code desc", false, where_condition, null, false,nav))
                                    {
                                    }
                                }
                            }
                            else
                            {
                                LogFile.Error.Show("ERROR:usrc_PriceList_Edit:usrc_EditTable_PriceList_after_InsertInDataBase:Err=" + Err + "\r\nSql=" + sql);
                                return;
                            }
                        }
                        else
                        {
                            sql = @" insert into Price_Item (Item_ID,PriceList_ID,Taxation_ID,RetailPricePerUnit,Discount)
                                            select id," + ID.ToString() + "," + id_Taxation.ToString() + ",-1,0 from Item where ToOffer = 1";
                            if (DBSync.DBSync.ExecuteNonQuerySQL(sql, null, ref ores, ref Err))
                            {
                                if (tbl_Price_Item == null)
                                {
                                    tbl_Price_Item = new SQLTable(DBSync.DBSync.DB_for_Tangenta.m_DBTables.GetTable(typeof(Price_Item)));
                                    tbl_Price_Item.CreateTableTree(DBSync.DBSync.DB_for_Tangenta.m_DBTables.items);
                                }
                                else
                                {
                                    tbl_Price_Item.DeleteInputControls();
                                }
                                string selection = @" ID,
                                                  Price_Item_$$RetailPricePerUnit,
                                                  Price_Item_$$Discount,
                                                  Price_Item_$_i_$$UniqueName,
                                                  Price_Item_$_i_$_iimg_$$Image_Data,
                                                  Price_Item_$_i_$$Name,
                                                  Price_Item_$_tax_$$Rate,
                                                  Price_Item_$_i_$_exp_$$ExpectedShelfLifeInDays,
                                                  Price_Item_$_i_$_exp_$$SaleBeforeExpiryDateInDays,
                                                  Price_Item_$_pl_$_Cur_$$Symbol,
                                                  Price_Item_$_pl_$_Cur_$$Abbreviation,
                                                  Price_Item_$_i_$$Code,
                                                  Price_Item_$_pl_$$Name
                                                  ";
                                string where_condition = " where Price_Item_$_pl_$$ID = " + ID.ToString() + " ";
                                if (usrc_EditTable_Shop_Prices != null)
                                {
                                    if (usrc_EditTable_Shop_Prices.Init(DBSync.DBSync.DB_for_Tangenta.m_DBTables, tbl_Price_Item, selection, " Price_Item_$_i_$$Code desc ", false, where_condition, null, false,nav))
                                    {
                                        if (!SetPriceListName(ID, ref Err))
                                        {
                                            LogFile.Error.Show("ERROR:usrc_PriceList_Edit:usrc_EditTable_PriceList_after_InsertInDataBase:Err=" + Err);
                                        }
                                        return;
                                    }
                                }
                            }
                            else
                            {
                                LogFile.Error.Show("ERROR:usrc_PriceList_Edit:usrc_EditTable_PriceList_after_InsertInDataBase:Err=" + Err + "\r\nSql=" + sql);
                            }
                        }
                    }
                }
            }
        }
Beispiel #7
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;
            }
        }
Beispiel #8
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;
        }
        private void Edit_PurchasePrice_Item(long id_Taxation)
        {
            string Err = null;
            string sql = @"select ID from PurchasePrice_Item ";
            DataTable dt_PurchasePrice_Item = new DataTable();
            if (DBSync.DBSync.ReadDataTable(ref dt_PurchasePrice_Item, sql, ref Err))
            {
                if (dt_PurchasePrice_Item.Rows.Count > 0)
                {
                    SQLTable tbl_PurchasePrice_Item = new SQLTable(DBSync.DBSync.DB_for_Tangenta.m_DBTables.GetTable(typeof(PurchasePrice_Item)));
                    tbl_PurchasePrice_Item.CreateTableTree(DBSync.DBSync.DB_for_Tangenta.m_DBTables.items);
                    string selection = @"ID,
                                 PurchasePrice_Item_$$PurchasePricePerUnit,
                                 PurchasePrice_Item_$_pp_$_Cur_$$Symbol,
                                 PurchasePrice_Item_$_i_$$UniqueName,
                                 PurchasePrice_Item_$_tax_$$Name,
                                 PurchasePrice_Item_$_tax_$$Rate,
                                 PurchasePrice_Item_$_pp_$$Valid,
                                 PurchasePrice_Item_$_pp_$_myOrganisation_Person_$_myOrganisation_$$Name,
                                 PurchasePrice_Item_$_pp_$_myOrganisation_Person_$$UserName,
                                 PurchasePrice_Item_$_pp_$_myOrganisation_Person_$$FirstName,
                                 PurchasePrice_Item_$_pp_$_myOrganisation_Person_$$LastName
                                 PurchasePrice_Item_$_i_$$Code
            ";

                    if (this.usrc_EditTable_PurchaseItem.Init(DBSync.DBSync.DB_for_Tangenta.m_DBTables, tbl_PurchasePrice_Item, selection, "PurchasePrice_Item_$_i_$$Code desc", false, null, null, false, nav))
                    {
                        return;
                    }
                }
                else
                {
                    sql = @"select ID from PriceList order by ID asc";
                    DataTable dt_PriceList = new DataTable();
                    if (DBSync.DBSync.ReadDataTable(ref dt_PriceList, sql, ref Err))
                    {
                        if (dt_PriceList.Rows.Count > 0)
                        {
                            long PriceList_ID = (long)dt_PriceList.Rows[0]["ID"];
                            sql = @" insert into PurchasePrice_Item (Item_ID,PriceList_ID,Taxation_ID,PurchasePricePerUnit)
                                                        select id," + PriceList_ID.ToString() + "," + id_Taxation.ToString() + ",-1 from Item where ToOffer = 1";
                            object ores = null;
                            if (DBSync.DBSync.ExecuteNonQuerySQL(sql, null, ref ores, ref Err))
                            {
                                SQLTable tbl_PurchasePrice_Item = new SQLTable(DBSync.DBSync.DB_for_Tangenta.m_DBTables.GetTable(typeof(PurchasePrice_Item)));
                                tbl_PurchasePrice_Item.CreateTableTree(DBSync.DBSync.DB_for_Tangenta.m_DBTables.items);
                                string selection = @"ID,
                                 PurchasePrice_Item_$$PurchasePricePerUnit,
                                 PurchasePrice_Item_$_pp_$_Cur_$$Symbol,
                                 PurchasePrice_Item_$_i_$$UniqueName,
                                 PurchasePrice_Item_$_tax_$$Name,
                                 PurchasePrice_Item_$_tax_$$Rate,
                                 PurchasePrice_Item_$_pp_$$Valid,
                                 PurchasePrice_Item_$_pp_$_myOrganisation_Person_$_myOrganisation_$$Name,
                                 PurchasePrice_Item_$_pp_$_myOrganisation_Person_$$UserName,
                                 PurchasePrice_Item_$_pp_$_myOrganisation_Person_$$FirstName,
                                 PurchasePrice_Item_$_pp_$_myOrganisation_Person_$$LastName
                                 PurchasePrice_Item_$_i_$$Code
            ";
                                if (usrc_EditTable_PurchaseItem.Init(DBSync.DBSync.DB_for_Tangenta.m_DBTables, tbl_PurchasePrice_Item, selection, "PurchasePrice_Item_$_i_$$Code desc", false, null, null, false, nav))
                                {
                                    return;
                                }
                            }
                            else
                            {
                                LogFile.Error.Show("ERROR:usrc_PriceList_Edit:usrc_EditTable_PriceList_after_InsertInDataBase:Err=" + Err + "\r\nSql=" + sql);
                            }
                        }
                    }
                }
            }
        }
        private void usrc_EditTable_PurchasePrice_after_InsertInDataBase(SQLTable m_tbl, long ID, bool bRes)
        {
            // Now create price lists
            if (bRes)
            {
                SQLTable tbl_Taxation = new SQLTable(DBSync.DBSync.DB_for_Tangenta.m_DBTables.GetTable(typeof(Taxation)));
                tbl_Taxation.CreateTableTree(DBSync.DBSync.DB_for_Tangenta.m_DBTables.items);
                SelectID_Table_Assistant_Form  SelectID_Table_dlg = new SelectID_Table_Assistant_Form(tbl_Taxation,DBSync.DBSync.DB_for_Tangenta.m_DBTables,null);
                SelectID_Table_dlg.ShowDialog();
                long id_Taxation = SelectID_Table_dlg.ID;
                if (id_Taxation>=0)
                {
                    string Err = null;
                    string sql = @" insert into PurchasePrice_Item (Item_ID,PurchasePrice_ID,Taxation_ID,PurchasePricePerUnit,Discount)
                                select id," + ID.ToString() + "," + id_Taxation.ToString() + ",-1,0 from Item where ToOffer = 1";
                    object ores = null;
                    if (DBSync.DBSync.ExecuteNonQuerySQL(sql, null, ref ores, ref Err))
                    {
                        SQLTable tbl_Price_Item = new SQLTable(DBSync.DBSync.DB_for_Tangenta.m_DBTables.GetTable(typeof(Price_Item)));
                        tbl_Price_Item.CreateTableTree(DBSync.DBSync.DB_for_Tangenta.m_DBTables.items);
                        string where_condition = " where PurchasePrice_$_ID = " + ID.ToString() + " ";
                        string selection = @"ID,
                                 PurchasePrice_Item_$$PurchasePricePerUnit,
                                 PurchasePrice_Item_$_pp_$_Cur_$$Symbol,
                                 PurchasePrice_Item_$_i_$$UniqueName,
                                 PurchasePrice_Item_$_tax_$$Name,
                                 PurchasePrice_Item_$_tax_$$Rate,
                                 PurchasePrice_Item_$_pp_$$Valid,
                                 PurchasePrice_Item_$_i_$$Code
            ";

                        if (usrc_EditTable_PurchaseItem.Init(DBSync.DBSync.DB_for_Tangenta.m_DBTables, tbl_Price_Item, selection, "PurchasePrice_Item_$_i_$$Code desc", false, where_condition, null, false,nav))
                        {
                            Edit_PurchasePrice_Item(id_Taxation);
                        }
                    }
                    else
                    {
                        LogFile.Error.Show("ERROR:usrc_PriceList_Edit:usrc_EditTable_PriceList_after_InsertInDataBase:Err=" + Err + "\r\nSql=" + sql);
                    }
                }
            }
            b_InsertInDataBase = false;
        }
        private void usrc_EditTable_PriceList_SelectedIndexChanged(SQLTable m_tbl, long ID, int index)
        {
            string where_condition = " where PurchasePrice_Item_$_pp_$$ID = " + ID.ToString() + " ";
            SQLTable tbl_Price_Item = new SQLTable(DBSync.DBSync.DB_for_Tangenta.m_DBTables.GetTable(typeof(Price_Item)));
            tbl_Price_Item.CreateTableTree(DBSync.DBSync.DB_for_Tangenta.m_DBTables.items);
            string selection = @"ID,
                                 PurchasePrice_Item_$$PurchasePricePerUnit,
                                 PurchasePrice_Item_$_pp_$_Cur_$$Symbol,
                                 PurchasePrice_Item_$_i_$$UniqueName,
                                 PurchasePrice_Item_$_tax_$$Name,
                                 PurchasePrice_Item_$_tax_$$Rate,
                                 PurchasePrice_Item_$_pp_$$Valid,
                                 PurchasePrice_Item_$_i_$$Code
            ";

            if (usrc_EditTable_PurchaseItem.Init(DBSync.DBSync.DB_for_Tangenta.m_DBTables, tbl_Price_Item, selection, "PurchasePrice_Item_$_i_$$Code desc", false, where_condition, null, false,nav))
            {

            }
        }
Beispiel #12
0
 public static bool Insert_ShopC_Items_in_PriceList(DataTable dt_Item_NotIn_PriceList, Control parent_ctrl)
 {
     string Err = null;
     for (;;)
     {
         SQLTable tbl_Taxation = new SQLTable(DBSync.DBSync.DB_for_Tangenta.m_DBTables.GetTable(typeof(Taxation)));
         tbl_Taxation.CreateTableTree(DBSync.DBSync.DB_for_Tangenta.m_DBTables.items);
         SelectID_Table_Assistant_Form SelectID_Table_dlg = new SelectID_Table_Assistant_Form(tbl_Taxation, DBSync.DBSync.DB_for_Tangenta.m_DBTables, null);
         if (parent_ctrl is Form)
         {
             if (((Form)parent_ctrl).TopMost)
             {
                 SelectID_Table_dlg.TopMost = true;
             }
         }
         SelectID_Table_dlg.ShowDialog(parent_ctrl);
         long id_Taxation = SelectID_Table_dlg.ID;
         if (id_Taxation >= 0)
         {
             foreach (DataRow dr in dt_Item_NotIn_PriceList.Rows)
             {
                 long PriceList_ID = (long)dr["PriceList_ID"];
                 long Item_ID = (long)dr["Item_ID"];
                 string sql = "insert into Price_Item (RetailPricePerUnit,Discount,Taxation_ID,Item_ID,PriceList_ID) values (-1,0," + id_Taxation.ToString() + "," + Item_ID.ToString() + "," + PriceList_ID.ToString() + ")";
                 object objresult = new object();
                 if (!DBSync.DBSync.ExecuteNonQuerySQL(sql, null, ref objresult, ref Err))
                 {
                     LogFile.Error.Show("ERROR:f_PriceList:Update:sql=" + sql + "\r\nErr=" + Err);
                     return false;
                 }
             }
             return true;
         }
         else
         {
             if (MessageBox.Show(parent_ctrl, lngRPM.s_PriceListIsNotUpdatedBecauseYouDidnotSelect.s, "?", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1) == DialogResult.Cancel)
             {
                 return false;
             }
         }
     }
 }
Beispiel #13
0
        public static bool SQLcmd_InsertLines(List<string> Line, DBTableControl dbTables, StringBuilder m_strSQLUseDatabase, ref string ErrorMsg)
        {
            List<SQL_Parameter> lsqlPar = new List<SQL_Parameter>();

            SQLTable sqlTbl = null;
            SQLTable refsqlTbl = null;
            int iTableNameStart;
            int iTableNameEnd;
            StringBuilder sbSQLInsert = new StringBuilder(m_strSQLUseDatabase.ToString());
            string sPrevVar = "";

            char[] trimChars = new char[] { ' ', '\t' };

            int index;
            int iCount = Line.Count();
            index = 0;
            while (index < iCount)
            {
                string sLine = Line[index];
                if (sqlTbl != null)
                {
                    iTableNameStart = sLine.IndexOf('<');
                    if (iTableNameStart != -1)
                    {
                        iTableNameStart++;
                        if (sLine[iTableNameStart].Equals('/'))
                        {
                            iTableNameStart++;
                            iTableNameEnd = sLine.IndexOf('>');
                            string sTblName = sLine.Substring(iTableNameStart, iTableNameEnd - iTableNameStart);
                            if (sqlTbl.TableName.Equals(sTblName))
                            {
                                string sVarID = Globals.sVar + "_" + sqlTbl.TableName;
                                sPrevVar = Globals.sVar;
                                if (dbTables.m_con.DBType == DBConnection.eDBType.SQLITE)
                                {
                                    string PrevVar = sqlTbl.TableName;
                                    sVarID = "";
                                    Int64 ID = -1;
                                    string csError = null;
                                    bool bSomethingDefined = false;
                                    if (sqlTbl.SQLcmd_InsertInto_SQLITE(dbTables.m_con, PrevVar, ref sVarID, /*ref  lsqlPar,*/ dbTables.items,ref bSomethingDefined, ref ID, ref csError))
                                    {
                                        if (ID != -1)
                                        {
                                            return true;
                                        }
                                        else
                                        {
                                            return false;
                                        }
                                    }
                                    else
                                    {
                                        LogFile.Error.Show("Error:" + csError);
                                    }
                                }
                                else
                                {
                                    sqlTbl.SQLcmd_Insert_MSSQL(ref sbSQLInsert, sPrevVar, ref sVarID, ref lsqlPar, dbTables.items,0);
                                    object oResult = null;
                                    if (dbTables.m_con.ExecuteNonQuerySQL(sbSQLInsert.ToString(), lsqlPar,ref oResult, ref ErrorMsg))
                                    {
                                        lsqlPar.Clear();
                                        sbSQLInsert.Remove(0, sbSQLInsert.Length);
                                        sbSQLInsert.Append(m_strSQLUseDatabase.ToString());
                                        sqlTbl = null;
                                    }
                                    else
                                    {
                                        return false;
                                    }
                                }
                            }
                            else
                            {
                                MessageBox.Show(lngRPM.s_Illegal_end_table_XML_command_expected.s + ": </" + sqlTbl.TableName + ">\n", lngRPM.s_Error.s, MessageBoxButtons.OK, MessageBoxIcon.Error);
                                //Source_Txt.CloseText();
                            }
                        }
                        else
                        {
                            MessageBox.Show(lngRPM.s_Illegal_end_table_XML_command_expected.s + ": </" + sqlTbl.TableName + ">\n", lngRPM.s_Error.s, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            //                                Source_Txt.CloseText();
                        }
                    }
                    else
                    {
                        string[] column = sLine.Split(',');
                        int iTokenCount = column.Count();
                        string s1;
                        string s2 = "";
                        if (iTokenCount >= 2)
                        {
                            s1 = column[0];
                            int i;
                            for (i = 1; i < iTokenCount; i++)
                            {
                                s2 += column[i];
                            }
                            string Value = "";
                            index = GetValue(index, Line, s2, ref Value);
                            if (sqlTbl.SetColumnValue(s1, Value))
                            {
                                index++;
                                continue;
                            }
                            else
                            {
                                //Source_Txt.CloseText();
                                return false;
                            }
                        }
                        else
                        {
                            //Source_Txt.ShowParseError(lngRPM.s_File.s + ":" + FileName + "\n" + lngRPM.s_Comma_is_missing_to_separate_cells_column_name_from_cell_value_in_line.s + ":" + Source_Txt.iLine.ToString(), lngRPM.s_Error.s, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            MessageBox.Show(lngRPM.s_File.s + lngRPM.s_Comma_is_missing_to_separate_cells_column_name_from_cell_value_in_line.s, lngRPM.s_Error.s, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            //Source_Txt.CloseText();
                            return false;
                        }
                    }
                }
                else
                {
                    iTableNameStart = sLine.IndexOf('<');
                    iTableNameEnd = sLine.IndexOf('>');
                    if ((iTableNameStart != -1) && (iTableNameEnd != -1) && (iTableNameEnd > iTableNameStart))
                    {
                        string sTableName = sLine.Substring(iTableNameStart + 1, iTableNameEnd - iTableNameStart - 1);
                        sTableName = sTableName.TrimStart(trimChars);
                        sTableName = sTableName.TrimEnd(trimChars);
                        if (Globals.FindTable(out refsqlTbl, sTableName, dbTables.items))
                        {
                            sqlTbl = new SQLTable(refsqlTbl);
                            sqlTbl.CreateTableTree(dbTables.items);
                            index++;
                            continue;
                        }
                        else
                        {
                            //Source_Txt.ShowParseError(lngRPM.s_TableNameIsExpectedToBeBeforeDataLines.s, lngRPM.s_Error.s, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            MessageBox.Show(lngRPM.s_TableNameIsExpectedToBeBeforeDataLines.s, lngRPM.s_Error.s, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return false;
                        }

                    }
                    else
                    {
                        //Source_Txt.ShowParseError(lngRPM.s_TableNameIsExpectedToBeBeforeDataLines.s, lngRPM.s_Error.s, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        MessageBox.Show(lngRPM.s_TableNameIsExpectedToBeBeforeDataLines.s, lngRPM.s_Error.s, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return false;
                    }
                }

                index++;
            }
            //Source_Txt.CloseText();
            //  Structures are filled now create SQL statements
            return true;
        }
        //private string alias_table_name = null;
        internal StringBuilder SQLCreateView_InDataBase(List<SQLTable> lTable)
        {
            StringBuilder SQL_View = new StringBuilder("");
            try
            {
                if (this.m_Fkey.Count > 0)
                {
                    jListClear();

                    if (this.m_Table_View == null)
                    {
                        m_Table_View = new Table_View();
                    }
                    m_Table_View.View_Name = TableName + const_DataBaseViewSuffix;

                    SQL_View.Append("\n\nCREATE VIEW " + ViewName + " AS ");

                    SQL_View.Append("\nSELECT ");

                    SQL_View.Append("\n  " + TableName + ".ID");

                    SQLTable xtbl = new SQLTable(this);
                    xtbl.CreateTableTree(lTable);

                    string alias_table_name = this.TableName;

                    foreach (Column col in xtbl.Column)
                    {
                        if (!col.IsIdentity)
                        {
                            if (col.fKey != null)
                            {
                                if (col.fKey.fTable != null)
                                {
                                    col.fKey.fTable.BasicColumns(ref SQL_View, ref m_Table_View, alias_table_name);
                                    if (!m_Table_View.defined)
                                    {
                                        string Column_Name_In_View = col.ownerTable.TableName + VIEW_TableName2ColumnName_SEPARATOR + col.Name;
                                        Table_View.ColumnNames x_Table_View_ColumnNames = new Table_View.ColumnNames();
                                        x_Table_View_ColumnNames.Name = Column_Name_In_View;
                                        x_Table_View_ColumnNames.Name_in_language = col.Name_in_language;
                                        this.m_Table_View.View_ColumnNames_List.Add(x_Table_View_ColumnNames);
                                    }
                                }
                            }
                            else
                            {
                                string Column_Name_In_View = col.ownerTable.TableName + VIEW_TableName2ColumnName_SEPARATOR + col.Name;
                                SQL_View.Append(",\n  " + col.ownerTable.TableName + "." + col.Name + " AS " + Column_Name_In_View);
                                if (!m_Table_View.defined)
                                {
                                    Table_View.ColumnNames x_Table_View_ColumnNames = new Table_View.ColumnNames();
                                    x_Table_View_ColumnNames.Name = Column_Name_In_View;
                                    x_Table_View_ColumnNames.Name_in_language = col.Name_in_language;
                                    this.m_Table_View.View_ColumnNames_List.Add(x_Table_View_ColumnNames);
                                }
                            }
                        }
                    }
                    m_Table_View.defined = true;

                    SQL_View.Append("\nFROM " + TableName);

                    foreach (Column col in xtbl.Column)
                    {
                        if (!col.IsIdentity)
                        {
                            if (col.fKey != null)
                            {
                                if (col.fKey.fTable != null)
                                {
                                    col.fKey.fTable.GetJoins(col.nulltype, this, alias_table_name, alias_table_name);
                                }
                            }
                        }
                    }
                    CreateJoins(ref SQL_View, false);
                }
            }
            catch (Exception Ex)
            {
                LogFile.Error.Show("ERROR:SQLTable:SQLCreateView_InDataBase:Exception=" + Ex.Message);
            }
            return SQL_View;
        }
Beispiel #15
0
        private bool Get_RowReferencedFromTable_List(DBTableControl dbTables,long id,ref List<usrc_RowReferencedFromTable> usrc_RowReferencedFromTable_List,ref int total_count, ref string Err)
        {
            total_count = 0;
            foreach (SQLTable x_tbl in dbTables.items)
            {
                SQLTable tbl = new SQLTable(x_tbl);
                tbl.CreateTableTree(dbTables.items);
                if (tbl.Column != null)
                {
                    foreach (Column col in tbl.Column)
                    {
                        if (col.fKey != null)
                        {
                            if (col.fKey.fTable != null)
                            {
                                if (col.fKey.fTable.TableName.Equals(this.TableName))
                                {
                                    DataTable dt = new DataTable();
                                    string sql_select = "select * from " + tbl.TableName + " where " + col.Name + " = " + id.ToString();
                                    if (dbTables.m_con.ReadDataTable(ref dt, sql_select, ref Err))
                                    {
                                        if (dt.Rows.Count > 0)
                                        {
                                            total_count += dt.Rows.Count;
                                            usrc_RowReferencedFromTable x_usrc_RowReferencedFromTable = new usrc_RowReferencedFromTable();
                                            x_usrc_RowReferencedFromTable.Init(tbl, col.fKey.fTable, id, dt);
                                            if (usrc_RowReferencedFromTable_List == null)
                                            {
                                                usrc_RowReferencedFromTable_List = new List<usrc_RowReferencedFromTable>();
                                            }
                                            usrc_RowReferencedFromTable_List.Add(x_usrc_RowReferencedFromTable);
                                        }
                                    }
                                    else
                                    {
                                        LogFile.Error.Show("ERROR:SQLTable.Update.cs:SQLTable:Get_RowReferencedFromTable_List:sql_select=" + sql_select + "\r\nErr=" + Err);
                                        return false;
                                    }

                                }
                            }
                        }
                    }
                }
                else
                {
                    LogFile.Error.Show("ERROR:SQLTable.Update.cs:SQLTable:Get_RowReferencedFromTable_List:Table " + tbl.TableName + " has no columns defined !");
                    return false;
                }
            }
            return true;
        }