|
@@ -21,6 +21,11 @@ using System.IO;
|
|
|
using System.Threading;
|
|
|
using static System.Net.Mime.MediaTypeNames;
|
|
|
using System.Drawing.Drawing2D;
|
|
|
+using travelExport.utility;
|
|
|
+using Aspose.Words.Tables;
|
|
|
+using System.Data.Entity.Migrations.Builders;
|
|
|
+using System.IO.Ports;
|
|
|
+using System.Reflection;
|
|
|
|
|
|
namespace travelExport
|
|
|
{
|
|
@@ -31,10 +36,70 @@ namespace travelExport
|
|
|
readonly static string[] weekdays = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
|
|
|
const decimal conversion = 1.61M;
|
|
|
readonly static string[] excludeArr = new string[] { "[中转]", "[转机]" };
|
|
|
+ public List<TripItem> dropDownItem = new List<TripItem>
|
|
|
+ {
|
|
|
+ new TripItem
|
|
|
+ {
|
|
|
+ Id = 1,
|
|
|
+ Name = "默认行程模板",
|
|
|
+ Path = "C:\\日行程3.docx#D:\\日行程3.docx"
|
|
|
+ },
|
|
|
|
|
|
- public Home()
|
|
|
+ new TripItem
|
|
|
+ {
|
|
|
+ Id = 2,
|
|
|
+ Name = "贵州行程模板",
|
|
|
+ Path = "C:\\贵州行程模板.docx#D:\\贵州行程模板1.docx"
|
|
|
+ },
|
|
|
+ };
|
|
|
+
|
|
|
+ public class TripItem
|
|
|
+ {
|
|
|
+ public int Id { get; set; }
|
|
|
+ public string Name { get; set; }
|
|
|
+ public string Path { get; set; }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public enum textTypeEnum
|
|
|
+ {
|
|
|
+ 标题 = 0 , 内容 = 1
|
|
|
+ };
|
|
|
+
|
|
|
+ public class textType
|
|
|
{
|
|
|
+ public textTypeEnum Type { get; set; }
|
|
|
+ public string Value { get; set; }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Home()
|
|
|
+ {
|
|
|
InitializeComponent();
|
|
|
+
|
|
|
+ Task.Run(() => {
|
|
|
+ if (versions.checkVersions())
|
|
|
+ {
|
|
|
+ // 在主线程中显示消息框
|
|
|
+ this.Invoke((MethodInvoker) delegate {
|
|
|
+ var result = MessageBoxEx.Show(this, "有新版本可用,是否更新!", "更新提示!", MessageBoxButtons.YesNo);
|
|
|
+ // 这里可以处理用户点击按钮后的逻辑
|
|
|
+ HandleUpdateResponse(result);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void HandleUpdateResponse(DialogResult result)
|
|
|
+ {
|
|
|
+ // 处理用户的选择
|
|
|
+ if (result == DialogResult.Yes)
|
|
|
+ {
|
|
|
+ // 用户选择“是”,进行更新
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // 用户选择“否”,不进行更新
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
@@ -49,6 +114,12 @@ namespace travelExport
|
|
|
FormBorderStyle = FormBorderStyle.FixedSingle;
|
|
|
MinimizeBox = false;
|
|
|
MaximizeBox = false;
|
|
|
+
|
|
|
+ tripItemSelect.DataSource = dropDownItem;
|
|
|
+ tripItemSelect.ValueMember = "Id";
|
|
|
+ tripItemSelect.DisplayMember = "Name";
|
|
|
+ tripItemSelect.DropDownStyle = ComboBoxStyle.DropDownList;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private void comb_Delegation_MouseClick(object sender, MouseEventArgs e)
|
|
@@ -82,6 +153,13 @@ namespace travelExport
|
|
|
|
|
|
private async void btnImport_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
+ var tripTempValue = tripItemSelect.SelectedValue;
|
|
|
+ if (!int.TryParse(tripTempValue.ToString() , out int tempValue))
|
|
|
+ {
|
|
|
+ MessageBoxEx.Show("请选择模板类型!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
var diid = -1;
|
|
|
try
|
|
|
{
|
|
@@ -105,19 +183,23 @@ namespace travelExport
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
- MessageBoxEx.Show(this, "黑屏代码有误!", "提示");
|
|
|
+ MessageBoxEx.Show(this, "黑屏代码有误!" + ex.Message, "提示");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (resultTable.Rows.Count == 0 || string.IsNullOrWhiteSpace(resultTable.Rows[0][1].ToString()))
|
|
|
{
|
|
|
- string msg = string.Empty;
|
|
|
- if (resultTable.Rows.Count > 0)
|
|
|
+ MessageBoxEx.Show(this, "黑屏代码有误! " , "提示");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach (DataRow row in resultTable.Rows)
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrWhiteSpace(row["Error"].ToString()))
|
|
|
{
|
|
|
- msg = resultTable.Rows[0]["Error"].ToString();
|
|
|
+ MessageBoxEx.Show(this, "黑屏代码有误! " + row["Error"].ToString(), "提示");
|
|
|
+ return;
|
|
|
}
|
|
|
- MessageBoxEx.Show(this, "黑屏代码有误! " + msg , "提示");
|
|
|
- return;
|
|
|
}
|
|
|
|
|
|
var isVPN = await Task.Run(() =>
|
|
@@ -134,8 +216,6 @@ namespace travelExport
|
|
|
|
|
|
var timeArr = GetTimeListByDataTable(resultTable);
|
|
|
|
|
|
- //本团行程单数据
|
|
|
- List<Grp_TravelList> listTravel = db.Grp_TravelList.Where(x => x.Diid == diid && x.IsDel == 0).ToList();
|
|
|
|
|
|
ChildThreadExceptionHandler wt = new
|
|
|
ChildThreadExceptionHandler((msg) =>
|
|
@@ -153,6 +233,9 @@ namespace travelExport
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+ //本团行程单数据
|
|
|
+ List<Grp_TravelList> listTravel = db.Grp_TravelList.Where(x => x.Diid == diid && x.IsDel == 0).ToList();
|
|
|
+
|
|
|
Thread threadExec = new Thread(() =>
|
|
|
{
|
|
|
try
|
|
@@ -168,6 +251,7 @@ namespace travelExport
|
|
|
|
|
|
foreach (var item in timeArr)
|
|
|
{
|
|
|
+ string tripGuiZhou = string.Empty;
|
|
|
string trip = string.Empty;
|
|
|
string weekDay = string.Empty;
|
|
|
DateTime time = DateTime.Now;
|
|
@@ -290,8 +374,12 @@ namespace travelExport
|
|
|
|
|
|
trip += $"{takeOffTime.ToString("HH:mm")} 搭乘{aircompany.CnName}{tabRow[0].ToString().Trim()}航班,由{start_Object.City}飞往{end_Object.City};\r\n ({start_Object.AirPort}/{end_Object.AirPort} 机型:{airModel} 飞行时间{flightTime});\r\n";
|
|
|
|
|
|
+ tripGuiZhou += $"{takeOffTime.ToString("HH:mm")} 乘坐{aircompany.CnName}从{start_Object.City}{start_Object.AirPort}飞往{end_Object.City}{end_Object.AirPort};\r\n";
|
|
|
+
|
|
|
isTrade = Convert.ToBoolean(tabRow["isTransitShipment"]);
|
|
|
|
|
|
+ tripGuiZhou += $"{fallToTime.ToString("HH:mm")} 到达{end_Object.AirPort}\r\n";
|
|
|
+
|
|
|
if (isTrade)
|
|
|
{
|
|
|
trip += $"{fallToTime.ToString("HH:mm")} 抵达{end_Object.AirPort}{tabRow["EndBuilding"].ToString().Trim()}航站楼(中转时间:行李直达)";
|
|
@@ -409,7 +497,13 @@ namespace travelExport
|
|
|
|
|
|
time = time.AddMinutes(GetGoogleResult); //到达市区时间
|
|
|
|
|
|
- if (index == timeArr.Count - 1)
|
|
|
+ if (index != timeArr.Count)
|
|
|
+ {
|
|
|
+ tripGuiZhou += $"{fallToTime.AddMinutes(10).ToString("HH:mm")} ";
|
|
|
+ tripGuiZhou += "从机场赴入住酒店";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (index == timeArr.Count)
|
|
|
{
|
|
|
trip += "圆满结束此次访问之行!";
|
|
|
NewListTravel.Add(new Grp_TravelList
|
|
@@ -418,7 +512,7 @@ namespace travelExport
|
|
|
CreateUserId = 0,
|
|
|
Diid = diid,
|
|
|
Date = Convert.ToDateTime(item).ToString("M月d日"),
|
|
|
- Trip = trip,
|
|
|
+ Trip = tempValue == 1 ? trip : tempValue == 2 ? tripGuiZhou : "",
|
|
|
WeekDay = weekDay,
|
|
|
Days = index,
|
|
|
Traffic_First = "飞机",
|
|
@@ -438,7 +532,7 @@ namespace travelExport
|
|
|
CreateUserId = 0,
|
|
|
Diid = diid,
|
|
|
Date = Convert.ToDateTime(item).ToString("M月d日"),
|
|
|
- Trip = trip,
|
|
|
+ Trip = tempValue == 1 ? trip : tempValue == 2 ? tripGuiZhou : "",
|
|
|
WeekDay = weekDay,
|
|
|
Days = index,
|
|
|
Traffic_First = "飞机",
|
|
@@ -511,6 +605,9 @@ namespace travelExport
|
|
|
16:00 公务活动;
|
|
|
18:00 晚餐于当地餐厅;
|
|
|
19:00 入住酒店休息;";
|
|
|
+
|
|
|
+
|
|
|
+ tripGuiZhou += $"上午\r\n08:30 从酒店出发\r\n09:00 公务活动\r\n12:00 返回酒店\r\n\r\n下午\r\n14:00 公务活动\r\n18:00 返回酒店";
|
|
|
}
|
|
|
|
|
|
string[] traffic = new string[] { "汽车", "飞机" };
|
|
@@ -525,7 +622,7 @@ namespace travelExport
|
|
|
CreateUserId = 0,
|
|
|
Diid = diid,
|
|
|
Date = Convert.ToDateTime(item).ToString("M月d日"),
|
|
|
- Trip = trip,
|
|
|
+ Trip = tempValue == 1 ? trip : tempValue == 2 ? tripGuiZhou : "",
|
|
|
WeekDay = weekDay,
|
|
|
Days = index,
|
|
|
Traffic_First = traffic[0],
|
|
@@ -541,9 +638,9 @@ namespace travelExport
|
|
|
db.Grp_TravelList.AddRange(NewListTravel);
|
|
|
db.SaveChanges();
|
|
|
|
|
|
- sw.Commit();
|
|
|
- wt.Invoke("数据导入完成!");
|
|
|
- }
|
|
|
+ sw.Commit();
|
|
|
+ wt.Invoke("数据导入完成!");
|
|
|
+ }
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
@@ -553,6 +650,186 @@ namespace travelExport
|
|
|
threadExec.Start();
|
|
|
}
|
|
|
|
|
|
+ private void execTemp(int tempValue, int diid, Grp_DelegationInfo di)
|
|
|
+ {
|
|
|
+ var dropItem = dropDownItem.FirstOrDefault(x => x.Id == tempValue);
|
|
|
+ var pathArr = Regex.Split(dropItem.Path, "#").ToList();
|
|
|
+ var UsePath = string.Empty;
|
|
|
+ foreach (var itemF in pathArr)
|
|
|
+ {
|
|
|
+ if (File.Exists(itemF))
|
|
|
+ {
|
|
|
+ UsePath = itemF;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (string.IsNullOrWhiteSpace(UsePath))
|
|
|
+ {
|
|
|
+ var txtPath = GetApplicationPath() + "\\path.txt";
|
|
|
+ if (File.Exists(txtPath))
|
|
|
+ {
|
|
|
+ //建立文件读取流对象
|
|
|
+ StreamReader str = new StreamReader(txtPath);
|
|
|
+ List<string> list = new List<string>();
|
|
|
+ //获取每行字符
|
|
|
+ string line;
|
|
|
+ while ((line = str.ReadLine()) != null)
|
|
|
+ {
|
|
|
+ list.Add(line);
|
|
|
+ }
|
|
|
+ str.Close();
|
|
|
+
|
|
|
+ foreach (var item in list)
|
|
|
+ {
|
|
|
+ if (File.Exists(item))
|
|
|
+ {
|
|
|
+ UsePath = item;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ using (var sw = File.CreateText(txtPath))
|
|
|
+ {
|
|
|
+ sw.WriteLine("path"); // 写入字符串
|
|
|
+ }
|
|
|
+ MessageBoxEx.Show(this, "创建成功!", "请配置文件路径!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var _travelList = db.Grp_TravelList.Where(x => x.IsDel == 0 && x.Diid == diid).ToList();
|
|
|
+
|
|
|
+ //设置源文件
|
|
|
+ Document doc = new Document(UsePath);
|
|
|
+
|
|
|
+ // 创建 DocumentBuilder 对象
|
|
|
+ DocumentBuilder builder = new DocumentBuilder(doc);
|
|
|
+
|
|
|
+ var titleCount = 1;
|
|
|
+ var conterCount = 1;
|
|
|
+ var index = 1;
|
|
|
+
|
|
|
+ foreach (var item in _travelList)
|
|
|
+ {
|
|
|
+ //移动到文档的最后一个段落之后
|
|
|
+ builder.MoveToDocumentEnd();
|
|
|
+
|
|
|
+ builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
|
|
|
+
|
|
|
+ // 开始书签
|
|
|
+ builder.StartBookmark("title" + titleCount);
|
|
|
+
|
|
|
+ // 设置文本格式为加粗
|
|
|
+ builder.Font.Bold = true;
|
|
|
+ builder.Font.Name = "KaiTi";
|
|
|
+ builder.Font.Size = 18;
|
|
|
+
|
|
|
+ // 插入加粗的文本
|
|
|
+ builder.Writeln($"{item.Date}({item.WeekDay},第{index}天)");
|
|
|
+ // 结束书签
|
|
|
+ builder.EndBookmark("title" + titleCount);
|
|
|
+ titleCount++;
|
|
|
+
|
|
|
+ // 在文档末尾插入一个空段落
|
|
|
+ builder.Writeln();
|
|
|
+
|
|
|
+ builder.MoveToDocumentEnd();
|
|
|
+
|
|
|
+ builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
|
|
|
+
|
|
|
+ // 取消文本格加粗
|
|
|
+ builder.Font.Bold = false;
|
|
|
+ builder.Font.Name = "仿宋";
|
|
|
+
|
|
|
+ // 开始书签
|
|
|
+ builder.StartBookmark("conter"+ conterCount);
|
|
|
+
|
|
|
+ // 插入文本
|
|
|
+ //builder.Writeln(item.Trip);
|
|
|
+
|
|
|
+
|
|
|
+ // 解析字符串中的时间和内容部分
|
|
|
+ string[] lines = item.Trip.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
+
|
|
|
+ // 使用正则表达式匹配时间格式
|
|
|
+ Regex timeRegex = new Regex(@"^\d{2}:\d{2}");
|
|
|
+
|
|
|
+ // 遍历每一行并格式化
|
|
|
+ foreach (string line in lines)
|
|
|
+ {
|
|
|
+ // 使用正则表达式提取时间
|
|
|
+ Match match = timeRegex.Match(line.Trim());
|
|
|
+ if (match.Success)
|
|
|
+ {
|
|
|
+ string timePart = match.Value; // 时间部分
|
|
|
+ string descriptionPart = line.Substring(match.Length).Trim(); // 描述部分
|
|
|
+
|
|
|
+ // 设置段落格式(制表符分隔时间和描述)
|
|
|
+ builder.ParagraphFormat.TabStops.Clear();
|
|
|
+ builder.ParagraphFormat.TabStops.Add(new TabStop(50)); // 设置制表符位置为50
|
|
|
+
|
|
|
+ // 插入时间
|
|
|
+ builder.Write(timePart + "\t");
|
|
|
+
|
|
|
+ if (descriptionPart.Length > 19)
|
|
|
+ {
|
|
|
+ builder.Writeln(descriptionPart.Substring(0,19));
|
|
|
+ builder.Writeln(" " + descriptionPart.Substring(19));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // 插入描述并换行
|
|
|
+ builder.Writeln(descriptionPart);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // 如果没有时间,直接插入整段文字
|
|
|
+ builder.Writeln(line);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 结束书签
|
|
|
+ builder.EndBookmark("conter" + conterCount);
|
|
|
+ conterCount++;
|
|
|
+
|
|
|
+ builder.Writeln();
|
|
|
+
|
|
|
+ index++;
|
|
|
+ }
|
|
|
+
|
|
|
+ CheckAndCenterParagraphs(doc);
|
|
|
+
|
|
|
+ string strFileName = "C:\\OP行程单\\" + di.TeamName + "贵州行程.docx";
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ doc.Save(strFileName, Aspose.Words.SaveFormat.Docx);
|
|
|
+ MessageBoxEx.Show(this, "文件导出完成!");
|
|
|
+ System.Diagnostics.Process.Start("Explorer.exe", "/select," + strFileName);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ MessageBoxEx.Show(this, "请关闭打开的文件后重试!");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private static string GetApplicationPath()
|
|
|
+ {
|
|
|
+ string path = System.Windows.Forms.Application.StartupPath;
|
|
|
+ string folderName = String.Empty;
|
|
|
+ while (folderName.ToLower() != "bin")
|
|
|
+ {
|
|
|
+ path = path.Substring(0, path.LastIndexOf("\\"));
|
|
|
+ folderName = path.Substring(path.LastIndexOf("\\") + 1);
|
|
|
+ }
|
|
|
+ return path.Substring(0, path.LastIndexOf("\\") + 1);
|
|
|
+ }
|
|
|
+
|
|
|
public async void btnImportInfo()
|
|
|
{
|
|
|
var diid = -1;
|
|
@@ -582,13 +859,17 @@ namespace travelExport
|
|
|
|
|
|
if (resultTable.Rows.Count == 0 || string.IsNullOrWhiteSpace(resultTable.Rows[0][1].ToString()))
|
|
|
{
|
|
|
- string msg = string.Empty;
|
|
|
- if (resultTable.Rows.Count > 0)
|
|
|
+ MessageBoxEx.Show(this, "黑屏代码有误! ", "提示");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach (DataRow row in resultTable.Rows)
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrWhiteSpace(row["Error"].ToString()))
|
|
|
{
|
|
|
- msg = resultTable.Rows[0]["Error"].ToString();
|
|
|
+ MessageBoxEx.Show(this, "黑屏代码有误! " + row["Error"].ToString(), "提示");
|
|
|
+ return;
|
|
|
}
|
|
|
- MessageBoxEx.Show(this, "黑屏代码有误! " + msg, "提示");
|
|
|
- return;
|
|
|
}
|
|
|
|
|
|
var isVPN = await Task.Run(() =>
|
|
@@ -1149,8 +1430,20 @@ namespace travelExport
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- var _travelList = db.Grp_TravelList.Where(x=>x.IsDel == 0 && x.Diid == diid).ToList();
|
|
|
+ var tripTempValue = tripItemSelect.SelectedValue;
|
|
|
+ if (!int.TryParse(tripTempValue.ToString(), out int tempValue))
|
|
|
+ {
|
|
|
+ MessageBoxEx.Show("请选择模板类型!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (tempValue != 1)
|
|
|
+ {
|
|
|
+ execTemp(tempValue,diid, di);
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
+ var _travelList = db.Grp_TravelList.Where(x=>x.IsDel == 0 && x.Diid == diid).ToList();
|
|
|
var city = GetAllCity(diid);
|
|
|
|
|
|
//创建数据源Table
|
|
@@ -1394,7 +1687,7 @@ namespace travelExport
|
|
|
dt.Columns.Add("Error", typeof(string));//整理的到达日期
|
|
|
dt.Columns.Add("Sign", typeof(string));//标识:0表示为原生黑屏代码、1表示“+1”新增的黑屏代码
|
|
|
|
|
|
- //添加转机标识
|
|
|
+ //添加转机标识 (中转写在第一趟航班)
|
|
|
dt.Columns.Add("isTransitShipment", typeof(bool));
|
|
|
|
|
|
//判断是否录入黑屏代码
|
|
@@ -2044,6 +2337,23 @@ namespace travelExport
|
|
|
|
|
|
return info;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ void CheckAndCenterParagraphs(Document doc)
|
|
|
+ {
|
|
|
+ // 遍历文档中的所有段落
|
|
|
+ foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
|
|
|
+ {
|
|
|
+ // 获取段落的文本
|
|
|
+ string paragraphText = para.GetText();
|
|
|
+ // 检查段落的文本是否为“下午”或“上午”
|
|
|
+ if (paragraphText.Trim().Equals("下午") || paragraphText.Trim().Equals("上午"))
|
|
|
+ {
|
|
|
+ // 设置段落格式为居中对齐
|
|
|
+ para.ParagraphFormat.Alignment = ParagraphAlignment.Center;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public class GoogleApiFormat
|