예제 #1
0
        private void BindRequest(int index, int size)
        {
            var result = DeviceHelperClient.GetDeviceList(index, size, QueryString);

            if (result == null || result.TotalCount == 0 || result.Source == null || result.Source.Rows.Count == 0)
            {
                Source    = null;
                PageTotal = 0;
                DataTotal = 0;
            }
            else
            {
                Source    = ConvertSource(result.Source);
                PageTotal = result.TotalCount % PageSize == 0 ? result.TotalCount / PageSize : result.TotalCount / PageSize + 1;
                DataTotal = result.TotalCount;
            }

            BindToGrid(Source);

            Numbers.Text        = string.Format("/ {0}", PageTotal);
            DataTotalLabel.Text = string.Format("共有数据 " + DataTotal + " 条");
            First.Enabled       = Previous.Enabled = PageIndex > 1;
            Next.Enabled        = Last.Enabled = PageIndex < PageTotal;

            Search.Enabled = true;

            if (PageIndex > PageTotal)
            {
                PageIndex = PageTotal;
            }

            Index.Text = PageIndex + "";
        }
예제 #2
0
        private void Reset()
        {
            var room = TestRoom.SelectedItem as PrjFolder;

            if (room == null || string.IsNullOrEmpty(room.FolderCode))
            {
                return;
            }

            MachineCode.Text = DeviceHelperClient.GenerateMachineCode(room.FolderCode);
            RemoteCode1.Text = RemoteCode2.Text = "";
        }
예제 #3
0
        private void MachineCode_Validating(object sender, CancelEventArgs e)
        {
            var code = MachineCode.Text;

            if (!string.IsNullOrEmpty(code))
            {
                if (code.Length == 20)
                {
                    if (code.Substring(0, 16) == TestRoom.SelectedValue.ToString())
                    {
                        var table = DeviceHelperClient.GetDevice(code);
                        if (table == null || table.Rows.Count == 0)
                        {
                            Errors.SetError(MachineCode, "");
                            return;
                        }
                        else
                        {
                            if (Source == null)
                            {
                                Errors.SetError(MachineCode, "设备编码不能重复");
                            }
                            else
                            {
                                if (table.Rows[0]["ID"].ToString() != Source.Device.ID.ToString())
                                {
                                    Errors.SetError(MachineCode, "设备编码与其他的设备重复,请设置新的编码");
                                }
                                else
                                {
                                    return;
                                }
                            }
                        }
                    }
                    else
                    {
                        Errors.SetError(MachineCode, "编码后4位无效");
                    }
                }
                else
                {
                    Errors.SetError(MachineCode, "设备编码必须为20位数字");
                }
            }
            else
            {
                Errors.SetError(MachineCode, "请输入试验室编码");
            }

            e.Cancel = true;
        }
