报修接口,打卡功能

master
zhaojian 2 years ago
parent 5d84acc2a8
commit b996f8388a

@ -116,12 +116,12 @@ namespace CommonFunc.Tools
if (result.code == 200) if (result.code == 200)
{ {
LogHelper.instance.log.Info($"报修成功>>" + result.msg); LogHelper.instance.log.Info($"报修成功>>" + result.msg);
CustomMessageBox.Show($"调用报修接口成功", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); CustomMessageBox.Show($"报修成功", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning);
} }
else else
{ {
LogHelper.instance.log.Error($"报修失败>>" + result.msg); LogHelper.instance.log.Error($"报修失败>>" + result.msg);
CustomMessageBox.Show($"调用报修接口失败:" + result.msg, CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); CustomMessageBox.Show($"报修失败:" + result.msg, CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning);
} }
} }
catch (Exception ex) catch (Exception ex)

@ -119,8 +119,20 @@ namespace XGL.Dats.DBServiceFinishProd
public bool UpdateAttendanceRecord(string userID, string deviceCode) public bool UpdateAttendanceRecord(string userID, string deviceCode)
{ {
string sql = $@" UPDATE mes_attendance_records set end_time = GETDATE(),end_addr = '{deviceCode}',work_hours = Convert(DECIMAL(12,2),DATEDIFF((MINUTE), start_time, GetDate()) / 60.00) string sql = $@"
where user_id = '{userID}' and start_addr = '{deviceCode}' "; UPDATE mes_attendance_records
SET end_time = GETDATE(),
end_addr = '{deviceCode}',
work_hours = CONVERT(DECIMAL(12,2), DATEDIFF(MINUTE, start_time, GETDATE()) / 60.00)
WHERE user_id = '{userID}'
AND start_addr = '{deviceCode}'
AND start_time = (
SELECT MAX(start_time)
FROM mes_attendance_records
WHERE user_id = '{userID}'
AND start_addr = '{deviceCode}'
)";
int ret = Utils.netClientDBHelper.executeUpdate(sql); int ret = Utils.netClientDBHelper.executeUpdate(sql);
return ret > 0 ? true : false; return ret > 0 ? true : false;
} }
@ -130,7 +142,7 @@ namespace XGL.Dats.DBServiceFinishProd
string sql = $@" select id, user_id, user_name, attendance_status, sex, age, string sql = $@" select id, user_id, user_name, attendance_status, sex, age,
id_number, start_time, start_addr, end_time, end_addr, attendance_time, id_number, start_time, start_addr, end_time, end_addr, attendance_time,
attendance_date, work_hours, create_time,Convert(DECIMAL(12,2),DATEDIFF((MINUTE), start_time, GetDate()) / 60.00) as diff attendance_date, work_hours, create_time,Convert(DECIMAL(12,2),DATEDIFF((MINUTE), start_time, GetDate()) / 60.00) as diff
from mes_attendance_records where start_addr = '{v}' and attendance_date = CONVERT(VARCHAR(10), GetDate() , 120)"; from mes_attendance_records where start_addr = '{v}' and attendance_date = CONVERT(VARCHAR(10), GetDate() , 120) order by create_time desc";
DataSet dtset = Utils.netClientDBHelper.getDataSet(sql); DataSet dtset = Utils.netClientDBHelper.getDataSet(sql);
if (dtset != null && dtset.Tables.Count > 0 && dtset.Tables[0].Rows.Count > 0) if (dtset != null && dtset.Tables.Count > 0 && dtset.Tables[0].Rows.Count > 0)
{ {

@ -12,7 +12,7 @@
<!--设备编码--> <!--设备编码-->
<add key="DeviceCode" value="C3" /> <add key="DeviceCode" value="C3" />
<!--上位机类型 0:工单准备1成型机\shoupei2烘房,3:人员登录--> <!--上位机类型 0:工单准备1成型机\shoupei2烘房,3:人员登录-->
<add key="ClientMode" value="1" /> <add key="ClientMode" value="2" />
<add key="SerialPort" value="COM5" /> <add key="SerialPort" value="COM5" />
<add key="DryingHouseList" value="H16,H17,H18"/> <add key="DryingHouseList" value="H16,H17,H18"/>
<!--线体编码--> <!--线体编码-->

@ -70,7 +70,7 @@
<DataGridTextColumn Width="350" Header="当前时长(小时)" Binding="{Binding diff}"/> <DataGridTextColumn Width="350" Header="当前时长(小时)" Binding="{Binding diff}"/>
<DataGridTextColumn Width="350" Header="时长(小时)" Binding="{Binding work_hours}"/> <DataGridTextColumn Width="350" Header="时长(小时)" Binding="{Binding work_hours}"/>
<DataGridTextColumn Width="*" Header="人员" Binding="{Binding user_name}"/> <DataGridTextColumn Width="*" Header="人员" Binding="{Binding user_name}"/>
<DataGridTextColumn Width="*" Header="工作区间" Binding="{Binding attendance_time}"/> <DataGridTextColumn Width="*" Header="状态" Binding="{Binding Status}"/>
</DataGrid.Columns> </DataGrid.Columns>
</DataGrid> </DataGrid>
</Grid> </Grid>

@ -42,15 +42,41 @@ namespace XGLFinishPro.Views
private void GetRecordInfo() private void GetRecordInfo()
{ {
DataTable dt = userDbWareHouse.GetAttendanceRecord(deviceCode); try
if (dt == null)
{ {
dgUserInfo.ItemsSource = null; DataTable dt = userDbWareHouse.GetAttendanceRecord(deviceCode);
if (dt == null)
{
dgUserInfo.ItemsSource = null;
}
else
{
// 添加一个新的列来表示上班/下班状态
dt.Columns.Add("Status", typeof(string));
// 遍历每一行,并根据 endTime 的值设置状态
foreach (DataRow row in dt.Rows)
{
if (row["end_time"] != DBNull.Value && !string.IsNullOrEmpty(row["end_time"].ToString()))
{
row["Status"] = "下班";
}
else
{
row["Status"] = "上班";
}
}
dgUserInfo.ItemsSource = dt.DefaultView;
}
} }
else catch (Exception ex)
{ {
dgUserInfo.ItemsSource = dt.DefaultView;
} }
} }
} }
} }

