Beispiel #1
1
 public static Task CreateTaskByTable(DataTable dt)
 {
     Task task = null;
     try
     {
         task = new Task();
         task.TaskNo = (dt.Rows[0]["TaskNo"] == null ? "" : dt.Rows[0]["TaskNo"].ToString());
         task.BatchNo = (dt.Rows[0]["BatchNo"] == null ? "" : dt.Rows[0]["BatchNo"].ToString());
         task.ItemNo = (dt.Rows[0]["ItemNo"] == null ? "" : dt.Rows[0]["ItemNo"].ToString());
         task.ItemName = (dt.Rows[0]["ItemName"] == null ? "" : dt.Rows[0]["ItemName"].ToString());
         task.Sn = (dt.Rows[0]["Sn"] == null ? "" : dt.Rows[0]["Sn"].ToString());
         task.PV = (dt.Rows[0]["PV"] == null ? 0 : int.Parse(dt.Rows[0]["PV"].ToString()));
         task.Result = (dt.Rows[0]["Result"] == null ? 0 : int.Parse(dt.Rows[0]["Result"].ToString()));
         task.redundantVaue = (dt.Rows[0]["RedundantVaue"] == null ? 0 : int.Parse(dt.Rows[0]["RedundantVaue"].ToString()));
         IFormatProvider ifp = new CultureInfo("zh-CN", true);
         if (dt.Rows[0]["StartTime"] != null)
         {
             DateTime.TryParseExact(dt.Rows[0]["StartTime"].ToString(), DateTimeFormat2, ifp, DateTimeStyles.None, out task.StartTime);
         }
         if (dt.Rows[0]["CompleteTime"] != null)
         {
             DateTime.TryParseExact(dt.Rows[0]["CompleteTime"].ToString(), DateTimeFormat2, ifp, DateTimeStyles.None, out task.CompleteTime);
         }
         return task;
     }
     catch (Exception ex)
     {
         Program.WriteErrorLog("CreateTaskByTable", ex);
         return task;
     }
 }
Beispiel #2
0
 public Task LoadCurrentTask()
 {
     Task task = null;
     try
     {
         StringBuilder sbstr = new StringBuilder("Select * From T_Task");
         DataTable dt = theDB.SelectDataTable(sbstr.ToString());
         if (dt.Rows.Count >= 1)
         {
             task = new Task();
             task = Task.CreateTaskByTable(dt);
         }
         return task;
     }
     catch (Exception ex)
     {
         Program.WriteErrorLog(this.GetType().FullName, ex);
         return task;
     }
 }
Beispiel #3
0
 private void Frm_Main_Load(object sender, EventArgs e)
 {
     Timer_ReadData.Interval = SysPara.RefreshTime;
     lastTask = mp.LoadCurrentTask();
     if (lastTask != null)
     {
         FillTaskToUI(lastTask);
         ctask = lastTask;
         HideMeasureInfo();
     }
     else
     {
         ShowMeasureInfo();
     }
 }
Beispiel #4
0
        private void FillTaskToUI(Task lasttask)
        {
            if (lasttask != null)
            {
                txt_batchNo.Text = lasttask.BatchNo;
                txt_ItemNo.Text = lasttask.ItemNo;
                txt_ItemName.Text = lasttask.ItemName;

                txt_StartTime.Text = lasttask.StartTime == new DateTime() ? "" : lasttask.StartTime.ToString(Task.DateTimeFormat1);
                txt_EndTime.Text = lasttask.CompleteTime == new DateTime() ? "" : lasttask.CompleteTime.ToString(Task.DateTimeFormat1);

                txt_SumLength.Text = lasttask.PV.ToString();

                if (lasttask.Status != eTaskSts.Start)
                {
                    btnSts_Started();
                }
            }
        }
Beispiel #5
0
 private void FillTaskFormUI(Task ctask)
 {
     Task lasttask = new Task();
     ctask.TaskNo = txt_batchNo.Text;
     ctask.BatchNo = txt_batchNo.Text;
     ctask.ItemNo = txt_ItemNo.Text;
     ctask.ItemName = txt_ItemName.Text;
     int.TryParse(txt_SumLength.Text, out ctask.PV);
     int.TryParse(txt_Rongyu.Text, out ctask.PV);
 }
Beispiel #6
0
 private void btn_SaveRecord_Click(object sender, EventArgs e)
 {
     int.TryParse(txt_SumLength.Text, out ctask.PV);
     int.TryParse(txt_Rongyu.Text, out ctask.PV);
     bool res = mp.SaveRecordTask(ctask);
     if (!res)
     {
         MessageBox.Show("记录当前任务失败。");
     }
     else
     {
         MessageBox.Show("保存成功。");
         ClearUITastInfo();
         lastTask = null;
         ctask = new Task();
     }
 }
