示例#1
0
        private void InsertMeasureLimit(DataSample data, clsDBUltity db, int _measureId)
        {
            var _hasErrDB = false;

            if (string.IsNullOrEmpty(data.strSample))
            {
                return;
            }

            if (!_hasErrDB)
            {
                if (!db.InsertMeasureDetailLimit(data.deviceId, _measureId, data.t, data.strSample, data.actualMaxValue, data.actualMinValue, data.actualDelegate, data.result))
                {
                    _hasErrDB         = true;
                    _nameErrFileLimit = clsConfig.MEASURE_DETAIL_LIMIT_NAME_FILE + DateTime.Now.ToString(clsDBUltity.cstrDateTimeFormatNoMiliSecond2);
                    string content = db.GetInsertMeasureDetailLimitSql(data.deviceId, _measureId, data.t, data.strSample, data.actualMaxValue, data.actualMinValue, data.actualDelegate, data.result);
                    WriteFileErrors(_nameErrFileLimit, content, _measureId);
                    _numberRecordWriteLimit++;
                }
            }
            else
            {
                if (string.IsNullOrEmpty(_nameErrFileLimit) || _numberRecordWriteLimit == clsConfig.MAX_RECORD_FILE_ERR)
                {
                    _numberRecordWriteLimit = 0;
                    _nameErrFileLimit       = clsConfig.MEASURE_DETAIL_LIMIT_NAME_FILE + DateTime.Now.ToString(clsDBUltity.cstrDateTimeFormatNoMiliSecond2);
                }
                string content = db.GetInsertMeasureDetailLimitSql(data.deviceId, _measureId, data.t, data.strSample, data.actualMaxValue, data.actualMinValue, data.actualDelegate, data.result);
                WriteFileErrors(_nameErrFileLimit, content, _measureId);
                _numberRecordWriteLimit++;
            }
        }
示例#2
0
        public List <DeviceInfo> GetListDevice()
        {
            lstDeviceInfo = new List <DeviceInfo>();

            using (var objDb = new clsDBUltity())
            {
                var deviceInfo = objDb.GetDeviceList();

                if (clsCommon.TableIsNullOrEmpty(deviceInfo))
                {
                    return(lstDeviceInfo);
                }

                foreach (DataRow row in deviceInfo.Rows)
                {
                    var device = new DeviceInfo();
                    device.DeviceId       = clsCommon.CnvNullToInt(row["device_id"]);
                    device.DeviceName     = clsCommon.CnvNullToString(row["device_name"]);
                    device.IpAddress      = clsCommon.CnvNullToString(row["ip_address"]).Trim();
                    device.Port           = clsCommon.CnvNullToInt(row["port"]);
                    device.AlarmValue     = clsCommon.CnvNullToInt(row["alarm_value"]);
                    device.Period         = clsCommon.CnvNullToInt(row["period"]);
                    device.FailLevel      = clsCommon.CnvNullToInt(row["fail_level"]);
                    device.Samples        = clsCommon.CnvNullToInt(row["samples"]);
                    device.WalkingMode    = clsCommon.CnvNullToInt(row["walking_mode"]) > 0;
                    device.OrdinalDisplay = clsCommon.CnvNullToInt(row["ordinal_display"]);
                    device.Active         = clsCommon.CnvNullToInt(row["active"]) > 0;
                    device.MacAddress     = clsCommon.CnvNullToString(row["mac_address"]);

                    lstDeviceInfo.Add(device);
                }

                return(lstDeviceInfo);
            }
        }