예제 #4
0
        private void Modify()
        {
            var device = GetDeviceFill(Source.Device);
            var result = DeviceHelperClient.EditDevice(device);

            if (result.HasValue && result.Value)
            {
                MessageBox.Show("修改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //Tip.Show("修改成功", MachineCode);
            }
            else
            {
                MessageBox.Show("抱歉,没有修改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
예제 #5
0
        private void GenerateMachineCode_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            //if (++GenerateCount >= 5)
            //{
            //    MachineCode.ReadOnly = false;
            //}

            var room = TestRoom.SelectedItem as PrjFolder;

            if (room == null || string.IsNullOrEmpty(room.FolderCode))
            {
                return;
            }

            MachineCode.Text = DeviceHelperClient.GenerateMachineCode(room.FolderCode);
        }
예제 #6
0
        private void Add()
        {
            var device = GetDeviceFill(null);
            var result = DeviceHelperClient.AddDevice(device);

            if (result.HasValue && result.Value)
            {
                //MessageBox.Show("添加成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Reset();
                //Tip.Show("添加成功", this.MachineCode, 5 * 1000);
                MessageBox.Show("添加成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("抱歉,没有添加成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
예제 #7
0
        private void TestRoom_SelectedIndexChanged(object sender, EventArgs e)
        {
            var room = TestRoom.SelectedItem as PrjFolder;

            if (room == null || string.IsNullOrEmpty(room.FolderCode))
            {
                return;
            }

            if (Source == null)
            {
                MachineCode.Text = DeviceHelperClient.GenerateMachineCode(room.FolderCode);
            }
            else
            {
                MachineCode.Text = Source.Device.MachineCode;
            }
        }
예제 #8
0
        private void Delete_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定要删除吗?", "询问", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                var ids = new List <string>();
                ids.Add(Source.Device.ID.ToString());

                var result = DeviceHelperClient.DeleteDevice(ids);
                if (result.HasValue && result.Value)
                {
                    MessageBox.Show("已删除", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
                else
                {
                    MessageBox.Show("删除失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
예제 #9
0
        private void Delete_Click(object sender, EventArgs e)
        {
            var selections = Cells.Selections;
            var sheet      = Cells.Sheets[0];
            var ids        = new List <string>();

            if (selections.Count == 0)
            {
                MessageBox.Show("请选择要修改的项目", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (MessageBox.Show("确定要删除所选项吗?", "询问", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
            {
                return;
            }

            foreach (var selection in selections)
            {
                for (int index = -1; index < selection.RowCount; index++)
                {
                    //至少执行一次下方的代码,即使 selection.RowCount = 0 的情况下
                    if (index == -1)
                    {
                        index = 0;
                    }


                    var i = selection.Row + index;

                    if (Source.Count > i)
                    {
                        ids.Add(Source[i].Device.ID.ToString());
                    }
                }
            }

            DeviceHelperClient.DeleteDevice(ids);
            MessageBox.Show("已删除", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            Go(0);
        }
예제 #10
0
        private DataSet QuerySet(SheetView sheet, int pageIndex, int pageSize, int meet)
        {
            var testRoomCode = "";

            if (ComboBox_TestRooms.SelectedItem is PrjFolder)
            {
                testRoomCode = (ComboBox_TestRooms.SelectedItem as PrjFolder).FolderCode;
            }
            else
            {
                testRoomCode = "";
            }


            var dataset = DeviceHelperClient.GetDeviceSummary(testRoomCode, meet, pageIndex, pageSize);

            if (dataset != null)
            {
                var total    = int.Parse(dataset.Tables[1].Rows[0][0].ToString());
                var summary  = dataset.Tables[0];
                var rowIndex = -1;
                var now      = DateTime.Now;

                if (summary != null)
                {
                    sheet.Rows.Count = pageSize > summary.Rows.Count ? summary.Rows.Count : pageSize;

                    foreach (DataRow row in summary.Rows)
                    {
                        rowIndex++;
                        sheet.Cells[rowIndex, 0].Value  = row["标段名称"];
                        sheet.Cells[rowIndex, 1].Value  = row["单位名称"];
                        sheet.Cells[rowIndex, 2].Value  = row["试验室名称"];
                        sheet.Cells[rowIndex, 3].Value  = row["管理编号"];
                        sheet.Cells[rowIndex, 4].Value  = row["设备名称"];
                        sheet.Cells[rowIndex, 5].Value  = row["生产厂家"];
                        sheet.Cells[rowIndex, 6].Value  = row["规格型号"];
                        sheet.Cells[rowIndex, 7].Value  = row["数量"];
                        sheet.Cells[rowIndex, 8].Value  = row["检定情况"];
                        sheet.Cells[rowIndex, 9].Value  = row["检定证书编号"];
                        sheet.Cells[rowIndex, 12].Value = row["检定周期"];
                        sheet.Rows[rowIndex].Tag        = row["id"];
                        sheet.Cells[rowIndex, 2].Tag    = row["试验室编码"];

                        DateTime start;
                        DateTime end;
                        bool     equal = true;
                        if (DateTime.TryParse(row["上次校验日期"].ToString(), out start))
                        {
                            sheet.Cells[rowIndex, 10].Value = start.ToString("yyyy年MM月dd日");
                        }
                        else
                        {
                            sheet.Cells[rowIndex, 10].BackColor = Color.FromArgb(110, 110, 110);
                            equal = false;
                        }

                        if (DateTime.TryParse(row["预计下次校验日期"].ToString(), out end))
                        {
                            sheet.Cells[rowIndex, 11].Value = end.ToString("yyyy年MM月dd日");
                        }
                        else
                        {
                            sheet.Cells[rowIndex, 11].BackColor = Color.FromArgb(110, 110, 110);
                            equal = false;
                        }

                        if (equal)
                        {
                            if (now > start && now < end)
                            {
                                sheet.Cells[rowIndex, 13].Value = "否";
                            }
                            else
                            {
                                sheet.Rows[rowIndex].BackColor  = Color.FromArgb(255, 86, 64);
                                sheet.Cells[rowIndex, 13].Value = "是";
                            }

                            int? unit;
                            bool?year;
                            var  c = row["检定周期"] == DBNull.Value ? "" : row["检定周期"].ToString();
                            ParseCycle(c, out unit, out year);
                            if (year.HasValue && unit.HasValue)
                            {
                                var time = default(DateTime);
                                if (year.Value == true)
                                {
                                    time = start.AddYears(unit.Value);
                                }
                                else
                                {
                                    time = end.AddMonths(unit.Value);
                                }

                                var dif = Math.Abs((end - time).TotalDays);
                                if (dif >= 2)
                                {
                                    sheet.Cells[rowIndex, 12].BackColor = Color.FromArgb(56, 178, 206);
                                }
                            }
                            else
                            {
                                sheet.Cells[rowIndex, 12].BackColor = Color.FromArgb(110, 110, 110);
                            }
                        }
                    }

                    return(dataset);
                }
            }

            return(dataset);
        }