Ejemplo n.º 1
0
        public static bool Get(string Name,string Abbreviation, ref long Atom_SimpleItem_Name_ID)
        {
            string Err = null;
            List<DBConnectionControl40.SQL_Parameter> lpar = new List<DBConnectionControl40.SQL_Parameter>();
            string sparam_Name = "@par_Name";
            DBConnectionControl40.SQL_Parameter par_Name = new DBConnectionControl40.SQL_Parameter(sparam_Name, DBConnectionControl40.SQL_Parameter.eSQL_Parameter.Nvarchar, false, Name);
            lpar.Add(par_Name);
            string sparam_Abbreviation = "@par_Abbreviation";
            DBConnectionControl40.SQL_Parameter par_Abbreviation = new DBConnectionControl40.SQL_Parameter(sparam_Abbreviation, DBConnectionControl40.SQL_Parameter.eSQL_Parameter.Nvarchar, false, Abbreviation);
            lpar.Add(par_Abbreviation);
            DataTable dt = new DataTable();
            string sql = @"select ID from Atom_SimpleItem_Name
                                                where Name = " + sparam_Name + " and Abbreviation = " + sparam_Abbreviation;

            if (DBSync.DBSync.ReadDataTable(ref dt, sql, lpar, ref Err))
            {
                if (dt.Rows.Count > 0)
                {
                    Atom_SimpleItem_Name_ID = (long)dt.Rows[0]["ID"];
                    return true;
                }
                else
                {
                    sql = @"insert into Atom_SimpleItem_Name (Name,Abbreviation) values (" + sparam_Name + "," + sparam_Abbreviation + ")";
                    object objretx = null;
                    if (DBSync.DBSync.ExecuteNonQuerySQLReturnID(sql, lpar, ref Atom_SimpleItem_Name_ID, ref objretx, ref Err, "Atom_SimpleItem_Name"))
                    {
                        return true;
                    }
                    else
                    {
                        LogFile.Error.Show("ERROR:f_Atom_SimpleItem_Name:Get:" + sql + "\r\nErr=" + Err);
                        return false;
                    }
                }
            }
            else
            {
                LogFile.Error.Show("ERROR:f_Atom_SimpleItem_Name:Get:" + sql + "\r\nErr=" + Err);
                return false;
            }
        }
