Beispiel #1
0
 internal static bool Get(string_v country_v, ref long_v cState_Person_ID_v)
 {
     if (country_v != null)
     {
         List<SQL_Parameter> lpar = new List<SQL_Parameter>();
         string spar = "@par";
         SQL_Parameter par = new SQL_Parameter(spar, SQL_Parameter.eSQL_Parameter.Nvarchar, false, country_v.v);
         lpar.Add(par);
         string sql = @"select ID from cState_Person where State = @par";
         DataTable dt = new DataTable();
         string Err = null;
         if (DBSync.DBSync.ReadDataTable(ref dt, sql, lpar, ref Err))
         {
             if (dt.Rows.Count > 0)
             {
                 if (cState_Person_ID_v == null)
                 {
                     cState_Person_ID_v = new long_v();
                 }
                 cState_Person_ID_v.v = (long)dt.Rows[0]["ID"];
                 return true;
             }
             else
             {
                 sql = @"insert into cState_Person (State) values (@par)";
                 long cState_Person_ID = -1;
                 object oret = null;
                 if (DBSync.DBSync.ExecuteNonQuerySQLReturnID(sql, lpar, ref cState_Person_ID, ref oret, ref Err, "cState_Person"))
                 {
                     if (cState_Person_ID_v == null)
                     {
                         cState_Person_ID_v = new long_v();
                     }
                     cState_Person_ID_v.v = cState_Person_ID;
                     return true;
                 }
                 else
                 {
                     LogFile.Error.Show("ERROR:TangentaDB:f_cState_Person:Get(string_v country_v, ref long_v atom_cState_Person_ID_v) sql=" + sql + "\r\nErr=" + Err);
                     return false;
                 }
             }
         }
         else
         {
             LogFile.Error.Show("ERROR:TangentaDB:f_cState_Person:Get(string_v country_v, ref long_v atom_cState_Person_ID_v) sql=" + sql + "\r\nErr=" + Err);
             return false;
         }
     }
     else
     {
         cState_Person_ID_v = null;
         return true;
     }
 }
Beispiel #2
0
 internal static bool Get(string_v OrgTYPE_v, ref long_v cOrgTYPE_ID_v)
 {
     if (OrgTYPE_v != null)
     {
         List<SQL_Parameter> lpar = new List<SQL_Parameter>();
         string spar = "@par";
         SQL_Parameter par = new SQL_Parameter(spar, SQL_Parameter.eSQL_Parameter.Nvarchar, false, OrgTYPE_v.v);
         lpar.Add(par);
         string sql = @"select ID from cOrgTYPE where OrganisationTYPE = @par";
         DataTable dt = new DataTable();
         string Err = null;
         if (DBSync.DBSync.ReadDataTable(ref dt, sql, lpar, ref Err))
         {
             if (dt.Rows.Count > 0)
             {
                 if (cOrgTYPE_ID_v == null)
                 {
                     cOrgTYPE_ID_v = new long_v();
                 }
                 cOrgTYPE_ID_v.v = (long)dt.Rows[0]["ID"];
                 return true;
             }
             else
             {
                 sql = @"insert into cOrgTYPE (OrganisationTYPE) values (@par)";
                 long cOrgTYPE_ID = -1;
                 object oret = null;
                 if (DBSync.DBSync.ExecuteNonQuerySQLReturnID(sql, lpar, ref cOrgTYPE_ID, ref oret, ref Err, "cOrgTYPE"))
                 {
                     if (cOrgTYPE_ID_v == null)
                     {
                         cOrgTYPE_ID_v = new long_v();
                     }
                     cOrgTYPE_ID_v.v = cOrgTYPE_ID;
                     return true;
                 }
                 else
                 {
                     LogFile.Error.Show("ERROR:TangentaDB:f_cOrgTYPE:Get(string_v OrgTYPE_v, ref long_v cOrgTYPE_ID_v) sql=" + sql + "\r\nErr=" + Err);
                     return false;
                 }
             }
         }
         else
         {
             LogFile.Error.Show("ERROR:TangentaDB:f_cOrgTYPE:Get(string_v OrgTYPE_v, ref long_v cOrgTYPE_ID_v) sql=" + sql + "\r\nErr=" + Err);
             return false;
         }
     }
     else
     {
         LogFile.Error.Show("ERROR:TangentaDB:f_cOrgTYPE:Get(string_v OrgTYPE_v, ref long_v cOrgTYPE_ID_v) OrgTYPE_v may not be null!");
         return false;
     }
 }
        public static bool Get(string Country,
            string Country_ISO_3166_a2,
            string Country_ISO_3166_a3,
            short Country_ISO_3166_num,
            ref long cCountry_Person_ID)
        {
            List<SQL_Parameter> lpar = new List<SQL_Parameter>();

            string spar_Country = "@par_Country";
            SQL_Parameter par_Country = new SQL_Parameter(spar_Country, SQL_Parameter.eSQL_Parameter.Nvarchar, false, Country);
            lpar.Add(par_Country);

            string spar_Country_ISO_3166_a2 = "@par_Country_ISO_3166_a2";
            SQL_Parameter par_Country_ISO_3166_a2 = new SQL_Parameter(spar_Country_ISO_3166_a2, SQL_Parameter.eSQL_Parameter.Nvarchar, false, Country_ISO_3166_a2);
            lpar.Add(par_Country_ISO_3166_a2);

            string spar_Country_ISO_3166_a3 = "@par_Country_ISO_3166_a3";
            SQL_Parameter par_Country_ISO_3166_a3 = new SQL_Parameter(spar_Country_ISO_3166_a3, SQL_Parameter.eSQL_Parameter.Nvarchar, false, Country_ISO_3166_a3);
            lpar.Add(par_Country_ISO_3166_a3);

            string spar_Country_ISO_3166_num = "@par_Country_ISO_3166_num";
            SQL_Parameter par_Country_ISO_3166_num = new SQL_Parameter(spar_Country_ISO_3166_num, SQL_Parameter.eSQL_Parameter.Smallint, false, Country_ISO_3166_num);
            lpar.Add(par_Country_ISO_3166_num);

            string Err = null;
            DataTable dt = new DataTable();
            string sql = @"select ID from cCountry_Person where Country= " + spar_Country + " and  Country_ISO_3166_a2 = " + spar_Country_ISO_3166_a2 + " and Country_ISO_3166_a3 = " + spar_Country_ISO_3166_a3 + " and Country_ISO_3166_num = " + spar_Country_ISO_3166_num;
            if (DBSync.DBSync.ReadDataTable(ref dt, sql, lpar, ref Err))
            {
                if (dt.Rows.Count > 0)
                {
                    cCountry_Person_ID = (long)dt.Rows[0]["ID"];
                    return true;
                }
                else
                {
                    sql = @"insert into cCountry_Person (Country,Country_ISO_3166_a2,Country_ISO_3166_a3,Country_ISO_3166_num) values (" + spar_Country + "," + spar_Country_ISO_3166_a2 + "," + spar_Country_ISO_3166_a3 + "," + spar_Country_ISO_3166_num + ")";
                    object objretx = null;
                    if (DBSync.DBSync.ExecuteNonQuerySQLReturnID(sql, lpar, ref cCountry_Person_ID, ref objretx, ref Err, "cCountry_Person"))
                    {
                        return true;
                    }
                    else
                    {
                        LogFile.Error.Show("ERROR:f_cCountry_Person:Get:sql=" + sql + "\r\nErr=" + Err);
                        return false;
                    }
                }
            }
            else
            {
                LogFile.Error.Show("ERROR:f_cCountry_Person:Get:sql=" + sql + "\r\nErr=" + Err);
                return false;
            }
        }