示例#3
0
        private void btSaveUser_Click(object sender, EventArgs e)
        {
            if (!xValidateInputUser())
            {
                return;
            }

            using (var objDb = new clsDBUltity())
            {
                if (_mode == emModeForm.CreateNewUser)
                {
                    if (!objDb.InsertUser(txtUserName.Text, txtPassword.Text, txtFullName.Text, txtEmail.Text, cboRole.SelectedIndex))
                    {
                        ShowMsg(MessageBoxIcon.Error, MSG_INSERT_ERR);
                        return;
                    }
                }
                else
                {
                    if (!objDb.UpdateUser(_userid, txtUserName.Text, txtPassword.Text, txtFullName.Text, txtEmail.Text, cboRole.SelectedIndex))
                    {
                        ShowMsg(MessageBoxIcon.Error, MSG_UPDATE_ERR);
                        return;
                    }
                }

                xModeUser(emModeForm.CreateNewUser);
                grvUser.DataSource = objDb.GetMUser();
                grvUser.ClearSelection();
            }
        }
示例#4
0
 private void MeasureManagement_FormClosed(object sender, FormClosedEventArgs e)
 {
     if (_objDB != null)
     {
         _objDB.Dispose();
         _objDB = null;
     }
 }
示例#5
0
        private void xExecuteNonQueryFromFile(string[] files, int measureid_selected)
        {
            if (files == null || files.Length == 0)
            {
                ShowMsg(MessageBoxIcon.Warning, "");
                return;
            }

            bool flagCheck = false;

            foreach (var path in files)
            {
                var filename = Path.GetFileName(path);
                var arrTemp  = filename.Split('_');

                if (arrTemp.Length == 3)
                {
                    var measureId = clsCommon.CnvNullToInt(arrTemp[0]);

                    if (measureId == measureid_selected)
                    {
                        using (var db = new clsDBUltity())
                        {
                            flagCheck = db.ExecuteNonQueryFromFile(path, false);

                            if (!flagCheck)
                            {
                                ShowMsg(MessageBoxIcon.Error, path);
                                return;
                            }
                        }
                    }
                    else
                    {
                        if (!ComfirmMsgErr(path + Environment.NewLine + COMFIRM_NEXT_FILE))
                        {
                            return;
                        }
                    }
                }
                else
                {
                    if (!ComfirmMsgErr(path + Environment.NewLine + COMFIRM_NEXT_FILE))
                    {
                        return;
                    }
                }
            }

            if (flagCheck)
            {
                LoadData();
                ShowMsg(MessageBoxIcon.Information, FIX_ERR_SUCCESS);
            }
        }
示例#6
0
        private static void deleteMeasureRawOld()
        {
            using (var db = new clsDBUltity())
            {
                var dateLimit = DateTime.Now.AddDays(-clsConfig.TimeDeleteMeasureDetailRaw);
                var tbl       = db.GetTBLMeasure(string.Empty, dateLimit.ToString(clsDBUltity.cstrDateTimeFormatNoMiliSecond));

                if (!clsCommon.TableIsNullOrEmpty(tbl))
                {
                    foreach (System.Data.DataRow row in tbl.Rows)
                    {
                        db.DeleteMeasureRaw(clsCommon.CnvNullToInt(row["measure_id"]));
                    }
                }
            }
        }
