using System; using System.Data; using System.Windows.Forms; namespace 成套报价软件 { /// /// MainForm 状态栏:分区显示 当前项目/定位/数据统计/保存状态/重算时间/时钟 + 操作提示区。 /// 全部更新走这里,避免各模块直接操作状态栏控件。 /// public partial class MainForm { private System.Windows.Forms.Timer _状态栏时钟; private bool _hasUnsavedChanges = false; /// 更新左侧操作提示区(关键操作的结果/进度消息)。 private void SetStatus(string msg) { if (lbl提示 != null) lbl提示.Text = msg; try { Log("[状态] " + msg); } catch { } } /// 刷新 定位/数据统计/重算时间 各区(随选择和数据变化调用)。 private void 刷新状态栏() { try { // 当前项目名称(从项目表内存数据按编号查) string 项目名 = _currentProjectId; try { var dt = this.advancedDataGridView6.DataSource as DataTable; if (dt != null && dt.Columns.Contains("项目编号") && dt.Columns.Contains("项目名称")) { foreach (DataRow r in dt.Rows) { if (string.Equals(Convert.ToString(r["项目编号"]), _currentProjectId, StringComparison.OrdinalIgnoreCase)) { var n = Convert.ToString(r["项目名称"]); if (!string.IsNullOrWhiteSpace(n)) 项目名 = n; break; } } } } catch { } // ★ 修复(2026-09-30):未进项目时按项目页当前选中行显示项目名(否则"项目:"一直空白) if (string.IsNullOrWhiteSpace(项目名)) { try { var r6 = this.advancedDataGridView6 != null ? this.advancedDataGridView6.CurrentRow : null; if (r6 != null && !r6.IsNewRow) { string pn = GetBoundValueAsString(r6, "项目名称"); if (string.IsNullOrWhiteSpace(pn)) pn = GetBoundValueAsString(r6, "项目编号"); if (!string.IsNullOrWhiteSpace(pn)) 项目名 = pn; } } catch { } } if (lbl项目 != null) lbl项目.Text = string.IsNullOrWhiteSpace(项目名) ? "项目: -" : "项目: " + 项目名; // 当前定位 if (lbl定位 != null) { string 图号 = string.IsNullOrWhiteSpace(_currentTuhao) ? "-" : _currentTuhao; // ★ 真隔离(2026-09-30):_currentXianghao 现在存内部ID GUID(不再等于显示名), // 显示名从箱号表当前选中行的"箱号"列读 lbl定位.Text = "图号: " + 图号 + " › 箱号: " + 取当前箱号显示名(); } // 保存状态 更新保存状态(); // (重算时间标签已被用户删除,不再刷新) } catch { } } /// 保存状态红绿切换(编辑后红"未保存",保存后绿"已保存")。 private void 更新保存状态() { if (lbl保存 == null) return; if (_hasUnsavedChanges) { lbl保存.Text = "● 未保存"; lbl保存.ForeColor = System.Drawing.Color.OrangeRed; } else { lbl保存.Text = "已保存 " + DateTime.Now.ToString("HH:mm"); lbl保存.ForeColor = System.Drawing.Color.FromArgb(60, 140, 60); } } /// 标记有未保存修改(编辑提交时调用)。 private void 标记未保存() { if (!_hasUnsavedChanges) { _hasUnsavedChanges = true; 更新保存状态(); } } /// 标记已保存(保存完成后调用)。 private void 标记已保存() { if (_hasUnsavedChanges) { _hasUnsavedChanges = false; 更新保存状态(); } } /// /// ★ 选区求和:统计选中单元格里的数值之和(Excel 风格)。 /// 非数值/空单元格跳过;选中量过大时只显示选中数(防卡)。 /// private void 更新选区求和(DataGridView dgv) { if (lbl求和 == null) return; try { if (dgv == null || dgv.SelectedCells == null || dgv.SelectedCells.Count == 0) { lbl求和.Text = "求和: -"; return; } int 选中数 = dgv.SelectedCells.Count; if (选中数 > 50000) { lbl求和.Text = "选区过大(" + 选中数 + ")"; return; } double sum = 0; int 数值个数 = 0; foreach (DataGridViewCell c in dgv.SelectedCells) { if (c == null || c.Value == null) continue; double d; var s = System.Convert.ToString(c.Value); if (string.IsNullOrWhiteSpace(s)) continue; if (double.TryParse(s.Trim().Replace(",", ""), System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out d)) { sum += d; 数值个数++; } } if (数值个数 == 0) { lbl求和.Text = "求和: -"; return; } string sumText = Math.Abs(sum) >= 1000000000 ? (sum / 1000000000d).ToString("0.##") + " 亿" : sum.ToString("N2"); lbl求和.Text = "求和: " + sumText + " (" + 数值个数 + "个数值)"; } catch { lbl求和.Text = "求和: -"; } } /// 三个报价表的选区/数值变化 → 刷新求和 + 定位。 private void 选区求和_Refresh(object sender, EventArgs e) { var dgv = sender as DataGridView; 更新选区求和(dgv); 更新选区定位(dgv); } /// 按选中单元格所在表更新 定位区(图号/箱号)。 private void 更新选区定位(DataGridView dgv) { if (lbl定位 == null) return; string 图号 = string.IsNullOrWhiteSpace(_currentTuhao) ? "-" : _currentTuhao; // ★ 真隔离(2026-09-30):_currentXianghao 是内部ID GUID,定位区显示名从表格当前行读 string 箱号 = 取当前箱号显示名(); try { if (dgv == this.advancedDataGridView9 && dgv.CurrentRow != null && !dgv.CurrentRow.IsNewRow) { // 图号表:读"图号"显示名列(不读"内部ID",那是 GUID) string dn = GetBoundValueAsString(dgv.CurrentRow, "图号"); if (!string.IsNullOrWhiteSpace(dn)) 图号 = dn; 箱号 = "-"; } else if (dgv == this.advancedDataGridView4 && dgv.CurrentRow != null && !dgv.CurrentRow.IsNewRow) { // 箱号表:读"箱号"显示名列 string dn = GetBoundValueAsString(dgv.CurrentRow, "箱号"); if (!string.IsNullOrWhiteSpace(dn)) 箱号 = dn; } } catch { } lbl定位.Text = "图号: " + 图号 + " › 箱号: " + 箱号; } /// ★ 真隔离(2026-09-30):箱号显示名(从箱号表当前选中行"箱号"列读)。 /// _currentXianghao 已改为内部ID GUID,不能直接当显示名用;读不到返回 "-"。 private string 取当前箱号显示名() { try { var r = this.advancedDataGridView4 != null ? this.advancedDataGridView4.CurrentRow : null; if (r != null && !r.IsNewRow) { string dn = GetBoundValueAsString(r, "箱号"); if (!string.IsNullOrWhiteSpace(dn)) return dn; } } catch { } return "-"; } /// 三个报价表的选区/数值变化 → 刷新求和。 private void 启动状态栏时钟() { if (_状态栏时钟 != null) return; _状态栏时钟 = new System.Windows.Forms.Timer(); _状态栏时钟.Interval = 1000; _状态栏时钟.Tick += (s, e) => { if (lbl时间 != null) lbl时间.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm"); }; _状态栏时钟.Start(); } } }