Beispiel #4
0
        public static bool Get(string Abbreviation,string Name,string Symbol,int CurrencyCode, int DecimalPlaces, ref long Currency_ID)
        {
            List<SQL_Parameter> lpar = new List<SQL_Parameter>();

            string spar_Abbreviation = "@par_Abbreviation";
            SQL_Parameter par_Abbreviation = new SQL_Parameter(spar_Abbreviation, SQL_Parameter.eSQL_Parameter.Nvarchar, false, Abbreviation);
            lpar.Add(par_Abbreviation);

            string spar_Name = "@par_Name";
            SQL_Parameter par_Name = new SQL_Parameter(spar_Name, SQL_Parameter.eSQL_Parameter.Nvarchar, false, Name);
            lpar.Add(par_Name);

            string spar_Symbol = "@par_Symbol";
            SQL_Parameter par_Symbol = new SQL_Parameter(spar_Symbol, SQL_Parameter.eSQL_Parameter.Nvarchar, false, Symbol);
            lpar.Add(par_Symbol);

            string spar_CurrencyCode = "@par_CurrencyCode";
            SQL_Parameter par_CurrencyCode = new SQL_Parameter(spar_CurrencyCode, SQL_Parameter.eSQL_Parameter.Int, false, CurrencyCode);
            lpar.Add(par_CurrencyCode);

            string spar_DecimalPlaces = "@par_DecimalPlaces";
            SQL_Parameter par_DecimalPlaces = new SQL_Parameter(spar_DecimalPlaces, SQL_Parameter.eSQL_Parameter.Int, false, DecimalPlaces);
            lpar.Add(par_DecimalPlaces);

            string sql = "select ID from Currency where Abbreviation = "+ spar_Abbreviation + " and  Name = " + spar_Name + " and CurrencyCode = " + spar_CurrencyCode + " and DecimalPlaces = " + spar_DecimalPlaces;
            DataTable dt = new DataTable();
            string Err = null;
            if (DBSync.DBSync.ReadDataTable(ref dt, sql, lpar, ref Err))
            {
                if (dt.Rows.Count > 0)
                {
                    Currency_ID = (long)dt.Rows[0]["ID"];
                    return true;
                }
                else
                {
                    sql = "insert into Currency (Abbreviation,Name,Symbol,CurrencyCode,DecimalPlaces)values(" + spar_Abbreviation + "," + spar_Name + "," + spar_Symbol+ "," + spar_CurrencyCode + "," + spar_DecimalPlaces + ")";
                    object oret = null;
                    if (DBSync.DBSync.ExecuteNonQuerySQLReturnID(sql, lpar, ref Currency_ID, ref oret, ref Err, "Currency"))
                    {
                        return true;
                    }
                    else
                    {
                        LogFile.Error.Show("ERROR:f_Currency:InsertDefault:sql=" + sql + "\r\nErr=" + Err);
                        return false;
                    }
                }
            }
            else
            {
                LogFile.Error.Show("ERROR:f_Currency:Get:sql=" + sql + "\r\nErr=" + Err);
                return false;
            }
        }
        public static bool Get_journal_docinvoice_type_id(string Event_Type, string Event_Description, ref long journal_invoice_type_id)
        {
            List<SQL_Parameter> lpar = new List<SQL_Parameter>();
            string spar_Name = "@par_Name";
            string spar_Description = "@par_Description";
            SQL_Parameter par_Name = new SQL_Parameter(spar_Name, SQL_Parameter.eSQL_Parameter.Nvarchar, false, Event_Type);
            lpar.Add(par_Name);

            string par_Description_cond = null;
            string par_Description_value = null;
            if (Event_Description != null)
            {
                par_Description_cond = " Description = " + spar_Description;
                par_Description_value = spar_Description;
            }
            else
            {
                par_Description_cond = " Description is null ";
                par_Description_value = "null";
            }

            SQL_Parameter par_Description = new SQL_Parameter(spar_Description, SQL_Parameter.eSQL_Parameter.Nvarchar, false, Event_Description);
            lpar.Add(par_Description);

            string Err = null;
            string sql = "select ID from journal_docinvoice_type where name = " + spar_Name + " and " + par_Description_cond;
            DataTable dt = new DataTable();
            if (DBSync.DBSync.ReadDataTable(ref dt, sql, lpar, ref Err))
            {
                if (dt.Rows.Count > 0)
                {
                    journal_invoice_type_id = (long)dt.Rows[0]["ID"];
                    return true;
                }
                else
                {
                    sql = "insert into journal_docinvoice_type (Name,Description) values (" + spar_Name + "," + par_Description_value + ")";
                    object ores = null;
                    if (DBSync.DBSync.ExecuteNonQuerySQLReturnID(sql, lpar, ref journal_invoice_type_id, ref ores, ref Err, "journal_docinvoice_type"))
                    {
                        return true;
                    }
                    else
                    {
                        LogFile.Error.Show("ERROR:f_Journal_DocInvoice:Get_journal_docinvoice_type_id:sql = " + sql + "\r\nErr=" + Err);
                        return false;
                    }
                }
            }
            else
            {
                LogFile.Error.Show("ERROR:f_Journal_DocInvoice:Get_journal_docinvoice_type_id:sql = " + sql + "\r\nErr=" + Err);
                return false;
            }
        }
        public static bool Add(long StockTake_ID, string Name, decimal Cost, string Description, ref long StockTake_AdditionalCost_ID)
        {
            string Err = null;
            List<SQL_Parameter> lpar = new List<SQL_Parameter>();
            long StocTakeCostName_ID = -1;
            if (f_StockTakeCostName.Get(Name, ref StocTakeCostName_ID))
            {
                string spar_StocTakeCostDescription_ID = "null";
                if (Description != null)
                {
                    if (Description.Length > 0)
                    {
                        long StocTakeCostDescription_ID = -1;
                        if (f_StockTakeCostDescription.Get(Description, ref StocTakeCostDescription_ID))
                        {
                            spar_StocTakeCostDescription_ID = "@par_StocTakeCostDescription_ID";
                            SQL_Parameter par_StocTakeCostDescription_ID = new SQL_Parameter(spar_StocTakeCostDescription_ID, SQL_Parameter.eSQL_Parameter.Bigint, false, StocTakeCostName_ID);
                            lpar.Add(par_StocTakeCostDescription_ID);
                        }
                    }
                }

                string spar_StocTakeCostName_ID = "@par_StocTakeCostName_ID";
                SQL_Parameter par_StocTakeCostName_ID = new SQL_Parameter(spar_StocTakeCostName_ID, SQL_Parameter.eSQL_Parameter.Bigint, false, StocTakeCostName_ID);
                lpar.Add(par_StocTakeCostName_ID);

                string spar_Cost = "@par_Cost";
                SQL_Parameter par_Cost = new SQL_Parameter(spar_Cost, SQL_Parameter.eSQL_Parameter.Decimal, false, Cost);
                lpar.Add(par_Cost);

                string spar_StocTake_ID = "@par_StocTake_ID";
                SQL_Parameter par_StocTake_ID = new SQL_Parameter(spar_StocTake_ID, SQL_Parameter.eSQL_Parameter.Bigint, false, StockTake_ID);
                lpar.Add(par_StocTake_ID);

                string sql = "insert into StockTake_AdditionalCost (StockTakeCostName_ID,Cost,StockTakeCostDescription_ID,StockTake_ID)values("
                              + spar_StocTakeCostName_ID + ","
                              + spar_Cost + ","
                              + spar_StocTakeCostDescription_ID + ","
                              + spar_StocTake_ID
                              + ")";
                object oret = null;
                if (DBSync.DBSync.ExecuteNonQuerySQLReturnID(sql, lpar, ref StockTake_AdditionalCost_ID, ref oret, ref Err, "StockTake_AdditionalCost"))
                {
                    return true;
                }
                else
                {
                    LogFile.Error.Show("ERROR:TangentaDB:f_StockTake_AdditionalCost.cs:Add:sql=" + sql + "\r\nErr=" + Err);
                }
            }
            return false;
        }
Beispiel #7
0
 public static bool Get(string_v FirstName_v, ref long cFirstName_ID)
 {
     string Err = null;
     string sql = null;
     List<SQL_Parameter> lpar = new List<SQL_Parameter>();
     string scond_FirstName = null;
     string sval_FirstName = "null";
     if (FirstName_v != null)
     {
         string spar_FirstName = "@par_FirstName";
         SQL_Parameter par_FirstName = new SQL_Parameter(spar_FirstName, SQL_Parameter.eSQL_Parameter.Nvarchar, false, FirstName_v.v);
         lpar.Add(par_FirstName);
         scond_FirstName = "FirstName = " + spar_FirstName;
         sval_FirstName = spar_FirstName;
     }
     else
     {
         scond_FirstName = "FirstName is null";
         sval_FirstName = "null";
     }
     DataTable dt = new DataTable();
     dt.Columns.Clear();
     dt.Clear();
     sql = @"select ID from cFirstName where " + scond_FirstName;
     if (DBSync.DBSync.ReadDataTable(ref dt, sql, lpar, ref Err))
     {
         if (dt.Rows.Count > 0)
         {
            cFirstName_ID = (long)dt.Rows[0]["ID"];
            return true;
         }
         else
         {
             sql = @"insert into cFirstName (FirstName) values (" + sval_FirstName + ")";
             object objretx = null;
             if (DBSync.DBSync.ExecuteNonQuerySQLReturnID(sql, lpar, ref cFirstName_ID, ref objretx, ref Err, "cFirstName"))
             {
                 return true;
             }
             else
             {
                 LogFile.Error.Show("ERROR:f_cFirstName:Get:sql=" + sql + "\r\nErr=" + Err);
                 return false;
             }
         }
     }
     else
     {
         LogFile.Error.Show("ERROR:f_cFirstName:Get:sql=" + sql + "\r\nErr=" + Err);
         return false;
     }
 }
Beispiel #8
0
 public static bool Get(string OrgTYPE, ref long cOrgTYPE_ID)
 {
     List<SQL_Parameter> lpar = new List<SQL_Parameter>();
     string scond_OrgTYPE = null;
     string sval_OrgTYPE = "null";
     if (OrgTYPE != null)
     {
         string spar_OrgTYPE = "@par_OrgTYPE";
         SQL_Parameter par_OrgTYPE = new SQL_Parameter(spar_OrgTYPE, SQL_Parameter.eSQL_Parameter.Nvarchar, false, OrgTYPE);
         lpar.Add(par_OrgTYPE);
         scond_OrgTYPE = "OrgTYPE = " + spar_OrgTYPE;
         sval_OrgTYPE = spar_OrgTYPE;
     }
     else
     {
         scond_OrgTYPE = "OrgTYPE is null";
         sval_OrgTYPE = "null";
     }
     DataTable dt = new DataTable();
     string Err = null;
     dt.Columns.Clear();
     dt.Clear();
     string sql = @"select ID from cOrgTYPE where " + scond_OrgTYPE;
     if (DBSync.DBSync.ReadDataTable(ref dt, sql, lpar, ref Err))
     {
         if (dt.Rows.Count > 0)
         {
             cOrgTYPE_ID = (long)dt.Rows[0]["ID"];
             return true;
         }
         else
         {
             sql = @"insert into cOrgTYPE (OrgTYPE) values (" + sval_OrgTYPE + ")";
             object objretx = null;
             if (DBSync.DBSync.ExecuteNonQuerySQLReturnID(sql, lpar, ref cOrgTYPE_ID, ref objretx, ref Err, "Atom_cOrgTYPE"))
             {
                 return true;
             }
             else
             {
                 LogFile.Error.Show("ERROR:f_cOrgTYPE:Get:sql=" + sql + "\r\nErr=" + Err);
                 return false;
             }
         }
     }
     else
     {
         LogFile.Error.Show("ERROR:f_cOrgTYPE:Get:sql=" + sql + "\r\nErr=" + Err);
         return false;
     }
 }
