Пример #1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ApplicationExit += new EventHandler(evenExitApp);

            clsDBCore.getInstance(clsDBUltity.ConnectionString);
            Common.CreateFolderHidden(Common.PathDataErrors);
            deleteMeasureRawOld();

            using (var db = new clsDBUltity())
            {
                db.LoginCheck("admin", "admin");
            }

            Application.Run(new GraphForm());

            //using (var frmLogin = new LoginForm())
            //{
            //    clsDBCore.getInstance(clsDBUltity.ConnectionString);
            //    Common.CreateFolderHidden(Common.PathDataErrors);
            //    deleteMeasureRawOld();

            //    frmLogin.ShowDialog();
            //    if (frmLogin.LoginSusses)
            //    {
            //        Application.Run(new GraphForm());
            //    } else
            //    {
            //        Application.Exit();
            //    }
            //}
        }
Пример #2
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))
                    {
                        Common.ShowMsg(MessageBoxIcon.Error, MSG_INSERT_ERR);
                        return;
                    }
                }
                else
                {
                    if (!objDb.UpdateUser(_userid, txtUserName.Text, txtPassword.Text, txtFullName.Text, txtEmail.Text, cboRole.SelectedIndex))
                    {
                        Common.ShowMsg(MessageBoxIcon.Error, MSG_UPDATE_ERR);
                        return;
                    }
                }

                xModeUser(emModeForm.CreateNewUser);
                grvUser.DataSource = objDb.GetMUser();
                grvUser.ClearSelection();
            }
        }
Пример #3
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            // Get value for search
            var dtStart = new DateTime(dtpStart.Value.Year, dtpStart.Value.Month, dtpStart.Value.Day, 0, 0, 0);
            var dtEnd   = new DateTime(dtpEnd.Value.Year, dtpEnd.Value.Month, dtpEnd.Value.Day, 23, 59, 59);

            var strSDate  = dtStart.ToString(clsDBUltity.cstrDateTimeFormatNoMiliSecond);
            var strEDate  = dtEnd.ToString(clsDBUltity.cstrDateTimeFormatNoMiliSecond);
            int intUser   = Common.CnvNullToInt(cmbUser.SelectedValue);
            int intType   = Common.CnvNullToInt(((dynamic)cmbType.SelectedItem).Value);
            int intResult = Common.CnvNullToInt(((dynamic)cmbResult.SelectedItem).Value);
            int intStatus = Common.CnvNullToInt(((dynamic)cmbStatus.SelectedItem).Value);

            if (intStatus == (int)clsDBUltity.emMeasureStatus.Complete)
            {
                dgvMeasure.Columns["colEnable"].Visible = false;
                //dgvMeasure.Columns["colDelete"].Visible = true;
            }
            else
            {
                dgvMeasure.Columns["colEnable"].Visible = true;
                //dgvMeasure.Columns["colDelete"].Visible = false;
            }

            using (var objDb = new clsDBUltity())
            {
                // Binding grid measure
                dgvMeasure.DataSource = objDb.GetTBLMeasure(strSDate, strEDate, intUser, intType, intResult, intStatus);
                dgvMeasure.ClearSelection();
                dgvMeasureDetail.DataSource = null;
            }
        }
Пример #4
0
        private void xExecuteNonQueryFromFile(string[] files, int measureid_selected)
        {
            if (files == null || files.Length == 0)
            {
                Common.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 = Common.CnvNullToInt(arrTemp[0]);

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

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

            if (flagCheck)
            {
                btnSearch.PerformClick();
                Common.ShowMsg(MessageBoxIcon.Information, FIX_ERR_SUCCESS);
            }
        }
Пример #5
0
        private static void deleteMeasureRawOld()
        {
            using (var db = new clsDBUltity())
            {
                var dateLimit = DateTime.Now.AddDays(-Common.TimeDeleteMeasureDetailRaw);
                var tbl       = db.GetTBLMeasure(string.Empty, dateLimit.ToString(clsDBUltity.cstrDateTimeFormatNoMiliSecond));

                if (!Common.TableIsNullOrEmpty(tbl))
                {
                    foreach (System.Data.DataRow row in tbl.Rows)
                    {
                        db.DeleteMeasureRaw(Common.CnvNullToInt(row["measure_id"]));
                    }
                }
            }
        }
Пример #6
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,
                                     Common.CnvNullToInt(txtPort.Text),
                                     Common.CnvNullToInt(txtAlarmValue.Text),
                                     Common.CnvNullToInt(txtPeriod.Text),
                                     Common.CnvNullToInt(txtFailLevel.Text),
                                     Common.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;
                    Common.ShowMsg(MessageBoxIcon.Information, MSG_SAVE_SETTING_SUCCESS);
                }
                else
                {
                    Common.ShowMsg(MessageBoxIcon.Error, MSG_SAVE_SETTING_ERR);
                }
            }
        }
