Exemple #1
0
        internal static List <IProduct> SearchProductByName(String nameData)
        {
            List <IProduct> productList = new List <IProduct>();
            string          strQuery    = "";

            strQuery  = String.Format("SELECT * FROM {0} ", ProductTable);
            strQuery += String.Format("WHERE Name Like '%{0}%'", nameData);

            try
            {
                DataSet ds = DBAdapter.Instance().GetDataSet(strQuery);
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    productList.Add(Parse(row));
                }
            }
            catch
            {
                // do nothing
            }
            return(productList);
        }
Exemple #2
0
        private static int DropTable(string tableName)
        {
            // Sample: DROP TABLE IF EXISTS TempProducts;

            String strQuery = String.Empty;
            int    response = 0;

            // Create command string
            strQuery = String.Format("DROP TABLE IF EXISTS {0} ", tableName);

            try
            {
                // execute drop command
                response = DBAdapter.Instance().ExecuteNonQuery(strQuery);
                response = 1;
            }
            catch (System.Exception ex)
            {
            }

            return(response);
        }
Exemple #3
0
        /* TODO: Try to increase speed of transaction
         * using (SQLiteTransaction mytransaction = myconnection.BeginTransaction())
         *  {
         *    using (SQLiteCommand mycommand = new SQLiteCommand(myconnection))
         *    {
         *      SQLiteParameter myparam = new SQLiteParameter();
         *      int n;
         *
         *      mycommand.CommandText = "INSERT INTO [MyTable] ([MyId]) VALUES(?)";
         *      mycommand.Parameters.Add(myparam);
         *
         *      for (n = 0; n < 100000; n ++)
         *      {
         *        myparam.Value = n + 1;
         *        mycommand.ExecuteNonQuery();
         *      }
         *    }
         *    mytransaction.Commit();
         *  }
         */
        internal static void LoadProductFileToDB(string path, out int successCount, out int failCount)
        {
            String  line    = "";
            String  tblName = "";
            Product p;

            successCount = 0;
            failCount    = 0;
            tblName      = inUpdateState ? TempProductTable : ProductTable;

            DataSet dsDocItems = DBAdapter.Instance().GetDataSet("SELECT * FROM " + tblName);

            using (StreamReader sr = new StreamReader(path, PosConfiguration.DefaultEncoding))
            {
                while ((line = @sr.ReadLine()) != null)
                {
                    //line[0] == '0' means invalid line
                    //Skip trailing blank lines and invalid lines
                    if (line.Trim().Length == 0 || line[0] == '0')
                    {
                        continue;
                    }

                    p = LineToProduct(line);
                    if (AddToProductTable(dsDocItems.Tables[0], p))
                    {
                        successCount++;
                    }
                    else
                    {
                        failCount++;
                    }
                }
                sr.Close();
            }
            DBAdapter.Instance().UpdateDataSet(dsDocItems);
        }
Exemple #4
0
        private static bool Add(Product p)
        {
            try
            {
                string   strQuery    = "";
                string   tblName     = inUpdateState ? TempProductTable : ProductTable;
                IProduct tempProduct = null;

                try
                {
                    tempProduct = FindByLabel(p.id.ToString());
                }
                catch (System.Exception ex)
                {
                }

                CultureInfo ci = CultureInfo.GetCultureInfo("en-US");

                if (tempProduct == null)
                {
                    strQuery += "INSERT INTO " + tblName;
                    strQuery += " (ID,Name,Barcode,DepartmentId,UnitPrice,SecondaryUnitPrice,Unit,ExtraProperty,Valid,CategoryId)";
                    strQuery += " VALUES ";
                    strQuery += String.Format("('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}')",
                                              p.id,
                                              p.name.TrimEnd(new char[] { ' ' }),
                                              p.barcode,
                                              p.department.Id,
                                              p.unitPrice.ToString("f", ci),
                                              p.secondaryUnitPrice.ToString("f", ci),
                                              p.Unit,
                                              GetAdditionalProperty(p),
                                              p.valid,
                                              p.category
                                              );
                }
                else
                {
                    strQuery += "UPDATE " + tblName;
                    strQuery += String.Format(" SET Name = '{0}', Barcode = '{1}', DepartmentId = '{2}',UnitPrice = '{3}'," +
                                              "SecondaryUnitPrice = '{4}', Unit = '{5}', ExtraProperty = '{6}'," +
                                              "Valid = '{7}', CategoryId = '{8}'",
                                              p.name.TrimEnd(new char[] { ' ' }),
                                              p.barcode,
                                              p.department.Id,
                                              p.unitPrice.ToString("f", ci),
                                              p.secondaryUnitPrice.ToString("f", ci),
                                              p.Unit,
                                              GetAdditionalProperty(p),
                                              p.valid,
                                              p.category
                                              );

                    strQuery += String.Format(" WHERE ID = '{0}'", p.id);
                }


                DataSet ds = DBAdapter.Instance().GetDataSet(strQuery);

                return(DBAdapter.Instance().ExecuteNonQuery(strQuery) > 0);
            }
            catch
            {
                EZLogger.Log.Error("Ürün eklenemedi : ", p.ToString());
            }
            return(false);
        }