/// <summary> /// 保存数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void rbtnSave_Click(object sender, EventArgs e) { //模版名称为空则提示 if (string.IsNullOrEmpty(rtxtName.Text)) { MessageBox.Show(PromptMessageXmlHelper.Instance.GetPromptMessage("customtemplatename", EnumPromptMessage.warning), "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //模版文件未传则提示 if (string.IsNullOrEmpty(rtxtFile.Text)) { MessageBox.Show(PromptMessageXmlHelper.Instance.GetPromptMessage("customtemplatefile", EnumPromptMessage.warning), "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //模版上传辅助类 TemFileUploadHelper temFileUploadHelper = new TemFileUploadHelper(); string fileName = reCnasRemotCall.RemotInterface.Get_SerialNumber(2) + Path.GetExtension(rtxtFile.Text); try { //判断是否是修改 if (tem_id == 0) { FileStream fileStream = File.Open(rtxtFile.Tag.ToString(), FileMode.Open); temFileUploadHelper.UploadTemFile(@"Template\", fileName, fileStream); fileStream.Close(); fileStream.Dispose(); SortedList addlist = new SortedList(); SortedList addlist01 = new SortedList(); addlist.Add(1, rtxtName.Text); addlist.Add(2, rtxtFile.Text); addlist.Add(3, DateTime.Now); addlist.Add(4, rtxtRemark.Text); addlist.Add(5, fileName); addlist01.Add(1, addlist); //string ss = reCnasRemotCall.RemotInterface.CheckUPData(1, "HCS-custom-template-add001", addlist01, null); int addDataService = reCnasRemotCall.RemotInterface.UPData(1, "HCS-custom-template-add001", addlist01, null); if (addDataService > -1) { MessageBox.Show(PromptMessageXmlHelper.Instance.GetPromptMessage("succeed", EnumPromptMessage.warning), "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } else { //如果是修改,但是未返回数据,则直接关闭窗体 if (dtRowDate.Rows.Count <= 0) { this.Close(); } //如果文件不一样,则说明重新上传了文件,则重新上传一次 if (dtRowDate.Rows[0]["filename"].ToString() != rtxtFile.Text) { temFileUploadHelper.DeleteTemFile(@"Template\", dtRowDate.Rows[0]["guidname"].ToString()); FileStream fileStream = File.Open(rtxtFile.Tag.ToString(), FileMode.Open); temFileUploadHelper.UploadTemFile(@"Template\", fileName, fileStream); fileStream.Close(); fileStream.Dispose(); } SortedList uplist = new SortedList(); SortedList uplist01 = new SortedList(); uplist.Add(1, rtxtName.Text); uplist.Add(2, rtxtFile.Text); uplist.Add(3, DateTime.Now); uplist.Add(4, rtxtRemark.Text); uplist.Add(5, fileName); uplist.Add(6, tem_id); uplist01.Add(1, uplist); string ss = reCnasRemotCall.RemotInterface.CheckUPData(1, "HCS-custom-template-up001", uplist01, null); int UpDataService = reCnasRemotCall.RemotInterface.UPData(1, "HCS-custom-template-up001", uplist01, null); if (UpDataService > -1) { MessageBox.Show(PromptMessageXmlHelper.Instance.GetPromptMessage("editsucceed", EnumPromptMessage.warning), "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } } catch (Exception ex) { MessageBox.Show(PromptMessageXmlHelper.Instance.GetPromptMessage("unknowerror", EnumPromptMessage.error, new string[] { ex.Message }), "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void rbtnSave_Click(object sender, EventArgs e) { //this.axFramerControl.Dispose(); //this.axFramerControl.Close(); //模版名称为空则提示 if (string.IsNullOrEmpty(rtxtTem_name.Text)) { MessageBox.Show(PromptMessageXmlHelper.Instance.GetPromptMessage("customtemplatename", EnumPromptMessage.warning), "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //模版上传辅助类 TemFileUploadHelper temFileUploadHelper = new TemFileUploadHelper(); //新建报表 if (custom_tem_id != 0 && id == 0) { if (dtTemRowDate.Rows.Count > 0) { string file = temFileUploadHelper.GetTemFilePath(@"Template\", dtTemRowDate.Rows[0]["guidname"].ToString()); //检测是否存在目录,不存在则先创建 if (!Directory.Exists(temFileUploadHelper.GetTemFilePath(@"Report\"))) { Directory.CreateDirectory(temFileUploadHelper.GetTemFilePath(@"Report\")); } string newGuid = Guid.NewGuid().ToString(); string reportFile = temFileUploadHelper.GetTemFilePath(@"Report\") + newGuid + Path.GetExtension(file); //生成一个临时的文件 string tem_fileName = dtTemRowDate.Rows[0]["guidname"].ToString().Replace(Path.GetExtension(file), ""); string tem_file = temFileUploadHelper.GetTemFilePath(@"Template\", dtTemRowDate.Rows[0]["guidname"].ToString()).Replace(tem_fileName, tem_fileName + "_tem"); this.axFramerControl.Save(); this.axFramerControl.Save(tem_file, true, "", ""); this.axFramerControl.Close(); //把数据存放到临时文件 File.Copy(file, reportFile); FileStream fileStream = File.Open(reportFile, FileMode.Open); temFileUploadHelper.UploadTemFile(@"Report\", newGuid + Path.GetExtension(file), fileStream); fileStream.Dispose(); fileStream.Close(); SortedList addlist = new SortedList(); SortedList addlist01 = new SortedList(); addlist.Add(1, custom_tem_id); addlist.Add(2, rtxtTem_name.Text); addlist.Add(3, newGuid + Path.GetExtension(file)); addlist.Add(4, DateTime.Now); addlist01.Add(1, addlist); string ss = reCnasRemotCall.RemotInterface.CheckUPData(1, "HCS-custom-template-report-add001", addlist01, null); int addDataService = reCnasRemotCall.RemotInterface.UPData(1, "HCS-custom-template-report-add001", addlist01, null); if (addDataService > -1) { MessageBox.Show(PromptMessageXmlHelper.Instance.GetPromptMessage("succeed", EnumPromptMessage.warning), "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); HCSRM_custom_template_report01.DataBindReport(); } } } //修改报表 if (custom_tem_id == 0 && id != 0) { string file = temFileUploadHelper.GetTemFilePath(@"Report\", dtRowDate.Rows[0]["file_name"].ToString()); //获取打开文档的句柄(文件类型) //Microsoft.Office.Interop.Excel.Workbook workbook = (Microsoft.Office.Interop.Excel.Workbook)this.axFramerControl.ActiveDocument; //workbook.Saved = true; //workbook.Save(); //Microsoft.Office.Interop.Word.Words words = (Microsoft.Office.Interop.Word.Words)this.axFramerControl.ActiveDocument; string tem_fileName = dtRowDate.Rows[0]["file_name"].ToString().Replace(Path.GetExtension(file), ""); string tem_file = temFileUploadHelper.GetTemFilePath(@"Report\", dtRowDate.Rows[0]["file_name"].ToString()).Replace(tem_fileName, tem_fileName + "_tem"); this.axFramerControl.Save(); this.axFramerControl.Save(tem_file, true, "", ""); this.axFramerControl.Close(); //return; //如果是修改,但是未返回数据,则直接关闭窗体 if (dtRowDate.Rows.Count <= 0) { this.Close(); } SortedList uplist = new SortedList(); SortedList uplist01 = new SortedList(); uplist.Add(1, rtxtTem_name.Text); uplist.Add(2, id); uplist01.Add(1, uplist); //string ss = reCnasRemotCall.RemotInterface.CheckUPData(1, "HCS-custom-template-report-up001", uplist01, null); int UpDataService = reCnasRemotCall.RemotInterface.UPData(1, "HCS-custom-template-report-up001", uplist01, null); //先删除服务器文件 temFileUploadHelper.DeleteTemFile(@"Report\", dtRowDate.Rows[0]["file_name"].ToString()); FileStream fileStream = File.Open(file, FileMode.Open); temFileUploadHelper.UploadTemFile(@"Report\", dtRowDate.Rows[0]["file_name"].ToString(), fileStream); fileStream.Dispose(); fileStream.Close(); if (UpDataService > -1) { MessageBox.Show(PromptMessageXmlHelper.Instance.GetPromptMessage("editsucceed", EnumPromptMessage.warning), "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); HCSRM_custom_template_report01.DataBindReport(); } } }