Пример #7
0
 private void btResetDefault_Click(object sender, EventArgs e)
 {
     if (Common.ComfirmMsg(MSG_COMFIRM_RESET))
     {
         using (var objDb = new clsDBUltity())
         {
             if (!objDb.ResetDefauleDevice(_deviceid, _devicetype))
             {
                 Common.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;
         }
     }
 }
Пример #8
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
                {
                    Common.ShowMsg(MessageBoxIcon.Error, MSG_ERR_LOGIN);
                }
            }
        }
Пример #9
0
        private void btSaveChange_Click(object sender, EventArgs e)
        {
            if (!xValidateChangePassword())
            {
                return;
            }

            using (var objDb = new clsDBUltity())
            {
                if (objDb.ChangePasswordUser(Common.UserLoginId, txtCurent.Text, txtNew.Text))
                {
                    Common.ShowMsg(MessageBoxIcon.Information, MSG_CHANGE_PASS_SUCCESS);
                    xResetModeChangePassword();
                }
                else
                {
                    Common.ShowMsg(MessageBoxIcon.Error, MSG_CHANGE_PASS_ERR);
                }
            }
        }
Пример #10
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();
            }
        }
Пример #11
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 (Common.ModeApp != Common.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));
                }
            }
        }
Пример #12
0
        private void grvUser_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1)
            {
                return;
            }

            xModeUser(emModeForm.UpdateUser);

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

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

                if (Common.ComfirmMsg(MSG_COMFIRM_DELETE))
                {
                    using (var objDb = new clsDBUltity())
                    {
                        objDb.DeleteUserById(_userid);
                        xModeUser(emModeForm.CreateNewUser);
                        grvUser.DataSource = objDb.GetMUser();
                        grvUser.ClearSelection();
                    }
                }
            }
        }
Пример #13
0
        private void IntForm()
        {
            PathBase = Application.StartupPath;

            dgvMeasure.AutoGenerateColumns = false;

            using (var objDb = new clsDBUltity())
            {
                // Binding combobox User
                var tblUser = objDb.GetMUser();
                if (tblUser != null)
                {
                    var rowFirst = tblUser.NewRow();
                    rowFirst["username"] = "******";
                    rowFirst["userid"]   = -1;
                    tblUser.Rows.InsertAt(rowFirst, 0);
                    Common.BindingDataTableToComboBox(cmbUser, tblUser, "username", "userid", -1);
                }

                // Binding Type
                cmbType.DisplayMember = "Display";
                cmbType.ValueMember   = "Value";
                cmbType.Items.Add(new { Display = "All type", Value = -1 });
                cmbType.Items.Add(new { Display = "Alarm Test", Value = (int)clsDBUltity.emMeasureType.AlarmTest });
                cmbType.Items.Add(new { Display = "Walking Test", Value = (int)clsDBUltity.emMeasureType.WalkingTest });
                cmbType.SelectedIndex = 0;

                // Binding Status
                cmbStatus.DisplayMember = "Display";
                cmbStatus.ValueMember   = "Value";
                cmbStatus.Items.Add(new { Display = "Complete", Value = (int)clsDBUltity.emMeasureStatus.Complete });
                cmbStatus.Items.Add(new { Display = "Error", Value = (int)clsDBUltity.emMeasureStatus.Error });
                cmbStatus.SelectedIndex = 0;

                var dtStart = new DateTime(dtpStart.Value.Year, dtpStart.Value.Month, dtpStart.Value.Day, 0, 0, 0);
                var dtEnd   = new DateTime(dtpEnd.Value.Year, dtpEnd.Value.Month, dtpEnd.Value.Day, 23, 59, 59);

                var strSDate  = dtStart.ToString(clsDBUltity.cstrDateTimeFormatNoMiliSecond);
                var strEDate  = dtEnd.ToString(clsDBUltity.cstrDateTimeFormatNoMiliSecond);
                int intUser   = Common.CnvNullToInt(cmbUser.SelectedValue);
                int intType   = Common.CnvNullToInt(((dynamic)cmbType.SelectedItem).Value);
                int intResult = Common.CnvNullToInt(((dynamic)cmbResult.SelectedItem).Value);
                int intStatus = Common.CnvNullToInt(((dynamic)cmbStatus.SelectedItem).Value);

                // Binding grid measure
                dgvMeasure.DataSource = objDb.GetTBLMeasure(strSDate, strEDate, intUser, intType, intResult, intStatus);
                dgvMeasure.ClearSelection();
                if (dgvMeasure.Rows.Count > 0)
                {
                    dgvMeasure_CellClick(dgvMeasure, new DataGridViewCellEventArgs(0, 0));
                }

                dgvMeasure.Columns["colEnable"].Visible = false;

                if (Common.ModeApp == Common.emModeApp.User)
                {
                    lblStatus.Visible = false;
                    cmbStatus.Visible = false;
                    dgvMeasure.Columns["colDelete"].Visible = false;
                }
            }
        }
