protected void btnProcess_Click(object sender, EventArgs e) { var items = gridCondition.GetSelectedFieldValues(new string[] { "ItemId", "StationId" }); if (items.Any()) { foreach (var item in items) { //convert object to readable type IEnumerable <object> prodItem = (IEnumerable <object>)item; var _itemId = Convert.ToInt32(prodItem.FirstOrDefault().ToString()); var _stationId = Convert.ToInt32(prodItem.LastOrDefault().ToString()); //get history item var histItem = ProductionRepository.GetProductionItemByHistoryStation(_stationId, _itemId); if (_condition == "isVoca") { //check if this car still have fault to solve if (FaultRepository.IsHaveFault(_itemId)) { ScriptManager.RegisterClientScriptBlock(this, GetType(), "alertMessage", @"alert('There are still unfinished fault, please solve this first.');", true); } else if (ProductionRepository.UpdateProductionHistoryVOCA(_itemId, false)) { // insert new inventory if (ProductionRepository.InsertProductionInventory(_itemId, assemblyTypeId) > 0) { //update this last item production history detail if (ProductionRepository.UpdateProductionHistoryDetail(_itemId, _stationId, histItem.IsOffline, histItem.IsRectification, histItem.IsOffline, histItem.IsRectification, true)) { //update production history status to complete if (ProductionRepository.UpdateProductionHistoryComplete(_itemId)) { //update all existing assembly for this part ProductionRepository.UpdateAllSubAssyBySerialNumber(histItem.FINNumber); //load data LoadData(); } else { ScriptManager.RegisterClientScriptBlock(this, GetType(), "alertMessage", @"alert('Failed Update Production History, please contact your administrator');", true); } } else { ScriptManager.RegisterClientScriptBlock(this, GetType(), "alertMessage", @"alert('Failed Update Production History Details, please contact your administrator');", true); } } else { ScriptManager.RegisterClientScriptBlock(this, GetType(), "alertMessage", @"alert('Failed Insert New Inventory, please contact your administrator');", true); } } else { ScriptManager.RegisterClientScriptBlock(this, GetType(), "alertMessage", @"alert('Failed Insert New Inventory, please contact your administrator');", true); } } else { var newStationId = _condition == "isRecti" ? ProductionRepository.GetFirstEndOfLineStation(assemblyTypeId) : ProductionRepository.GetFirstStation(assemblyTypeId); //insert new station detail to start eol if (0 != ProductionRepository.InsertProductionHistoryDetail(histItem.ItemId, newStationId, _condition == "isRecti" ? histItem.IsOffline : false, _condition == "isRecti" ? false : histItem.IsRectification, "")) { //update last un done history detail if (ProductionRepository.UpdateProductionHistoryDetail(histItem.ItemId, histItem.StationId, histItem.IsOffline, histItem.IsRectification, histItem.IsOffline, true, true)) { if (_condition == "isRecti") { ProductionRepository.UpdateAllSubAssyBySerialNumber(histItem.FINNumber); } //todo success LoadData(); } else { ScriptManager.RegisterClientScriptBlock(this, GetType(), "alertMessage", @"alert('Cannot update last history details.');", true); } } else { ScriptManager.RegisterClientScriptBlock(this, GetType(), "alertMessage", @"alert('Cannot send " + histItem.FINNumber + " to " + _condition == "isRecti" ? "End of Line" : "Trimming Line" + ".');", true); } } } } else { ScriptManager.RegisterClientScriptBlock(this, GetType(), "alertMessage", @"alert('No Rows Selected.');", true); } }