Beispiel #9
0
 public static bool Get(string City, ref long cCity_Org_ID)
 {
     List<SQL_Parameter> lpar = new List<SQL_Parameter>();
     string scond_City = null;
     string sval_City = "null";
     if (City != null)
     {
         string spar_City = "@par_City";
         SQL_Parameter par_City = new SQL_Parameter(spar_City, SQL_Parameter.eSQL_Parameter.Nvarchar, false, City);
         lpar.Add(par_City);
         scond_City = "City = " + spar_City;
         sval_City = spar_City;
     }
     else
     {
         scond_City = "City is null";
         sval_City = "null";
     }
     DataTable dt = new DataTable();
     string Err = null;
     dt.Columns.Clear();
     dt.Clear();
     string sql = @"select ID from cCity_Org where " + scond_City;
     if (DBSync.DBSync.ReadDataTable(ref dt, sql, lpar, ref Err))
     {
         if (dt.Rows.Count > 0)
         {
             cCity_Org_ID = (long)dt.Rows[0]["ID"];
             return true;
         }
         else
         {
             sql = @"insert into cCity_Org (City) values (" + sval_City + ")";
             object objretx = null;
             if (DBSync.DBSync.ExecuteNonQuerySQLReturnID(sql, lpar, ref cCity_Org_ID, ref objretx, ref Err, "Atom_cCity_Org"))
             {
                 return true;
             }
             else
             {
                 LogFile.Error.Show("ERROR:f_cCity_Org:Get:sql=" + sql + "\r\nErr=" + Err);
                 return false;
             }
         }
     }
     else
     {
         LogFile.Error.Show("ERROR:f_cCity_Org:Get:sql=" + sql + "\r\nErr=" + Err);
         return false;
     }
 }
        internal static bool Get(string Name, string Description, ref long JOURNAL_Invoice_type_ID)
        {
            string Err = null;
            DataTable dt = new DataTable();
            string sql = null;

            sql = @"select ID from JOURNAL_Invoice_Type where Name = '" + Name + "'";
            if (Program.LocalDB_for_Tangenta.m_DBTables.m_con.ReadDataTable(ref dt, sql, null, ref Err))
            {
                if (dt.Rows.Count > 0)
                {
                    JOURNAL_Invoice_type_ID = (long)dt.Rows[0]["ID"];
                    return true;
                }
                else
                {

                    List<SQL_Parameter> lpar = new List<SQL_Parameter>();
                    string sPar_Description = "@Description";
                    if (Description != null)
                    {
                        SQL_Parameter par_Description = new SQL_Parameter(sPar_Description, SQL_Parameter.eSQL_Parameter.Nvarchar, false, sPar_Description);
                        lpar.Add(par_Description);
                    }
                    else
                    {
                        sPar_Description = "null";
                    }
                    string sPar_Name = "@Name";
                    SQL_Parameter par_Name = new SQL_Parameter(sPar_Name, SQL_Parameter.eSQL_Parameter.Nvarchar, false, sPar_Name);
                    lpar.Add(par_Name);

                    sql = @"insert into JOURNAL_Invoice_Type (Name,Description)values(" + sPar_Name + "," + sPar_Description + ")";
                    object objretx = null;
                    if (Program.LocalDB_for_Tangenta.m_DBTables.m_con.ExecuteNonQuerySQLReturnID(sql, null, ref JOURNAL_Invoice_type_ID, ref objretx, ref Err, "JOURNAL_Invoice_Type"))
                    {
                        return true;
                    }
                    else
                    {
                        LogFile.Error.Show("ERROR:f_JOURNAL_Invoice_Type:Get:" + sql + "\r\nErr=" + Err);
                        return false;
                    }
                }
            }
            else
            {
                LogFile.Error.Show("ERROR:f_JOURNAL_Invoice_Type:Get:" + sql + "\r\nErr=" + Err);
                return false;
            }
        }
Beispiel #11
0
        public static bool Get(string State, ref long cState_Person_ID)
        {
            string Err = null;

            List<SQL_Parameter> lpar = new List<SQL_Parameter>();
            string scond_State = null;
            string sval_State = "null";
            if (State != null)
            {
                string spar_State = "@par_State";
                SQL_Parameter par_State = new SQL_Parameter(spar_State, SQL_Parameter.eSQL_Parameter.Nvarchar, false, State);
                lpar.Add(par_State);
                scond_State = "State = " + spar_State;
                sval_State = spar_State;
            }
            else
            {
                scond_State = "State is null";
                sval_State = "null";
            }
            DataTable dt = new DataTable();

            string sql = @"select ID from cState_Person where " + scond_State;
            if (DBSync.DBSync.ReadDataTable(ref dt, sql, lpar, ref Err))
            {
                if (dt.Rows.Count > 0)
                {
                    cState_Person_ID = (long)dt.Rows[0]["ID"];
                    return true;
                }
                else
                {
                    sql = @"insert into cState_Person (State) values (" + sval_State + ")";
                    object objretx = null;
                    if (DBSync.DBSync.ExecuteNonQuerySQLReturnID(sql, lpar, ref cState_Person_ID, ref objretx, ref Err, "cState_Person"))
                    {
                        return true;
                    }
                    else
                    {
                        LogFile.Error.Show("ERROR:f_cState_Person:Get:sql=" + sql + "\r\nErr=" + Err);
                        return false;
                    }
                }
            }
            else
            {
                LogFile.Error.Show("ERROR:f_cState_Person:Get:sql=" + sql + "\r\nErr=" + Err);
                return false;
            }
        }
Beispiel #12
0
        public static bool Get(decimal PricePerUnit,long ID_Taxation,long ID_Currency, ref long PurchasePrice_ID)
        {
            List<SQL_Parameter> lpar = new List<SQL_Parameter>();

            string spar_PricePerUnit = "@par_PricePerUnit";
            SQL_Parameter par_PricePerUnit = new SQL_Parameter(spar_PricePerUnit, SQL_Parameter.eSQL_Parameter.Decimal, false, PricePerUnit);
            lpar.Add(par_PricePerUnit);

            string spar_ID_Taxation = "@par_ID_Taxation";
            SQL_Parameter par_ID_Taxation = new SQL_Parameter(spar_ID_Taxation, SQL_Parameter.eSQL_Parameter.Bigint, false, ID_Taxation);
            lpar.Add(par_ID_Taxation);

            string spar_ID_Currency = "@par_ID_Currency";
            SQL_Parameter par_ID_Currency = new SQL_Parameter(spar_ID_Currency, SQL_Parameter.eSQL_Parameter.Bigint, false, ID_Currency);
            lpar.Add(par_ID_Currency);

            string sql = "select ID from PurchasePrice where PurchasePricePerUnit = " + spar_PricePerUnit + " and  Currency_ID = " + spar_ID_Currency + " and Taxation_ID = " + spar_ID_Taxation;
            DataTable dt = new DataTable();
            string Err = null;
            if (DBSync.DBSync.ReadDataTable(ref dt, sql, lpar, ref Err))
            {
                if (dt.Rows.Count > 0)
                {
                    PurchasePrice_ID = (long)dt.Rows[0]["ID"];
                    return true;
                }
                else
                {
                    DateTime dtPurchasePriceDate = DateTime.Now;
                    string spar_PurchasePriceDate = "@par_PurchasePriceDate";
                    SQL_Parameter par_PurchasePriceDate = new SQL_Parameter(spar_PurchasePriceDate, SQL_Parameter.eSQL_Parameter.Datetime, false, dtPurchasePriceDate);
                    lpar.Add(par_PurchasePriceDate);
                    sql = "insert into PurchasePrice (PurchasePricePerUnit,Currency_ID,Taxation_ID,PurchasePriceDate)values(" + spar_PricePerUnit + "," + spar_ID_Currency + "," + spar_ID_Taxation + ","+ spar_PurchasePriceDate + ")";
                    object oret = null;
                    if (DBSync.DBSync.ExecuteNonQuerySQLReturnID(sql, lpar, ref PurchasePrice_ID, ref oret, ref Err, "PurchasePrice"))
                    {
                        return true;
                    }
                    else
                    {
                        LogFile.Error.Show("ERROR:TangentaDB:f_PurchasePrice:Get:sql=" + sql + "\r\nErr=" + Err);
                        return false;
                    }
                }
            }
            else
            {
                LogFile.Error.Show("ERROR:TangentaDB:f_PurchasePrice:Get:sql=" + sql + "\r\nErr=" + Err);
                return false;
            }
        }
Beispiel #13
0
 public static bool AddPar(string spar, ref List<SQL_Parameter> lpar, object obj_v, ref string cond, ref string value)
 {
     string spar_name = "@par_" + spar;
     SQL_Parameter par = null;
     if (obj_v == null)
     {
         cond = spar + " is null ";
         value = "null";
     }
     else
     {
         if (obj_v is bool_v)
         {
             par = new SQL_Parameter(spar_name, SQL_Parameter.eSQL_Parameter.Bit, false, ((bool_v)obj_v).v);
         }
         else if (obj_v is string_v)
         {
             par = new SQL_Parameter(spar_name, SQL_Parameter.eSQL_Parameter.Nvarchar, false, ((string_v)obj_v).v);
         }
         else if (obj_v is int_v)
         {
             par = new SQL_Parameter(spar_name, SQL_Parameter.eSQL_Parameter.Int, false, ((int_v)obj_v).v);
         }
         else if (obj_v is long_v)
         {
             par = new SQL_Parameter(spar_name, SQL_Parameter.eSQL_Parameter.Bigint, false, ((long_v)obj_v).v);
         }
         else if (obj_v is DateTime_v)
         {
             par = new SQL_Parameter(spar_name, SQL_Parameter.eSQL_Parameter.Datetime, false, ((DateTime_v)obj_v).v);
         }
         else if (obj_v is byte_array_v)
         {
             par = new SQL_Parameter(spar_name, SQL_Parameter.eSQL_Parameter.Varbinary, false, ((byte_array_v)obj_v).v);
         }
         else
         {
             LogFile.Error.Show("ERROR:f_Atom_Customer_Person:AddPar: Type " + obj_v.GetType().ToString() + " not implemented!");
             return false;
         }
         cond = spar + " = " + spar_name;
         value = spar_name;
         if (lpar == null)
         {
             lpar = new List<SQL_Parameter>();
         }
         lpar.Add(par);
     }
     return true;
 }
Beispiel #14
0
        public static bool Get(string ZIP, ref long cZIP_Org_ID)
        {
            string Err = null;

            List<SQL_Parameter> lpar = new List<SQL_Parameter>();
            string scond_ZIP = null;
            string sval_ZIP = "null";
            if (ZIP != null)
            {
                string spar_ZIP = "@par_ZIP";
                SQL_Parameter par_ZIP = new SQL_Parameter(spar_ZIP, SQL_Parameter.eSQL_Parameter.Nvarchar, false, ZIP);
                lpar.Add(par_ZIP);
                scond_ZIP = "ZIP = " + spar_ZIP;
                sval_ZIP = spar_ZIP;
            }
            else
            {
                scond_ZIP = "ZIP is null";
                sval_ZIP = "null";
            }
            DataTable dt = new DataTable();
            string sql = @"select ID from cZIP_Org where " + scond_ZIP;
            if (DBSync.DBSync.ReadDataTable(ref dt, sql, lpar, ref Err))
            {
                if (dt.Rows.Count > 0)
                {
                    cZIP_Org_ID = (long)dt.Rows[0]["ID"];
                    return true;
                }
                else
                {
                    sql = @"insert into cZIP_Org (ZIP) values (" + sval_ZIP + ")";
                    object objretx = null;
                    if (DBSync.DBSync.ExecuteNonQuerySQLReturnID(sql, lpar, ref cZIP_Org_ID, ref objretx, ref Err, "cZIP_Org"))
                    {
                        return true;
                    }
                    else
                    {
                        LogFile.Error.Show("ERROR:f_cZIP_Org:Get:sql=" + sql + "\r\nErr=" + Err);
                        return false;
                    }
                }
            }
            else
            {
                LogFile.Error.Show("ERROR:f_cZIP_Org:Get:sql=" + sql + "\r\nErr=" + Err);
                return false;
            }
        }