Пример #14
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            if (dgvMeasure.SelectedRows.Count == 1)
            {
                var targetPath = string.Empty;
                // Get value for export
                //var dtStart = new DateTime(dtpStart.Value.Year, dtpStart.Value.Month, dtpStart.Value.Day, 0, 0, 0);
                //var dtEnd = new DateTime(dtpEnd.Value.Year, dtpEnd.Value.Month, dtpEnd.Value.Day, 23, 59, 59);

                var strSDate  = dgvMeasure.CurrentRow.Cells[StartTime.Index].Value.ToString();
                var strEDate  = dgvMeasure.CurrentRow.Cells[EndTime.Index].Value.ToString();
                int intUser   = Common.CnvNullToInt(cmbUser.SelectedValue);
                int intType   = Common.CnvNullToInt(((dynamic)cmbType.SelectedItem).Value);
                int intResult = Common.CnvNullToInt(((dynamic)cmbResult.SelectedItem).Value);

                var intMeasureId   = Common.CnvNullToString(dgvMeasure.CurrentRow.Cells[MeasureID.Index].Value);
                var strDeviceName  = Common.CnvNullToString(dgvMeasure.CurrentRow.Cells[DeviceName.Index].Value);
                var intMeasureType = Common.CnvNullToInt(dgvMeasure.CurrentRow.Cells[MeasureType.Index].Value);
                var strType        = string.Empty;

                if (intMeasureType == (int)clsDBUltity.emMeasureType.AlarmTest)
                {
                    strType = "Alarm Test";
                }
                else if (intMeasureType == (int)clsDBUltity.emMeasureType.WalkingTest)
                {
                    strType = "Walking Test";
                }

                var strResult = Common.CnvNullToString(Common.MeasureResultDisplay(Common.CnvNullToInt(dgvMeasure.CurrentRow.Cells[Result.Index].Value)));
                var strUser   = Common.CnvNullToString(dgvMeasure.CurrentRow.Cells[User.Index].Value);

                // Export excel
                var exportExcel = new AkbExcel();

                TempPath   = (intMeasureType == 0) ? PathBase + SOURCE_PATH + File_Name : PathBase + SOURCE_PATH + File_Name_Walking;
                TargetPath = PathBase + SOURCE_PATH;

                if (!File.Exists(TempPath))
                {
                    Common.ShowMsg(MessageBoxIcon.Warning, "Not excel template");
                    return;
                }

                var flag = false;

                try
                {
                    if (intMeasureType == 0)
                    {
                        var    strAlarmValue = Common.CnvNullToString(dgvMeasure.CurrentRow.Cells[AlarmValue.Index].Value);
                        string dtNow         = DateTime.Now.ToString(clsDBUltity.cstrDateTimeFormatNoMiliSecond);
                        var    sourcePath    = TargetPath + "Report.xlsx";
                        targetPath = ValidateExportExcel(sourcePath, DateTime.Now.ToString("yyyyMMddHHmmss") + "_Report");

                        if (string.IsNullOrEmpty(targetPath))
                        {
                            return;
                        }

                        exportExcel.OpenExcel(targetPath, false, false, sourcePath);

                        using (var objDb = new clsDBUltity())
                        {
                            // Binding grid measure detail
                            var dataExport = objDb.GetTBLMeasureDetail(intMeasureId, chkView.Checked);

                            if (Common.TableIsNullOrEmpty(dataExport))
                            {
                                return;
                            }

                            var cellTimeExport       = new AkbExcelCellCoordinate(3, 5);    //Time export
                            var cellMeasureID        = new AkbExcelCellCoordinate(4, 3);    //Measure ID
                            var cellStart            = new AkbExcelCellCoordinate(5, 3);    //Start
                            var cellEnd              = new AkbExcelCellCoordinate(6, 3);    //End
                            var cellAlarmValue       = new AkbExcelCellCoordinate(7, 3);    //Alarm Value
                            var cellUser             = new AkbExcelCellCoordinate(4, 5);    //Alarm Value
                            var cellType             = new AkbExcelCellCoordinate(5, 5);    //Type
                            var cellResult           = new AkbExcelCellCoordinate(6, 5);    //Result
                            var cellDeviceName       = new AkbExcelCellCoordinate(7, 5);    //Device Name
                            var cellStartBindingGrid = new AkbExcelCellCoordinate(11, 2);   //Starting row to binding data

                            exportExcel.SetCellValue(cellTimeExport, dtNow);
                            exportExcel.SetCellValue(cellMeasureID, intMeasureId);
                            exportExcel.SetCellValue(cellStart, strSDate);
                            exportExcel.SetCellValue(cellEnd, strEDate);
                            exportExcel.SetCellValue(cellAlarmValue, strAlarmValue);
                            exportExcel.SetCellValue(cellUser, strUser);
                            exportExcel.SetCellValue(cellType, strType);
                            exportExcel.SetCellValue(cellResult, strResult);
                            exportExcel.SetCellValue(cellDeviceName, strDeviceName);

                            var objData = new object[dataExport.Rows.Count, 4];
                            int i       = 0;
                            var no      = 0;
                            foreach (DataRow item in dataExport.Rows)
                            {
                                objData[i, 0] = Common.CnvNullToString(++no);
                                objData[i, 1] = Common.CnvNullToString(item["samples_time"]);
                                objData[i, 2] = Common.CnvNullToString(item["actual_delegate"]);
                                objData[i, 3] = Common.CnvNullToString(Common.MeasureResultDisplay(Common.CnvNullToInt(item["result"])));
                                i++;
                            }
                            string strRange = exportExcel.SetRangeValue(cellStartBindingGrid, objData);
                            exportExcel.SetBorderAllRange(strRange, Color.Black);
                            if (!exportExcel.Save())
                            {
                                Common.ShowMsg(MessageBoxIcon.Warning, "Error exporting excel data");
                                return;
                            }
                        }
                    }
                    else
                    {
                        var    strFailLevel = Common.CnvNullToString(dgvMeasure.CurrentRow.Cells[FailLevel.Index].Value);
                        var    strPeriod    = Common.CnvNullToString(dgvMeasure.CurrentRow.Cells[colPeriod.Index].Value);
                        string dtNow        = DateTime.Now.ToString(clsDBUltity.cstrDateTimeFormatMiliSecond);
                        var    sourcePath   = TargetPath + "ReportWalking.xlsx";
                        targetPath = ValidateExportExcel(sourcePath, DateTime.Now.ToString("yyyyMMddHHmmss") + "_ReportWalking");

                        if (string.IsNullOrEmpty(targetPath))
                        {
                            return;
                        }

                        exportExcel.OpenExcel(targetPath, false, false, sourcePath);

                        using (var objDb = new clsDBUltity())
                        {
                            // Get value measure detail limit
                            var dataLimit = objDb.GetTBLMeasureDetailLimit(intMeasureId);

                            // Get value measure detail
                            var dataExport = objDb.GetTBLMeasureDetail(intMeasureId, chkView.Checked);

                            if (Common.TableIsNullOrEmpty(dataLimit) && Common.TableIsNullOrEmpty(dataExport))
                            {
                                return;
                            }

                            var cellTimeExport        = new AkbExcelCellCoordinate(3, 5);   //Time export
                            var cellMeasureID         = new AkbExcelCellCoordinate(4, 3);   //Measure ID
                            var cellStart             = new AkbExcelCellCoordinate(5, 3);   //Start
                            var cellEnd               = new AkbExcelCellCoordinate(6, 3);   //End
                            var cellAlarmValue        = new AkbExcelCellCoordinate(7, 3);   //Alarm Value
                            var cellUser              = new AkbExcelCellCoordinate(4, 5);   //Alarm Value
                            var cellType              = new AkbExcelCellCoordinate(5, 5);   //Type
                            var cellResult            = new AkbExcelCellCoordinate(6, 5);   //Result
                            var cellDeviceName        = new AkbExcelCellCoordinate(7, 5);   //Device Name
                            var cellFailLevel         = new AkbExcelCellCoordinate(8, 3);   //Fail Level
                            var cellStartBindingLimit = new AkbExcelCellCoordinate(12, 2);  //Fail Level
                            var cellStartBindingGrid  = new AkbExcelCellCoordinate(20, 2);  //Starting row to binding data

                            exportExcel.SetCellValue(cellTimeExport, dtNow);
                            exportExcel.SetCellValue(cellMeasureID, intMeasureId);
                            exportExcel.SetCellValue(cellStart, strSDate);
                            exportExcel.SetCellValue(cellEnd, strEDate);
                            exportExcel.SetCellValue(cellAlarmValue, strPeriod);
                            exportExcel.SetCellValue(cellUser, strUser);
                            exportExcel.SetCellValue(cellType, strType);
                            exportExcel.SetCellValue(cellResult, strResult);
                            exportExcel.SetCellValue(cellFailLevel, strFailLevel);
                            exportExcel.SetCellValue(cellDeviceName, strDeviceName);

                            var objLimit = new object[dataLimit.Rows.Count, 3];
                            var j        = 0;
                            var num      = 0;
                            foreach (DataRow item in dataLimit.Rows)
                            {
                                DateTime samplesTime;
                                objLimit[j, 0] = Common.CnvNullToString(++num);

                                if (DateTime.TryParse(Common.CnvNullToString(item["samples_time"]), out samplesTime))
                                {
                                    objLimit[j, 1] = ((DateTime)item["samples_time"]).ToString(clsDBUltity.cstrDateTimeFormatMiliSecond);
                                }
                                else
                                {
                                    objLimit[j, 1] = string.Empty;
                                }

                                objLimit[j, 2] = Common.CnvNullToString(item["actual_delegate"]);
                                j++;
                            }
                            string strRangeLimit = exportExcel.SetRangeValue(cellStartBindingLimit, objLimit);
                            exportExcel.SetBorderAllRange(strRangeLimit, Color.Black);

                            var objData = new object[dataExport.Rows.Count, 3];
                            int i       = 0;
                            var no      = 0;
                            foreach (DataRow item in dataExport.Rows)
                            {
                                DateTime samplesTime;
                                objData[i, 0] = Common.CnvNullToString(++no);

                                if (DateTime.TryParse(Common.CnvNullToString(item["samples_time"]), out samplesTime))
                                {
                                    objData[i, 1] = ((DateTime)item["samples_time"]).ToString(clsDBUltity.cstrDateTimeFormatMiliSecond);
                                }
                                else
                                {
                                    objData[i, 1] = string.Empty;
                                }

                                objData[i, 2] = Common.CnvNullToString(item["actual_value"]);
                                i++;
                            }
                            string strRange = exportExcel.SetRangeValue(cellStartBindingGrid, objData);
                            exportExcel.SetBorderAllRange(strRange, Color.Black);

                            if (!exportExcel.Save())
                            {
                                Common.ShowMsg(MessageBoxIcon.Warning, "Error exporting excel data");
                                return;
                            }
                        }
                    }

                    flag = true;
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    if (exportExcel != null)
                    {
                        exportExcel.CloseExcel();
                    }
                    exportExcel = null;

                    // Open file saved
                    if (flag && Common.ComfirmMsg("Do you want open file?") == true)
                    {
                        if (File.Exists(targetPath))
                        {
                            System.Diagnostics.Process.Start(targetPath);
                        }
                        else
                        {
                            Common.ShowMsg(MessageBoxIcon.Error, "File export not found");
                        }
                    }
                }
            }
            else
            {
                Common.ShowMsg(MessageBoxIcon.Warning, "Please select 1 row data to export excel");
                return;
            }
        }
