public DeliveryReceiptWithDepartment getItemCreateAna(SqlConnection connection, int id, string _userID) { DeliveryReceiptWithDepartment ret = new DeliveryReceiptWithDepartment(); using (var command = new SqlCommand( " select P.DepartmentID, QC.CustomerID, CT.CustomerName, C.ContractCode, C.UserI as UserIContract from tbl_DeliveryReceipt DR " + " join tbl_proposal_process PP on DR.DeliveryReceiptID = PP.DeliveryReceiptID " + " join tbl_Quote_Customer QC on QC.QuoteID = PP.QuoteID and QC.IsChoosed = 1 " + " join tbl_Customer CT on CT.CustomerID = QC.CustomerID " + " join tbl_proposal P on P.ProposalID = PP.ProposalID " + " join tbl_Contract C on C.ContractID = PP.ContractID " + " where DR.DeliveryReceiptID = @id" , connection)) { if (!string.IsNullOrEmpty(_userID) && _userID != "admin") { command.CommandText += " and (DR.UserAssign = @UserID )"; AddSqlParameter(command, "@UserID", _userID, SqlDbType.VarChar); } AddSqlParameter(command, "@id", id, SqlDbType.Int); WriteLogExecutingCommand(command); using (var reader = command.ExecuteReader()) { while (reader.Read()) { ret.CustomerID = GetDbReaderValue <int>(reader["CustomerID"]); ret.DepartmentID = GetDbReaderValue <int>(reader["DepartmentID"]); ret.CustomerName = GetDbReaderValue <string>(reader["CustomerName"]); ret.ContractCode = GetDbReaderValue <string>(reader["ContractCode"]); ret.UserIContract = GetDbReaderValue <string>(reader["UserIContract"]); } } } return(ret); }
public async Task <ActionMessage> Create(DeliveryReceiptInfo obj, [FromForm] List <IFormFile> files, string _userI, string _userID) { ActionMessage ret = new ActionMessage(); int insetId = -1; SqlConnectionFactory sqlConnection = new SqlConnectionFactory(); using (SqlConnection connection = sqlConnection.GetConnection()) { try { insetId = DeliveryReceiptDataLayer.GetInstance().Create(connection, obj, _userI); } catch (Exception ex) { throw ex; } } if (insetId > -1) { ret.id = insetId; using (SqlConnection connection = sqlConnection.GetConnection()) { try { if (obj.Items != null) { // insertEmployees(insetId, obj.Employees); foreach (DeliveryReceiptItemInfoNew item in obj.Items) { item.DeliveryReceiptID = insetId; if (item.Amount > 0) { //input tai san DeliveryReceiptWithDepartment deliveryReceipt = DeliveryReceiptDataLayer.GetInstance().getItemCreateAna(connection, item.DeliveryReceiptID, _userID); AnalyzerInfo analyzerInfo = new AnalyzerInfo() { AnalyzerAccountantCode = "", AnalyzerName = item.ItemName, AnalyzerType = 0, QuoteItemID = item.QuoteItemID, Description = "", Amount = item.Amount, ItemPrice = item.ItemPrice, TotalPrice = item.TotalPrice, DepartmentRootID = deliveryReceipt.DepartmentID, DepartmentID = deliveryReceipt.DepartmentID, ContractCode = deliveryReceipt.ContractCode, UserIContract = deliveryReceipt.UserIContract, CustomerID = deliveryReceipt.CustomerID, CustomerName = deliveryReceipt.CustomerName, ExpirationDate = DateTime.Now, DateIn = obj.DeliveryReceiptDate, DeliveryReceiptID = item.DeliveryReceiptID, Serial = "", }; int seq = AnalyzerDataLayer.GetInstance().GetMaxPropCode(connection, analyzerInfo.DateIn.Year); int insertID = AnalyzerDataLayer.GetInstance().InsertAnalyzer(connection, analyzerInfo, seq, _userI); string[] _anaNamesSplit = analyzerInfo.AnalyzerName.Split(' '); string _anaNameSplit = ""; for (int i = 0; i < _anaNamesSplit.Count(); i++) { if (i == 4) { break; } else { _anaNameSplit += (_anaNamesSplit[i][0]).ToString().ToUpper(); } } string anacode = _anaNameSplit + "." + analyzerInfo.DateIn.Year + "." + String.Format("{0:000000}", seq); AnalyzerDataLayer.GetInstance().UpdateAnalyzer(connection, insertID, anacode); // end insert DeliveryReceiptDataLayer.GetInstance().CreateDeliveryReceiptItem(connection, item, _userI); } } } } catch (Exception ex) { throw ex; } } using (SqlConnection connection = sqlConnection.GetConnection()) { try { if (obj.Employees != null) { foreach (DeliveryReceiptEmployeeInfo item in obj.Employees) { item.DeliveryReceiptID = insetId; DeliveryReceiptDataLayer.GetInstance().CreateDeliveryReceiptItemUser(connection, item, _userI); } } } catch (Exception ex) { throw ex; } } foreach (var item in files) { DocumentInfo documentInfo = new DocumentInfo(); documentInfo.TableName = TableFile.DeliveryReceipt.ToString(); documentInfo.PreferId = insetId.ToString(); documentInfo.Link = DateTime.Now.ToString("yyMMddHHmmssfff") + "-" + Utils.ChuyenTVKhongDau(item.FileName); documentInfo.FileName = item.FileName; documentInfo.Length = item.Length.ToString(); documentInfo.Type = item.ContentType; ret = await FilesHelpers.UploadFile(TableFile.DeliveryReceipt.ToString(), insetId.ToString(), item, documentInfo.Link); DocumentService.GetInstance().InsertDocument(documentInfo, _userI.ToString()); } ret.isSuccess = true; } else { ret.isSuccess = false; ret.err.msgCode = "lỗi thêm phiếu nghiệm thu"; ret.err.msgString = "lỗi thêm phiếu nghiệm thu"; } return(ret); }