Esempio n. 1
0
        public static User Login(Context ctx, string username, string password)
        {
            User user = null;

            using (IConnection conn = Sync.GetConnection(ctx)) {
                IPreparedStatement ps = conn.PrepareStatement(@"SELECT deal_id,
user_id,
login_name,
user_pass,
user_active
FROM rusers 
WHERE user_active = 1 AND login_name = :login_name AND user_pass = :user_pass ");
                ps.Set("login_name", username);
                ps.Set("user_pass", password);

                IResultSet result = ps.ExecuteQuery();

                if (result.Next())
                {
                    user            = new User();
                    user.deal_id    = result.GetInt("deal_id");
                    user.user_id    = result.GetInt("user_id");
                    user.login_name = result.GetString("login_name");
                    user.user_pass  = result.GetString("user_pass");
                }

                result.Close();
                ps.Close();
                conn.Commit();
                conn.Release();
            }

            return(user);
        }
Esempio n. 2
0
        private SmartMatchResult GetResultSmartMatch(IResultSet reader)
        {
            var index = 0;

            var result = new SmartMatchResult
            {
                Id = reader.GetGuid(0)
            };

            index++;
            result.ItemName = reader.GetString(index);

            index++;
            result.DisplayName = reader.GetString(index);

            index++;
            result.OrganizerType = (FileOrganizerType)Enum.Parse(typeof(FileOrganizerType), reader.GetString(index), true);

            index++;
            if (!reader.IsDBNull(index))
            {
                result.MatchStrings = _json.DeserializeFromString <List <string> >(reader.GetString(index));
            }

            return(result);
        }
Esempio n. 3
0
        public void Fetch(IResultSet result)
        {
            HtrnId     = result.GetInt("id");
            CstId      = result.GetInt("cust_id");
            HtrnExpl   = result.GetString("htrn_explanation");
            HtrnDocnum = result.GetInt("docnum");
            TransDate  = Common.JavaDateToDatetime(result.GetDate("trans_date"));
            CstName    = result.GetString("cst_desc");

            IsNew = false;
        }
Esempio n. 4
0
        public static Category GetCategory(Context ctx, long categId, int categTbl)
        {
            Category info = new Category();

            using (IConnection conn = Sync.GetConnection(ctx))
            {
                string tableName = "ritem_categ";

                if (categTbl == 2)
                {
                    tableName += "2";
                }

                IPreparedStatement ps = conn.PrepareStatement(@"SELECT 
id, 
item_categ_desc
FROM " + tableName + " WHERE id = :CategId");
                ps.Set("categId", categId);

                IResultSet result = ps.ExecuteQuery();

                if (result.Next())
                {
                    info.Id            = result.GetInt("id");
                    info.ItemCategDesc = result.GetString("item_categ_desc");
                }

                result.Close();
                ps.Close();
                conn.Release();
            }

            return(info);
        }
Esempio n. 5
0
        public void Fetch(IResultSet result)
        {
            DtrnId        = result.GetInt("id");
            HtrnId        = result.GetInt("htrn_id");
            ItemId        = result.GetInt("item_id");
            ItemCode      = result.GetString("item_cod");
            ItemDesc      = result.GetString("item_desc");
            DtrnUnitPrice = result.GetDouble("unit_price");
            dtrnQty1      = result.GetDouble("qty1");
            dtrnDiscLine1 = result.GetDouble("disc_line1");
            DtrnNetValue  = result.GetDouble("net_value");
            DtrnVatValue  = result.GetDouble("vat_value");
            ItemVatId     = result.GetInt("item_vat");
            DtrnNum       = result.GetInt("dtrn_num");

            IsNew = false;
        }
        public static DateTime ReadDateTime(this IResultSet result, int index)
        {
            var dateText = result.GetString(index);

            return(DateTime.ParseExact(
                       dateText, _datetimeFormats,
                       DateTimeFormatInfo.InvariantInfo,
                       DateTimeStyles.None).ToUniversalTime());
        }
Esempio n. 7
0
 internal void Fetch(IResultSet result)
 {
     CstId         = result.GetInt("cst_id");
     ItemKateg     = result.GetInt("item_kateg");
     Month         = result.GetInt("month");
     AmountCurr    = result.GetDouble("amount_curr");
     AmountPrev    = result.GetDouble("amount_prev");
     ItemKategDesc = result.GetString("item_categ_desc");
 }
Esempio n. 8
0
        public static CustomerInfoList GetCustomerInfoList(Context ctx, Criteria crit)
        {
            CustomerInfoList customers = new CustomerInfoList();

            using (IConnection conn = Sync.GetConnection(ctx))
            {
                string query = @"
SELECT TOP 100 id, cst_cod, cst_desc 
FROM rcustomer
WHERE 1=1 ";
                if (crit.CustCode != "")
                {
                    query += " AND cst_cod like \'" + crit.CustCode + "%\'";
                }

                if (crit.CustName != "")
                {
                    query += " AND cst_desc like \'" + crit.CustName + "%\'";
                }

                query += " ORDER BY cst_desc ";

                Log.Debug("GetCustomerInfoList", query);
                IPreparedStatement ps     = conn.PrepareStatement(query);
                IResultSet         result = ps.ExecuteQuery();

                while (result.Next())
                {
                    CustomerInfo customer = new CustomerInfo();
                    customer.CustID = result.GetInt("id");
                    customer.Code   = result.GetString("cst_cod");
                    customer.Name   = result.GetString("cst_desc");

                    customers.Add(customer);
                }

                result.Close();
                ps.Close();
                conn.Release();
            }

            return(customers);
        }
Esempio n. 9
0
 public static TransCust GetTransCustStat(IResultSet result)
 {
     return(new TransCust()
     {
         CstId = result.GetInt("cst_id"),
         Credit = (decimal)result.GetDouble("credit"),
         Debit = (decimal)result.GetDouble("debit"),
         CreditMinusDebit = (decimal)result.GetDouble("crdb"),
         Cst_desc = result.GetString("cst_desc")
     });
 }
Esempio n. 10
0
        public static CustomerInfo GetCustomer(Context ctx, string code)
        {
            CustomerInfo info = new CustomerInfo();

            if (code == "")
            {
                return(info);
            }

            using (IConnection conn = Sync.GetConnection(ctx))
            {
                IPreparedStatement ps = conn.PrepareStatement(@"SELECT id, cst_cod, cst_desc, cst_ypol, cst_kat_disc, 
					cst_tax_num, cst_trus_id, cst_addr, cst_city, cst_zip, cst_phone, cst_gsm, cst_comments
					FROM rcustomer WHERE cst_cod = :Code"                    );
                ps.Set("Code", code);

                IResultSet result = ps.ExecuteQuery();

                if (result.Next())
                {
                    info.CustID      = result.GetInt("id");
                    info.Code        = result.GetString("cst_cod");
                    info.Name        = result.GetString("cst_desc");
                    info.CustAddress = result.GetString("cst_addr");
                    info.CustTaxNum  = result.GetString("cst_tax_num");
                    info.CustDebt    = result.GetDouble("cst_ypol");
                    info.CustPhone   = result.GetString("cst_phone");

                    info.IsNew = false;
                }

                result.Close();
                ps.Close();
                conn.Commit();
                conn.Release();
            }

            return(info);
        }
 /// <exception cref="Java.Sql.SQLException"/>
 public static bool ExistsTable(string tablename)
 {
     if (existingTablenames == null)
     {
         existingTablenames = new HashSet <string>();
         IDatabaseMetaData md = connection.GetMetaData();
         IResultSet        rs = md.GetTables(null, null, "%", null);
         while (rs.Next())
         {
             existingTablenames.Add(rs.GetString(3).ToLower());
         }
     }
     return(existingTablenames.Contains(tablename.ToLower()));
 }
Esempio n. 12
0
 public static TransCust GetTransCust(IResultSet result)
 {
     return(new TransCust()
     {
         Id = result.GetInt("id"),
         CstId = result.GetInt("cst_id"),
         VouchId = result.GetInt("vouch_id"),
         VoserId = result.GetInt("voser_id"),
         Docnum = result.GetInt("docnum"),
         DtrnType = result.GetString("dtrn_type"),
         DtrnNetValue = (decimal)result.GetDouble("dtrn_net_value"),
         DtrnVatValue = (decimal)result.GetDouble("dtrn_vat_value"),
         DtrnDate = Common.JavaDateToDatetime(result.GetDate("dtrn_date")),
         HtrnId = result.GetInt("htrn_id"),
     });
 }
Esempio n. 13
0
        public static CategoryList GetCategoryList(Context ctx, int categTbl)
        {
            CategoryList items = new CategoryList();

            using (IConnection conn = Sync.GetConnection(ctx))
            {
                string tableName = "ritem_categ";

                if (categTbl == 2)
                {
                    tableName += "2";
                }

                IPreparedStatement ps = conn.PrepareStatement(@"SELECT 
id, 
item_categ_desc
FROM " + tableName);

                IResultSet result = ps.ExecuteQuery();

                while (result.Next())
                {
                    items.Add(new Category()
                    {
                        Id            = result.GetInt("id"),
                        ItemCategDesc = result.GetString("item_categ_desc")
                    }
                              );
                }
                result.Close();
                ps.Close();
                conn.Release();
            }

            return(items);
        }
Esempio n. 14
0
        public void LoadItems(Context ctx)
        {
            Criteria c = CurrentCriteria;

            using (IConnection conn = Sync.GetConnection(ctx))
            {
//				IPreparedStatement ps1 = conn.PrepareStatement ("select * from ritemlast");
//
//				IResultSet result1 = ps1.ExecuteQuery ();
//
//				while (result1.Next()) {
//					Log.Debug ("", result1.GetInt (0) + " " + result1.GetInt (1));
//				}

                string joinLastDate = "";
                string fields       = "";

                if (c.CstId > 0)
                {
                    fields      += @",
    ritemlast.last_date";
                    joinLastDate = @"
LEFT OUTER JOIN ritemlast ON ritemlast.item_id = ritems.id AND ritemlast.cst_id = " + c.CstId;
                }

                string query = @"
SELECT TOP 30
    ritems.ID, 
    ritems.item_cod, 
    ritems.item_desc,
    ritems.item_image,
    ritems.item_qty_left " +
                               fields + @" 
FROM ritems" +
                               joinLastDate + @" 
WHERE 1 = 1  ";

                if (c.ItemDesc != "")
                {
//					query += " AND ritems.item_desc like \'" + c.ItemDesc + "%\'";
                    query += " AND ritems.item_desc like :ItemDesc ";
                }

                if (c.Category1 != 0)
                {
                    query += " AND ritems.item_ctg_id = " + c.Category1;
                }

                if (c.Category2 != 0)
                {
                    query += " AND ritems.item_ctg2_id = " + c.Category2;
                }

                if (c.RetVal != 0)
                {
                    //                    query += " AND ritems.item_qty_left = " + c.RetVal;
                }

                query += " ORDER BY ritems.item_desc ";

                IPreparedStatement ps = conn.PrepareStatement(query);
                if (c.ItemDesc != "")
                {
                    ps.Set("ItemDesc", c.ItemDesc);
                }

                IResultSet result = ps.ExecuteQuery();

                while (result.Next())
                {
                    ItemInfo item = new ItemInfo()
                    {
                        ItemId      = result.GetInt("id"),
                        item_cod    = result.GetString("item_cod"),
                        ItemDesc    = result.GetString("item_desc"),
                        ItemQtyLeft = Convert.ToDecimal(result.GetDouble("item_qty_left"))
                    };

                    byte[] signatureBytes = result.GetBytes("item_image");
                    try
                    {
                        if (signatureBytes.Length > 0)
                        {
                            Android.Graphics.Bitmap img = Android.Graphics.BitmapFactory.DecodeByteArray(signatureBytes,
                                                                                                         0, signatureBytes.Length);
                            item.ItemImage = Android.Graphics.Bitmap.CreateScaledBitmap(img, 64, 64, true);
                            img.Recycle();
                            img = null;
                        }
                        else
                        {
                            item.ItemImage = null;
                        }
                    }
                    catch (Exception ex)
                    {
                        item.ItemImage = null;
                    }

                    if (c.CstId > 0)
                    {
                        item.ItemLastBuyDate = Common.JavaDateToDatetime(result.GetDate("last_date"));
                    }

                    lastLoadedID = item.ItemId;
                    Add(item);
                }
                result.Close();
                ps.Close();
                conn.Release();
            }
        }
Esempio n. 15
0
        public void Connect()
        {
            Java.Sql.IConnection con = null;
            try {
                var    driver     = new Net.Sourceforge.Jtds.Jdbc.Driver();
                String username   = "******";
                String password   = "******";
                String address    = "192.168.1.101";
                String port       = "1433";
                String database   = "Database";
                String connString = String.Format("jdbc:jtds:sqlserver://{0}:{1}/{2};user={3};password={4}",
                                                  address, port, database, username, password);
                con = DriverManager.GetConnection(connString, username, password);
                IPreparedStatement stmt = null;
                try {
                    //Prepared statement
                    stmt = con.PrepareStatement("SELECT * FROM Users WHERE Id = ? AND Name = ?");
                    stmt.SetLong(1, 1);
                    stmt.SetString(2, "John Doe");
                    stmt.Execute();

                    RunOnUiThread(() => Toast.MakeText(this, "SUCCESS!", ToastLength.Short).Show());

                    IResultSet rs = stmt.ResultSet;

                    IResultSetMetaData rsmd = rs.MetaData;
                    PrintColumnTypes.PrintColTypes(rsmd);
                    Console.WriteLine("");

                    int numberOfColumns = rsmd.ColumnCount;

                    for (int i = 1; i <= numberOfColumns; i++)
                    {
                        if (i > 1)
                        {
                            Console.Write(",  ");
                        }
                        String columnName = rsmd.GetColumnName(i);
                        Console.Write(columnName);
                    }
                    Console.WriteLine("");
                    while (rs.Next())
                    {
                        for (int i = 1; i <= numberOfColumns; i++)
                        {
                            if (i > 1)
                            {
                                Console.Write(",  ");
                            }
                            String columnValue = rs.GetString(i);
                            Console.Write(columnValue);
                        }
                        Console.WriteLine("");
                    }

                    stmt.Close();
                    con.Close();
                } catch (Exception e) {
                    RunOnUiThread(() => Toast.MakeText(this, e.Message, ToastLength.Long).Show());
                    Console.WriteLine(e.StackTrace);
                    stmt.Close();
                }
                con.Close();
            } catch (Exception e) {
                Console.WriteLine(e.StackTrace);
                RunOnUiThread(() => Toast.MakeText(this, e.Message, ToastLength.Long).Show());
            }
            RunOnUiThread(() => _button.Enabled = true);
        }
Esempio n. 16
0
 //
 //  @Override
 //  public ConcurrentHashIndex<SurfacePattern> readPatternIndex(String dir){
 //    //dir parameter is not used!
 //    try{
 //      Connection conn = SQLConnection.getConnection();
 //      //Map<Integer, Set<Integer>> pats = new ConcurrentHashMap<Integer, Set<Integer>>();
 //      String query = "Select index from " + patternindicesTable + " where tablename=\'" + tableName + "\'";
 //      Statement stmt = conn.createStatement();
 //      ResultSet rs = stmt.executeQuery(query);
 //      ConcurrentHashIndex<SurfacePattern> index = null;
 //      if(rs.next()){
 //        byte[] st = (byte[]) rs.getObject(1);
 //        ByteArrayInputStream baip = new ByteArrayInputStream(st);
 //        ObjectInputStream ois = new ObjectInputStream(baip);
 //        index  = (ConcurrentHashIndex<SurfacePattern>) ois.readObject();
 //      }
 //      assert index != null;
 //      return index;
 //    }catch(SQLException e){
 //      throw new RuntimeException(e);
 //    } catch (ClassNotFoundException e) {
 //      throw new RuntimeException(e);
 //    } catch (IOException e) {
 //      throw new RuntimeException(e);
 //    }
 //  }
 //
 //  @Override
 //  public void savePatternIndex(ConcurrentHashIndex<SurfacePattern> index, String file) {
 //    try {
 //      createUpsertFunctionPatternIndex();
 //      Connection conn = SQLConnection.getConnection();
 //      PreparedStatement  st = conn.prepareStatement("select upsert_patternindex(?,?)");
 //      st.setString(1,tableName);
 //      ByteArrayOutputStream baos = new ByteArrayOutputStream();
 //      ObjectOutputStream oos = new ObjectOutputStream(baos);
 //      oos.writeObject(index);
 //      byte[] patsAsBytes = baos.toByteArray();
 //      ByteArrayInputStream bais = new ByteArrayInputStream(patsAsBytes);
 //      st.setBinaryStream(2, bais, patsAsBytes.length);
 //      st.execute();
 //      st.close();
 //      conn.close();
 //      System.out.println("Saved the pattern hash index for " + tableName + " in DB table " + patternindicesTable);
 //    }catch (SQLException e){
 //      throw new RuntimeException(e);
 //    } catch (IOException e) {
 //      throw new RuntimeException(e);
 //    }
 //  }
 //batch processing below is copied from Java Ranch
 //TODO: make this into an iterator!!
 public override IDictionary <string, IDictionary <int, ICollection <E> > > GetPatternsForAllTokens(ICollection <string> sampledSentIds)
 {
     try
     {
         IDictionary <string, IDictionary <int, ICollection <E> > > pats = new Dictionary <string, IDictionary <int, ICollection <E> > >();
         IConnection          conn          = SQLConnection.GetConnection();
         IEnumerator <string> iter          = sampledSentIds.GetEnumerator();
         int totalNumberOfValuesLeftToBatch = sampledSentIds.Count;
         while (totalNumberOfValuesLeftToBatch > 0)
         {
             int batchSize = SingleBatch;
             if (totalNumberOfValuesLeftToBatch >= LargeBatch)
             {
                 batchSize = LargeBatch;
             }
             else
             {
                 if (totalNumberOfValuesLeftToBatch >= MediumBatch)
                 {
                     batchSize = MediumBatch;
                 }
                 else
                 {
                     if (totalNumberOfValuesLeftToBatch >= SmallBatch)
                     {
                         batchSize = SmallBatch;
                     }
                 }
             }
             totalNumberOfValuesLeftToBatch -= batchSize;
             StringBuilder inClause = new StringBuilder();
             for (int i = 0; i < batchSize; i++)
             {
                 inClause.Append('?');
                 if (i != batchSize - 1)
                 {
                     inClause.Append(',');
                 }
             }
             IPreparedStatement stmt = conn.PrepareStatement("select sentid, patterns from " + tableName + " where sentid in (" + inClause.ToString() + ")");
             for (int i_1 = 0; i_1 < batchSize && iter.MoveNext(); i_1++)
             {
                 stmt.SetString(i_1 + 1, iter.Current);
             }
             // or whatever values you are trying to query by
             stmt.Execute();
             IResultSet rs = stmt.GetResultSet();
             while (rs.Next())
             {
                 string sentid             = rs.GetString(1);
                 byte[] st                 = (byte[])rs.GetObject(2);
                 ByteArrayInputStream baip = new ByteArrayInputStream(st);
                 ObjectInputStream    ois  = new ObjectInputStream(baip);
                 pats[sentid] = (IDictionary <int, ICollection <E> >)ois.ReadObject();
             }
         }
         conn.Close();
         return(pats);
     }
     catch (Exception e)
     {
         throw new Exception(e);
     }
 }
Esempio n. 17
0
        public FileOrganizationResult GetResult(IResultSet reader)
        {
            var index = 0;

            var result = new FileOrganizationResult
            {
                Id = reader.GetGuid(0).ToString("N")
            };

            index++;
            if (!reader.IsDBNull(index))
            {
                result.OriginalPath = reader.GetString(index);
            }

            index++;
            if (!reader.IsDBNull(index))
            {
                result.TargetPath = reader.GetString(index);
            }

            index++;
            result.FileSize = reader.GetInt64(index);

            index++;
            result.Date = reader.ReadDateTime(index);

            index++;
            result.Status = (FileSortingStatus)Enum.Parse(typeof(FileSortingStatus), reader.GetString(index), true);

            index++;
            result.Type = (FileOrganizerType)Enum.Parse(typeof(FileOrganizerType), reader.GetString(index), true);

            index++;
            if (!reader.IsDBNull(index))
            {
                result.StatusMessage = reader.GetString(index);
            }

            result.OriginalFileName = Path.GetFileName(result.OriginalPath);

            index++;
            if (!reader.IsDBNull(index))
            {
                result.ExtractedName = reader.GetString(index);
            }

            index++;
            if (!reader.IsDBNull(index))
            {
                result.ExtractedYear = reader.GetInt(index);
            }

            index++;
            if (!reader.IsDBNull(index))
            {
                result.ExtractedSeasonNumber = reader.GetInt(index);
            }

            index++;
            if (!reader.IsDBNull(index))
            {
                result.ExtractedEpisodeNumber = reader.GetInt(index);
            }

            index++;
            if (!reader.IsDBNull(index))
            {
                result.ExtractedEndingEpisodeNumber = reader.GetInt(index);
            }

            index++;
            if (!reader.IsDBNull(index))
            {
                result.DuplicatePaths = reader.GetString(index).Split('|').Where(i => !string.IsNullOrEmpty(i)).ToList();
            }

            return(result);
        }
Esempio n. 18
0
        public static ItemInfo GetItem(Context ctx, decimal itemID, bool loadImage)
        {
            ItemInfo info = new ItemInfo();

            using (IConnection conn = Sync.GetConnection(ctx))
            {
                /*IPreparedStatement ps = conn.PrepareStatement(@"SELECT item_id,
                 * item_cod,
                 * item_desc,
                 * item_long_des,
                 * item_ret_val1,
                 * item_sale_val1 ,
                 * item_buy_val1
                 * FROM items WHERE item_id = :ItemID");*/

                IPreparedStatement ps = conn.PrepareStatement(@"SELECT
id,
item_cod,
item_desc,
item_alter_desc,
unit_price,
item_qty_left ,
item_vat,
item_ctg_id,
item_ctg_disc,
item_image
FROM ritems WHERE id = :ItemID");
                ps.Set("ItemID", itemID.ToString());

                IResultSet result = ps.ExecuteQuery();

                if (result.Next())
                {
                    /*info.ItemId = Convert.ToInt64(result.GetDouble("item_id"));
                     * info.item_cod = result.GetString("item_cod");
                     * info.item_desc = result.GetString("item_desc");
                     * info.item_long_desc = result.GetString("item_long_des");
                     * info.item_ret_val1 = Convert.ToDecimal(result.GetDouble("item_ret_val1"));
                     * info.item_sale_val1 = Convert.ToDecimal(result.GetDouble("item_sale_val1"));
                     * info.item_buy_val1 = Convert.ToDecimal(result.GetDouble("item_buy_val1"));*/
                    //info.ItemId = Convert.ToInt64(result.GetDouble("id"));
                    info.ItemId         = result.GetInt("id");
                    info.item_cod       = result.GetString("item_cod");
                    info.ItemDesc       = result.GetString("item_desc");
                    info.item_long_desc = result.GetString("item_alter_desc");
                    info.ItemSaleVal1   = Convert.ToDecimal(result.GetDouble("unit_price"));
                    info.ItemQtyLeft    = Convert.ToDecimal(result.GetDouble("item_qty_left"));
                    info.ItemVatId      = result.GetInt("item_vat");
                    if (loadImage)
                    {
                        byte[] signatureBytes = result.GetBytes("item_image");
                        try
                        {
                            if (signatureBytes.Length > 0)
                            {
                                info.ItemImage = Android.Graphics.BitmapFactory.DecodeByteArray(signatureBytes,
                                                                                                0, signatureBytes.Length);
                            }
                            else
                            {
                                info.ItemImage = null;
                            }
                        }
                        catch (Exception ex)
                        {
                            info.ItemImage = null;
                        }
                    }

                    Log.Debug("item_vat", "item_vat=" + info.ItemVatId);
                }

                result.Close();
                ps.Close();
                conn.Release();
            }

            return(info);
        }
Esempio n. 19
0
        public static void LoadAdapterItems(Context ctx, int page, ArrayAdapter <ItemInfo> adapter, Criteria c)
        {
            using (IConnection conn = Sync.GetConnection(ctx))
            {
                string joinLastDate = "";
                string fields       = "";

                if (c.CstId > 0)
                {
                    fields      += @",
    ritemlast.last_date";//OUTER
                    joinLastDate = @"
LEFT JOIN ritemlast ON ritemlast.item_id = ritems.id AND ritemlast.cst_id = " + c.CstId;
                }
                int    offset = 1 + page * 30;
                string query  = @"
SELECT TOP 30 START AT " + offset + @" 
    ritems.ID, 
    ritems.item_cod, 
    ritems.item_desc,
    ritems.item_image,
    ritems.item_qty_left " +
                                fields + @" 
FROM ritems" +
                                joinLastDate + @" 
WHERE 1 = 1  ";

                if (c.ItemDesc != "")
                {
                    query += " AND ritems.item_desc like \'" + c.ItemDesc + "%\'";
                }

                if (c.Category1 != 0)
                {
                    query += " AND ritems.item_ctg_id = " + c.Category1;
                }

                if (c.Category2 != 0)
                {
                    query += " AND ritems.item_ctg2_id = " + c.Category2;
                }

                if (c.RetVal != 0)
                {
                    //                    query += " AND ritems.item_qty_left = " + c.RetVal;
                }


                query += " ORDER BY ritems.item_desc ";
                Log.Debug("select items", query);
                IPreparedStatement ps = conn.PrepareStatement(query);

                IResultSet result = ps.ExecuteQuery();

                while (result.Next())
                {
                    ItemInfo item = new ItemInfo()
                    {
                        ItemId      = result.GetInt("id"),
                        item_cod    = result.GetString("item_cod"),
                        ItemDesc    = result.GetString("item_desc"),
                        ItemQtyLeft = Convert.ToDecimal(result.GetDouble("item_qty_left"))
                    };

                    byte[] signatureBytes = result.GetBytes("item_image");
                    try
                    {
                        if (signatureBytes.Length > 0)
                        {
                            Android.Graphics.Bitmap img = Android.Graphics.BitmapFactory.DecodeByteArray(signatureBytes,
                                                                                                         0, signatureBytes.Length);
                            item.ItemImage = Android.Graphics.Bitmap.CreateScaledBitmap(img, 64, 64, true);
                            img.Recycle();
                            img = null;
                        }
                        else
                        {
                            item.ItemImage = null;
                        }
                    }
                    catch (Exception ex)
                    {
                        item.ItemImage = null;
                    }

                    if (c.CstId > 0)
                    {
                        item.ItemLastBuyDate = Common.JavaDateToDatetime(result.GetDate("last_date"));
                    }

                    adapter.Add(item);
                }

                result.Close();
                ps.Close();
                conn.Release();
            }
        }