我还在学习C#,我的SAP附加工资单程序有问题.
我有一个用户选择开始时段的表单.即"2011年1月1日"通过visual basic 2010创建的日期时间选择器(1).
我想在表单上另一个日期时间选择器(2)自动显示一年后的结束时段.在开始期间="2011年1月1日"的情况下,我希望结束期间为"2011年12月31日".
我的代码:
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
var endDate = default(DateTime);
endDate = dateTimePicker1.Value.AddDays(365);
dateTimePicker2.Value = endDate;
}
Run Code Online (Sandbox Code Playgroud)
我的2个问题.
以上并未说明闰年.我该如何解决这个问题?
使用上面的代码,当选择2011年1月1日时,结束日期显示不正确,2012年1月1日,但是当我输入2011年3月1日时,结束日期正确显示,2012年2月29日.这可能与第一个问题有关?
任何帮助赞赏.
我正在制作一个程序,该程序将允许用户单击由动态链接标签创建的公司名称。
在想知道如何做到这一点之前,我从未在C#中使用链接标签。可以为特定用户生成的业务数量各不相同,因此每个用户的链接标签的数量都不相同。
然后,我想捕获业务ID以进行Json呼叫。
我用来填充公司名称的代码
// fill in the business names as linked labels
if (GlobalClass.Businesses != null)
{
tableLayoutPanel.Controls.Clear();
foreach (var business in GlobalClass.Businesses)
{
tableLayoutPanel.Controls.Add(new LinkLabel { Text = business.businessName.ToString() });
}
}
Run Code Online (Sandbox Code Playgroud)
业务类如下所示,上面的业务中有一个列表。
public class Business
{
public string businessID { get; set; }
public string businessName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我需要做什么才能通过点击公司名称来捕获公司ID?
我已经看过在c#中使用foreach动态创建链接标签,但并没有太大帮助
我是使用C#/ .NET编程语言的新手,我创建了一个DataGridView来添加,编辑和删除记录.
我正在使用Visual Studio 2010进行编码.我已为行号放入一个未绑定的列,并使用此方法显示自动生成的行号.
private void dataGridView1_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
row.Cells["rownumber"].Value = row.Index + 1;
}
e.Row.Cells["min_bracket"].Value = 0;
e.Row.Cells["max_bracket"].Value = 0;
e.Row.Cells["tax_percent"].Value = 0;
e.Row.Cells["add_amount"].Value = 0;
}
Run Code Online (Sandbox Code Playgroud)
这在将值插入数据网格时有效,但在检索值时不会在rownumber列中显示任何数字.
如何在标题中获得自动生成的数字,而不必像插入行和检索记录时那样创建一个未绑定的列?
我有这个应用程序,我试图将列表传递给另一个类.我一直在收到错误
Cannot implicitly convert type 'System.Collections.Generic.List<eko_app.LoginForm.Business>' to 'System.Collections.Generic.List<eko_app.GlobalClass.Business>'
Run Code Online (Sandbox Code Playgroud)
该列表由Json生成.
private void Connect()
{
try
{
serverUrl = "https://eko-app.com/Users/login/username:" + usernameEntered + "/password:" + passwordEntered + ".json";
var w = new WebClient();
var jsonData = string.Empty;
// make the login api call
jsonData = w.DownloadString(serverUrl);
if (!string.IsNullOrEmpty(jsonData))
{
// deserialize the json to c# .net
var response = Newtonsoft.Json.JsonConvert.DeserializeObject<RootObject>(jsonData);
// Get the sessionId
GlobalClass.SessionId = string.Empty;
GlobalClass.SessionId = response.response.SessionId;
if (GlobalClass.SessionId != null)
{
var businesses = response.response.Businesses;
GlobalClass.Username = …Run Code Online (Sandbox Code Playgroud) 我有一个datagridview,我已经设置allow user将row属性添加到false.
我还让它只能在datagridview上进行全视图选择.
用户通过按工具条的"+"按钮将行添加到数据网格.通过将数据拖动到添加了绑定导航器工具条的表单来创建DGV.
我的问题是在我的行删除代码中,我检查
private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
{
try
{
if (dgvUsers.SelectedRows.Count > 0 && dgvUsers.Rows[0].Selected)
MessageBox.Show("You cannot remove the user admin");
else
{
if (MessageBox.Show("Are you sure you want to remove the user?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int code = 0;
UserService userService = new UserService();
if (dgvUsers.SelectedRows.Count > 0)
{
int selectedrowindex = dgvUsers.SelectedCells[0].RowIndex;
DataGridViewRow selectedRow = dgvUsers.Rows[selectedrowindex];
code = (int)(selectedRow.Cells[0].Value);
if (GlobalClass.SessionId == "admin")
{
userService.RemoveUsers(code);
}
else
MessageBox.Show("Only username 'admin' …Run Code Online (Sandbox Code Playgroud) 我已将客户端的Web应用程序复制到我的C:\inetpub\wwwroot.
我aslo运行Aspnet_regiis.exe -i来解决我之前遇到的错误
现在我有这个错误:
配置错误
描述:处理为此请求提供服务所需的配置文件时发生错误.请查看下面的具体错误详细信息并相应地修改配置文件.
分析器错误消息:在应用程序级别之外使用注册为allowDefinition ='MachineToApplication'的部分是错误的.此错误可能是由于未在IIS中将虚拟目录配置为应用程序引起的.
来源错误:
Line 31:
Line 32: <compilation debug="true" targetFramework="4.0" />
Line 33: <authentication mode="Forms">
Line 34: <forms loginUrl="~/Default.aspx" timeout="2880" />
Line 35: </authentication>
Run Code Online (Sandbox Code Playgroud)
源文件:C:\ inetpub\wwwroot\site\web.config行:33
版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.0.30319.18408
我试图运行该应用程序:http://localhost/site/Default.aspx.我该如何修复错误?
我正在学习C#并使用Visual Studio 2010来构建工资单程序.我收到错误"无法将类型'int'隐式转换为'short'".
我的代码是:
private void btn_add_Click(object sender, EventArgs e)
{
try
{
// Get service instance
var employerPeriodService = Program.Kernel.Get<IEmployerPeriodService>();
// Get new code
var newCode = employerPeriodService.GenerateSAPCode();
// Create object
var employerPeriodAdd =
new EmployerPeriod
{
Code = newCode,
Name = newCode,
U_Tax_year = int.Parse(cb_tax_year.Text),
//U_Day_hrs = cb_number_hours.Text,
//U_Week_days = cb_number_days_week.Text,
//U_Week_hrs = txt_number_hours_week.Text,
//U_Month_days = cb_number_days_month.Text,
//U_Month_hrs = txt_number_hours_month.Text,
//U_Fortnight_days = cb_number_days_fortnight.Text,
//U_Fortnight_hrs = txt_number_hours_fortnight.Text,
//U_Weeks_in_month = cb_avg_weeks_month.Text,
//U_No_of_Fortnights = cb_avg_fortnights_month.Text,
U_Starting_period = Convert.ToDateTime(dateTimePicker1.Text),
U_Ending_period = Convert.ToDateTime(dateTimePicker2.Text) …Run Code Online (Sandbox Code Playgroud) 我是Visual Basic的新手(使用visual studio 2010).我只是做一些连接到mysql数据库的测试.
我做了sql查询后,我不知道如何调用这些值.
我该怎么做,即在表格上的标签上显示价值?
码:
Imports MySql.Data.MySqlClient
Public Class Form1
Dim ServerString As String = "Server = localhost; User Id = root; database = CALIBRA"
Dim SQLConnection As MySqlConnection = New MySqlConnection
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SQLConnection.ConnectionString = ServerString
Try
If SQLConnection.State = ConnectionState.Closed Then
SQLConnection.Open()
MsgBox("Successfully connected to MySQL database.")
Else
SQLConnection.Close()
MsgBox("Connection is closed.")
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Public Sub calibra_query(ByRef …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个从Json调用中获取的客户名称列表,但是我收到一个错误:
无法隐式转换
System.Collections.Generic.List<char>为System.Collections.Generic.List<string>
我正在使用这两个类:
namespace eko_app
{
static class Customers
{
public static List<CustomerResponse> GetCustomers(string customerURL)
{
List<CustomerResponse> customers = new List<CustomerResponse>();
try
{
var w = new WebClient();
var jsonData = string.Empty;
// make the select products call
jsonData = w.DownloadString(customerURL);
if (!string.IsNullOrEmpty(jsonData))
{
// deserialize the json to c# .net
var response = Newtonsoft.Json.JsonConvert.DeserializeObject<RootObject>(jsonData);
if (response != null)
{
customers = response.response;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return customers;
}
public …Run Code Online (Sandbox Code Playgroud) 我有这个电话号码文本框,我想让用户能够根据区号输入零作为第一个数字.
例如0720-123-456

在我的程序中,当我单击"保存"时,零被省略并保存为

在我的MySQL数据库中有一个INT字段.我已经验证了文本框按键事件只允许数字.
如何让用户能够保存从零开始的数字?