示例#7
0
        private void InsertMeasureRaw(DataSample data, clsDBUltity db, DeviceInfo device)
        {
            var _hasErrDB = false;

            if (string.IsNullOrEmpty(data.strSample))
            {
                return;
            }

            double dblMax;
            double dblMin;
            double dblDelegate;
            string strValue;

            string[] arrValue;
            var      result = (int)clsDBUltity.emMeasureResult.Pass;

            GetDataFromSample(data.strSample, out arrValue, out strValue, out dblMax, out dblMin, out dblDelegate);

            if (device.MeasureType == emMeasureType.AlarmTest)
            {
                result = device.AlarmValue > (int)dblDelegate ? (int)clsDBUltity.emMeasureResult.Normal : (int)clsDBUltity.emMeasureResult.Alarm;
            }

            if (!_hasErrDB)
            {
                if (!db.InsertMeasureDetailRaw(data.deviceId, device.MeasureId, data.t, data.strSample, (int)dblMax, (int)dblMin, (int)dblDelegate, result))
                {
                    _hasErrDB       = true;
                    _nameErrFileRaw = clsConfig.MEASURE_DETAIL_RAW_NAME_FILE + DateTime.Now.ToString(clsDBUltity.cstrDateTimeFormatNoMiliSecond2);
                    string content = db.GetInsertMeasureDetailRawSql(data.deviceId, device.MeasureId, data.t, data.strSample, (int)dblMax, (int)dblMin, (int)dblDelegate, result);
                    WriteFileErrors(_nameErrFileRaw, content, device.MeasureId);
                    _numberRecordWriteRaw++;
                }
            }
            else
            {
                if (string.IsNullOrEmpty(_nameErrFileRaw) || _numberRecordWriteRaw == clsConfig.MAX_RECORD_FILE_ERR)
                {
                    _numberRecordWriteRaw = 0;
                    _nameErrFileRaw       = clsConfig.MEASURE_DETAIL_RAW_NAME_FILE + DateTime.Now.ToString(clsDBUltity.cstrDateTimeFormatNoMiliSecond2);
                }
                string content = db.GetInsertMeasureDetailRawSql(data.deviceId, device.MeasureId, data.t, data.strSample, (int)dblMax, (int)dblMin, (int)dblDelegate, result);
                WriteFileErrors(_nameErrFileRaw, content, device.MeasureId);
                _numberRecordWriteRaw++;
            }
        }
示例#8
0
        private void btSaveSetting_Click(object sender, EventArgs e)
        {
            if (!xValidateInputDevice())
            {
                return;
            }

            using (var objDb = new clsDBUltity())
            {
                var emDeviceType = clsDBUltity.emDeviceType.None;

                if (_devicetype == (int)clsDBUltity.emDeviceType.Device1)
                {
                    emDeviceType = clsDBUltity.emDeviceType.Device1;
                }
                else if (_devicetype == (int)clsDBUltity.emDeviceType.Device2)
                {
                    emDeviceType = clsDBUltity.emDeviceType.Device2;
                }

                if (objDb.SaveDevice(_deviceid,
                                     txtDeviceName.Text,
                                     txtIpAddress.Text,
                                     clsCommon.CnvNullToInt(txtPort.Text),
                                     clsCommon.CnvNullToInt(txtAlarmValue.Text),
                                     clsCommon.CnvNullToInt(txtPeriod.Text),
                                     clsCommon.CnvNullToInt(txtFailLevel.Text),
                                     clsCommon.CnvNullToInt(txtSamples.Text),
                                     chkActive.Checked,
                                     emDeviceType))
                {
                    var intColumnIndexCurrent = grvDevice.CurrentCell.ColumnIndex;
                    var intRowIndexCurrent    = grvDevice.CurrentCell.RowIndex;
                    grvDevice.DataSource = objDb.GetDeviceList();
                    grvDevice_CellClick(grvDevice, new DataGridViewCellEventArgs(intColumnIndexCurrent, intRowIndexCurrent));
                    _changeSetting = true;
                    ShowMsg(MessageBoxIcon.Information, MSG_SAVE_SETTING_SUCCESS);
                }
                else
                {
                    ShowMsg(MessageBoxIcon.Error, MSG_SAVE_SETTING_ERR);
                }
            }
        }
示例#9
0
 private void btResetDefault_Click(object sender, EventArgs e)
 {
     if (ComfirmMsg(MSG_COMFIRM_RESET))
     {
         using (var objDb = new clsDBUltity())
         {
             if (!objDb.ResetDefauleDevice(_deviceid, _devicetype))
             {
                 ShowMsg(MessageBoxIcon.Error, MSG_RESET_SETTING_ERR);
                 return;
             }
             var intColumnIndexCurrent = grvDevice.CurrentCell.ColumnIndex;
             var intRowIndexCurrent    = grvDevice.CurrentCell.RowIndex;
             grvDevice.DataSource = objDb.GetDeviceList();
             grvDevice_CellClick(grvDevice, new DataGridViewCellEventArgs(intColumnIndexCurrent, intRowIndexCurrent));
             _changeSetting = true;
         }
     }
 }