Пример #15
0
        private void dgvMeasure_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1)
            {
                return;
            }
            dgvMeasureDetail.AutoGenerateColumns = false;

            // btnDelete
            if (e.ColumnIndex == dgvMeasure.Columns["colDelete"].Index && e.RowIndex >= 0)
            {
                var measureid = Common.CnvNullToInt(dgvMeasure.Rows[e.RowIndex].Cells[MeasureID.Index].Value);
                using (var objDb = new clsDBUltity())
                {
                    // Binding grid measure detail
                    if (Common.ComfirmMsg("Do you want delete this record?"))
                    {
                        objDb.DeleteMeasure(measureid);

                        var dtStart = new DateTime(dtpStart.Value.Year, dtpStart.Value.Month, dtpStart.Value.Day, 0, 0, 0);
                        var dtEnd   = new DateTime(dtpEnd.Value.Year, dtpEnd.Value.Month, dtpEnd.Value.Day, 23, 59, 59);

                        var strSDate  = dtStart.ToString(clsDBUltity.cstrDateTimeFormatNoMiliSecond);
                        var strEDate  = dtEnd.ToString(clsDBUltity.cstrDateTimeFormatNoMiliSecond);
                        int intUser   = Common.CnvNullToInt(cmbUser.SelectedValue);
                        int intType   = Common.CnvNullToInt(((dynamic)cmbType.SelectedItem).Value);
                        int intResult = Common.CnvNullToInt(((dynamic)cmbResult.SelectedItem).Value);
                        int intStatus = Common.CnvNullToInt(((dynamic)cmbStatus.SelectedItem).Value);

                        // Binding grid measure
                        dgvMeasure.DataSource = objDb.GetTBLMeasure(strSDate, strEDate, intUser, intType, intResult, intStatus);
                        dgvMeasure.ClearSelection();
                        dgvMeasureDetail.DataSource = null;
                        dgvMeasureDetail.ClearSelection();
                    }
                    else
                    {
                        return;
                    }
                }
                return;
            }

            // btnEnable
            if (e.ColumnIndex == dgvMeasure.Columns["colEnable"].Index && e.RowIndex >= 0 && dgvMeasure.Columns["colEnable"].Visible)
            {
                var      measureid_selected = Common.CnvNullToInt(dgvMeasure.Rows[e.RowIndex].Cells[MeasureID.Index].Value);
                var      pathErrors         = Common.PathDataErrors + @"\" + measureid_selected;
                string[] files = null;

                if (Directory.Exists(pathErrors))
                {
                    files = Directory.GetFiles(pathErrors);
                }
                else
                {
                    using (var fbd = new FolderBrowserDialog())
                    {
                        DialogResult result = fbd.ShowDialog();

                        if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
                        {
                            files = Directory.GetFiles(fbd.SelectedPath);
                        }
                        else
                        {
                            return;
                        }
                    }
                }

                xExecuteNonQueryFromFile(files, measureid_selected);
            }

            var measure_id = Common.CnvNullToString(dgvMeasure.Rows[e.RowIndex].Cells[MeasureID.Index].Value);

            using (var objDb = new clsDBUltity())
            {
                // Binding grid measure detail
                dgvMeasureDetail.DataSource = objDb.GetTBLMeasureDetail(measure_id, chkView.Checked);
                dgvMeasureDetail.ClearSelection();
            }

            // keep selected row after onclick
            int index = e.RowIndex;

            dgvMeasure.Rows[index].Selected = true;
        }