KellyReport_D/JQSalesSummaryPanel.cs

90 lines
3.0 KiB
C#

using KellyReport_D.Properties;
using KellyReport_D.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Office.Interop.Excel;
using System.Windows.Forms;
namespace KellyReport_D
{
public partial class JQSalesSummaryPanel : UserControl
{
public JQSalesSummaryPanel()
{
InitializeComponent();
}
override
protected void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.step1Lab.Text = Resources.Step1;
this.step1DescLab.Text = Resources.STEP1_DESC;
this.step1NoteLab.Text = Resources.STEP1_NOTE;
this.initForecastBtn.Text = Resources.INIT_FORECAST;
this.step2Lab.Text = Resources.Step2;
this.step2DescLab.Text = Resources.STEP2_DESC;
this.importSalesBtn.Text = Resources.IMPORT_SALES;
}
private void panel1_Resize(object sender, EventArgs e)
{
initForecastBtn.Left = (buttonWrapper1.ClientSize.Width - initForecastBtn.Width) / 2;
initForecastBtn.Top = (buttonWrapper1.ClientSize.Height - initForecastBtn.Height) / 2; // 可选:垂直居中
}
private void JQSalesSummaryPanel_Resize(object sender, EventArgs e)
{
//this.step2DescLab.Size = new Size(this.Width, 65);
int width = this.Width;
// 预留内边距
int padding = this.step2DescLab.Padding.Vertical + 4;
// 计算文本所需高度
Size textSize = TextRenderer.MeasureText(
this.step2DescLab.Text,
this.step2DescLab.Font,
new Size(width, int.MaxValue),
TextFormatFlags.WordBreak
);
step2DescLab.Size = new Size(width, textSize.Height + padding);
}
private void initForecastBtn_Click(object sender, EventArgs e)
{
WorkBookUtils.GenForecast(this.initForecastBtn);
MessageBox.Show("生成年度预估表完成", "完成", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void importSalesBtn_Click(object sender, EventArgs e)
{
var workBook = WorkBookUtils.SelectAndOpenExcelFile();
if (workBook == null)
{
MessageBox.Show("未选择文件或文件打开失败,请重试。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
WorkBookUtils.importSalesDetailFromWorkBook(workBook);
}
catch (Exception ex)
{
MessageBox.Show($"导入过程中发生错误:{ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
workBook.Close(false); // 关闭工作簿
}
}
}
}