Пример #1
0
        public bool CalcDemarcateResult()
        {
            if (dataGridView1.Rows.Count <= 0)
            {
                MessageBox.Show("请先使用标定仪器标定!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }
            List <DemarcateData> demarcateDatas = GetAllToolsInfoFromGrid();
            ToolsInfo            toolsInfo      = toolsInfoManage.QueryOneToolsInfo(SerialNum);

            foreach (DemarcateData demarcate in demarcateDatas)
            {
                if (double.Parse(demarcate.Torque) > toolsInfo.TorqueMax || double.Parse(demarcate.Torque) < toolsInfo.TorqueMin)
                {
                    DemarcateResult = false;
                    return(true);
                }
            }
            DemarcateResult = true;
            return(true);
        }
Пример #2
0
        public string ExportSingleData2Excel(string filePath, ToolsInfo toolsInfo)
        {
            int affected = 0;

            try
            {
                affected = toolsInfoService.CreateToolsInfoExcelTable(filePath);
                Console.WriteLine("affected is {0}", affected);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"CreateToolsInfoExcelTable fail: {ex.Message}");
            }

            //if (affected < 1) return "创建导出文件失败";
            affected = toolsInfoService.InsertToolsInfo2ExcelTable(filePath, toolsInfo);
            if (affected < 1)
            {
                return("导出数据失败");
            }
            return("导出数据成功");
        }
Пример #3
0
        private DemarcateRecords GetDemarcateRecords()
        {
            ToolsInfo      toolsInfo      = toolsInfoManage.QueryOneToolsInfo(txtSerialNum.Text.Trim());
            DemarcateTools demarcateTools = demarcateRecordManage.getOneDemarcateToolBySerialNum(txtSerialNum.Text.Trim());

            if (toolsInfo == null || demarcateTools == null)
            {
                MessageBox.Show("工具序列号有误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }
            string nextTime = DateTime.Now.AddDays(demarcateTools.Cycle).ToString("d");

            return(new DemarcateRecords
            {
                DemarcateNum = "",
                SerialNum = toolsInfo.SerialNum,
                WorkStation = toolsInfo.Workstation,
                Validity = nextTime,
                Examinant = "",
                CheckTime = DateTime.Now.ToString("d")
            });
        }
Пример #4
0
        private ToolsInfo[] getTextBox()
        {
            ToolsInfo[]      toolsInfos = new ToolsInfo[] { };
            List <ToolsInfo> ktls       = toolsInfos.ToList();

            for (int i = 1; i <= addTimes; i++)
            {
                foreach (Control txtBox in panel1.Controls)
                {
                    foreach (Control comboBox in panel1.Controls)
                    {
                        if (txtBox is TextBox && txtBox.Name.Contains(i.ToString()) && comboBox is ComboBox && comboBox.Name.Contains(i.ToString()))
                        {
                            if (txtBox.Text != "" && comboBox.Text != "")
                            {
                                ktls.Add(getOneInput(txtBox as TextBox, comboBox as ComboBox));
                            }
                        }
                    }
                }
            }
            toolsInfos = ktls.ToArray();
            return(toolsInfos);
        }
Пример #5
0
        private void btnNextStep_Click(object sender, EventArgs e)
        {
            if (pageNum == 1)
            {
                if (txtSerialNum.Text.Trim() == "")
                {
                    MessageBox.Show("序列号不能为空,请输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (cmbCheckMan.Text.Trim() == "")
                {
                    MessageBox.Show("校准检查员不能为空,请输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (!isToolsExist(txtSerialNum.Text.Trim()))
                {
                    if (!toolsInfoManage.IsToolExistInDb(txtSerialNum.Text.Trim()))
                    {
                        MessageBox.Show("仓库中不存在序列号为" + txtSerialNum.Text.Trim() + "的工具,请先录入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    if (MessageBox.Show("工具序列号不在校准计划中,是否继续?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
                    {
                        return;
                    }
                }
                try
                {
                    checkManManage.AddOneName(cmbCheckMan.Text.Trim());
                }
                catch (Exception ex)
                {
                    Console.Write("add name fail", ex.Message);
                }
            }
            pageNum++;
            DemarcateTools demarcateTools = demarcateRecordManage.getOneDemarcateToolBySerialNum(txtSerialNum.Text.Trim());

            if (pageNum == 2)
            {
                if (Convert.ToDateTime(demarcateTools.NextTime) > DateTime.Now)
                {
                    pageNum--;
                    if (MessageBox.Show($"该工具的预计校准日期为{demarcateTools.NextTime},确定要继续校准吗?", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.Cancel)
                    {
                        return;
                    }
                }

                btnNextStep.Text = "下一步";
                //btnLastStep.Visible = true;
                btnNextStep.Enabled = true;
                btnLastStep.Enabled = true;
                foreach (Control c in panel2.Controls)
                {
                    c.Visible = false;
                }
                demarcateDataUploadForm.FormBorderStyle = FormBorderStyle.None;
                demarcateDataUploadForm.Dock            = DockStyle.Fill;
                demarcateDataUploadForm.TopLevel        = false;
                demarcateDataUploadForm.SerialNum       = txtSerialNum.Text.Trim();
                demarcateDataUploadForm.CheckMan        = cmbCheckMan.Text.Trim();
                panel2.Controls.Add(demarcateDataUploadForm);
                demarcateDataUploadForm.Show();
            }
            if (pageNum == 3)
            {
                if (!demarcateDataUploadForm.CalcDemarcateResult())
                {
                    pageNum--;
                    return;
                }
                if (!demarcateDataUploadForm.DemarcateResult)
                {
                    pageNum--;
                    demarcateDataUploadForm.setResultLabel("校准结果:不合格");
                    if (MessageBox.Show("校准结果不合格,是否重新校准?\n点击确定将会清除校准数据\n点击取消将会把工具标记为待修", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                    {
                        demarcateDataUploadForm.reDemarcateActon();
                        demarcateDataUploadForm.setResultLabel("校准结果:");
                    }
                    else
                    {
                        MaintainManageInfo maintainManageInfo = new MaintainManageInfo
                        {
                            ToolSerialName = txtSerialNum.Text.Trim(),
                            ToolModeName   = toolsInfoManage.QueryOneToolsInfo(txtSerialNum.Text.Trim()).Model,
                            SendFixTime    = DateTime.Now.ToString("yyyy-MM-dd"),
                            Detail         = DemarcateStatusDeclare.OffGrade
                        };
                        string msg = maintainInfoManage.RegisterBreakTool(maintainManageInfo);
                        if (!msg.Contains("成功"))
                        {
                            MessageBox.Show($"移至待修出错!原因:{msg}", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    return;
                }
                btnNextStep.Text = "进入下一个工具校准";
                //btnNextStep.Location = new Point(btnNextStep.Location.X -90, btnNextStep.Location.Y);
                btnNextStep.Enabled = true;
                //btnLastStep.Visible = true;
                btnLastStep.Enabled = true;
                btnFinsih.Visible   = true;
                btnFinsih.Location  = new Point(btnNextStep.Location.X - btnFinsih.Width - 15, btnNextStep.Location.Y);
                panel3.Controls.Add(btnFinsih);
                btnFinsih.BringToFront();
                foreach (Control c in panel2.Controls)
                {
                    c.Visible = false;
                }
                qRCodePrintForm.demarcateRecords = demarcateDataUploadForm.GetDemarcateRecords();
                qRCodePrintForm.FormBorderStyle  = FormBorderStyle.None;
                qRCodePrintForm.Dock             = DockStyle.Fill;
                //qRCodePrintForm.Location = new Point(panel2.Location.X + (panel2.Width - qRCodePrintForm.Width)/2, 0);
                qRCodePrintForm.Width    = panel2.Width;
                qRCodePrintForm.TopLevel = false;
                panel2.Controls.Add(qRCodePrintForm);
                qRCodePrintForm.Show();

                //Graphics g = gbStep.CreateGraphics();
            }
            if (pageNum == 4)
            {
                if (IsdemarcateFinsih)
                {
                    toolStripButton2_Click(null, null);
                    return;
                }
                try
                {
                    DemarcateHistory demarcateHistory = new DemarcateHistory
                    {
                        DemarcateNum  = qRCodePrintForm.demarcateRecords.DemarcateNum,
                        SerialNum     = qRCodePrintForm.demarcateRecords.SerialNum,
                        Cycle         = demarcateTools.Cycle,
                        LastTime      = demarcateTools.LastTime,
                        DemarcateTime = DateTime.Now.ToString("yyyy-MM-dd"),
                        NextTime      = DateTime.Now.AddDays(demarcateTools.Cycle).ToString("yyyy-MM-dd"),
                        CheckMan      = qRCodePrintForm.demarcateRecords.Examinant
                    };
                    int affected = demarcateRecordManage.AddDemarcateHistory(demarcateHistory);
                    if (affected < 1)
                    {
                        throw new Exception("系统出现错误,请重新校准!");
                    }
                    string sql = $"update DemarcateTools set LastTime='{demarcateHistory.DemarcateTime}',NextTime='{demarcateHistory.NextTime}' where SerialNum='{demarcateDataUploadForm.SerialNum}'";
                    affected = demarcateRecordManage.UpdateOneDemarcateToolBySql(sql);
                    if (affected < 1)
                    {
                        throw new Exception("系统出现错误,请重新校准!");
                    }
                    //更新维修次数
                    ToolsInfo toolsInfo   = toolsInfoManage.QueryOneToolsInfo(qRCodePrintForm.demarcateRecords.SerialNum);
                    int       repairTimes = toolsInfo.RepairTimes++;
                    sql      = $"update ToolsInfo set RepairTimes={repairTimes} where SerialNum='{toolsInfo.SerialNum}'";
                    affected = toolsInfoManage.UpdateToolsInfoBySql(sql);
                    if (affected < 1)
                    {
                        throw new Exception("系统出现错误,请重新校准!");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                toolStripButton2_Click(null, null);
            }
        }
Пример #6
0
        public void OnTimer(object sender, System.Timers.ElapsedEventArgs args)
        {
            // TODO: Insert monitoring activities here.
            Library.WriteErrorLog("Heart Beat");
            if (tSchLastRun.Hour == tSch.Hours && tSchLastRun.Minute == tSch.Minutes)
            {
                //assure do not run multiple times in same minutes
                return;
            }

            timer.Enabled = false;

            if (DateTime.Now.Hour == tSch.Hours && DateTime.Now.Minute == tSch.Minutes)
            {
                tSchLastRun = DateTime.Now;

                List <ToolsInfo> temp = new List <ToolsInfo>();

                string err = string.Empty;

                //get list of pending ->exactly 30 days
                string  sql     = "SELECT * FROM V_Tools_Insp_History where RejectedFlg = 0 and InspDue = 1 and DueInspDt = DateAdd(day,30,GetDate()) Order By [RespEmailID]";
                DataSet ds30    = Library.GetData(sql, constr, out err);
                bool    hasRows = ds30.Tables.Cast <DataTable>().Any(table => table.Rows.Count != 0);
                if (hasRows)
                {
                    foreach (DataRow dr in ds30.Tables[0].Rows)
                    {
                        ToolsInfo t = new ToolsInfo();
                        t.ToolsID     = Convert.ToInt32(dr["ToolsID"]);
                        t.Plant       = dr["PlantName"].ToString();
                        t.Location    = dr["Location"].ToString();
                        t.Department  = dr["DeptName"].ToString();
                        t.LastInspDt  = Convert.ToDateTime(dr["LastInspDt"]);
                        t.DueInspDt   = Convert.ToDateTime(dr["DueInspDt"]);
                        t.ToolsName   = dr["ToolsName"].ToString();
                        t.Capacity    = dr["Capacity"].ToString();
                        t.RespEmailID = dr["RespEmailID"].ToString();
                        t.RespPerson  = dr["RespPerson"].ToString();
                        t.Remarks     = "Pending At 30th Day From :" + DateTime.Now.ToString("dd/MM/yyyy");

                        temp.Add(t);
                    }
                }

                //get list of pending ->exactly 30 days
                sql = "SELECT * FROM V_Tools_Insp_History where RejectedFlg = 0 and  InspDue = 1 and DueInspDt = DateAdd(day,15,GetDate()) Order By [RespEmailID]";
                DataSet ds15 = Library.GetData(sql, constr, out err);
                hasRows = ds15.Tables.Cast <DataTable>().Any(table => table.Rows.Count != 0);
                if (hasRows)
                {
                    foreach (DataRow dr in ds15.Tables[0].Rows)
                    {
                        ToolsInfo t = new ToolsInfo();
                        t.ToolsID     = Convert.ToInt32(dr["ToolsID"]);
                        t.Plant       = dr["PlantName"].ToString();
                        t.Location    = dr["Location"].ToString();
                        t.Department  = dr["DeptName"].ToString();
                        t.LastInspDt  = Convert.ToDateTime(dr["LastInspDt"]);
                        t.DueInspDt   = Convert.ToDateTime(dr["DueInspDt"]);
                        t.ToolsName   = dr["ToolsName"].ToString();
                        t.Capacity    = dr["Capacity"].ToString();
                        t.RespEmailID = dr["RespEmailID"].ToString();
                        t.RespPerson  = dr["RespPerson"].ToString();
                        t.Remarks     = "Pending At 15th Day From :" + DateTime.Now.ToString("dd/MM/yyyy");

                        temp.Add(t);
                    }
                }

                //get list of pending ->exactly 30 days
                sql = "SELECT * FROM V_Tools_Insp_History where RejectedFlg = 0 and InspDue = 1 and DueInspDt = DateAdd(day,3,GetDate()) Order By [RespEmailID]";
                DataSet ds3 = Library.GetData(sql, constr, out err);
                hasRows = ds3.Tables.Cast <DataTable>().Any(table => table.Rows.Count != 0);
                if (hasRows)
                {
                    foreach (DataRow dr in ds3.Tables[0].Rows)
                    {
                        ToolsInfo t = new ToolsInfo();
                        t.ToolsID     = Convert.ToInt32(dr["ToolsID"]);
                        t.Plant       = dr["PlantName"].ToString();
                        t.Location    = dr["Location"].ToString();
                        t.Department  = dr["DeptName"].ToString();
                        t.LastInspDt  = Convert.ToDateTime(dr["LastInspDt"]);
                        t.DueInspDt   = Convert.ToDateTime(dr["DueInspDt"]);
                        t.ToolsName   = dr["ToolsName"].ToString();
                        t.Capacity    = dr["Capacity"].ToString();
                        t.RespEmailID = dr["RespEmailID"].ToString();
                        t.RespPerson  = dr["RespPerson"].ToString();
                        t.Remarks     = "Pending At 3rd Day From :" + DateTime.Now.ToString("dd/MM/yyyy");

                        temp.Add(t);
                    }
                }

                sql = "SELECT * FROM V_Tools_Insp_History where RejectedFlg = 0 and InspDue = 1 and DueInspDt <= GetDate() Order By [RespEmailID]";
                DataSet ds4 = Library.GetData(sql, constr, out err);
                hasRows = ds4.Tables.Cast <DataTable>().Any(table => table.Rows.Count != 0);
                if (hasRows)
                {
                    foreach (DataRow dr in ds4.Tables[0].Rows)
                    {
                        ToolsInfo t = new ToolsInfo();
                        t.ToolsID     = Convert.ToInt32(dr["ToolsID"]);
                        t.Plant       = dr["PlantName"].ToString();
                        t.Location    = dr["Location"].ToString();
                        t.Department  = dr["DeptName"].ToString();
                        t.LastInspDt  = Convert.ToDateTime(dr["LastInspDt"]);
                        t.DueInspDt   = Convert.ToDateTime(dr["DueInspDt"]);
                        t.ToolsName   = dr["ToolsName"].ToString();
                        t.Capacity    = dr["Capacity"].ToString();
                        t.RespEmailID = dr["RespEmailID"].ToString();
                        t.RespPerson  = dr["RespPerson"].ToString();
                        t.Remarks     = "Inspection till Pending";

                        temp.Add(t);
                    }
                }

                if (temp.Count <= 0)
                {
                    return;
                }

                List <ToolsInfo> SortedList = temp.OrderBy(o => o.RespEmailID).ToList();


                List <ToolsInfo>         tools = new List <ToolsInfo>();
                List <List <ToolsInfo> > mails = new List <List <ToolsInfo> >();

                if (SortedList.Count > 0)
                {
                    //prepare mails and shoot
                    string PreMailID = string.Empty, NextMailID = string.Empty;
                    foreach (ToolsInfo t in SortedList)
                    {
                        NextMailID = t.RespEmailID;

                        if (NextMailID != PreMailID)
                        {
                            if (tools.Count > 0)
                            {
                                mails.Add(tools);
                            }
                            tools = new List <ToolsInfo>();
                        }
                        tools.Add(t);
                        PreMailID = NextMailID;
                    }
                }
                if (tools.Count > 0)
                {
                    mails.Add(tools);
                }

                //here we get list of list of tools
                if (mails.Count > 0)
                {
                    err = string.Empty;
                    DataSet ds = Library.GetData("Select top 1  * from  EMailConfig", constr, out err);
                    if (!string.IsNullOrEmpty(err))
                    {
                        return;
                    }

                    hasRows = ds.Tables.Cast <DataTable>().Any(table => table.Rows.Count != 0);
                    DataRow dr;
                    if (!hasRows)
                    {
                        return;
                    }
                    else
                    {
                        dr = ds.Tables[0].Rows[0];
                    }

                    foreach (List <ToolsInfo> listoftools in mails)
                    {
                        //prepare new mail
                        //testing use anand's mailid
                        string smtphost     = dr["smtpHost"].ToString();
                        string emailaccount = dr["EmailID"].ToString();         //"*****@*****.**";
                        string accountuser  = dr["EmailAccount"].ToString();    //"*****@*****.**";
                        string accountpss   = dr["AccountPassword"].ToString(); //"Jind@l123";
                        string subject      = "Tools & Tackles Inspection Reminder";
                        string emailto      = listoftools[0].RespEmailID;
                        //string emailto = "*****@*****.**";
                        string thead = "<html> " +
                                       "<head>" +
                                       "<style>" +
                                       " table { " +
                                       " font-family: arial, sans-serif; " +
                                       " border-collapse: collapse; " +
                                       " width: 100%; " +
                                       "} " +

                                       " td, th { " +
                                       "    border: 1px solid #dddddd; " +
                                       "    text-align: left; " +
                                       "    padding: 8px; " +
                                       "} " +

                                       " tr:nth-child(even) { " +
                                       "    background-color: #dddddd;" +
                                       "}" +
                                       "</style>" +
                                       "</head>" +
                                       "<body>" +
                                       "Sir, </br><p>" + "Please Find the List of tools which are pending for inspection. " + "</p> <br/> <br/> " +
                                       "<p>Responsible Person : " + listoftools[0].RespPerson + "</p>" +
                                       "<table>" +
                                       "<thead>" +
                                       "<tr>" +
                                       "<th>ToolsSrNo</th>" +
                                       "<th>PlantName</th>" +
                                       "<th>Department</th>" +
                                       "<th>Location</th>" +
                                       "<th>Tools Name</th>" +
                                       "<th>Capacity</th>" +
                                       "<th>LastInsp.Dt.</th>" +
                                       "<th>DueInsp.Dt</th>" +
                                       "<th>Remarks</th>" +
                                       "</tr>" +
                                       "</thead>" +
                                       "<tbody>";

                        string trows = string.Empty;
                        Library.WriteErrorLog("Trying to Send Email to : " + emailto);
                        foreach (ToolsInfo t in listoftools)
                        {
                            //build contents
                            trows += "<tr><td>" + t.ToolsID.ToString() + "</td>" +
                                     "<td>" + t.Plant.ToString() + "</td>" +
                                     "<td>" + t.Department.ToString() + "</td>" +
                                     "<td>" + t.Location.ToString() + "</td>" +
                                     "<td>" + t.ToolsName.ToString() + "</td>" +
                                     "<td>" + t.Capacity.ToString() + "</td>" +
                                     "<td>" + t.LastInspDt.ToString("dd/MM/yyyy") + "</td>" +
                                     "<td>" + t.DueInspDt.ToString("dd/MM/yyyy") + "</td>" +
                                     "<td>" + t.Remarks + "</td></tr>";
                        }
                        string tbody = thead + trows + "</tbody></table></br>*This is Auto-generated notification, do not reply on this e-mail id. </body></html>";
                        //send mail
                        bool test = Library.SendMail(smtphost, emailaccount, accountuser, accountpss, emailto, "", "", subject, tbody);
                        if (!test)
                        {
                            Library.WriteErrorLog("Email Send Fails to : " + emailto);
                        }
                        else
                        {
                            Library.WriteErrorLog("Email Successfully Sent to : " + emailto);
                        }
                    }
                }
            }

            timer.Enabled = true;
        }
Пример #7
0
 public Tools() : base()
 {
     info = ToolsInfo.Instance();
 }
Пример #8
0
 public ToolsDetailForm(ToolsInfo info)
 {
     InitializeComponent();
     toolsInfo = info;
 }