示例#10
0
        private void btLogin_Click(object sender, EventArgs e)
        {
            if (!ValidateLogin())
            {
                return;
            }

            using (var objDb = new clsDBUltity())
            {
                if (objDb.LoginCheck(txtUser.Text, txtPass.Text))
                {
                    ExitForm(true);
                }
                else
                {
                    ShowMsg(MessageBoxIcon.Error, MSG_ERR_LOGIN);
                }
            }
        }
示例#11
0
        private void btSaveChange_Click(object sender, EventArgs e)
        {
            if (!xValidateChangePassword())
            {
                return;
            }

            using (var objDb = new clsDBUltity())
            {
                if (objDb.ChangePasswordUser(clsConfig.UserLoginId, txtCurent.Text, txtNew.Text))
                {
                    ShowMsg(MessageBoxIcon.Information, MSG_CHANGE_PASS_SUCCESS);
                    xResetModeChangePassword();
                }
                else
                {
                    ShowMsg(MessageBoxIcon.Error, MSG_CHANGE_PASS_ERR);
                }
            }
        }
示例#12
0
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    // TODO: dispose managed state (managed objects).
                    if (_DBUltity != null)
                    {
                        _DBUltity.Dispose();
                        _DBUltity = null;
                    }
                }

                // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
                // TODO: set large fields to null.

                disposedValue = true;
            }
        }
示例#13
0
        private void btnSaveSetting_Click(object sender, EventArgs e)
        {
            var deviceManagement  = (DeviceManagement)sender;
            var gridDevice        = deviceManagement.GridDeviceSelected;
            var swapDevice        = deviceManagement.SwapDeviceSelected;
            var swapOrdinalDevice = deviceManagement.SwapOrdinalDisplayDevice;

            using (var objDb = new clsDBUltity())
            {
                if (objDb.SaveDevice(gridDevice) && objDb.SaveDevice(swapDevice) && objDb.SaveDevice(swapOrdinalDevice))
                {
                    this.dvcManagement.SetListDevice(deviceManagement.ListDevice);
                    this.ChangeSetting = true;
                    ShowMsg(MessageBoxIcon.Information, MSG_SAVE_SETTING_SUCCESS);
                }
                else
                {
                    ShowMsg(MessageBoxIcon.Error, MSG_SAVE_SETTING_ERR);
                }
            }
        }
示例#14
0
        public void UpdateListDevice(List <DeviceInfo> lstDevice)
        {
            using (var objDb = new clsDBUltity())
            {
                try
                {
                    foreach (var device in lstDevice)
                    {
                        if (!string.IsNullOrEmpty(device.MacAddress))
                        {
                            objDb.SaveDevice(device);
                        }
                    }
                }
                catch (Exception)
                {
                }
            }

            FormSetting?.LoadInfoDevice();
        }
示例#15
0
        private void tabMngt_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (tabMngt.SelectedTab == tabUsers)
            {
                using (var objDb = new clsDBUltity())
                {
                    grvUser.DataSource = objDb.GetMUser();
                    grvUser.ClearSelection();
                }

                if (cboRole.Items.Count == 0)
                {
                    cboRole.Items.Add(ADMIN);
                    cboRole.Items.Add(USER);
                    cboRole.SelectedIndex = 0;
                }
            }
            else if (tabMngt.SelectedTab == tabChangePassword)
            {
                xResetModeChangePassword();
            }
        }
