コード例 #1
0
ファイル: PartRepository.cs プロジェクト: oghenez/profitz
 public IList GetAllUnit(int partID, int unitID)
 {
     try
     {
         OpenConnection();
         MySql.Data.MySqlClient.MySqlCommand    aCommand = new MySql.Data.MySqlClient.MySqlCommand(UnitConversion.GetAllByPartSQL(partID), m_connection);
         MySql.Data.MySqlClient.MySqlDataReader aReader  = aCommand.ExecuteReader();
         IList a = UnitConversion.GetAllStatic(aReader);
         aReader.Close();
         IList result = new ArrayList();
         foreach (UnitConversion uc in a)
         {
             aCommand.CommandText = Unit.GetByIDSQLstatic(uc.CONVERSION_UNIT.ID);
             aReader = aCommand.ExecuteReader();
             Unit u = Unit.GetUnit(aReader);
             aReader.Close();
             result.Add(u);
         }
         if (!result.Contains(new Unit(unitID)))
         {
             aCommand.CommandText = Unit.GetByIDSQLstatic(unitID);
             aReader = aCommand.ExecuteReader();
             Unit up = Unit.GetUnit(aReader);
             aReader.Close();
             result.Add(up);
         }
         return(result);
     }
     catch (Exception x)
     {
         throw new Exception(getErrorMessage(x));
     }
     finally
     {
         m_connection.Close();
     }
 }
コード例 #2
0
ファイル: PartRepository.cs プロジェクト: oghenez/profitz
        public override void Update(IEntity en)
        {
            OpenConnection();
            MySql.Data.MySqlClient.MySqlTransaction trans    = m_connection.BeginTransaction();
            MySql.Data.MySqlClient.MySqlCommand     aCommand = new MySql.Data.MySqlClient.MySqlCommand();
            aCommand.Connection  = m_connection;
            aCommand.Transaction = trans;
            try
            {
                Part e = (Part)en;
                aCommand.CommandText = e.GetUpdateSQL();
                this.SavePicture(e.PICTURE, e.CODE);
                aCommand.ExecuteNonQuery();
                //Update base unit---------------------------
                aCommand.CommandText = UnitConversion.GetByPartAndUnitConIDSQL(e.ID, e.UNIT.ID);
                MySql.Data.MySqlClient.MySqlDataReader r = aCommand.ExecuteReader();
                UnitConversion uc = UnitConversion.GetUnitConversion(r);
                r.Close();
                if (uc == null)
                {
                    uc = new UnitConversion();
                }
                uc.BARCODE         = e.BARCODE;
                uc.CONVERSION_QTY  = 1;
                uc.CONVERSION_UNIT = e.UNIT;
                uc.COST_PRICE      = e.COST_PRICE;
                uc.ORIGINAL_QTY    = 1;
                uc.PART            = e;
                uc.SELL_PRICE      = e.SELL_PRICE;
                e.UNIT_CONVERSION_LIST.Add(uc);
                //------------------------------
                foreach (UnitConversion ucp in e.UNIT_CONVERSION_LIST)
                {
                    if (ucp.ID > 0)
                    {
                        aCommand.CommandText = ucp.GetUpdateSQL();
                        aCommand.ExecuteNonQuery();
                    }
                    else
                    {
                        aCommand.CommandText = ucp.GetInsertSQL();
                        aCommand.ExecuteNonQuery();
                        aCommand.CommandText = ucp.GetMaximumIDSQL();
                        ucp.ID = Convert.ToInt32(aCommand.ExecuteScalar());
                    }
                }
                aCommand.CommandText = UnitConversion.DeleteUpdate(e.ID, e.UNIT_CONVERSION_LIST);
                aCommand.ExecuteNonQuery();

                //IList luc = UnitConversion.GetAllStatic(r);
                //r.Close();
                //foreach (UnitConversion chk in luc)
                //{
                //    chk.UPDATED = e.UNIT_CONVERSION_LIST.Contains(chk);
                //}
                //foreach (UnitConversion chk in luc)
                //{
                //    if (!chk.UPDATED)
                //    {
                //        aCommand.CommandText = chk.GetDeleteSQL();
                //        aCommand.ExecuteNonQuery();
                //    }
                //}

                trans.Commit();
            }
            catch (Exception x)
            {
                trans.Rollback();
                throw new Exception(getErrorMessage(x));
            }
            finally
            {
                m_connection.Close();
            }
        }
コード例 #3
0
ファイル: PartRepository.cs プロジェクト: oghenez/profitz
 public virtual IList GetUnitConversions(int partID)
 {
     try
     {
         OpenConnection();
         MySql.Data.MySqlClient.MySqlCommand    aCommand = new MySql.Data.MySqlClient.MySqlCommand(UnitConversion.GetAllByPartSQL(partID), m_connection);
         MySql.Data.MySqlClient.MySqlDataReader aReader  = aCommand.ExecuteReader();
         IList a = UnitConversion.GetAllStatic(aReader);
         //if(a.Contains(
         return(a);
     }
     catch (Exception x)
     {
         throw new Exception(getErrorMessage(x));
     }
     finally
     {
         m_connection.Close();
     }
 }