public void Delete(UnitOfPurchase unitOfPurchase) { this._itemRepository.Delete(unitOfPurchase); this.Reload("Item"); this.StatusText = string.Format("Satuan beli [{0}] telah dihapus.", unitOfPurchase.Name); }
public bool Save(UnitOfPurchase unitOfPurchase, ObservableCollection <UnitOfPurchase> clusterMembers) { ValidationHelper validation = new ValidationHelper(); bool isSaved = false; int retry = 0; if (validation.HasNoEquals(unitOfPurchase, clusterMembers, this._uopStore)) { if (string.IsNullOrEmpty(unitOfPurchase.Id)) { while ((!isSaved) && (retry < 3)) { unitOfPurchase.Id = "000000"; try { this.InsertData(unitOfPurchase); isSaved = true; } catch (SqlException) { retry++; } } } else { while ((!isSaved) && (retry < 3)) { try { this.UpdateData(unitOfPurchase); isSaved = true; } catch (SqlException) { retry++; } } } if (!isSaved) { MessageBox.Show("Terjadi kesalahan program. Silahkan coba beberapa saat lagi.", "Proses Gagal", MessageBoxButton.OK); } } else { MessageBox.Show(string.Format("Satuan beli dengan nama [{0}] dan kode barang [{1}] telah terdaftar.\n\nPastikan Anda menggunakan nama dan kode barang yang belum terdaftar sebelum melanjutkan proses.", unitOfPurchase.Name, unitOfPurchase.Code), "Proses Gagal", MessageBoxButton.OK); } this.PopulateData(); return(isSaved); }
private ValidationResult Result(UnitOfPurchase property, string errorMessage) { ValidationResult result = new ValidationResult(true, null); if (this.FindInvalid(property).Count > 0) { result = new ValidationResult(false, errorMessage); } return(result); }
public bool Save(UnitOfPurchase unitOfPurchase, ObservableCollection <UnitOfPurchase> clusterMembers) { bool isSaved = false; if (this._uopRepository.Save(unitOfPurchase, clusterMembers)) { isSaved = true; } this.PopulateData(); return(isSaved); }
private void FillTemp(UnitOfPurchase unitOfPurchase) { this.CurrentUnitOfPurchaseTemp = new UnitOfPurchase() { Id = unitOfPurchase.Id, ClusterId = unitOfPurchase.ClusterId, Barcode = unitOfPurchase.Barcode, Code = unitOfPurchase.Code, Name = unitOfPurchase.Name, QtyPerUOP = unitOfPurchase.QtyPerUOP, Status = unitOfPurchase.Status }; }
private void DeleteData(UnitOfPurchase unitOfPurchase) { using (SqlConnection connection = new SqlConnection(this._connString)) { string deleteSql = @"DELETE FROM dbo.posTbUnitOfPurchase WHERE IdUnitOfPurchase = @UOPIdUnitOfPurchase;"; SqlCommand command = new SqlCommand(deleteSql, connection); command.Parameters.Add("@UOPIdUnitOfPurchase", SqlDbType.Char).Value = unitOfPurchase.Id; connection.Open(); command.ExecuteNonQuery(); } }
public void DeleteUnitOfPurchase(UnitOfPurchase unitOfPurchase) { this.CurrentUnitOfPurchase = unitOfPurchase; this.Presenter.Delete(this.CurrentUnitOfPurchase); for (int i = 0; i < this.CurrentItemCollection.Count; i++) { if (this.CurrentItemCollection[i].Equals(this.CurrentItem)) { this.CurrentItem = this.CurrentItemCollection[i]; this.CurrentUnitOfPurchaseCollection = new ObservableCollection <UnitOfPurchase>(this.CurrentItemCollection[i].UnitsOfPurchase); break; } } }
public List <string> FindInvalid(UnitOfPurchase unitOfPurchase) { List <ValidationResult> results = new List <ValidationResult>() { this.Result(unitOfPurchase.Name, " * [Nama satuan beli] tidak dapat dikosongkan.", Enumerable.Range(1, 15)), this.Result(unitOfPurchase.QtyPerUOP, " * Nilai minimum [Jumlah per satuan beli] adalah 1.", Enumerable.Range(1, 9), (int)1) }; IEnumerable <string> found = from result in results where (result.IsValid == false) select result.ErrorContent as string; List <string> errorList = found.ToList(); return(errorList); }
public bool HasNoEquals(UnitOfPurchase unitOfPurchase, ObservableCollection <UnitOfPurchase> clusterMembers, List <UnitOfPurchase> store) { for (int i = 0; i < clusterMembers.Count; i++) { if (clusterMembers[i].Name == unitOfPurchase.Name) { if (!string.IsNullOrEmpty(unitOfPurchase.Id)) { if (clusterMembers[i].Id != unitOfPurchase.Id) { return(false); } } else { return(false); } } } if (!string.IsNullOrEmpty(unitOfPurchase.Code)) { for (int i = 0; i < store.Count; i++) { if (store[i].Code == unitOfPurchase.Code) { if (!string.IsNullOrEmpty(unitOfPurchase.Id)) { if (store[i].Id != unitOfPurchase.Id) { return(false); } } else { return(false); } } } } return(true); }
public bool Save(UnitOfPurchase unitOfPurchase, ObservableCollection <UnitOfPurchase> clusterMembers) { bool isSaved = false; if (this._itemRepository.Save(unitOfPurchase, clusterMembers)) { this.StatusText = string.Format("Satuan beli [{0}] telah disimpan.", unitOfPurchase.Name); isSaved = true; } else { this.StatusText = "Terjadi kesalahan program. Silahkan coba beberapa saat lagi."; } this.Reload("Item"); return(isSaved); }
private void UpdateData(UnitOfPurchase unitOfPurchase) { using (SqlConnection connection = new SqlConnection(this._connString)) { string updateSql = @"UPDATE dbo.posTbUnitOfPurchase SET Barcode = @UOPBarcode, Code = @UOPCode, Name = @UOPName, QtyPerUOP = @UOPQtyPerUOP, Status = @UOPStatus WHERE IdUnitOfPurchase = @UOPIdUnitOfPurchase;"; SqlCommand command = new SqlCommand(updateSql, connection); command.Parameters.Add("@UOPIdUnitOfPurchase", SqlDbType.Char).Value = unitOfPurchase.Id; command.Parameters.Add("@UOPBarcode", SqlDbType.VarChar).Value = unitOfPurchase.Barcode; command.Parameters.Add("@UOPCode", SqlDbType.VarChar).Value = unitOfPurchase.Code; command.Parameters.Add("@UOPName", SqlDbType.VarChar).Value = unitOfPurchase.Name; command.Parameters.Add("@UOPQtyPerUOP", SqlDbType.Int).Value = unitOfPurchase.QtyPerUOP; command.Parameters.Add("@UOPStatus", SqlDbType.Bit).Value = unitOfPurchase.Status; connection.Open(); command.ExecuteNonQuery(); } }
private void InsertData(UnitOfPurchase unitOfPurchase) { using (SqlConnection connection = new SqlConnection(this._connString)) { string insertIntoSql = @"INSERT INTO dbo.posTbUnitOfPurchase (IdUnitOfPurchase, IdItem, Barcode, Code, Name, QtyPerUOP, Status) VALUES (@UOPIdUnitOfPurchase, @UOPClusterId, @UOPBarcode, @UOPCode, @UOPName, @UOPQtyPerUOP, @UOPStatus);"; SqlCommand command = new SqlCommand(insertIntoSql, connection); command.Parameters.Add("@UOPIdUnitOfPurchase", SqlDbType.Char).Value = unitOfPurchase.Id; command.Parameters.Add("@UOPClusterId", SqlDbType.Char).Value = unitOfPurchase.ClusterId; command.Parameters.Add("@UOPBarcode", SqlDbType.VarChar).Value = unitOfPurchase.Barcode; command.Parameters.Add("@UOPCode", SqlDbType.VarChar).Value = unitOfPurchase.Code; command.Parameters.Add("@UOPName", SqlDbType.VarChar).Value = unitOfPurchase.Name; command.Parameters.Add("@UOPQtyPerUOP", SqlDbType.Int).Value = unitOfPurchase.QtyPerUOP; command.Parameters.Add("@UOPStatus", SqlDbType.Bit).Value = unitOfPurchase.Status; connection.Open(); command.ExecuteNonQuery(); } }
public void Delete(UnitOfPurchase unitOfPurchase) { this.DeleteData(unitOfPurchase); this.PopulateData(); }
public void Delete(UnitOfPurchase unitOfPurchase) { this._uopRepository.Delete(unitOfPurchase); this.PopulateData(); }
public void UnitOfPurchaseDetail(UnitOfPurchase unitOfPurchase) { this.CurrentUnitOfPurchase = unitOfPurchase; this.FillTemp(unitOfPurchase); }