我在我們的資料庫中創建了下面的表,并使用 C# 和 Binding Source 連接到我的資料庫中。我有一些日期時間欄位,我需要對這些欄位執行一些加法和減法運算。我將 C# 表單中的日期時間文本欄位系結到兩個文本框,并為它們添加了兩個 Leave 和 textchange 事件處理程式,然后我得到了日期并進行了計算操作。現在我的問題是有什么方法可以在沒有其他物件的情況下直接從 Binding 源獲取日期時間值(例如不使用文本框文本值)。
USE [TradeSaleMainDB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DepoCosts](
[TrDepoCostsID] [bigint] NOT NULL,
[TrDepoFiscYear] [smallint] NOT NULL,
[TrDepoSaleCustomerCode] [int] NOT NULL,
[TrDepoSaleTreatyCode] [int] NOT NULL,
[TrDepoRegisterDate] [datetime] NOT NULL,
[TrDepoDateFrom] [datetime] NOT NULL,
[TrDepoDateTo] [datetime] NOT NULL,
[TrDepoCostPersentage] [decimal](18, 2) NOT NULL,
[TrDepoRemainQ] [decimal](18, 2) NOT NULL,
[TrDepoRegisteredBy] [smallint] NOT NULL,
[TrDepoDepoCostQ] [decimal](18, 2) NOT NULL,
[TrDepoDepoCostR] [decimal](18, 2) NOT NULL,
[TrDepoTotalOrder] [decimal](18, 2) NOT NULL,
[TrDepoRemainOrder] [decimal](18, 2) NOT NULL,
[TrDepoIsCancel] [bit] NOT NULL,
[TrDepoCanceledBy] [smallint] NULL,
[TrDepoCancelDate] [datetime] NULL,
CONSTRAINT [PK_DepoCosts] PRIMARY KEY CLUSTERED
(
[TrDepoCostsID] ASC,
[TrDepoFiscYear] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[DepoCosts] ADD CONSTRAINT [DF_DepoCosts_DpIsCancel] DEFAULT ((0)) FOR [DpIsCancel]
GO
我的 C# 代碼如下:
private void TxtDateFrom_Leave(object sender, EventArgs e)
{
TxtDateTo.Text = ConvertToCustomerOmitDate(DateTime.Parse(T2.Text));
}
uj5u.com熱心網友回復:
嘗試如下:
private void YourBindingSourceName_PositionChanged(object sender, EventArgs e)
{
TxtDateTo.Text = ConvertToCustomerOmitDate(DateTime.Parse(T2.Text));
}
并且您應該將該事件系結到您的系結源。

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/388630.html
標籤:C#
上一篇:拆分字串如何不包含第一個字符?