Beispiel #15
0
        public static bool Get(string Name,string_v Description_v,ref long Language_ID)
        {
            List<SQL_Parameter> lpar = new List<SQL_Parameter>();

            //Table Language
            string spar_Name = "@par_Name";
            SQL_Parameter par_Name = new SQL_Parameter(spar_Name, SQL_Parameter.eSQL_Parameter.Nvarchar, false, Name);
            lpar.Add(par_Name);

            string spar_Description = "@par_Description";
            string sval_Description = "null";
            if (Description_v != null)
            {
                SQL_Parameter par_Description = new SQL_Parameter(spar_Description, SQL_Parameter.eSQL_Parameter.Nvarchar, false, Description_v.v);
                lpar.Add(par_Description);
                sval_Description = spar_Description;
            }

            string sql = "select ID from Language where Name = " + spar_Name + " and Description = " + sval_Description;
            DataTable dt = new DataTable();
            string Err = null;
            if (DBSync.DBSync.ReadDataTable(ref dt, sql, lpar, ref Err))
            {
                if (dt.Rows.Count > 0)
                {
                    Language_ID = (long)dt.Rows[0]["ID"];
                    return true;
                }
                else
                {
                    sql = "insert into Language (Name,Description,bDefault)values(" + spar_Name + "," + sval_Description + ",0)";
                    object oret = null;
                    if (DBSync.DBSync.ExecuteNonQuerySQLReturnID(sql, lpar, ref Language_ID, ref oret, ref Err, "Language"))
                    {
                        return true;
                    }
                    else
                    {
                        LogFile.Error.Show("ERROR:f_doc:InsertDefault:sql=" + sql + "\r\nErr=" + Err);
                        return false;
                    }
                }
            }
            else
            {
                LogFile.Error.Show("ERROR:f_Language:Get:sql=" + sql + "\r\nErr=" + Err);
                return false;
            }
        }
        public static bool Get(long Invoice_ID, string xSerialNumber,string xSetNumber,string xInvoiceNumber, ref long FVI_SLO_SalesBookInvoice_ID)
        {
            string Err = null;
            DataTable dt = new DataTable();
            List<SQL_Parameter> lpar = new List<SQL_Parameter>();
            string spar_Invoice_ID = "@par_Invoice_ID";
            SQL_Parameter par_Invoice_ID = new SQL_Parameter(spar_Invoice_ID, SQL_Parameter.eSQL_Parameter.Bigint, false, Invoice_ID);
                lpar.Add(par_Invoice_ID);
            string spar_SerialNumber = "@par_SerialNumber";
            SQL_Parameter par_SerialNumber = new SQL_Parameter(spar_SerialNumber, SQL_Parameter.eSQL_Parameter.Varchar, false, xSerialNumber);
            lpar.Add(par_SerialNumber);
            string spar_SetNumber = "@par_SetNumber";
            SQL_Parameter par_SetNumber = new SQL_Parameter(spar_SetNumber, SQL_Parameter.eSQL_Parameter.Varchar, false, xSetNumber);
            lpar.Add(par_SetNumber);
            string spar_InvoiceNumber = "@par_InvoiceNumber";
            SQL_Parameter par_InvoiceNumber = new SQL_Parameter(spar_InvoiceNumber, SQL_Parameter.eSQL_Parameter.Varchar, false, xInvoiceNumber);
            lpar.Add(par_InvoiceNumber);

            string sql = @"select ID from FVI_SLO_SalesBookInvoice
                                where Invoice_ID = " + spar_Invoice_ID + " and SerialNumber = " + spar_SerialNumber + " and SetNumber = " + spar_SetNumber + " and InvoiceNumber = " + spar_InvoiceNumber;

            if (DBSync.DBSync.ReadDataTable(ref dt, sql, lpar, ref Err))
            {
                if (dt.Rows.Count > 0)
                {
                    FVI_SLO_SalesBookInvoice_ID = (long)dt.Rows[0]["ID"];
                    return true;
                }
                else
                {
                sql = @"insert into FVI_SLO_SalesBookInvoice (Invoice_ID,SerialNumber,SetNumber,InvoiceNumber) values(" + spar_Invoice_ID + "," + spar_SerialNumber + "," + spar_SetNumber + "," + spar_InvoiceNumber + ")";
                    object objretx = null;
                    if (DBSync.DBSync.ExecuteNonQuerySQLReturnID(sql, lpar, ref FVI_SLO_SalesBookInvoice_ID, ref objretx, ref Err, "FVI_SLO_SalesBookInvoice"))
                    {
                        return true;
                    }
                    else
                    {
                        LogFile.Error.Show("ERROR:f_FVI_SLO_SalesBookInvoice:Get:" + sql + "\r\nErr=" + Err);
                        return false;
                    }
                }
            }
            else
            {
                LogFile.Error.Show("ERROR:f_FVI_SLO_SalesBookInvoice:Get:" + sql + "\r\nErr=" + Err);
                return false;
            }
        }
Beispiel #17
0
        public static bool Get(string Name,decimal Rate, ref long Taxation_ID)
        {
            List<SQL_Parameter> lpar = new List<SQL_Parameter>();

            //Table Language
            string spar_Name = "@par_Name";
            SQL_Parameter par_Name = new SQL_Parameter(spar_Name, SQL_Parameter.eSQL_Parameter.Nvarchar, false, Name);
            lpar.Add(par_Name);

            string spar_Rate = "@par_Rate";
            string sval_Rate = "null";
            SQL_Parameter par_Rate = new SQL_Parameter(spar_Rate, SQL_Parameter.eSQL_Parameter.Decimal, false, Rate);
            lpar.Add(par_Rate);
            sval_Rate = spar_Rate;

            string sql = "select ID from Taxation where Name = " + spar_Name + " and Rate = " + sval_Rate;
            DataTable dt = new DataTable();
            string Err = null;
            if (DBSync.DBSync.ReadDataTable(ref dt, sql, lpar, ref Err))
            {
                if (dt.Rows.Count > 0)
                {
                    Taxation_ID = (long)dt.Rows[0]["ID"];
                    return true;
                }
                else
                {
                    sql = "insert into Taxation (Name,Rate)values(" + spar_Name + "," + sval_Rate + ")";
                    object oret = null;
                    if (DBSync.DBSync.ExecuteNonQuerySQLReturnID(sql, lpar, ref Taxation_ID, ref oret, ref Err, "Taxation"))
                    {
                        return true;
                    }
                    else
                    {
                        LogFile.Error.Show("ERROR:f_Taxation:InsertDefault:sql=" + sql + "\r\nErr=" + Err);
                        return false;
                    }
                }
            }
            else
            {
                LogFile.Error.Show("ERROR:f_Taxation:Get:sql=" + sql + "\r\nErr=" + Err);
                return false;
            }
        }
Beispiel #18
0
        public static bool Get(long Stock_id, long stock_type_id, DateTime dEventTime, decimal dQuantity, ref long_v JOURNAL_Stock_ID)
        {
            List<SQL_Parameter> lpar = new List<SQL_Parameter>();
            string spar_JOURNAL_Stock_Type_ID = "@par_JOURNAL_Stock_Type_ID";
            SQL_Parameter par_JOURNAL_Stock_Type_ID = new SQL_Parameter(spar_JOURNAL_Stock_Type_ID, SQL_Parameter.eSQL_Parameter.Bigint, false, stock_type_id);
            lpar.Add(par_JOURNAL_Stock_Type_ID);

            string spar_Stock_ID = "@par_Stock_ID";
            SQL_Parameter par_Stock_ID = new SQL_Parameter(spar_Stock_ID, SQL_Parameter.eSQL_Parameter.Bigint, false, Stock_id);
            lpar.Add(par_Stock_ID);

            string spar_EventTime = "@par_EventTime";
            SQL_Parameter par_EventTime = new SQL_Parameter(spar_EventTime, SQL_Parameter.eSQL_Parameter.Datetime, false, dEventTime);
            lpar.Add(par_EventTime);

            long Atom_WorkPeriod_id = GlobalData.Atom_WorkPeriod_ID;
            string spar_Atom_WorkPeriod_ID = "@par_Atom_WorkPeriod_ID";
            SQL_Parameter par_Atom_WorkPeriod_ID = new SQL_Parameter(spar_Atom_WorkPeriod_ID, SQL_Parameter.eSQL_Parameter.Bigint, false, Atom_WorkPeriod_id);
            lpar.Add(par_Atom_WorkPeriod_ID);

            string spar_dQuantity = "@par_dQuantity";
            SQL_Parameter par_dQuantity = new SQL_Parameter(spar_dQuantity, SQL_Parameter.eSQL_Parameter.Decimal, false, dQuantity);
            lpar.Add(par_dQuantity);

            string table_name = "JOURNAL_Stock";
            string sql = "insert into " + table_name + " (JOURNAL_Stock_Type_ID,Stock_ID,EventTime,Atom_WorkPeriod_ID,dQuantity)values(" + spar_JOURNAL_Stock_Type_ID + "," + spar_Stock_ID + "," + spar_EventTime + "," + spar_Atom_WorkPeriod_ID + "," + spar_dQuantity + ")";
            long id = -1;
            object oret = null;
            string Err = null;
            if (DBSync.DBSync.ExecuteNonQuerySQLReturnID(sql, lpar, ref id, ref oret, ref Err, table_name))
            {
                if (JOURNAL_Stock_ID == null)
                {
                    JOURNAL_Stock_ID = new long_v();
                }
                JOURNAL_Stock_ID.v = id;
                return true;
            }
            else
            {
                LogFile.Error.Show("ERROR:f_JOURNAL_Stock:Get:sql=" + sql + "\r\nErr=" + Err);
                return false;
            }
        }