@ -6,7 +6,7 @@
xmlns:local="clr-namespace:XGLFinishPro.Views" xmlns:local="clr-namespace:XGLFinishPro.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" VerticalAlignment="Stretch" Loaded="UserControl_Loaded"
mc:Ignorable="d"> mc:Ignorable="d">
<UserControl.Resources> <UserControl.Resources>
<Style TargetType="TextBox"> <Style TargetType="TextBox">
@ -71,23 +71,11 @@
<TextBlock <TextBlock
FontSize="22" FontSize="22"
FontWeight="Bold" FontWeight="Bold"
Text="上班打卡:" /> Text=" 打卡:" />
</Label> </Label>
<TextBox Name="txtOnWorkUserID" KeyDown="txtOnWorkUserID_KeyDown"/> <TextBox Name="txtOnWorkUserID" KeyDown="txtOnWorkUserID_KeyDown"/>
<Label
Grid.Row="0"
Width="175"
Height="37"
Margin="25,20,0,25"
HorizontalAlignment="Left"
VerticalAlignment="Center">
<TextBlock
FontSize="22"
FontWeight="Bold"
Text="下班打卡:" />
</Label>
<TextBox Name="txtOffWorkUserID" KeyDown="txtOffWorkUserID_KeyDown"/>
</StackPanel> </StackPanel>

