public SRDSRDue GetSrDsrDue(string Id) { DbCommand comm = null; SRDSRDue srDsrDue = null; try { comm = GenericDataAccess.CreateCommand(); comm.CommandType = CommandType.Text; comm.CommandText = @"SELECT * FROM IM_SR_DSR_ORDER_DUE WHERE SrId = @SrId"; CreateParameter.AddParam(comm, "@SrId", Id, DbType.String); DbDataReader dr = GenericDataAccess.ExecuteQuery(comm); if (dr.Read()) { srDsrDue = MapSrDsrDue(dr); } } catch (Exception ex) { } finally { if (comm != null && comm.Connection.State != ConnectionState.Closed) { comm.Connection.Close(); } } return(srDsrDue); }
private SRDSRDue MapSrDsrDue(DbDataReader dr) { SRDSRDue srDsrDue = new SRDSRDue(); srDsrDue.Id = NullHandler.GetString(dr["SrId"]); srDsrDue.Due = NullHandler.GetDouble(dr["TotalDue"]); return(srDsrDue); }
private SRDSRDue MapSrDsrWithDue(DbDataReader dr) { SRDSRDue srDsr = new SRDSRDue(); srDsr.Id = NullHandler.GetString(dr["Id"]); srDsr.Name = NullHandler.GetString(dr["Name"]); srDsr.Type = (SRType)NullHandler.GetInt32(dr["Type"]); srDsr.CellNo = NullHandler.GetString(dr["CellNo"]); srDsr.Due = NullHandler.GetDouble(dr["TotalDue"]); return(srDsr); }
public Report(string companyName, string srDsrName, string marketName, DateTime orderDate, List <ItemOrder> order, string paid, SRDSRDue previousDue) : this() { this.companyName = companyName; this.srDsrName = srDsrName; this.marketName = marketName; this.orderDate = orderDate; this.paid = paid; this.previousDue = previousDue; itemOrderBindingSource.DataSource = order; UpdateReportParameters(); }
public SavingState SaveSrDsrDue(SRDSRDue srDsrDue) { SavingState svState = SavingState.Failed; if (!string.IsNullOrEmpty(srDsrDue.Id)) { DbCommand thisCommand = null; try { thisCommand = GenericDataAccess.CreateCommand(); thisCommand.CommandType = CommandType.Text; /// if new sr if (!IsSRDSRDueExist(srDsrDue.Id)) { thisCommand.CommandText = "INSERT INTO IM_SR_DSR_ORDER_DUE (SrId, TotalDue) VALUES(@SrId, @TotalDue)"; } else { thisCommand.CommandText = "UPDATE IM_SR_DSR_ORDER_DUE SET TotalDue = @TotalDue WHERE SrId = @SrId"; } CreateParameter.AddParam(thisCommand, "@SrId", srDsrDue.Id, DbType.String); CreateParameter.AddParam(thisCommand, "@TotalDue", Math.Round(srDsrDue.Due, 2), DbType.Double); GenericDataAccess.ExecuteNonQuery(thisCommand); thisCommand.Parameters.Clear(); svState = SavingState.Success; } catch (Exception ex) { if (ex.Message.ToLower().Contains("duplicate key")) { svState = SavingState.DuplicateExists; } } finally { if (thisCommand != null && thisCommand.Connection.State != ConnectionState.Closed) { thisCommand.Connection.Close(); } } } return(svState); }
public SavingState SaveItemsOrder(DataGridView dataGridViewOrder, string companyId, string srDsrId, string marketId, DateTime orderDate, SRDSRDue srDsrDue, bool isFromTemplate = false, bool isItemReturnedFromOrder = false, bool isDamagedItemReturnedFromOrder = false) { SavingState svState = SavingState.Failed; DbCommand thisCommand = null; try { thisCommand = GenericDataAccess.CreateCommand(); thisCommand.CommandType = CommandType.Text; GenericDataAccess.OpenDBConnection(thisCommand); if ((isFromTemplate && !IsSrDsrOrderExist(companyId, srDsrId, marketId, orderDate)) || (!isFromTemplate && IsSrDsrOrderExist(companyId, srDsrId, marketId, orderDate))) { foreach (DataGridViewRow row in dataGridViewOrder.Rows) { int stockAvailableInStore = 0; int damagedItemAvailableInStock = 0; if (string.IsNullOrEmpty(NullHandler.GetString(row.Cells["OrderId"].Value))) { /// insert the item order thisCommand.CommandText = "INSERT INTO IM_Orders (OrderId, CompanyId, SrId, MarketId, ItemId, Date, OrderCount, ReturnCount, SoldCount, DamagedCount) VALUES(@OrderId, @CompanyId, @SrId, @MarketId, @ItemId, @Date, @OrderCount, @ReturnCount, @SoldCount, @DamagedCount)"; CreateParameter.AddParam(thisCommand, "@OrderId", Guid.NewGuid().ToString(), DbType.String); CreateParameter.AddParam(thisCommand, "@CompanyId", companyId, DbType.String); CreateParameter.AddParam(thisCommand, "@SrId", srDsrId, DbType.String); CreateParameter.AddParam(thisCommand, "@MarketId", marketId, DbType.String); CreateParameter.AddParam(thisCommand, "@ItemId", NullHandler.GetString(row.Cells["ItemId"].Value), DbType.String); CreateParameter.AddParam(thisCommand, "@Date", orderDate.Date, DbType.Date); stockAvailableInStore = NullHandler.GetInt32(row.Cells["CurrentStockTotal"].Value) - NullHandler.GetInt32(row.Cells["SellsCount"].Value); damagedItemAvailableInStock = NullHandler.GetInt32(row.Cells["CurrentDamagedStockTotal"].Value); } else { /// update the item order based on OrderId thisCommand.CommandText = "UPDATE IM_Orders SET OrderCount = @OrderCount, ReturnCount = @ReturnCount, SoldCount = @SoldCount, DamagedCount = @DamagedCount WHERE OrderId = @OrderId"; CreateParameter.AddParam(thisCommand, "@OrderId", row.Cells["OrderId"].Value.ToString(), DbType.String); stockAvailableInStore = isItemReturnedFromOrder ? (NullHandler.GetInt32(row.Cells["CurrentStockTotal"].Value) + NullHandler.GetInt32(row.Cells["ReturnCount"].Value)) : NullHandler.GetInt32(row.Cells["CurrentStockTotal"].Value); damagedItemAvailableInStock = isDamagedItemReturnedFromOrder? (NullHandler.GetInt32(row.Cells["CurrentDamagedStockTotal"].Value) + NullHandler.GetInt32(row.Cells["DamageCount"].Value)): NullHandler.GetInt32(row.Cells["CurrentDamagedStockTotal"].Value); } CreateParameter.AddParam(thisCommand, "@OrderCount", row.Cells["OrderCount"].Value, DbType.Int32); CreateParameter.AddParam(thisCommand, "@ReturnCount", row.Cells["ReturnCount"].Value, DbType.Int32); CreateParameter.AddParam(thisCommand, "@DamagedCount", row.Cells["DamageCount"].Value, DbType.Int32); CreateParameter.AddParam(thisCommand, "@SoldCount", row.Cells["SellsCount"].Value, DbType.Int32); GenericDataAccess.ExecuteNonQueryTransaction(thisCommand); thisCommand.Parameters.Clear(); if (!string.IsNullOrEmpty(NullHandler.GetString(row.Cells["StockId"].Value))) { ItemStock stock = new ItemStock(); stock.StockId = NullHandler.GetString(row.Cells["StockId"].Value); stock.ItemId = NullHandler.GetString(row.Cells["ItemId"].Value); stock.ChalanNo = NullHandler.GetString(row.Cells["ChalanNo"].Value); stock.StockEntryDate = NullHandler.GetDateTime(row.Cells["StockEntryDate"].Value); stock.CurrentStockTotal = stockAvailableInStore;//NullHandler.GetInt32(row.Cells["CurrentStockTotal"].Value); stock.CurrentDamagedStockTotal = damagedItemAvailableInStock; svState = SaveStockItem(stock, thisCommand, true); } } } else { svState = SavingState.DuplicateExists; } } catch (Exception ex) { if (ex.Message.ToLower().Contains("duplicate key")) { svState = SavingState.DuplicateExists; } } finally { GenericDataAccess.CloseDBConnection(thisCommand); } if (svState.Equals(SavingState.Success) && !string.IsNullOrEmpty(srDsrDue.Id)) { svState = SRDSRManager.Instance.SaveSrDsrDue(srDsrDue); } return(svState); }