Ejemplo n.º 2
0
        public bool Update_SelectedSimpleItem(long DocInvoice_ShopB_Item_ID,
                                             int iCount,
                                             decimal Discount,
                                             decimal ExtraDiscount,
                                             decimal RetailSimpleItemPrice,
                                             string Taxation_Name,
                                             decimal Taxation_Rate,
                                             ref decimal RetailSimpleItemPriceWithDiscount,
                                             ref decimal TaxPrice,
                                             ref decimal PriceWithoutTax,
                                             ref string Err)
        {
            int decimal_places = 2;
            if (GlobalData.BaseCurrency != null)
            {
                decimal_places = GlobalData.BaseCurrency.DecimalPlaces;
            }
            List<DBConnectionControl40.SQL_Parameter> lpar = new List<DBConnectionControl40.SQL_Parameter>();
            bool bUpdate_Atom_SimpleItem_Taxation_ID = false;
            int irow_Atom_SimpleItem = (int)FindRowIndex_In_dtDraft_Atom_SimpleItem(DocInvoice_ShopB_Item_ID);
            long new_Atom_Taxation_ID = -1;
            if (irow_Atom_SimpleItem >= 0)
            {
                long Atom_Taxation_ID = (long)m_CurrentInvoice.dtCurrent_Atom_Price_ShopBItem.Rows[irow_Atom_SimpleItem]["Atom_Taxation_ID"];

                string sparam_Atom_Taxation_Rate = "@Atom_Taxation_Rate";
                DBConnectionControl40.SQL_Parameter par_Atom_Taxation_Rate = new DBConnectionControl40.SQL_Parameter(sparam_Atom_Taxation_Rate, DBConnectionControl40.SQL_Parameter.eSQL_Parameter.Decimal, false, Taxation_Rate);
                lpar.Add(par_Atom_Taxation_Rate);

                DataTable dt = new DataTable();
                string sql_get_Atom_SimpleItem_Taxation = "select ID from Atom_Taxation where Name = '" + Taxation_Name + "' and Rate = " + sparam_Atom_Taxation_Rate;
                if (DBSync.DBSync.ReadDataTable(ref dt, sql_get_Atom_SimpleItem_Taxation, lpar, ref Err))
                {
                    if (dt.Rows.Count > 0)
                    {
                        new_Atom_Taxation_ID = (long)dt.Rows[0]["ID"];
                        if (Atom_Taxation_ID != new_Atom_Taxation_ID)
                        {
                            bUpdate_Atom_SimpleItem_Taxation_ID = true;
                        }
                    }
                    else
                    {
                        string sql_insert_Atom_SimpleItem_Taxation = "insert into Atom_Taxation (Name,Rate) values ('" + Taxation_Name + "'," + sparam_Atom_Taxation_Rate + ")";
                        object objretx = null;
                        if (DBSync.DBSync.ExecuteNonQuerySQLReturnID(sql_insert_Atom_SimpleItem_Taxation, lpar, ref new_Atom_Taxation_ID, ref objretx, ref Err, DBtcn.stbl_Atom_Taxation_TableName))
                        {
                            if (Atom_Taxation_ID != new_Atom_Taxation_ID)
                            {
                                bUpdate_Atom_SimpleItem_Taxation_ID = true;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                }
                else
                {
                    return false;
                }

                lpar.Clear();

                string param_RetailSimpleItemPrice = "@RetailSimpleItemPrice";
                DBConnectionControl40.SQL_Parameter par_RetailSimpleItemPrice = new DBConnectionControl40.SQL_Parameter(param_RetailSimpleItemPrice, DBConnectionControl40.SQL_Parameter.eSQL_Parameter.Decimal, false, RetailSimpleItemPrice);
                lpar.Add(par_RetailSimpleItemPrice);

                string param_Discount = "@Discount";
                DBConnectionControl40.SQL_Parameter par_Discount = new DBConnectionControl40.SQL_Parameter(param_Discount, DBConnectionControl40.SQL_Parameter.eSQL_Parameter.Decimal, false, Discount);
                lpar.Add(par_Discount);

                string param_ExtraDiscount = "@ExtraDiscount";
                DBConnectionControl40.SQL_Parameter par_ExtraDiscount = new DBConnectionControl40.SQL_Parameter(param_ExtraDiscount, DBConnectionControl40.SQL_Parameter.eSQL_Parameter.Decimal, false, ExtraDiscount);
                lpar.Add(par_ExtraDiscount);

                decimal dQuantity = Convert.ToDecimal(iCount);
                StaticLib.Func.CalculatePrice(RetailSimpleItemPrice, dQuantity, Discount, ExtraDiscount, Taxation_Rate, ref RetailSimpleItemPriceWithDiscount, ref TaxPrice, ref PriceWithoutTax, decimal_places);

                string param_RetailSimpleItemPriceWithDiscount = "@RetailSimpleItemPriceWithDiscount";
                DBConnectionControl40.SQL_Parameter par_RetailSimpleItemPriceWithDiscount = new DBConnectionControl40.SQL_Parameter(param_RetailSimpleItemPriceWithDiscount, DBConnectionControl40.SQL_Parameter.eSQL_Parameter.Decimal, false, RetailSimpleItemPriceWithDiscount);
                lpar.Add(par_RetailSimpleItemPriceWithDiscount);

                string param_TaxPrice = "@TaxPrice";
                DBConnectionControl40.SQL_Parameter par_TaxPrice = new DBConnectionControl40.SQL_Parameter(param_TaxPrice, DBConnectionControl40.SQL_Parameter.eSQL_Parameter.Decimal, false, TaxPrice);
                lpar.Add(par_TaxPrice);

                long to_update_Atom_Taxation_ID = -1;
                if (bUpdate_Atom_SimpleItem_Taxation_ID)
                {
                    to_update_Atom_Taxation_ID = new_Atom_Taxation_ID;
                }
                else
                {
                    to_update_Atom_Taxation_ID = Atom_Taxation_ID;
                }
                string sql_update_Atom_SimpleItem = null;
                if (IsDocInvoice)
                {
                    sql_update_Atom_SimpleItem = @"Update  DocInvoice_ShopB_Item
                                                  set iQuantity = " + iCount.ToString() + @",
                                                      RetailSimpleItemPrice = " + param_RetailSimpleItemPrice + @",
                                                      Discount = " + param_Discount + @",
                                                      ExtraDiscount = " + param_ExtraDiscount + @",
                                                      TaxPrice = " + param_TaxPrice + @",
                                                      Atom_Taxation_ID = " + to_update_Atom_Taxation_ID.ToString() + @",
                                                      RetailSimpleItemPriceWithDiscount = " + param_RetailSimpleItemPriceWithDiscount + @"
                                                   where ID = " + DocInvoice_ShopB_Item_ID.ToString();
                }
                else if (IsDocProformaInvoice)
                {
                    sql_update_Atom_SimpleItem = @"Update  DocProformaInvoice_ShopB_Item
                                                  set iQuantity = " + iCount.ToString() + @",
                                                      RetailSimpleItemPrice = " + param_RetailSimpleItemPrice + @",
                                                      Discount = " + param_Discount + @",
                                                      ExtraDiscount = " + param_ExtraDiscount + @",
                                                      TaxPrice = " + param_TaxPrice + @",
                                                      Atom_Taxation_ID = " + to_update_Atom_Taxation_ID.ToString() + @",
                                                      RetailSimpleItemPriceWithDiscount = " + param_RetailSimpleItemPriceWithDiscount + @"
                                                   where ID = " + DocInvoice_ShopB_Item_ID.ToString();
                }
                else
                {
                    Err="ERROR:Update_SelectedSimpleItem:FindRowIndex_In_dtDraft_Atom_SimpleItem:DocInvoice=" + DocInvoice + " not implemented";
                    LogFile.Error.Show(Err);
                    return false;
                }
                object ores = null;
                if (DBSync.DBSync.ExecuteNonQuerySQL(sql_update_Atom_SimpleItem, lpar, ref ores, ref Err))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                LogFile.Error.Show("ERROR:Update_SelectedSimpleItem:FindRowIndex_In_dtDraft_Atom_SimpleItem FAILED!");
                return false;
            }
        }
Ejemplo n.º 3
0
        private bool Find_Atom_Taxation_ID(string Atom_Taxation_Name, decimal Atom_Taxation_Rate, ref long Atom_Taxation_ID, ref string Err)
        {
            DataTable dt = new DataTable();
            List<DBConnectionControl40.SQL_Parameter> lpar = new List<DBConnectionControl40.SQL_Parameter>();
            string param_Taxation_Rate = "@taxation_rate";
            DBConnectionControl40.SQL_Parameter par = new DBConnectionControl40.SQL_Parameter(param_Taxation_Rate, DBConnectionControl40.SQL_Parameter.eSQL_Parameter.Decimal, false, Atom_Taxation_Rate);
            lpar.Add(par);

            string sql_find_Atom_Taxation_ID = @"select
                                                    Atom_Taxation.ID as Atom_Taxation_ID
                                                    from Atom_Taxation
                                                    where Name = '" + Atom_Taxation_Name + @"'
                                                          and Rate = " + param_Taxation_Rate;

            if (DBSync.DBSync.ReadDataTable(ref dt, sql_find_Atom_Taxation_ID, lpar, ref Err))
            {
                if (dt.Rows.Count > 0)
                {
                    Atom_Taxation_ID = (long)dt.Rows[0]["Atom_Taxation_ID"];
                }
                else
                {
                    Atom_Taxation_ID = -1;
                }
                return true;
            }
            else
            {
                LogFile.Error.Show(@"ERROR:Find_Atom_Taxation_ID:
                                          select
                                         Atom_Taxation.ID as Atom_Taxation_ID
                                          from Atom_Taxation:\r\nErr=" + Err);
                return false;
            }
        }
Ejemplo n.º 4
0
        public static bool Get(string DocInvoice,
                                 long Price_SimpleItem_ID,
                                 long DocInvoice_ID,
                                 ref long DocInvoice_ShopB_Item_ID,
                                 ref int Quantity,
                                 ref decimal RetailSimpleItemPrice,
                                 ref decimal Discount,
                                 ref decimal ExtraDiscount,
                                 ref decimal taxRate,
                                 ref string taxName,
                                 ref decimal RetailSimpleItemPriceWithDiscount,
                                 ref decimal TaxPrice,
                                 ref decimal PriceWithoutTax
                                 )
        {
            if (Find_DocInvoice_ShopB_Item_ID(DocInvoice,DocInvoice_ID, Price_SimpleItem_ID, ref DocInvoice_ShopB_Item_ID, ref Quantity, ref RetailSimpleItemPrice, ref Discount, ref ExtraDiscount, ref taxRate, ref taxName, ref RetailSimpleItemPriceWithDiscount, ref TaxPrice))
            {
                if (DocInvoice_ShopB_Item_ID >= 0)
                {
                    return true;
                }
                else
                {
                    long PriceList_ID = -1;
                    long SimpleItem_ID = -1;
                    long Taxation_ID = -1;
                    if (Find_PriceList_SimpleItem_Taxation(Price_SimpleItem_ID,ref RetailSimpleItemPrice,ref Discount,ref taxRate,ref taxName, ref PriceList_ID, ref SimpleItem_ID, ref Taxation_ID))
                    {
                        long Atom_PriceList_ID = -1;

                        if (f_Atom_PriceList.Get(PriceList_ID, ref Atom_PriceList_ID))
                        {
                            long Atom_SimpleItem_ID = -1;
                            if (f_Atom_ShopBItem.Get(SimpleItem_ID, ref Atom_SimpleItem_ID))
                            {
                                long Atom_Taxation_ID = -1;
                                if (f_Atom_Taxation.Get(Taxation_ID, ref Atom_Taxation_ID))
                                {
                                    List<DBConnectionControl40.SQL_Parameter> lpar = new List<DBConnectionControl40.SQL_Parameter>();
                                    string sparam_RetailSimpleItemPrice = "@par_RetailSimpleItemPrice";
                                    DBConnectionControl40.SQL_Parameter par_RetailSimpleItemPrice = new DBConnectionControl40.SQL_Parameter(sparam_RetailSimpleItemPrice, DBConnectionControl40.SQL_Parameter.eSQL_Parameter.Decimal, false, RetailSimpleItemPrice);
                                    lpar.Add(par_RetailSimpleItemPrice);

                                    int decimal_places = 2;
                                    if (GlobalData.BaseCurrency!=null)
                                    {
                                        decimal_places = GlobalData.BaseCurrency.DecimalPlaces;
                                    }

                                    decimal dQuantity = Convert.ToDecimal(Quantity);

                                    StaticLib.Func.CalculatePrice(RetailSimpleItemPrice, dQuantity, Discount, ExtraDiscount, taxRate, ref RetailSimpleItemPriceWithDiscount, ref TaxPrice, ref PriceWithoutTax, decimal_places);

                                    //decimal xRetailSimpleItemPriceWithDiscount =  decimal.Round((RetailSimpleItemPrice - RetailSimpleItemPrice * Discount),decimal_places);
                                    //RetailSimpleItemPriceWithDiscount = decimal.Round((xRetailSimpleItemPriceWithDiscount - decimal.Round(xRetailSimpleItemPriceWithDiscount * ExtraDiscount, decimal_places)) * Quantity, decimal_places);

                                    //TaxPrice = decimal.Round(RetailSimpleItemPriceWithDiscount * taxRate, decimal_places);
                                    //PriceWithoutTax = RetailSimpleItemPriceWithDiscount - TaxPrice;

                                    string sparam_RetailSimpleItemPriceWithDiscount = "@par_RetailSimpleItemPriceWithDiscount";
                                    DBConnectionControl40.SQL_Parameter par_RetailSimpleItemPriceWithDiscount = new DBConnectionControl40.SQL_Parameter(sparam_RetailSimpleItemPriceWithDiscount, DBConnectionControl40.SQL_Parameter.eSQL_Parameter.Decimal, false, RetailSimpleItemPriceWithDiscount);
                                    lpar.Add(par_RetailSimpleItemPriceWithDiscount);
                                    string sparam_Discount = "@par_Discount";
                                    DBConnectionControl40.SQL_Parameter par_Discount = new DBConnectionControl40.SQL_Parameter(sparam_Discount, DBConnectionControl40.SQL_Parameter.eSQL_Parameter.Decimal, false, Discount);
                                    lpar.Add(par_Discount);
                                    string sparam_ExtraDiscount = "@par_ExtraDiscount";
                                    DBConnectionControl40.SQL_Parameter par_ExtraDiscount = new DBConnectionControl40.SQL_Parameter(sparam_ExtraDiscount, DBConnectionControl40.SQL_Parameter.eSQL_Parameter.Decimal, false, ExtraDiscount);
                                    lpar.Add(par_ExtraDiscount);
                                    string sparam_TaxPrice = "@par_TaxPrice";
                                    DBConnectionControl40.SQL_Parameter par_TaxPrice = new DBConnectionControl40.SQL_Parameter(sparam_TaxPrice, DBConnectionControl40.SQL_Parameter.eSQL_Parameter.Decimal, false, TaxPrice);
                                    lpar.Add(par_TaxPrice);
                                    string sql = null;
                                    if (DocInvoice == null)
                                    {
                                        LogFile.Error.Show("ERROR:TangentaDB:f_PriceAtom_ServiceAtom.cs:f_Atom_Price_ShopBItem:DocInvoice is null.");
                                        return false;
                                    }
                                    else
                                    {
                                        sql = @"insert into "+DocInvoice+@"_ShopB_Item
                                                            (RetailSimpleItemPrice,
                                                             Discount,
                                                             iQuantity,
                                                             RetailSimpleItemPriceWithDiscount,
                                                             ExtraDiscount,
                                                             TaxPrice,
                                                             Atom_SimpleItem_ID,
                                                             Atom_PriceList_ID,
                                                             Atom_Taxation_ID,
                                                             "+ DocInvoice + @"_ID
                                                            )
                                                            values
                                                            (" + sparam_RetailSimpleItemPrice + @",
                                                             " + sparam_Discount + @",
                                                             1,
                                                             " + sparam_RetailSimpleItemPriceWithDiscount + @",
                                                             " + sparam_ExtraDiscount + @",
                                                             " + sparam_TaxPrice + @",
                                                             " + Atom_SimpleItem_ID.ToString() + @",
                                                             " + Atom_PriceList_ID.ToString() + @",
                                                             " + Atom_Taxation_ID.ToString() + @",
                                                             " + DocInvoice_ID.ToString() + @"
                                                            )";
                                    }
                                    object objretx = null;
                                    string Err = null;
                                    if (DBSync.DBSync.ExecuteNonQuerySQLReturnID(sql, lpar, ref DocInvoice_ShopB_Item_ID, ref objretx, ref Err, DocInvoice+"_ShopB_Item"))
                                    {
                                        return true;
                                    }
                                    else
                                    {
                                        LogFile.Error.Show("ERROR:f_DocInvoice_ShopB_Item:Get:" + sql + "\r\nErr=" + Err);
                                        return false;
                                    }
                                }
                                else
                                {
                                    return false;
                                }
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                    else
                    {
                        return false;
                    }
                }
            }
            else
            {
                return false;
            }
        }