@ -69,13 +69,6 @@ namespace XGLFinishPro.Views
try try
{ {
string userID = txtOnWorkUserID.Text; string userID = txtOnWorkUserID.Text;
DataTable dt = finishProdDBService.GetExistAttendanceRecord(deviceCode);
if (dt != null && dt.Select("user_id = '" + userID + "'").Length > 0)
{
CustomMessageBox.Show("您已经上班打卡成功,请勿再次打卡!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning);
return;
}
DataTable dtUserInfo = finishProdDBService.GetUserInfoFromCloudServer(userID); DataTable dtUserInfo = finishProdDBService.GetUserInfoFromCloudServer(userID);
if (dtUserInfo == null || dtUserInfo.Rows.Count <= 0) if (dtUserInfo == null || dtUserInfo.Rows.Count <= 0)
{ {
@ -85,17 +78,34 @@ namespace XGLFinishPro.Views
string userCode = dtUserInfo.Rows[0]["user_name"].ToString(); string userCode = dtUserInfo.Rows[0]["user_name"].ToString();
string userName = dtUserInfo.Rows[0]["nick_name"].ToString(); string userName = dtUserInfo.Rows[0]["nick_name"].ToString();
string sex = dtUserInfo.Rows[0]["sex"].ToString(); string sex = dtUserInfo.Rows[0]["sex"].ToString();
bool isSucc = finishProdDBService.InsertAttendanceRecord(userCode, userName, sex,deviceCode); DataTable dt = finishProdDBService.GetExistAttendanceRecord(deviceCode);
if (isSucc) if (dt != null && dt.Select("user_id = '" + userID + "' AND end_time IS NULL").Length > 0)
{ {
CustomMessageBox.Show("打卡成功,祝您工作愉快!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); bool isSucc = finishProdDBService.UpdateAttendanceRecord(userCode, deviceCode);
txtOnWorkUserID.Text = ""; if (isSucc)
txtOnWorkUserID.Focus(); {
Now_Click(null, null); CustomMessageBox.Show("打卡成功,再见!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Success);
Now_Click(null, null);
txtOnWorkUserID.Text = "";
txtOnWorkUserID.Focus();
return;
}
} }
else { else
CustomMessageBox.Show("打卡失败,请重试!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); {
bool isSucc = finishProdDBService.InsertAttendanceRecord(userCode, userName, sex, deviceCode);
if (isSucc)
{
CustomMessageBox.Show("打卡成功,祝您工作愉快!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Success);
txtOnWorkUserID.Text = "";
txtOnWorkUserID.Focus();
Now_Click(null, null);
}
else
{
CustomMessageBox.Show("打卡失败,请重试!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Error);
}
} }
} }
catch (Exception ex) catch (Exception ex)
@ -106,48 +116,9 @@ namespace XGLFinishPro.Views
} }
} }
private void UserControl_Loaded(object sender, RoutedEventArgs e)
private void txtOffWorkUserID_KeyDown(object sender, KeyEventArgs e)
{ {
if (e.Key == Key.Enter) txtOnWorkUserID.Focus();
{ }
try
{
string userID = txtOffWorkUserID.Text;
DataTable dtUserInfo = finishProdDBService.GetUserInfoFromCloudServer(userID);
if (dtUserInfo == null || dtUserInfo.Rows.Count <= 0)
{
CustomMessageBox.Show("找不到该账户,请重试!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning);
return;
}
string userCode = dtUserInfo.Rows[0]["user_name"].ToString();
DataTable dt = finishProdDBService.GetExistAttendanceRecord(deviceCode);
if (dt!=null && dt.Select("user_id = '" + userCode + "'").Length > 0)
{
if (dt.Select("user_id = '" + userCode + "' and start_addr = '" + deviceCode + "'").Length > 0)
{
bool isSucc = finishProdDBService.UpdateAttendanceRecord(userCode, deviceCode);
if (isSucc)
{
CustomMessageBox.Show("打卡成功,再见!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning);
Now_Click(null, null);
}
}
else
{
string start_addr = dt.Select("user_id = '" + userCode + "'")[0]["start_addr"].ToString();
CustomMessageBox.Show("打卡失败,您的打卡地址在" + start_addr + "", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning);
return;
}
}
}
catch (Exception ex)
{
LogHelper.instance.log.Error("下班打卡发生异常>>" + ex.Message);
CustomMessageBox.Show("下班打卡发生异常!" + ex.Message, CustomMessageBoxButton.OK, CustomMessageBoxIcon.Error);
}
}
}
} }
} }

@ -5,10 +5,10 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:XGLFinishPro.Views" xmlns:local="clr-namespace:XGLFinishPro.Views"
mc:Ignorable="d" mc:Ignorable="d"
WindowState="Maximized" WindowStartupLocation="CenterScreen"
Title="打卡" Title="打卡"
Width="1920" Width="1220"
Height="1080"> Height="780">
<Grid Name="content" <Grid Name="content"
Background="#F2F3F5"> Background="#F2F3F5">
<ContentControl Name="Index" /> <ContentControl Name="Index" />

Loading…
Cancel
Save