Beispiel #7
0
        private void btn_Create_Click(object sender, EventArgs e)
        {
            //检查批次号重复
            //创建当前任务
            //锁定任务修改
            //开启设备连接
            //读取计米器数据
            try
            {
                if (txt_batchNo.Text.Trim().Length < 1)
                {
                    txt_batchNo.Focus();
                    throw new ApplicationException("批次不能为空。");
                }
                if (txt_ItemNo.Text.Trim().Length < 1)
                {
                    txt_batchNo.Focus();
                    throw new ApplicationException("品规不能为空。");
                }
                ctask = new Task();
                FillTaskFormUI(ctask);
                Task lasttask = mp.LoadCurrentTask();
                if (lasttask != null)
                {
                    DialogResult dres = MessageBox.Show("已存在当前未完成任务是否继续,点(是)继续创建新任务,点(否)读取为完成任务。","任务已存在",
                                        MessageBoxButtons.YesNoCancel,MessageBoxIcon.Question,MessageBoxDefaultButton.Button1);
                    if (dres == DialogResult.Yes)
                    {
                        //ClearUITastInfo();
                        //ClearUIMeasureInfo();
                    }
                    else if (dres == DialogResult.No)
                    {
                        FillTaskToUI(lasttask);
                        btnSts_Started();
                        return;
                    }
                    else
                    {
                        return;
                    }
                }
                btnSts_Created();
                ShowMeasureInfo();
                FillTaskFormUI(ctask);

                bool res = mp.SaveCurrentTask(ctask);
                if (!res)
                {
                    throw new ApplicationException("保存作业至数据库失败。");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("新建作业失败!{0}",ex.Message));
            }
        }
Beispiel #8
0
 public MeasurerProcess()
 {
     CurrentTask = new Task();
     theDB = DBServiceFactory.GetDBService("MeasurerXML");
 }
Beispiel #9
0
 public bool SaveRecordTask(Task task)
 {
     bool result=false;
     try
     {
         StringBuilder sbstr = new StringBuilder("Insert into T_Record(TaskNo,BatchNo,ItemNo,ItemName,Sn,PV,Result,redundantVaue,Status,StartTime,CompleteTime) Values(");
         sbstr.Append(string.Format("{0},", FunBase.ChkField(task.TaskNo,true)));
         sbstr.Append(string.Format("{0},", FunBase.ChkField(task.BatchNo,true)));
         sbstr.Append(string.Format("{0},", FunBase.ChkField(task.ItemNo,true)));
         sbstr.Append(string.Format("{0},", FunBase.ChkField(task.ItemName,true)));
         sbstr.Append(string.Format("{0},", FunBase.ChkField(task.Sn, true)));
         sbstr.Append(string.Format("{0},", FunBase.ChkField(task.PV.ToString(), true)));
         sbstr.Append(string.Format("{0},", FunBase.ChkField(task.Result.ToString(), true)));
         sbstr.Append(string.Format("{0},", FunBase.ChkField(task.redundantVaue.ToString(),true)));
         sbstr.Append("1,");
         sbstr.Append(string.Format("{0},", FunBase.ChkField(task.StartTime.ToString(Task.DateTimeFormat1))));
         sbstr.Append(string.Format("{0}",  FunBase.ChkField(task.CompleteTime.ToString(Task.DateTimeFormat1))));
         sbstr.Append(")");
         result = theDB.UpdataDataBase(sbstr.ToString());
         if(result)
         {
             result = theDB.UpdataDataBase("Delete Table T_Task");
         }
         return result;
     }
     catch (Exception ex)
     {
         Program.WriteErrorLog(this.GetType().FullName, ex);
         return false;
     }
 }
Beispiel #10
0
 public bool SaveCurrentTask(Task task)
 {
     try
     {
         bool result = false;
         StringBuilder sbstr = new StringBuilder("insert into T_Task(TaskNo,BatchNo,ItemNo,ItemName,Sn,PV,Result,redundantVaue,Status,StartTime,CompleteTime) Values(");
         sbstr.Append(string.Format("'{0}',", task.TaskNo));
         sbstr.Append(string.Format("'{0}',", task.BatchNo));
         sbstr.Append(string.Format("'{0}',", task.ItemNo));
         sbstr.Append(string.Format("'{0}',", task.ItemName));
         sbstr.Append(string.Format("'{0}',", task.Sn));
         sbstr.Append(string.Format("'{0}',", task.PV));
         sbstr.Append(string.Format("'{0}',", task.Result));
         sbstr.Append(string.Format("'{0}',", task.redundantVaue));
         sbstr.Append("0,");
         sbstr.Append(string.Format("'{0}',", task.StartTime));
         sbstr.Append(string.Format("'{0}'", task.CompleteTime));
         sbstr.Append(")");
         result = theDB.UpdataDataBase("Delete T_Task");
         return theDB.UpdataDataBase(sbstr.ToString());
     }
     catch(Exception ex)
     {
         Program.WriteErrorLog(this.GetType().FullName, ex);
         return false;
     }
 }