protected override void doDelete(Event e) { SalesReturn st = (SalesReturn)e;//this.Get(e.ID); MySql.Data.MySqlClient.MySqlTransaction trc = m_connection.BeginTransaction(); m_command.Transaction = trc; try { if (getEventStatus(st.ID) == EventStatus.Confirm) { throw new Exception("Revise before delete"); } m_command.CommandText = ARCreditNoteItem.GetSRUsedByARCR(st.ID); int count = Convert.ToInt32(m_command.ExecuteScalar()); if (count > 0) { throw new Exception("Can not delete this Sales Return, this Sales Return used by ARCR"); } m_command.CommandText = SalesReturnItem.DeleteAllByEventSQL(st.ID); m_command.ExecuteNonQuery(); m_command.CommandText = SalesReturn.DeleteSQL(st.ID); m_command.ExecuteNonQuery(); trc.Commit(); } catch (Exception x) { trc.Rollback(); throw x; } }
public IList FindSRForARCreditNote(string find, int supID, DateTime trdate, IList added) { m_command.CommandText = ARCreditNoteItem.GetSRUsedByARCR(); MySql.Data.MySqlClient.MySqlDataReader r = m_command.ExecuteReader(); if (r.HasRows) { while (r.Read()) { int id = Convert.ToInt32(r[0]); if (!added.Contains(id)) { added.Add(id); } } } r.Close(); StringBuilder poisSB = new StringBuilder(); foreach (int i in added) { poisSB.Append(i.ToString()); poisSB.Append(','); } string pois = poisSB.ToString(); pois = added.Count > 0 ? pois.Substring(0, pois.Length - 1) : ""; m_command.CommandText = SalesReturn.GetSearchSRNoForARCR(find, supID, pois, trdate); r = m_command.ExecuteReader(); IList result = SalesReturn.TransformReaderList(r); r.Close(); foreach (SalesReturn p in result) { m_command.CommandText = SalesReturnItem.GetByEventIDSQL(p.ID); r = m_command.ExecuteReader(); p.EVENT_ITEMS = SalesReturnItem.TransformReaderList(r); r.Close(); foreach (SalesReturnItem t in p.EVENT_ITEMS) { if ((t.DO_ITEM == null) && (t.DO_ITEM.ID == 0)) { continue; } m_command.CommandText = DeliveryOrderItem.GetByIDSQL(t.DO_ITEM.ID); r = m_command.ExecuteReader(); t.DO_ITEM = DeliveryOrderItem.TransformReader(r); r.Close(); if ((t.DO_ITEM.SO_ITEM == null)) { continue; } if (t.DO_ITEM.SO_ITEM.ID == 0) { continue; } m_command.CommandText = SalesOrderItem.GetByIDSQL(t.DO_ITEM.SO_ITEM.ID); r = m_command.ExecuteReader(); t.DO_ITEM.SO_ITEM = SalesOrderItem.TransformReader(r); r.Close(); t.DO_ITEM.PART = PartRepository.GetByID(m_command, t.DO_ITEM.PART.ID); t.DO_ITEM.PART.UNIT_CONVERSION_LIST = PartRepository.GetUnitConversionsStatic(m_command, t.DO_ITEM.SO_ITEM.PART.ID); t.PART = t.DO_ITEM.SO_ITEM.PART = t.DO_ITEM.PART; double subamount = (t.DO_ITEM.SO_ITEM.SUBTOTAL / t.DO_ITEM.SO_ITEM.GetAmountInSmallestUnit()) * t.GetAmountInSmallestUnit(); p.TOTAL_AMOUNT_FROM_SO += subamount; t.DO_ITEM.SO_ITEM.EVENT = SalesOrderRepository.GetHeaderOnly(m_command, t.DO_ITEM.SO_ITEM.EVENT.ID); p.CURRENCY = ((SalesOrder)t.DO_ITEM.SO_ITEM.EVENT).CURRENCY; } } return(result); }