C# 组合框ComoBox 实现厂区班组复位功能

本文描述了一个项目中的功能需求,涉及班组(早班、中班、晚班)之间的绩效管理,包括数据复位、保存和显示。设计中强调了数据库查询和操作,如使用SQLite进行数据插入、更新和删除,以实现不同班组间绩效的无缝切换。
摘要由CSDN通过智能技术生成

功能要求

有个项目中要求添加功能如下:厂区有三个班组,早班-中班-晚班

1 由早班切换到中班时,早班绩效保存,绩效复位

2 当切换回早班时显示早班的绩效

3 当切换回中班时显示目前中班的绩效,中班绩效累加

4 当切换到晚班时,中班绩效保存,绩效复位

5 第二天切换到早班时,前日晚班绩效保存,早班绩效复位

设计方案

如果数据库中没有查询到选中班组的信息
1 判断运行时(系统运行时的全局变量)捆数信息是否为0  如果为0 则无需复位  如果不为0 则插入前一组的捆数信息并初始化当前组的信息,最后复位  
如果查询到选中班组的信息
1 判断有没有同时存在初始化的缓存信息和复位而插入的信息,如果都存在,则删除缓存信息并显示选中班组的信息
2 如果只有初始化信息,更新当前班组的捆数信息 并显示在界面上

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
     
    
    string name = this.comboBox1.Text;
    //ComboBox cb =sender as ComboBox;
    //string team= cb.SelectedItem as string;

    string teams="",preteams="",nextteams=""; 
    string teamID = DateTime.Now.ToString("yyyyMMdd");//20231121  
    string selectSQL="";
    //string insertSQL = "";
    string bundleNos = "";
    int temp=0;

    if (name == "早班")
    {
        teams = "早班";
        preteams = "晚班";
        nextteams = "中班";

    }
    else if (name == "中班")
    {
        teams = "中班";
        preteams = "早班";
        nextteams = "晚班";
        
    }
    else if (name == "晚班")
    {
        teams = "晚班";
        preteams = "中班";
        nextteams = "早班";
    
    }
    else
        return;
    //查询选中班组是否存在捆数信息
    selectSQL = string.Format("select * from FJ_bundleNoS where teams='{0}' and teamID='{1}'",teams, teamID);
    SQLiteDataReader reader =sqliteHelper.ExecuteReaderA(selectSQL);//自己封装的sqlite类的方法,实现执行sql语句
   
    if(!reader.Read())
    {
        reader.Close();
        temp = bundleNo; // bundleNo为系统运行时绩效信息,先获取前一个班的捆数
        //捆数为0 无需复位
        if (temp == 0)
        {
            return;
        }
           
        //复位
        else 
        {
            
            bundleNos = bundleNo.tostring();
            textBoxKS.Text = 0.ToString();//将绩效信息显示复位
            bundleNo = 0;//将运行时参数设置为0
            
            //第一步 向FJ_bundleNoS表中插入前一班组数据
            string currentTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            string insertSQLStr = string.Format("insert into FJ_bundleNoS(endTime,bundleNo,data1,teams,teamID) values('{0}','{1}','{2}','{3}','{4}')", currentTime, bundleNos, "1", preteams, teamID);
            SystemTools.UpdateDataBySQL(insertSQLStr);
            //第二步 初始化当前班组信息
            insertSQLStr = string.Format("insert into FJ_bundleNoS(endTime,bundleNo,data1,teams,teamID) values('{0}','{1}','{2}','{3}','{4}')", currentTime+"_temp", "0", "0", teams, teamID);
            SystemTools.UpdateDataBySQL(insertSQLStr);
            //第三步 将FJ_RunTimeParam bundleNo清0 并且程序中运行的参数设置为0
            string updateSQLStr = "update FJ_RunTimeParam set bundleNo = 0";
            SystemTools.UpdateDataBySQL(updateSQLStr);
            return;
        }

        
    }
    
    //查询到结果,显示 bundleNo 仍会自加
    else
    {
        //先读取data1字段是否为1  如果为1则是以往班组捆数信息的显示功能
        string data1 = Convert.ToString(reader["data1"]);
        if(data1=="1")
        {
            string bundle = Convert.ToString(reader["bundleNo"]);
            textBoxKS.Text = bundle;
            reader.Close();
        }
        //如果不为1 则是更新当前班组的数据与显示当前班组的捆数信息
        else
        {   //如果能读到下一条信息,删除缓存信息
            if(reader.Read())
            {
                bundleNos = Convert.ToString(reader["bundleNo"]);
                reader.Close();
                string delSQLStr = string.Format("delete from FJ_bundleNoS where data1='0' and teams='{0}'", teams);
                SystemTools.UpdateDataBySQL(delSQLStr);
                textBoxKS.Text = bundleNos.ToString();
            }
            else
            {
                reader.Close();
                string updateSQLStr = string.Format("update FJ_bundleNoS set bundleNo = '{0}' where teams='{1}' and teamID='{2}'", GlobalSystemParam.fJRunTimeParam.bundleNo.ToString(), teams, teamID);
                SystemTools.UpdateDataBySQL(updateSQLStr);
                textBoxKS.Text = bundleNo.ToString();

            }
            
        }
        

    }
    
 
}

  • 8
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值