Пример #1
0
        private void LockerCabinetPage()
        {
            _cabinetStatus = "<> 'Disabled'";

            string condition = "status {0} AND locker_type_id {1}";

            condition = String.Format(condition, _cabinetStatus, _cabinetSize);

            _lockerCabinetPage.FinalIndex = Cabinet.Count(condition);
            _lockerCabinetPage.LastPage   = Convert.ToInt32(Math.Ceiling(_lockerCabinetPage.FinalIndex / _lockerCabinetPage.MaxItems));
            _lockerCabinetPage.PageSetting();

            if (_lockerCabinetPage.FinalIndex == 0)
            {
                _lockerCabinetPage.PageReset();
            }


            if (_lockerCabinetPage.PageNumber == _lockerCabinetPage.LastPage)
            {
                _lockerCabinetPage.LastIndex = (int)_lockerCabinetPage.FinalIndex;
            }

            toolStripLabelPageNoLockerCabinet.Text = String.Format("Page {0} / {1}", _lockerCabinetPage.PageNumber, _lockerCabinetPage.LastPage);

            ReloadLockerCabinetList(_lockerCabinetPage.IndexLimit, _lockerCabinetPage.MaxItems, condition);
        }
 // Function to verify cabinet code
 public void CheckCabinet()
 {
     if (Cabinet.Count(String.Format("code = '{0}'", _cabinetCode)) <= 0)
     {
         throw new InvalidCabinetException("Invalid Cabinet", _cabinetCode);
     }
 }
        public void DeleteLockerTypeData(int id)
        {
            // Check if any cabinet exists for this locker type. If yes, show error.
            if (Cabinet.Count(String.Format("locker_type_id = {0} AND status <> 'Disabled'", id)) > 0)
            {
                throw new InvalidUserInputException("Delete Error - Locker Type Cabinet");
            }

            // Delete the locker type
            LockerType deletedLockerType = LockerType.Get(id);

            deletedLockerType.TempDelete();
        }
        public void ExportLockerTypeData(int id)
        {
            var    delType         = LockerType.Where(String.Format("id = {0}", id), 0, 1);
            string defaultFileName = String.Format("EXPORT_LOCKER_TYPE_{0}_{1}", id, DateTime.Now.ToString("ddMMyyyy_HHmmss"));

            int noOfCabinet = Cabinet.Count(String.Format("locker_type_id = {0}", id));

            if (noOfCabinet > 0)
            {
                throw new InvalidUserInputException("Export Fail - Cabinet");
            }

            var workbook = new XLWorkbook();
            var ws       = workbook.AddWorksheet("DeletedCabinet");

            ws.Cell(1, 1).Value = "Locker Type";
            ws.Cell(2, 1).InsertTable(delType);

            SaveFileDialog sf = new SaveFileDialog
            {
                FileName    = defaultFileName,
                Filter      = "Excel Workbook (.xlsx) |*.xlsx",
                Title       = "Export Locker Type as",
                FilterIndex = 1
            };

            if (sf.ShowDialog() == DialogResult.OK)
            {
                string savePath = Path.GetDirectoryName(sf.FileName);
                string fileName = Path.GetFileName(sf.FileName);
                string saveFile = Path.Combine(savePath, fileName);
                try
                {
                    workbook.SaveAs(saveFile); //Save the file

                    delType[0].Delete();
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message);
                    throw new InvalidUserInputException("Export Fail", "", "", "locker type");
                }
            }
            else
            {
                throw new InvalidUserInputException("Export Fail", "", "", "locker type");
            }
        }