public SingleResponeMessage <SurveyDetailInfo> Get(int id, string _userID) { SingleResponeMessage <SurveyDetailInfo> ret = new SingleResponeMessage <SurveyDetailInfo>(); try { SurveyDetailInfo item = SurveyService.GetInstance().GetDetailSurvey(id, _userID); if (item == null) { ret.isSuccess = false; ret.err.msgCode = "001"; ret.err.msgString = "no Survey 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 SurveyDetailInfo getSurveyDetail(SqlConnection connection, int ID, string _userID) { SurveyDetailInfo result = null; using (var command = new SqlCommand("Select S.*, SD.DepartmentName, P.ProposalCode, P.ProposalType, PT.TypeName, P.DepartmentID as ProDepartmentID, " + "D.DepartmentName as ProDepartmentName, P.DateIn as ProposalDate " + "from (Select * from tbl_Survey where 1= 1 ", connection)) { { if (!string.IsNullOrEmpty(_userID) && _userID != "admin") { command.CommandText += " and ( UserAssign = " + _userID + " ) or ( UserI = " + _userID + " )"; } command.CommandText += " and SurveyID = @SurveyID"; AddSqlParameter(command, "@SurveyID", ID, System.Data.SqlDbType.Int); command.CommandText += " ) as S " + " left join tbl_Department SD on S.SurveyDepartmentID = SD.DepartmentID " + " left join tbl_Proposal P on P.ProposalID = S.ProposalID" + " left join tbl_Department D on P.DepartmentID = D.DepartmentID " + " left join tbl_ProposalType PT on PT.TypeID = P.ProposalType "; WriteLogExecutingCommand(command); using (var reader = command.ExecuteReader()) { while (reader.Read()) { result = new SurveyDetailInfo(); result.SurveyID = GetDbReaderValue <int>(reader["SurveyID"]); result.SurveyCode = GetDbReaderValue <string>(reader["SurveyCode"]); result.SurveyName = GetDbReaderValue <string>(reader["SurveyName"]); result.ProposalID = GetDbReaderValue <int>(reader["ProposalID"]); result.ProposalCode = GetDbReaderValue <string>(reader["ProposalCode"]); result.ProposalType = GetDbReaderValue <int>(reader["ProposalType"]); result.ProposalTypeName = GetDbReaderValue <string>(reader["TypeName"]); result.TypeName = GetDbReaderValue <string>(reader["TypeName"]); result.DepartmentID = GetDbReaderValue <int>(reader["ProDepartmentID"]); result.DepartmentName = GetDbReaderValue <string>(reader["ProDepartmentName"]); result.SurveyDepartmentID = GetDbReaderValue <int>(reader["SurveyDepartmentID"]); result.SurveyDepartmentName = GetDbReaderValue <string>(reader["DepartmentName"]); result.Comment = GetDbReaderValue <string>(reader["Comment"]); result.Status = GetDbReaderValue <string>(reader["Status"]); result.Solution = GetDbReaderValue <int>(reader["Solution"]); result.SolutionText = GetDbReaderValue <string>(reader["SolutionText"]); result.IsSample = GetDbReaderValue <bool>(reader["IsSample"]); result.Valid = GetDbReaderValue <bool>(reader["Valid"]); result.ValidText = GetDbReaderValue <string>(reader["ValidText"]); result.UserI = GetDbReaderValue <string>(reader["UserI"]); result.ProposalDate = GetDbReaderValue <DateTime>(reader["ProposalDate"]); result.ProductsName = GetDbReaderValue <string>(reader["ProductsName"]); result.DepartmentComment = GetDbReaderValue <string>(reader["DepartmentComment"]); result.InTime = GetDbReaderValue <DateTime?>(reader["InTime"]); result.DateIn = GetDbReaderValue <DateTime?>(reader["DateIn"]); result.UserU = GetDbReaderValue <string>(reader["UserU"]); result.UpdateTime = GetDbReaderValue <DateTime>(reader["UpdateTime"]); } } return(result); } } }
public ActionMessage DeleteSurvey(int id, string user, string _userID) { ActionMessage ret = new ActionMessage(); SurveyDetailInfo temp = GetDetailSurvey(id, _userID); SqlConnectionFactory sqlConnection = new SqlConnectionFactory(); using (SqlConnection connection = sqlConnection.GetConnection()) { try { UserLogInfo info = new UserLogInfo(); info.Action = "Delete"; if (temp != null) { info.Description = "code : " + temp.SurveyCode + " 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); SurveyDataLayer.GetInstance().Delete(connection, id); ret.isSuccess = true; } catch (Exception ex) { ret.isSuccess = false; ret.err.msgCode = "Internal Error"; ret.err.msgString = ex.ToString(); } } return(ret); }
public SurveyDetailInfo GetDetailSurvey(int _ID, string _userID) { SurveyDetailInfo record = new SurveyDetailInfo(); SqlConnectionFactory sqlConnection = new SqlConnectionFactory(); using (SqlConnection connection = sqlConnection.GetConnection()) { record = SurveyDataLayer.GetInstance().getSurveyDetail(connection, _ID, _userID); if (record == null) { return(null); } //Get document DocumentSeachCriteria documentCriteria = new DocumentSeachCriteria(); documentCriteria.TableName = TableFile.Survey.ToString(); documentCriteria.PreferId = _ID.ToString(); record.ListDocument = DocumentService.GetInstance().GetDocument(documentCriteria); record.Items = ProposalDataLayer.GetInstance().GetPropsalItems(connection, _ID); record.SurveyItems = ProposalDataLayer.GetInstance().GetSurveyItem(connection, _ID); //get Comment CommentSeachCriteria commentCriteria = new CommentSeachCriteria(); commentCriteria.TableName = TableFile.Survey.ToString(); commentCriteria.PreferId = _ID.ToString(); record.ListComment = CommentService.GetInstance().getComment(commentCriteria); foreach (var item in record.ListComment) { DocumentSeachCriteria documentCriteria2 = new DocumentSeachCriteria(); documentCriteria2.TableName = TableFile.Comment.ToString(); documentCriteria2.PreferId = item.AutoID.ToString(); item.ListDocument = DocumentService.GetInstance().GetDocument(documentCriteria2); } return(record); } }
public static MemoryStream GetTempPlate(int id, string path, out string code, string _userID) { var memoryStream = new MemoryStream(); SurveyDetailInfo item = SurveyService.GetInstance().GetDetailSurvey(id, _userID); 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 curDate = date.ToString("dd/MM/yyyy"); string currentdate = "Ngày " + date.Day + " tháng " + date.Month + " năm" + date.Year; var body = document.MainDocumentPart.Document.Body; var paras = body.Elements <Paragraph>(); var itemName = ""; foreach (ItemPropsalInfo record in item.Items) { itemName = itemName + record.ItemName + ", "; } itemName = itemName.Substring(0, itemName.Length - 1); List <string> headers = new List <string>(); List <List <string> > items = new List <List <string> >(); headers.Add("STT"); headers.Add("Tên linh kiện, tài sản"); headers.Add("ĐVT"); headers.Add("Số Lượng"); headers.Add("Ghi Chú"); var sttIndex = 1; foreach (ItemSurveyInfo record in item.SurveyItems) { List <string> row = new List <string>(); row.Add(sttIndex.ToString()); row.Add(record.ItemName); row.Add(record.ItemUnit); row.Add(record.ItemAmount.ToString()); row.Add(record.Note); items.Add(row); sttIndex++; } Table tableData = CreateTable(headers, items); foreach (var text in body.Descendants <Text>()) { text.Text = text.Text.Replace("#", ""); text.Text = text.Text.Replace("proposalcode", WordUtils.checkNull(item.ProposalCode)); text.Text = text.Text.Replace("surveycode", WordUtils.checkNull(item.SurveyCode)); text.Text = text.Text.Replace("solution", WordUtils.checkNull(item.SolutionText)); text.Text = text.Text.Replace("validtext", WordUtils.checkNull(item.ValidText)); text.Text = text.Text.Replace("proposaldate", WordUtils.checkNull(item.ProposalDate.ToString("dd/MM/yyyy"))); text.Text = text.Text.Replace("curdate", WordUtils.checkNull(curDate)); text.Text = text.Text.Replace("currentdate", WordUtils.checkNull(currentdate)); text.Text = text.Text.Replace("itemname", WordUtils.checkNull(itemName)); text.Text = text.Text.Replace("depart", WordUtils.checkNull(item.DepartmentName)); if (text.Text == "lstItem") { DocumentFormat.OpenXml.OpenXmlElement textP1 = text.Parent; DocumentFormat.OpenXml.OpenXmlElement textP2 = textP1.Parent; body.InsertAfter(tableData, textP2); textP1.Remove(); } } List <int> Checks = new List <int>(); Checks.Add(item.Solution - 1); if (item.IsSample == true) { Checks.Add(4); } if (item.Valid == true) { Checks.Add(5); } else { Checks.Add(6); } int i = 0; foreach (SdtContentCheckBox ctrl in body.Descendants <SdtContentCheckBox>()) { if (Checks.IndexOf(i) > -1) { ctrl.Checked.Val = OnOffValues.One; ctrl.Parent.Parent.Descendants <Run>().First().GetFirstChild <Text>().Text = "☒"; } i++; } document.Save(); document.Close(); } return(memoryStream); }