Beispiel #19
0
        public static bool Get(string Image_Hash, byte[] Image_Data, ref long Item_Image_ID)
        {
            DataTable dt = new DataTable();
            string Err = null;
            List<SQL_Parameter> lpar = new List<SQL_Parameter>();
            string spar_Image_Hash = "@par_Image_Hash";
            SQL_Parameter par_Image_Hash = new SQL_Parameter(spar_Image_Hash, SQL_Parameter.eSQL_Parameter.Nvarchar, false, Image_Hash);
            lpar.Add(par_Image_Hash);
            string sql = "select ID from Item_Image where Image_Hash = " + spar_Image_Hash;
            if (DBSync.DBSync.ReadDataTable(ref dt, sql, lpar, ref Err))
            {
                if (dt.Rows.Count > 0)
                {
                    Item_Image_ID = (long)dt.Rows[0]["ID"];
                    return true;
                }
                else
                {
                    string spar_Image_Data = "@par_Image_Data";
                    SQL_Parameter par_Image_Data = new SQL_Parameter(spar_Image_Hash, SQL_Parameter.eSQL_Parameter.Varbinary, false, Image_Data);
                    lpar.Add(par_Image_Data);

                    sql = "insert into Item_Image (Image_Hash,Image_Data)values(" + spar_Image_Hash + "," + spar_Image_Data + ")";
                    object oret = null;
                    if (DBSync.DBSync.ExecuteNonQuerySQLReturnID(sql, lpar, ref Item_Image_ID, ref oret, ref Err, "Item_Image"))
                    {
                        return true;
                    }
                    else
                    {
                        LogFile.Error.Show("ERROR:f_Item_Image:Get:sql=" + sql + "\r\nErr=" + Err);
                        return false;
                    }
                }
            }
            else
            {
                LogFile.Error.Show("ERROR:f_Item_Image:Get:sql=" + sql + "\r\nErr=" + Err);
                return false;
            }
        }
Beispiel #20
0
        public static bool End(long Atom_WorkPeriod_ID)
        {
            List<SQL_Parameter> lpar = new List<SQL_Parameter>();
            DateTime dtWorkPeriodEnd = DateTime.Now;
            string spar_WorkPeriodEnd = "@par_WorkPeriodEnd";
            SQL_Parameter par_PeriodEnd = new SQL_Parameter(spar_WorkPeriodEnd,SQL_Parameter.eSQL_Parameter.Datetime,false,dtWorkPeriodEnd);
            lpar.Add(par_PeriodEnd);

            string sql = "update Atom_WorkPeriod set LogoutTime = " + spar_WorkPeriodEnd + " where ID = " + Atom_WorkPeriod_ID.ToString();
            object ores = null;
            string Err = null;
            if (DBSync.DBSync.ExecuteNonQuerySQL(sql,lpar,ref ores,ref Err))
            {
                return true;
            }
            else
            {
                LogFile.Error.Show("ERROR:f_Atom_WorkPeriod:End:sql=" + sql + "\r\nErr=" + Err);
                return false;
            }
        }
        public static bool Get(string Name, ref long ID)
        {
            string Err = null;
            List<SQL_Parameter> lpar = new List<SQL_Parameter>();
            string spar_Name = "@par_Name";
            SQL_Parameter par = new SQL_Parameter(spar_Name, SQL_Parameter.eSQL_Parameter.Nvarchar, false, Name);
            lpar.Add(par);

            string sql = "select ID from StockTakeCostName where Name =" + spar_Name;
            DataTable dt = new DataTable();
            if (DBSync.DBSync.ReadDataTable(ref dt, sql, lpar, ref Err))
            {
                if (dt.Rows.Count > 0)
                {
                    ID = (long)dt.Rows[0]["ID"];
                    return true;
                }
                else
                {
                    sql = "insert into StockTakeCostName (Name)values(" + spar_Name + ")";
                    object oret = null;
                    if (DBSync.DBSync.ExecuteNonQuerySQLReturnID(sql, lpar, ref ID, ref oret, ref Err, "StockTakeCostName"))
                    {
                        return true;
                    }
                    else
                    {
                        LogFile.Error.Show("ERROR:TangentaDB:f_StocTakeCostName.cs:Get:sql=" + sql + "\r\nErr=" + Err);
                    }
                }
            }
            else
            {
                LogFile.Error.Show("ERROR:TangentaDB:f_StocTakeCostName.cs:Get:sql=" + sql + "\r\nErr=" + Err);
            }
            return false;
        }
 public static bool Get(string Name, ref long SimpleItem_ParentGroup3_ID)
 {
     List<SQL_Parameter> lpar = new List<SQL_Parameter>();
     string spar_Name = "@par_Name";
     SQL_Parameter par_Name = new SQL_Parameter(spar_Name, SQL_Parameter.eSQL_Parameter.Nvarchar, false, Name);
     lpar.Add(par_Name);
     string sql = "select ID from SimpleItem_ParentGroup3 where Name = " + spar_Name;
     DataTable dt = new DataTable();
     string Err = null;
     if (DBSync.DBSync.ReadDataTable(ref dt, sql, lpar, ref Err))
     {
         if (dt.Rows.Count > 0)
         {
             SimpleItem_ParentGroup3_ID = (long)dt.Rows[0]["ID"];
             return true;
         }
         else
         {
             sql = "insert into SimpleItem_ParentGroup3 (Name) values (" + spar_Name + ")";
             object oret = null;
             if (DBSync.DBSync.ExecuteNonQuerySQLReturnID(sql, lpar, ref SimpleItem_ParentGroup3_ID, ref oret, ref Err, "SimpleItem_ParentGroup3"))
             {
                 return true;
             }
             else
             {
                 LogFile.Error.Show("ERROR:f_SimpleItem_ParentGroup3:Get:sql=" + sql + "\r\nErr=" + Err);
                 return false;
             }
         }
     }
     else
     {
         LogFile.Error.Show("ERROR:f_SimpleItem_ParentGroup3:Get:sql=" + sql + "\r\nErr=" + Err);
         return false;
     }
 }
Beispiel #23
0
 public bool Remove_from_StockShelf()
 {
     if (Stock_ID != null)
     {
         if (dQuantity_New_in_Stock != null)
         {
             List<SQL_Parameter> lpar = new List<SQL_Parameter>();
             string spar_dQuantity_New_in_Stock = "@par_dQuantity_New_in_Stock";
             SQL_Parameter par_dQuantity_New_in_Stock = new SQL_Parameter(spar_dQuantity_New_in_Stock, SQL_Parameter.eSQL_Parameter.Decimal, false, dQuantity_New_in_Stock.v);
             lpar.Add(par_dQuantity_New_in_Stock);
             string sql = "update stock set dQuantity = " + spar_dQuantity_New_in_Stock + " where ID = " + Stock_ID.v.ToString();
             object ores = null;
             string Err = null;
             if (DBSync.DBSync.ExecuteNonQuerySQL(sql, lpar, ref ores, ref Err))
             {
                 long_v JOURNAL_Stock_ID = null;
                 DateTime EventTime = DateTime.Now;
                 decimal dQuantityRemovedFromStock = dQuantity.v;
                 return f_JOURNAL_Stock.Get(Stock_ID.v, f_JOURNAL_Stock.JOURNAL_Stock_Type_ID_from_stock_to_basket, EventTime, dQuantityRemovedFromStock, ref JOURNAL_Stock_ID);
             }
             else
             {
                 LogFile.Error.Show("ERROR:Stock_Data:Remove_from_StockShelf:sql = " + sql + "\r\nErr=" + Err);
             }
         }
         else
         {
             LogFile.Error.Show("ERROR:Stock_Data:Remove_from_StockShelf:dQuantity_New_in_Stock==null!");
         }
     }
     else
     {
         LogFile.Error.Show("ERROR:Stock_Data:Remove_from_StockShelf:dQuantity_New_in_Stock==null!");
     }
     return false;
 }
Beispiel #24
0
        private bool Get_Atom_Item_barcode(string_v Item_barcode, ref long Atom_Item_barcode_ID, ref string Err)
        {
            if (Item_barcode != null)
            {
                List<DBConnectionControl40.SQL_Parameter> lpar = new List<DBConnectionControl40.SQL_Parameter>();
                string spar_barcode = "@par_barcode";
                DBConnectionControl40.SQL_Parameter par_barcode = new DBConnectionControl40.SQL_Parameter(spar_barcode, DBConnectionControl40.SQL_Parameter.eSQL_Parameter.Varchar, false, Item_barcode.v);
                lpar.Add(par_barcode);
                string sql_select_Atom_Item_barcode_ID = @"select ID as Atom_Item_barcode_ID from Atom_Item_barcode where barcode = " + spar_barcode;
                DataTable dt = new DataTable();
                if (DBSync.DBSync.ReadDataTable(ref dt, sql_select_Atom_Item_barcode_ID, lpar, ref Err))
                {
                    if (dt.Rows.Count > 0)
                    {
                        Atom_Item_barcode_ID = (long)dt.Rows[0]["Atom_Item_barcode_ID"];
                        return true;
                    }
                    else
                    {
                        string sql_Insert_Atom_Item_barcode = @"insert into Atom_Item_barcode (barcode)values(" + spar_barcode + ")";
                        object objret = null;
                        if (DBSync.DBSync.ExecuteNonQuerySQLReturnID(sql_Insert_Atom_Item_barcode, lpar, ref Atom_Item_barcode_ID, ref objret, ref Err, DBtcn.stbl_Atom_Item_barcode_TableName))
                        {
                            return true;
                        }
                        else
                        {
                            LogFile.Error.Show("ERROR:Get_Atom_Item_barcode:insert into Atom_Item_barcode failed!\r\nErr=" + Err);
                            return false;
                        }
                    }
                }
                else
                {
                    return false;
                }

            }
            else
            {
                Atom_Item_barcode_ID = -1;
                return true;
            }
        }
