public bool processProblemMedicine(ProcessDTO processDTO) { try { Db.Ado.BeginTran(); DateTime dateTime = DateTime.Now; var tempResult = Db.Queryable <MEDICINE_STOCK, STOCK_IN, CONTRACT> ((ms, si, c) => ms.STOCK_ID == si.STOCK_ID && si.CONTRACT_ID == c.CONTRACT_ID). Where((ms, si, c) => ms.BATCH_ID == processDTO._batch_id && ms.MEDICINE_ID == processDTO._medicine_id) .Select((ms, si, c) => new { ms.STOCK_ID, c.CONTRACT_ID, ms.AMOUNT }).Single(); if (tempResult.AMOUNT < processDTO._num) { throw new Exception(); } PROBLEM_MEDICINE_RETURN problemMedicineReturn = new PROBLEM_MEDICINE_RETURN { STOCK_ID = tempResult.STOCK_ID, CONTRACT_ID = tempResult.CONTRACT_ID, STAFF_ID = processDTO._staff_id, RETURN_NUMBER = processDTO._num, RETURN_DATE = dateTime }; Db.Insertable(problemMedicineReturn).ExecuteCommand(); MEDICINE_STOCK medicine = new MEDICINE_STOCK { STOCK_ID = tempResult.STOCK_ID, MEDICINE_ID = processDTO._medicine_id, BATCH_ID = processDTO._batch_id, AMOUNT = tempResult.AMOUNT - processDTO._num }; Db.Updateable(medicine).ExecuteCommand(); Db.Ado.CommitTran(); return(true); }catch (Exception e) { Db.Ado.RollbackTran(); return(false); } }
/// <summary> /// /// </summary> /// <param name="completeContractDTO"></param> public bool completeOneContract(CompleteContractDTO completeContractDTO) { try { Db.Ado.BeginTran(); CONTRACT contract = Db.Queryable <CONTRACT>().InSingle(completeContractDTO._contract_id); contract.CONTRACT_STATUS = 2; Db.Updateable(contract).ExecuteCommand(); var length = Db.Queryable <CONTRACT_ITEM>().Where((it) => it.CONTRACT_ID == completeContractDTO._contract_id) .Select(it => SqlFunc.AggregateCount(it.MEDICINE_ID)).Single(); if (length != completeContractDTO.stockInDTOs.Count) { throw new Exception(); } foreach (StockInDTO stockInDTO in completeContractDTO.stockInDTOs) { CONTRACT_ITEM contractItem = Db.Queryable <CONTRACT_ITEM>(). Where((it) => it.MEDICINE_ID == stockInDTO._medicine_id && it.CONTRACT_ID == completeContractDTO._contract_id).Single(); if (contractItem.MEDICINE_STATUS == 2) { continue; } contractItem.MEDICINE_STATUS = 2; Db.Updateable(contractItem).ExecuteCommand(); MEDICINE_INSTANCE medicineInstance = new MEDICINE_INSTANCE { MEDICINE_ID = stockInDTO._medicine_id, BATCH_ID = stockInDTO._batch_id, PRODUCTION_DATE = stockInDTO._production_date, VALIDITY_DATE = stockInDTO._validity_date, PURCHASE_PRICE = contractItem.MEDICINE_MONEY, SALE_PRICE = stockInDTO._sale_price }; Db.Insertable(medicineInstance).ExecuteCommand(); MEDICINE_STOCK medicineStock = new MEDICINE_STOCK { MEDICINE_ID = stockInDTO._medicine_id, BATCH_ID = stockInDTO._batch_id, AMOUNT = stockInDTO._in_num }; Db.Insertable(medicineStock).IgnoreColumns(it => new { it.STOCK_ID }).ExecuteCommand(); var id = Db.Ado.SqlQuery <int>("select ISEQ$$_84079.currval from dual").Single(); STOCK_IN stockIn = new STOCK_IN { STOCK_ID = id, CONTRACT_ID = completeContractDTO._contract_id, IN_NUM = stockInDTO._in_num, IN_TIME = stockInDTO._in_time }; Db.Insertable(stockIn).ExecuteCommand(); } Db.Ado.CommitTran(); return(true); } catch (Exception e) { Db.Ado.RollbackTran(); return(false); } //stock_in.IN_NUM=contract. }