public SingleResponeMessage <ProposalDetailInfo> Get(int id) { SingleResponeMessage <ProposalDetailInfo> ret = new SingleResponeMessage <ProposalDetailInfo>(); try { string _userID = GetUserId(); ProposalDetailInfo item = ProposalService.GetInstance().getDetailProposal(id, _userID); if (item == null) { ret.isSuccess = false; ret.err.msgCode = "001"; ret.err.msgString = "no proposal found"; return(ret); } ret.item = item; ret.isSuccess = true; } catch (Exception ex) { ret.isSuccess = false; ret.err.msgCode = "Internal Error !!!"; ret.err.msgString = ex.ToString(); } return(ret); }
public ProposalDetailInfo GetDetailProposalByCode(string code, string _userID) { ProposalDetailBase proposalDetail = new ProposalDetailBase(); SqlConnectionFactory sqlConnection = new SqlConnectionFactory(); ProposalDetailInfo ret; using (SqlConnection connection = sqlConnection.GetConnection()) { proposalDetail = ProposalDataLayer.GetInstance().getProposalDetailByCode(connection, code, _userID); if (proposalDetail == null) { return(null); } ret = new ProposalDetailInfo(proposalDetail); ret.ListComment = new List <CommentInfo>(); //Get document DocumentSeachCriteria documentCriteria = new DocumentSeachCriteria(); documentCriteria.TableName = TableFile.Proposal.ToString(); documentCriteria.PreferId = proposalDetail.ProposalID.ToString(); ret.ListDocument = DocumentService.GetInstance().GetDocument(documentCriteria); ret.Items = new List <ItemPropsalInfo>(); ret.Items = ProposalDataLayer.GetInstance().GetPropsalItems(connection, proposalDetail.ProposalID); //get Comment CommentSeachCriteria commentCriteria = new CommentSeachCriteria(); commentCriteria.TableName = TableFile.Proposal.ToString(); commentCriteria.PreferId = proposalDetail.ProposalID.ToString(); ret.ListComment = CommentService.GetInstance().getComment(commentCriteria); foreach (var item in ret.ListComment) { DocumentSeachCriteria documentCriteria2 = new DocumentSeachCriteria(); documentCriteria2.TableName = TableFile.Comment.ToString(); documentCriteria2.PreferId = item.AutoID.ToString(); item.ListDocument = DocumentService.GetInstance().GetDocument(documentCriteria2); } } return(ret); }
public ActionMessage DeleteProposal(int id, string user, string _userID) { ActionMessage ret = new ActionMessage(); SqlConnectionFactory sqlConnection = new SqlConnectionFactory(); using (SqlConnection connection = sqlConnection.GetConnection()) { try { ProposalDetailInfo temp = ProposalService.GetInstance().getDetailProposal(id, ""); UserLogInfo info = new UserLogInfo(); info.Action = "Delete "; if (temp != null) { info.Description = "code : " + temp.ProposalCode + " id : " + id; } else { info.Description = " id : " + id; } info.Feature = TableFile.Proposal.ToString(); info.Time = DateTime.Now; info.UserName = user; info.UserID = 1; UserService.GetInstance().TrackUserAction(info); //delete Items Table List <ItemPropsalInfo> currentItems = ProposalDataLayer.GetInstance().GetPropsalItems(connection, id); if (currentItems.Count > 0) { string autoIds = ""; foreach (var item in currentItems) { autoIds = autoIds + item.AutoID + ','; } autoIds = autoIds.Remove(autoIds.Length - 1); ProposalDataLayer.GetInstance().DeleteProposalItems(connection, autoIds); } CommentSeachCriteria _criteria = new CommentSeachCriteria(); _criteria.TableName = TableFile.Proposal.ToString(); _criteria.PreferId = id.ToString(); CommentDataLayer.GetInstance().DeleteComment(connection, _criteria); //delete attach files and DB of attach files DocumentService.GetInstance().DeleteDocumentByFeature(TableFile.Proposal.ToString(), id); //deleteRelatedProsal // .. var quoteIds = QuoteDataLayer.GetInstance().GetQuotesByProposalId(connection,id.ToString()); // if(quoteIds.Count > 0) // QuoteService.DeleteMuti(String.Join(", ", quoteIds.ToArray())); var surveyIds = SurveyDataLayer.GetInstance().GetSurveyByProposalId(connection, id.ToString()); if (surveyIds.Count > 0) { SurveyDataLayer.GetInstance().DeleteMuti(connection, String.Join(", ", surveyIds.ToArray())); } var explanationServiceIds = ExplanationDataLayer.GetInstance().GetExplanationsByProposalId(connection, id.ToString(), _userID); if (explanationServiceIds.Count > 0) { ExplanationDataLayer.GetInstance().DeleteMuti(connection, String.Join(", ", explanationServiceIds.ToArray())); } //delete record ProposalDataLayer.GetInstance().DeleteProposal(connection, id); ret.isSuccess = true; } catch (Exception ex) { ret.isSuccess = false; ret.err.msgCode = "Internal Error"; ret.err.msgString = ex.ToString(); } } return(ret); }
public static MemoryStream GetTemplate(int id, string path, out string code) { var memoryStream = new MemoryStream(); ProposalDetailInfo item = ProposalService.GetInstance().getDetailProposal(id, ""); var index = item.ProposalType - 1; using (var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read)) fileStream.CopyTo(memoryStream); code = item.ProposalCode; using (var document = WordprocessingDocument.Open(memoryStream, true)) { document.ChangeDocumentType(WordprocessingDocumentType.Document); // change from template to document DateTime date = DateTime.Now; string currentDate = "Ngày " + date.ToString("dd/MM/yyyy"); var body = document.MainDocumentPart.Document.Body; var paras = body.Elements <Paragraph>(); List <string> headers = new List <string>(); List <List <string> > items = new List <List <string> >(); headers.Add("Tên"); headers.Add("Số Lượng"); headers.Add("Ghi Chú"); foreach (ItemPropsalInfo record in item.Items) { List <string> row = new List <string>(); row.Add(record.ItemName); row.Add(record.Amount.ToString()); row.Add(record.Note); items.Add(row); } Table tableData = CreateTable(headers, items); foreach (var text in body.Descendants <Text>()) { text.Text = text.Text.Replace("#", ""); text.Text = text.Text.Replace("reason", WordUtils.checkNull(item.FollowComment)); text.Text = text.Text.Replace("survey", WordUtils.checkNull(item.Comment)); text.Text = text.Text.Replace("currentdate", WordUtils.checkNull(currentDate)); text.Text = text.Text.Replace("curdepart", WordUtils.checkNull(item.CurDepartmentCode)); text.Text = text.Text.Replace("proposalcode", WordUtils.checkNull(item.ProposalCode)); text.Text = text.Text.Replace("depart", WordUtils.checkNull(item.DepartmentCode)); if (text.Text == "lstItem") { DocumentFormat.OpenXml.OpenXmlElement textP1 = text.Parent; DocumentFormat.OpenXml.OpenXmlElement textP2 = textP1.Parent; body.InsertAfter(tableData, textP2); textP1.Remove(); } } int i = 0; foreach (SdtContentCheckBox ctrl in body.Descendants <SdtContentCheckBox>()) { if (i == index) { ctrl.Checked.Val = OnOffValues.One; ctrl.Parent.Parent.Descendants <Run>().First().GetFirstChild <Text>().Text = "☒"; break; } i++; } document.Save(); document.Close(); } return(memoryStream); }