Beispiel #25
0
        public static bool Get(string Name, string Symbol, int DecimalPlaces, bool StorageOption, string Description, ref long Unit_ID)
        {
            List<SQL_Parameter> lpar = new List<SQL_Parameter>();

            string spar_Name = "@par_Name";
            SQL_Parameter par_Name = new SQL_Parameter(spar_Name, SQL_Parameter.eSQL_Parameter.Nvarchar, false, Name);
            lpar.Add(par_Name);

            string spar_Symbol = "@par_Symbol";
            SQL_Parameter par_Symbol = new SQL_Parameter(spar_Symbol, SQL_Parameter.eSQL_Parameter.Nvarchar, false, Symbol);
            lpar.Add(par_Symbol);

            string spar_DecimalPlaces = "@par_DecimalPlaces";
            SQL_Parameter par_DecimalPlaces = new SQL_Parameter(spar_DecimalPlaces, SQL_Parameter.eSQL_Parameter.Int, false, DecimalPlaces);
            lpar.Add(par_DecimalPlaces);

            string spar_StorageOption = "@par_StorageOption";
            SQL_Parameter par_StorageOption = new SQL_Parameter(spar_StorageOption, SQL_Parameter.eSQL_Parameter.Bit, false, StorageOption);
            lpar.Add(par_StorageOption);

            string scond_Description = " Description is null ";
            string sval_Description = " null ";
            if (Description != null)
            {
                string spar_Description = "@par_Description";
                SQL_Parameter par_Description = new SQL_Parameter(spar_Description, SQL_Parameter.eSQL_Parameter.Nvarchar, false, Description);
                lpar.Add(par_Description);
                scond_Description = " Description = " + spar_Description + " ";
                sval_Description = " " + spar_Description + " ";
            }

            string sql = "select ID from Unit where Name = " + spar_Name + " and  Symbol = " + spar_Symbol + " and DecimalPlaces = " + spar_DecimalPlaces + " and StorageOption = " + spar_StorageOption + " and " + scond_Description;

            DataTable dt = new DataTable();
            string Err = null;
            if (DBSync.DBSync.ReadDataTable(ref dt, sql, lpar, ref Err))
            {
                if (dt.Rows.Count > 0)
                {
                    Unit_ID = (long)dt.Rows[0]["ID"];
                    return true;
                }
                else
                {
                    sql = "insert into Unit (Name,Symbol,DecimalPlaces,StorageOption,Description)values(" + spar_Name + "," + spar_Symbol + "," + spar_DecimalPlaces + "," + spar_StorageOption + "," + sval_Description + ")";
                    object oret = null;
                    if (DBSync.DBSync.ExecuteNonQuerySQLReturnID(sql, lpar, ref Unit_ID, ref oret, ref Err, "Unit"))
                    {
                        return true;
                    }
                    else
                    {
                        LogFile.Error.Show("ERROR:f_Unit:InsertDefault:sql=" + sql + "\r\nErr=" + Err);
                        return false;
                    }
                }
            }
            else
            {
                LogFile.Error.Show("ERROR:f_Unit:Get:sql=" + sql + "\r\nErr=" + Err);
                return false;
            }
        }
