public List <LocationBarcode> GetSearchSection(LocationManagementModel searchSection) { List <LocationManagementModel> searchSectionList = locationDAO.GetSectionOptionalKey(searchSection.SectionCode, searchSection.SectionName, searchSection.LocationFrom, searchSection.LocationTo, searchSection.SectionType, searchSection.DepartmentCode); if (searchSectionList.Count() == 0) { return(null); } else { List <LocationBarcode> searchDataList = GenDataToDisplay(searchSectionList, searchSection); return(searchDataList); } }
private void searchButton_Click(object sender, EventArgs e) { try { this.resultGridView.Rows.Clear(); LocationManagementModel searchSection = GetSearchCondition(); int x; bool resultValidate = true; if (!(string.IsNullOrWhiteSpace(searchSection.LocationFrom.Trim()))) { if (!(Int32.TryParse(searchSection.LocationFrom.Trim(), out x))) { resultValidate = false; MessageBox.Show(MessageConstants.LocationFrommustbenumberonly, MessageConstants.TitleWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } if (!(string.IsNullOrWhiteSpace(searchSection.LocationTo.Trim()))) { if (!(Int32.TryParse(searchSection.LocationTo.Trim(), out x))) { resultValidate = false; MessageBox.Show(MessageConstants.LocationTomustbenumberonly, MessageConstants.TitleWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } if (!(string.IsNullOrWhiteSpace(searchSection.SectionCode.Trim()))) { if (!(Int32.TryParse(searchSection.SectionCode.Trim(), out x))) { resultValidate = false; MessageBox.Show(MessageConstants.Sectioncodemustbenumberonly, MessageConstants.TitleWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } if (!(string.IsNullOrWhiteSpace(searchSection.DepartmentCode.Trim()))) { if (!(Int32.TryParse(searchSection.DepartmentCode.Trim(), out x))) { resultValidate = false; MessageBox.Show(MessageConstants.Departmentisnumberonly, MessageConstants.TitleWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } if (resultValidate) { displayData = barcodeBLL.GetSearchSection(searchSection); if (displayData == null) { MessageBox.Show(MessageConstants.Nosectiondatafound, MessageConstants.TitleInfomation, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { foreach (LocationBarcode result in displayData) { this.resultGridView.Rows.Add(result.LocationCode, result.SectionCode, result.SectionName); } if (this.resultGridView.Rows.Count <= 0) { MessageBox.Show(MessageConstants.Nosectiondatafound, MessageConstants.TitleInfomation, MessageBoxButtons.OK, MessageBoxIcon.Information); } } } } catch (Exception ex) { log.Error(String.Format("Exception : {0}", ex.StackTrace)); } }
private List <LocationBarcode> GenDataToDisplay(List <LocationManagementModel> resultData, LocationManagementModel searchSection) { List <LocationBarcode> dataToDisplay = new List <LocationBarcode>(); foreach (LocationManagementModel data in resultData) { if (string.IsNullOrWhiteSpace(searchSection.LocationFrom) && string.IsNullOrWhiteSpace(searchSection.LocationTo)) { int sectionFrom = Int32.Parse(data.LocationFrom); int sectionTo = Int32.Parse(data.LocationTo); for (int i = sectionFrom; i <= sectionTo; i++) { LocationBarcode section = new LocationBarcode(); section.SectionCode = data.SectionCode; section.SectionName = data.SectionName; section.Location = i.ToString().PadLeft(5, '0'); section.LocationCode = "Section Code " + data.SectionCode + " , Location " + section.Location; dataToDisplay.Add(section); } } else if (string.IsNullOrWhiteSpace(searchSection.LocationFrom)) { int sectionFrom = Int32.Parse(data.LocationFrom); int sectionTo = Int32.Parse(data.LocationTo); int searchLocalTo = Int32.Parse(searchSection.LocationTo); for (int i = sectionFrom; i <= sectionTo; i++) { if (i == searchLocalTo) { LocationBarcode section = new LocationBarcode(); section.SectionCode = data.SectionCode; section.SectionName = data.SectionName; section.Location = i.ToString().PadLeft(5, '0'); section.LocationCode = "Section Code " + data.SectionCode + " , Location " + section.Location; dataToDisplay.Add(section); break; } } } else if (string.IsNullOrWhiteSpace(searchSection.LocationTo)) { int sectionFrom = Int32.Parse(data.LocationFrom); int sectionTo = Int32.Parse(data.LocationTo); int searchLocalFrom = Int32.Parse(searchSection.LocationFrom); for (int i = sectionFrom; i <= sectionTo; i++) { if (i == searchLocalFrom) { LocationBarcode section = new LocationBarcode(); section.SectionCode = data.SectionCode; section.SectionName = data.SectionName; section.Location = i.ToString().PadLeft(5, '0'); section.LocationCode = "Section Code " + data.SectionCode + " , Location " + section.Location; dataToDisplay.Add(section); break; } } } else { int searchLocalFrom = Int32.Parse(searchSection.LocationFrom); int searchLocalTo = Int32.Parse(searchSection.LocationTo); int dataFrom = Int32.Parse(data.LocationFrom); int dataTo = Int32.Parse(data.LocationTo); if (dataFrom < searchLocalFrom) { dataFrom = searchLocalFrom; } for (int i = dataFrom; i <= dataTo; i++) { if (i > searchLocalTo) { break; } LocationBarcode section = new LocationBarcode(); section.SectionCode = data.SectionCode; section.SectionName = data.SectionName; section.Location = i.ToString().PadLeft(5, '0'); section.LocationCode = "Section Code " + data.SectionCode + " , Location " + section.Location; dataToDisplay.Add(section); } } } return(dataToDisplay); }
private LocationManagementModel GetSearchCondition() { //sectioncode if (textBoxSecCode.Text.Trim().Length == 1) { textBoxSecCode.Text = "0000" + textBoxSecCode.Text.Trim(); } else if (textBoxSecCode.Text.Trim().Length == 2) { textBoxSecCode.Text = "000" + textBoxSecCode.Text.Trim(); } else if (textBoxSecCode.Text.Trim().Length == 3) { textBoxSecCode.Text = "00" + textBoxSecCode.Text.Trim(); } else if (textBoxSecCode.Text.Trim().Length == 4) { textBoxSecCode.Text = "0" + textBoxSecCode.Text.Trim(); } ////locationfrom if (textBoxLoFrom.Text.Trim().Length == 1) { textBoxLoFrom.Text = "0000" + textBoxLoFrom.Text.Trim(); } else if (textBoxLoFrom.Text.Trim().Length == 2) { textBoxLoFrom.Text = "000" + textBoxLoFrom.Text.Trim(); } else if (textBoxLoFrom.Text.Trim().Length == 3) { textBoxLoFrom.Text = "00" + textBoxLoFrom.Text.Trim(); } else if (textBoxLoFrom.Text.Trim().Length == 4) { textBoxLoFrom.Text = "0" + textBoxLoFrom.Text.Trim(); } ////locationto if (textBoxLoTo.Text.Trim().Length == 1) { textBoxLoTo.Text = "0000" + textBoxLoTo.Text.Trim(); } else if (textBoxLoTo.Text.Trim().Length == 2) { textBoxLoTo.Text = "000" + textBoxLoTo.Text.Trim(); } else if (textBoxLoTo.Text.Trim().Length == 3) { textBoxLoTo.Text = "00" + textBoxLoTo.Text.Trim(); } else if (textBoxLoTo.Text.Trim().Length == 4) { textBoxLoTo.Text = "0" + textBoxLoTo.Text.Trim(); } LocationManagementModel searchSection = new LocationManagementModel(); searchSection.SectionCode = textBoxSecCode.Text; searchSection.SectionName = textBoxSecName.Text; searchSection.LocationFrom = textBoxLoFrom.Text; searchSection.LocationTo = textBoxLoTo.Text; searchSection.DepartmentCode = textBoxDeptCode.Text; string sectionTypeList = ""; foreach (CheckBox sectionType in groupSectionType.Controls) { if (sectionType.Checked == true) { sectionTypeList = sectionTypeList + (sectionTypeList == "" ? "" : "|") + (string)sectionType.Text; } } searchSection.SectionType = sectionTypeList; return(searchSection); }