示例#16
0
        private void IntForm()
        {
            // Limit resize form
            this.MinimumSize = this.Size;
            this.MaximumSize = Screen.PrimaryScreen.Bounds.Size;

            grvUser.AutoGenerateColumns   = false;
            grvDevice.AutoGenerateColumns = false;
            txtPort.KeyPress       += onlyInputNumber;
            txtAlarmValue.KeyPress += onlyInputNumber;
            txtPeriod.KeyPress     += onlyInputNumber;
            txtFailLevel.KeyPress  += onlyInputNumber;
            txtSamples.KeyPress    += onlyInputNumber;

            tabMngt.TabPages.Remove(tabUsers);

            if (clsConfig.ModeApp != clsConfig.emModeApp.Admin)
            {
                tabMngt.TabPages.Remove(tabSetting);
                this.MaximizeBox     = false;
                this.MinimizeBox     = false;
                this.FormBorderStyle = FormBorderStyle.FixedDialog;
            }
            else
            {
                tabMngt.TabPages.Remove(tabChangePassword);
            }

            using (var objDb = new clsDBUltity())
            {
                grvDevice.DataSource = objDb.GetDeviceList();
                grvDevice.ClearSelection();
                if (grvDevice.Rows.Count > 0)
                {
                    grvDevice.Rows[0].Selected = true;
                    grvDevice_CellClick(grvDevice, new DataGridViewCellEventArgs(0, 0));
                }
            }
        }
示例#17
0
        public DeviceInfo[] GetListDevice()
        {
            var listDeviceInfo = new DeviceInfo[2];

            using (var objDb = new clsDBUltity())
            {
                var deviceInfo = objDb.GetDeviceList(false);

                if (clsCommon.TableIsNullOrEmpty(deviceInfo))
                {
                    return(listDeviceInfo);
                }

                var i = -1;

                foreach (DataRow row in deviceInfo.Rows)
                {
                    i++;

                    if (i > 1)
                    {
                        break;
                    }

                    listDeviceInfo[i].deviceId   = clsCommon.CnvNullToInt(row["device_id"]);
                    listDeviceInfo[i].deviceType = clsCommon.CnvNullToInt(row["device_type"]);
                    listDeviceInfo[i].ipAddress  = clsCommon.CnvNullToString(row["ip_address"]).Trim();
                    listDeviceInfo[i].port       = clsCommon.CnvNullToInt(row["port"]);
                    listDeviceInfo[i].AlarmValue = clsCommon.CnvNullToInt(row["alarm_value"]);
                    listDeviceInfo[i].period     = clsCommon.CnvNullToInt(row["period"]);
                    listDeviceInfo[i].failLevel  = clsCommon.CnvNullToInt(row["fail_level"]);
                    listDeviceInfo[i].samples    = clsCommon.CnvNullToInt(row["samples"]);
                    listDeviceInfo[i].active     = clsCommon.CnvNullToInt(row["active"]) > 0;
                }

                return(listDeviceInfo);
            }
        }
示例#18
0
        private void grvUser_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1)
            {
                return;
            }

            xModeUser(emModeForm.UpdateUser);

            _userid               = clsCommon.CnvNullToInt(grvUser.Rows[e.RowIndex].Cells[colUserId.Index].Value);
            txtUserName.Text      = clsCommon.CnvNullToString(grvUser.Rows[e.RowIndex].Cells[colUserName.Index].Value);
            txtPassword.Text      = clsCommon.CnvNullToString(grvUser.Rows[e.RowIndex].Cells[colUserName.Index].Value);
            txtFullName.Text      = clsCommon.CnvNullToString(grvUser.Rows[e.RowIndex].Cells[colFullName.Index].Value);
            txtEmail.Text         = clsCommon.CnvNullToString(grvUser.Rows[e.RowIndex].Cells[colEmail.Index].Value);
            cboRole.SelectedIndex = clsCommon.CnvNullToInt(grvUser.Rows[e.RowIndex].Cells[colRole.Index].Value);
            cboRole.Enabled       = _userid != clsConfig.UserLoginId;

            if (e.ColumnIndex == colDeleteUser.Index)
            {
                if (_userid == clsConfig.UserLoginId)
                {
                    return;
                }

                if (ComfirmMsg(MSG_COMFIRM_DELETE))
                {
                    using (var objDb = new clsDBUltity())
                    {
                        objDb.DeleteUserById(_userid);
                        xModeUser(emModeForm.CreateNewUser);
                        grvUser.DataSource = objDb.GetMUser();
                        grvUser.ClearSelection();
                    }
                }
            }
        }