Beispiel #26
0
        private bool Get_Atom_Item(ref Atom_DocInvoice_ShopC_Item_Price_Stock_Data appisd)
        {
            string Err = null;
            string sAtom_Item_Name_ID = null;
            long Atom_Item_Name_ID = -1;
            if (Get_Atom_Item_Name(appisd.Atom_Item_Name_Name, ref Atom_Item_Name_ID))
            {
                if (Atom_Item_Name_ID >= 0)
                {

                    sAtom_Item_Name_ID = Atom_Item_Name_ID.ToString();

                    string sAtom_Unit_ID = null;
                    long Atom_Unit_ID = -1;

                    if (Get_Atom_Unit_ID(appisd, ref Atom_Unit_ID))
                    {

                        if (Atom_Unit_ID >= 0)
                        {
                            string scond_UniqueName = null;
                            string sv_UniqueName = null;

                            List<DBConnectionControl40.SQL_Parameter> lpar = new List<DBConnectionControl40.SQL_Parameter>();
                            string spar_UniqueName = "@par_UniqueName";
                            DBConnectionControl40.SQL_Parameter par_UniqueName = new DBConnectionControl40.SQL_Parameter(spar_UniqueName, DBConnectionControl40.SQL_Parameter.eSQL_Parameter.Nvarchar, false, appisd.Atom_Item_UniqueName.v);
                            lpar.Add(par_UniqueName);
                            scond_UniqueName = "(UniqueName = @par_UniqueName)";
                            sv_UniqueName = spar_UniqueName;

                            sAtom_Unit_ID = Atom_Unit_ID.ToString();
                            long Atom_Item_barcode_ID = -1;
                            string scond_Atom_Item_barcode_ID = null;
                            string sv_Atom_Item_barcode_ID = null;
                            if (Get_Atom_Item_barcode(appisd.Atom_Item_barcode_barcode, ref Atom_Item_barcode_ID, ref Err))
                            {
                                if (Atom_Item_barcode_ID >= 0)
                                {
                                    scond_Atom_Item_barcode_ID = "(Atom_Item_barcode_ID = " + Atom_Item_barcode_ID.ToString() + ")";
                                    sv_Atom_Item_barcode_ID = Atom_Item_barcode_ID.ToString();
                                }
                                else
                                {
                                    scond_Atom_Item_barcode_ID = "(Atom_Item_barcode_ID is null)";
                                    sv_Atom_Item_barcode_ID = "null";
                                }
                            }
                            long Atom_Item_Description_ID = -1;
                            string scond_Atom_Item_Description_ID = null;
                            string sv_Atom_Item_Description_ID = null;
                            if (Get_Atom_Item_Description(appisd.Atom_Item_Description_Description, ref Atom_Item_Description_ID, ref Err))
                            {
                                if (Atom_Item_Description_ID >= 0)
                                {
                                    scond_Atom_Item_Description_ID = "(Atom_Item_Description_ID = " + Atom_Item_Description_ID.ToString() + ")";
                                    sv_Atom_Item_Description_ID = Atom_Item_Description_ID.ToString();
                                }
                                else
                                {
                                    scond_Atom_Item_Description_ID = "(Atom_Item_Description_ID is null)";
                                    sv_Atom_Item_Description_ID = "null";
                                }
                            }

                            long Atom_Expiry_ID = -1;
                            string scond_Atom_Expiry_ID = null;
                            string sv_Atom_Expiry_ID = null;
                            if (appisd.Atom_Expiry_ExpectedShelfLifeInDays != null)
                            {
                                if (Get_Atom_Expiry(appisd.Atom_Expiry_ExpectedShelfLifeInDays,
                                                    appisd.Atom_Expiry_SaleBeforeExpiryDateInDays,
                                                    appisd.Atom_Expiry_DiscardBeforeExpiryDateInDays,
                                                    appisd.Atom_Expiry_ExpiryDescription,
                                                   ref Atom_Expiry_ID, ref Err))
                                {
                                    scond_Atom_Expiry_ID = "(Atom_Expiry_ID = " + Atom_Expiry_ID.ToString() + ")";
                                    sv_Atom_Expiry_ID = Atom_Expiry_ID.ToString();
                                }
                                else
                                {
                                    return false;
                                }
                            }
                            else
                            {
                                scond_Atom_Expiry_ID = "(Atom_Expiry_ID is null)";
                                sv_Atom_Expiry_ID = "null";
                            }

                            long Atom_Item_Atom_Warranty_ID = -1;
                            string scond_Atom_Warranty_ID = null;
                            string sv_Atom_Warranty_ID = null;
                            if (appisd.Atom_Warranty_ID != null)
                            {
                                if (Get_Atom_Warranty(appisd.Atom_Warranty_WarrantyDurationType, appisd.Atom_Warranty_WarrantyDuration, appisd.Atom_Warranty_WarrantyConditions, ref Atom_Item_Atom_Warranty_ID, ref Err))
                                {
                                    scond_Atom_Warranty_ID = "(Atom_Warranty_ID = " + Atom_Item_Atom_Warranty_ID.ToString() + ")";
                                    sv_Atom_Warranty_ID = Atom_Item_Atom_Warranty_ID.ToString();

                                }
                                else
                                {
                                    return false;
                                }
                            }
                            else
                            {
                                scond_Atom_Warranty_ID = "(Atom_Warranty_ID is null)";
                                sv_Atom_Warranty_ID = "null";

                            }

                            string sql = @"select ID as Atom_Item_ID from Atom_Item
                                                            where
                                                           " + scond_UniqueName + @" and
                                                           Atom_Item_Name_ID = " + Atom_Item_Name_ID.ToString() + @" and
                                                           Atom_Unit_ID = " + sAtom_Unit_ID + @" and
                                                           " + scond_Atom_Item_barcode_ID + @" and
                                                           " + scond_Atom_Item_Description_ID + @" and
                                                           " + scond_Atom_Warranty_ID + @" and
                                                           " + scond_Atom_Expiry_ID;

                            DataTable dt = new DataTable();

                            if (DBSync.DBSync.ReadDataTable(ref dt, sql, lpar, ref Err))
                            {
                                if (dt.Rows.Count > 0)
                                {
                                    if (appisd.Atom_Item_ID == null)
                                    {
                                        appisd.Atom_Item_ID = new long_v();
                                    }
                                    appisd.Atom_Item_ID.v = (long)dt.Rows[0]["Atom_Item_ID"];
                                    return true;
                                }
                                else
                                {
                                    sql = @"insert into Atom_Item
                                            (
                                                UniqueName,
                                                Atom_Item_Name_ID,
                                                Atom_Unit_ID,
                                                Atom_Item_barcode_ID,
                                                Atom_Item_Description_ID,
                                                Atom_Warranty_ID,
                                                Atom_Expiry_ID
                                            )   values("
                                            + sv_UniqueName + ",\r\n"
                                            + Atom_Item_Name_ID.ToString() + ",\r\n"
                                            + sAtom_Unit_ID + ",\r\n"
                                            + sv_Atom_Item_barcode_ID + ",\r\n"
                                            + sv_Atom_Item_Description_ID + ",\r\n"
                                            + sv_Atom_Warranty_ID + ",\r\n"
                                            + sv_Atom_Expiry_ID
                                            + ")";

                                    object objret = null;
                                    long Atom_Item_ID = -1;
                                    if (DBSync.DBSync.ExecuteNonQuerySQLReturnID(sql, lpar, ref Atom_Item_ID, ref objret, ref Err, DBtcn.stbl_Atom_Item_TableName))
                                    {
                                        if (appisd.Atom_Item_ID == null)
                                        {
                                            appisd.Atom_Item_ID = new long_v();
                                        }
                                        appisd.Atom_Item_ID.v = Atom_Item_ID;
                                        return true;
                                    }
                                    else
                                    {
                                        LogFile.Error.Show("ERROR:Get_Atom_Item:insert into Atom_Item failed!\r\nErr=" + Err);
                                        return false;
                                    }
                                }
                            }
                            else
                            {

                                LogFile.Error.Show("ERROR:Get_Atom_Item:select ID as Atom_Item_ID from Atom_Item failed!\r\nErr=" + Err);
                                return false;
                            }
                        }
                        else
                        {
                            LogFile.Error.Show("ERROR:Get_Atom_Item:Atom_Unit_ID not found!");
                            return false;
                        }
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    LogFile.Error.Show("ERROR:No Atom_Item_Name_ID !");
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
Beispiel #27
0
        bool Get_Atom_Expiry(int_v Expiry_ExpectedShelfLifeInDays,
                                    int_v Expiry_SaleBeforeExpiryDateInDays,
                                    int_v Expiry_DiscardBeforeExpiryDateInDays,
                                    string_v Expiry_ExpiryDescription,
                                    ref long Atom_Expiry_ID, ref string Err)
        {
            string scond_ExpectedShelfLifeInDays = null;
            string sv_ExpectedShelfLifeInDays = null;
            List<DBConnectionControl40.SQL_Parameter> lpar = new List<DBConnectionControl40.SQL_Parameter>();
            if (Expiry_ExpectedShelfLifeInDays != null)
            {
                string spar_ExpectedShelfLifeInDays = "@par_ExpectedShelfLifeInDays";
                DBConnectionControl40.SQL_Parameter par_ExpectedShelfLifeInDays = new DBConnectionControl40.SQL_Parameter(spar_ExpectedShelfLifeInDays, DBConnectionControl40.SQL_Parameter.eSQL_Parameter.Int, false, Expiry_ExpectedShelfLifeInDays.v);
                lpar.Add(par_ExpectedShelfLifeInDays);
                scond_ExpectedShelfLifeInDays = "(ExpectedShelfLifeInDays = " + spar_ExpectedShelfLifeInDays + ")";
                sv_ExpectedShelfLifeInDays = spar_ExpectedShelfLifeInDays;
            }
            else
            {
                scond_ExpectedShelfLifeInDays = "(ExpectedShelfLifeInDays is null)";
                sv_ExpectedShelfLifeInDays = "null";
            }
            string scond_Expiry_SaleBeforeExpiryDateInDays = null;
            string sv_Expiry_SaleBeforeExpiryDateInDays = null;
            if (Expiry_SaleBeforeExpiryDateInDays != null)
            {
                string spar_SaleBeforeExpiryDateInDays = "@par_SaleBeforeExpiryDateInDays";
                DBConnectionControl40.SQL_Parameter par_SaleBeforeExpiryDateInDays = new DBConnectionControl40.SQL_Parameter(spar_SaleBeforeExpiryDateInDays, DBConnectionControl40.SQL_Parameter.eSQL_Parameter.Int, false, Expiry_SaleBeforeExpiryDateInDays.v);
                lpar.Add(par_SaleBeforeExpiryDateInDays);
                scond_Expiry_SaleBeforeExpiryDateInDays = "(SaleBeforeExpiryDateInDays = " + spar_SaleBeforeExpiryDateInDays + ")";
                sv_Expiry_SaleBeforeExpiryDateInDays = spar_SaleBeforeExpiryDateInDays;
            }
            else
            {
                scond_Expiry_SaleBeforeExpiryDateInDays = "(SaleBeforeExpiryDateInDays is null)";
                sv_Expiry_SaleBeforeExpiryDateInDays = "null";
            }

            string scond_Expiry_DiscardBeforeExpiryDateInDays = null;
            string sv_Expiry_DiscardBeforeExpiryDateInDays = null;
            if (Expiry_DiscardBeforeExpiryDateInDays != null)
            {
                string spar_DiscardBeforeExpiryDateInDays = "@par_DiscardBeforeExpiryDateInDays";
                DBConnectionControl40.SQL_Parameter par_DiscardBeforeExpiryDateInDays = new DBConnectionControl40.SQL_Parameter(spar_DiscardBeforeExpiryDateInDays, DBConnectionControl40.SQL_Parameter.eSQL_Parameter.Int, false, Expiry_DiscardBeforeExpiryDateInDays.v);
                lpar.Add(par_DiscardBeforeExpiryDateInDays);
                scond_Expiry_DiscardBeforeExpiryDateInDays = "(DiscardBeforeExpiryDateInDays = " + spar_DiscardBeforeExpiryDateInDays + ")";
                sv_Expiry_DiscardBeforeExpiryDateInDays = spar_DiscardBeforeExpiryDateInDays;
            }
            else
            {
                scond_Expiry_DiscardBeforeExpiryDateInDays = "(DiscardBeforeExpiryDateInDays is null)";
                sv_Expiry_DiscardBeforeExpiryDateInDays = "null";
            }

            string scond_Expiry_ExpiryDescription = null;
            string sv_Expiry_ExpiryDescription = null;
            if (Expiry_ExpiryDescription != null)
            {
                string spar_ExpiryDescription = "@par_ExpiryDescription";
                DBConnectionControl40.SQL_Parameter par_ExpiryDescription = new DBConnectionControl40.SQL_Parameter(spar_ExpiryDescription, DBConnectionControl40.SQL_Parameter.eSQL_Parameter.Varchar, false, Expiry_ExpiryDescription.v);
                lpar.Add(par_ExpiryDescription);
                scond_Expiry_ExpiryDescription = "(ExpiryDescription = " + spar_ExpiryDescription + ")";
                sv_Expiry_ExpiryDescription = spar_ExpiryDescription;
            }
            else
            {
                scond_Expiry_ExpiryDescription = "(ExpiryDescription is null)";
                sv_Expiry_ExpiryDescription = "null";
            }

            string sql_select_Atom_Expiry_ID = @"select ID as Atom_Expiry_ID from Atom_Expiry where " + scond_ExpectedShelfLifeInDays + " and "
                                                                                                   + scond_Expiry_SaleBeforeExpiryDateInDays + " and "
                                                                                                   + scond_Expiry_DiscardBeforeExpiryDateInDays + " and "
                                                                                                   + scond_Expiry_ExpiryDescription;

            DataTable dt = new DataTable();
            if (DBSync.DBSync.ReadDataTable(ref dt, sql_select_Atom_Expiry_ID, lpar, ref Err))
            {
                if (dt.Rows.Count > 0)
                {
                    Atom_Expiry_ID = (long)dt.Rows[0]["Atom_Expiry_ID"];
                    return true;
                }
                else
                {
                    string sql_Insert_Atom_Item_ExpiryDescription = @"insert into Atom_Expiry (ExpectedShelfLifeInDays,
                                                                                             SaleBeforeExpiryDateInDays,
                                                                                             DiscardBeforeExpiryDateInDays,
                                                                                             ExpiryDescription)values("
                                                                                             + sv_ExpectedShelfLifeInDays + ","
                                                                                             + sv_Expiry_SaleBeforeExpiryDateInDays + ","
                                                                                             + sv_Expiry_DiscardBeforeExpiryDateInDays + ","
                                                                                             + sv_Expiry_ExpiryDescription
                                                                                            + ")";
                    object objret = null;
                    if (DBSync.DBSync.ExecuteNonQuerySQLReturnID(sql_Insert_Atom_Item_ExpiryDescription, lpar, ref Atom_Expiry_ID, ref objret, ref Err, DBtcn.stbl_Atom_Item_ExpiryDescription_TableName))
                    {
                        return true;
                    }
                    else
                    {
                        LogFile.Error.Show("ERROR:Get_Atom_Expiry:insert into Atom_Expiry failed!\r\nErr=" + Err);
                        return false;
                    }
                }
            }
            else
            {
                LogFile.Error.Show("ERROR:Get_Atom_Expiry:select ID as Atom_Expiry_ID from Atom_Expiry failed!\r\nErr=" + Err);
                return false;
            }
        }
Beispiel #28
0
        internal bool SaveDocProformaInvoice(ref long xDocProformaInvoice_ID, GlobalData.ePaymentType ePaymentType, long MethodOfPayment_ID, long docDuration, long docDurationType, long termsOfPayment_ID, ref int xNumberInFinancialYear)
        {
            List<SQL_Parameter> lpar = new List<SQL_Parameter>();
            string spar_PrintTime = "@par_PrintTime";
            DateTime dtnow = DateTime.Now;
            SQL_Parameter par_PrintTime = new SQL_Parameter(spar_PrintTime, DBConnectionControl40.SQL_Parameter.eSQL_Parameter.Datetime, false, dtnow);
            lpar.Add(par_PrintTime);
            string spar_docDuration = "@par_docDuration";
            SQL_Parameter par_docDuration = new SQL_Parameter(spar_docDuration, DBConnectionControl40.SQL_Parameter.eSQL_Parameter.Bigint, false, docDuration);
            lpar.Add(par_docDuration);
            string spar_docDurationType = "@par_docDurationType";
            SQL_Parameter par_docDurationType = new SQL_Parameter(spar_docDurationType, DBConnectionControl40.SQL_Parameter.eSQL_Parameter.Bigint, false, docDurationType);
            lpar.Add(par_docDurationType);
            string spar_TermsOfPayment_ID = "@par_TermsOfPayment_ID";
            SQL_Parameter par_TermsOfPayment_ID = new SQL_Parameter(spar_TermsOfPayment_ID, DBConnectionControl40.SQL_Parameter.eSQL_Parameter.Bigint, false, termsOfPayment_ID);
            lpar.Add(par_TermsOfPayment_ID);
            string spar_MethodOfPayment_ID = "@par_MethodOfPayment_ID";
            SQL_Parameter par_MethodOfPayment_ID = new SQL_Parameter(spar_MethodOfPayment_ID, DBConnectionControl40.SQL_Parameter.eSQL_Parameter.Bigint, false, MethodOfPayment_ID);
            lpar.Add(par_MethodOfPayment_ID);

            string sql = null;
            object ores = null;
            string Err = null;
            if (GetNewNumberInFinancialYear())
            {
                xNumberInFinancialYear = NumberInFinancialYear;
                sql = @"update DocProformaInvoice set Draft =0,
                        NumberInFinancialYear = " + NumberInFinancialYear.ToString()
                        + ", DocDuration = " + spar_docDuration
                        + ", DocDurationType = " + spar_docDurationType
                        + ", TermsOfPayment_ID = " + spar_TermsOfPayment_ID
                        + ", MethodOfPayment_ID = " + spar_MethodOfPayment_ID
                        +"  where ID = " + Doc_ID.ToString(); // Close Proforma Invoice
                if (DBSync.DBSync.ExecuteNonQuerySQL(sql, lpar, ref ores, ref Err))
                {
                    xDocProformaInvoice_ID = Doc_ID;
                    return true;
                }
                else
                {
                    LogFile.Error.Show("ERROR:usrc_Invoice_Preview:SaveDocProformaInvoice:sql=" + sql+"\r\nErr=" + Err);
                }
            }
            return false;
        }
Beispiel #29
0
 public bool SaveDocInvoice(ref long xDocInvoice_ID, GlobalData.ePaymentType ePaymentType, string p1, string p2, string p3, ref int xNumberInFinancialYear)
 {
     List<SQL_Parameter> lpar = new List<SQL_Parameter>();
     string spar_PrintTime = "@par_PrintTime";
     DateTime dtnow = DateTime.Now;
     SQL_Parameter par_PrintTime = new SQL_Parameter(spar_PrintTime, DBConnectionControl40.SQL_Parameter.eSQL_Parameter.Datetime, false, dtnow);
     lpar.Add(par_PrintTime);
     string sql = null;
     object ores = null;
     string Err = null;
     if (GetNewNumberInFinancialYear())
     {
         xNumberInFinancialYear = NumberInFinancialYear;
         sql = "update DocInvoice set Draft =0,NumberInFinancialYear = " + NumberInFinancialYear.ToString() + "  where ID = " + Doc_ID.ToString(); // Close Proforma Invoice
         if (DBSync.DBSync.ExecuteNonQuerySQL(sql, lpar, ref ores, ref Err))
         {
             xDocInvoice_ID = Doc_ID;
             return true;
         }
         else
         {
             LogFile.Error.Show("ERROR:usrc_Invoice_Preview:Save:Err=" + Err);
         }
     }
     return false;
 }
Beispiel #30
0
        private bool Get_DocInvoice_ShopC_Item(string DocInvoice,ref Atom_DocInvoice_ShopC_Item_Price_Stock_Data appisd, bool b_from_stock)
        {
            long Atom_Price_Item_ID = -1;
            if (Get_Atom_Price_Item(ref appisd))
            {
                List<SQL_Parameter> lpar = new List<SQL_Parameter>();
                int decimal_places = GlobalData.Get_BaseCurrency_DecimalPlaces();
                Atom_Price_Item_ID = appisd.Atom_Price_Item_ID.v;

                string spar_ExtraDiscount = "@par_ExtraDiscount";
                SQL_Parameter par_ExtraDiscount = new SQL_Parameter(spar_ExtraDiscount, SQL_Parameter.eSQL_Parameter.Decimal, false, appisd.ExtraDiscount.v);

                decimal dQuantity_from_factory = appisd.m_ShopShelf_Source.dQuantity_from_factory;
                decimal dQuantity_from_stock = appisd.m_ShopShelf_Source.dQuantity_from_stock;

                string spar_RetailPriceWithDiscount = "@par_RetailPriceWithDiscount";
                string spar_TaxPrice = "@par_TaxPrice";
                string spar_dQuantity = "@par_dQuantity";

                foreach (Stock_Data stock_data in appisd.m_ShopShelf_Source.Stock_Data_List)
                {
                    if (b_from_stock)
                    {
                        if (stock_data.Stock_ID == null)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        if (stock_data.Stock_ID != null)
                        {
                            continue;
                        }
                    }
                    decimal RetailPriceWithDiscount = 0;

                    decimal TaxPrice = 0;

                    decimal RetailPriceWithDiscount_WithoutTax = 0;

                    lpar.Clear();
                    lpar.Add(par_ExtraDiscount);
                    long_v Stock_ID = stock_data.Stock_ID;

                    string scond_Stock_ID = null;
                    string sValue_Stock_ID = null;
                    if (Stock_ID != null)
                    {
                        decimal dquantity = stock_data.dQuantity.v;
                        StaticLib.Func.CalculatePrice(appisd.RetailPricePerUnit.v, dquantity, appisd.Discount.v, appisd.ExtraDiscount.v, appisd.Atom_Taxation_Rate.v, ref RetailPriceWithDiscount, ref TaxPrice, ref RetailPriceWithDiscount_WithoutTax, decimal_places);
                        SQL_Parameter par_dQuantity = null;
                        par_dQuantity = new SQL_Parameter(spar_dQuantity, SQL_Parameter.eSQL_Parameter.Decimal, false, dquantity);
                        lpar.Add(par_dQuantity);
                        scond_Stock_ID = "(Stock_ID = " + Stock_ID.v.ToString() + ")";
                        sValue_Stock_ID = Stock_ID.v.ToString();
                        SQL_Parameter par_RetailPriceWithDiscount = new SQL_Parameter(spar_RetailPriceWithDiscount, SQL_Parameter.eSQL_Parameter.Decimal, false, RetailPriceWithDiscount);
                        lpar.Add(par_RetailPriceWithDiscount);
                        SQL_Parameter par_TaxPrice = new SQL_Parameter(spar_TaxPrice, SQL_Parameter.eSQL_Parameter.Decimal, false, TaxPrice);
                        lpar.Add(par_TaxPrice);
                    }
                    else
                    {
                        StaticLib.Func.CalculatePrice(appisd.RetailPricePerUnit.v, dQuantity_from_factory, appisd.Discount.v, appisd.ExtraDiscount.v, appisd.Atom_Taxation_Rate.v, ref RetailPriceWithDiscount, ref TaxPrice, ref RetailPriceWithDiscount_WithoutTax, decimal_places);
                        SQL_Parameter par_dQuantity = null;
                        par_dQuantity = new SQL_Parameter(spar_dQuantity, SQL_Parameter.eSQL_Parameter.Decimal, false, dQuantity_from_factory);
                        lpar.Add(par_dQuantity);
                        SQL_Parameter par_RetailPriceWithDiscount = new SQL_Parameter(spar_RetailPriceWithDiscount, SQL_Parameter.eSQL_Parameter.Decimal, false, RetailPriceWithDiscount);
                        lpar.Add(par_RetailPriceWithDiscount);
                        SQL_Parameter par_TaxPrice = new SQL_Parameter(spar_TaxPrice, SQL_Parameter.eSQL_Parameter.Decimal, false, TaxPrice);
                        lpar.Add(par_TaxPrice);
                        scond_Stock_ID = "(Stock_ID is null)";
                        sValue_Stock_ID = "null";
                    }

                    string spar_ExpiryDate = "@par_ExpiryDate";

                    string scond_ExpiryDate = null;

                    string sValue_ExpiryDate = null;
                    if (stock_data.Stock_ExpiryDate != null)
                    {
                        SQL_Parameter par_ExpiryDate = new SQL_Parameter(spar_ExpiryDate, SQL_Parameter.eSQL_Parameter.Datetime, false, stock_data.Stock_ExpiryDate.v);
                        lpar.Add(par_ExpiryDate);
                        scond_ExpiryDate = "(ExpiryDate = " + spar_ExpiryDate + ")";
                        sValue_ExpiryDate = spar_ExpiryDate;
                    }
                    else
                    {
                        scond_ExpiryDate = "(ExpiryDate is null)";
                        sValue_ExpiryDate = "null";
                    }

                    if (DocInvoice==null)
                    {
                        LogFile.Error.Show("ERROR:TangentaDB:CurrentInvoice.cs:Get_DocInvoice_ShopC_Item:DocInvoice==null.");
                        return false;
                    }

                    string sql_select_DocInvoice_ShopC_Item_ID = @"select ID as "[email protected]"_ShopC_Item_ID,
                                                                    dQuantity,
                                                                    ExtraDiscount,
                                                                    RetailPriceWithDiscount,
                                                                    TaxPrice
                                                                    from "[email protected]"_ShopC_Item
                                                                    where "[email protected]"_ID = " + Doc_ID.ToString() + @" and
                                                                            Atom_Price_Item_ID = " + Atom_Price_Item_ID.ToString() + @" and "
                                                                                    + scond_ExpiryDate + @" and "
                                                                                    + scond_Stock_ID;
                    DataTable dt = new DataTable();
                    string Err = null;
                    if (DBSync.DBSync.ReadDataTable(ref dt, sql_select_DocInvoice_ShopC_Item_ID, lpar, ref Err))
                    {
                        if (dt.Rows.Count > 0)
                        {
                            appisd.DocInvoice_ShopC_Item_ID = tf.set_long(dt.Rows[0][DocInvoice+"_ShopC_Item_ID"]);
                            // appisd.dQuantity_all.v = appisd.m_Warehouse.dQuantity_all;
                            appisd.RetailPriceWithDiscount = tf.set_decimal(dt.Rows[0]["RetailPriceWithDiscount"]);
                            appisd.ExtraDiscount = tf.set_decimal(dt.Rows[0]["ExtraDiscount"]);
                            appisd.TaxPrice = tf.set_decimal(dt.Rows[0]["TaxPrice"]);
                            //$$TODO  pias.Stock_ID = long_v.Copy(pis.Stock_ID);
                            return true;
                        }
                        else
                        {

                            string sql_insert_DocInvoice_ShopC_Item_ID = @"insert into "[email protected]"_ShopC_Item
                                                                            (
                                                                            dQuantity,
                                                                            ExtraDiscount,
                                                                            RetailPriceWithDiscount,
                                                                            TaxPrice,
                                                                            "[email protected]"_ID,
                                                                            Atom_Price_Item_ID,
                                                                            ExpiryDate,
                                                                            Stock_ID
                                                                            )
                                                                            values
                                                                            (
                                                                            " + spar_dQuantity + @",
                                                                            " + spar_ExtraDiscount + @",
                                                                            " + spar_RetailPriceWithDiscount + @",
                                                                            " + spar_TaxPrice + @",
                                                                            " + Doc_ID.ToString() + @",
                                                                            " + Atom_Price_Item_ID.ToString() + @",
                                                                            " + sValue_ExpiryDate + @",
                                                                            " + sValue_Stock_ID
                                                                                    + ")";
                            object objret = null;
                            long DocInvoice_ShopC_Item_ID = -1;
                            if (DBSync.DBSync.ExecuteNonQuerySQLReturnID(sql_insert_DocInvoice_ShopC_Item_ID, lpar, ref DocInvoice_ShopC_Item_ID, ref objret, ref Err, DocInvoice))
                            {
                                appisd.DocInvoice_ShopC_Item_ID = tf.set_long(DocInvoice_ShopC_Item_ID);

                                if (Stock_ID != null)
                                {
                                    stock_data.Remove_from_StockShelf();
                                }
                            }
                            else
                            {
                                LogFile.Error.Show("ERROR:Get_DocInvoice_ShopC_Item:sql="+ sql_insert_DocInvoice_ShopC_Item_ID + " failed!\r\nErr=" + Err);
                                return false;
                            }
                        }
                    }
                    else
                    {
                        LogFile.Error.Show("ERROR:Get_DocInvoice_ShopC_Item:sql="+ sql_select_DocInvoice_ShopC_Item_ID+" failed!\r\nErr=" + Err);
                        return false;
                    }

                } // foreach
                return true;
            }
            else
            {
                return false;
            }
        }