コード例 #1
0
        /// <summary>
        /// Analyzes a business entity against the snapshot and saves log if there has been a change.
        /// Returns true if there has been a change.
        /// </summary>
        /// <param name="entity">The entity to be compared to the snapshot</param>
        /// <param name="userName">The username that's performing the change</param>
        /// <returns></returns>
        public bool SaveChangeLog(MyGeneration.dOOdads.BusinessEntity entity, int userId)
        {
            bool dataChanged = false;

            foreach (DataColumn col in entity.DefaultView.Table.Columns)
            {
                string colBeforeChange = snapShot.GetColumn(col.ColumnName).ToString();
                string colAfterChange  = entity.GetColumn(col.ColumnName).ToString();
                if (colBeforeChange != colAfterChange) //This column has been changed
                {
                    dataChanged = true;
                    LogReceiptChange log = new LogReceiptChange();
                    log.AddNew();
                    log.TableName   = entity.GetType().ToString();
                    log.ColumnName  = col.ColumnName;
                    log.ChangedBy   = userId;
                    log.DateChanged = DateTimeHelper.ServerDateTime;
                    log.RefID       = int.Parse(snapShot.GetColumn("ID").ToString());
                    if (snapShot.GetColumn(col.ColumnName) != null)
                    {
                        log.OldValue = snapShot.GetColumn(col.ColumnName).ToString();
                    }
                    if (entity.GetColumn(col.ColumnName) != null)
                    {
                        log.NewValue = entity.GetColumn(col.ColumnName).ToString();
                    }
                    log.Save();
                }
            }
            return(dataChanged);
        }
コード例 #2
0
 /// <summary>
 /// Analyzes a business entity against the snapshot and saves log if there has been a change.
 /// Returns true if there has been a change.
 /// </summary>
 /// <param name="entity">The entity to be compared to the snapshot</param>
 /// <param name="userName">The username that's performing the change</param>
 /// <returns></returns>
 public bool SaveChangeLog(MyGeneration.dOOdads.BusinessEntity entity, int userId)
 {
     bool dataChanged=false;
     foreach(DataColumn col in entity.DefaultView.Table.Columns)
     {
         string colBeforeChange = snapShot.GetColumn(col.ColumnName).ToString();
         string colAfterChange=entity.GetColumn(col.ColumnName).ToString();
         if (colBeforeChange != colAfterChange) //This column has been changed
         {
             dataChanged = true;
             LogReceiptChange log = new LogReceiptChange();
             log.AddNew();
             log.TableName = entity.GetType().ToString();
             log.ColumnName = col.ColumnName;
             log.ChangedBy = userId;
             log.DateChanged = DateTimeHelper.ServerDateTime;
             log.RefID = int.Parse(snapShot.GetColumn("ID").ToString());
             if (snapShot.GetColumn(col.ColumnName) != null)
                 log.OldValue = snapShot.GetColumn(col.ColumnName).ToString();
             if (entity.GetColumn(col.ColumnName) != null)
                 log.NewValue = entity.GetColumn(col.ColumnName).ToString();
             log.Save();
         }
     }
     return dataChanged;
 }
コード例 #3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            LogReceiptChange change = new LogReceiptChange(rDoc);

            if (txtBatchNo.EditValue != null)
            {
                rDoc.BatchNo = txtBatchNo.Text;
            }
            if (dtExpiry.EditValue != null)
            {
                rDoc.ExpDate = dtExpiry.DateTime;
            }
            else
            {
                rDoc.SetColumnNull("ExpDate");
            }
            if (txtPrice.EditValue != null)
            {
                rDoc.Cost = Convert.ToDouble(txtPrice.EditValue);
            }

            if(lkAccount.EditValue!=null)
            {
                rDoc.StoreID = Convert.ToInt32(lkAccount.EditValue);
                //TODO:Edit other tables as well.
            }

            if(lkUnit.EditValue!=null)
            {
                int unitID = Convert.ToInt32(lkUnit.EditValue);
                if (rDoc.UnitID != unitID)
                {

                    rDoc.UnitID = Convert.ToInt32(lkUnit.EditValue);
                    BLL.ItemUnit itemUnit = new ItemUnit();
                    itemUnit.LoadByPrimaryKey(rDoc.UnitID);
                    rDoc.QtyPerPack = itemUnit.QtyPerUnit;
                    rDoc.Quantity = rDoc.NoOfPack * rDoc.QtyPerPack;
                    rDoc.QuantityLeft = rDoc.Quantity;

                    BLL.ReceivePallet rp = new ReceivePallet();
                    rp.LoadByReceiveDocID(rDoc.ID);
                    rp.Balance = rDoc.QuantityLeft;
                    rp.ReceivedQuantity = rDoc.Quantity;

                    rDoc.Save();
                    rp.Save();
                }
            }

            // decide to save the quantity or not
            //Lord have mercy, this is not a proper way to do it,
            decimal quantity = Convert.ToDecimal(txtQuanitity.EditValue.ToString().Replace(",", ""));

            if (txtQuanitity.Enabled && !rDoc.HasTransactions() && rDoc.Quantity != rDoc.QtyPerPack * quantity)
            {
                // now find the receive pallets
                ReceivePallet receivePallet = new ReceivePallet();
                receivePallet.LoadNonZeroRPByReceiveID(rDoc.ID);
                if (receivePallet.RowCount > 1)
                {
                    //
                    XtraMessageBox.Show(
                        "This Item is stored in more than one location and chaning the quanitity is not implemented. try to consolidate it and try again");
                }
                else
                {

                    rDoc.NoOfPack = quantity;
                    receivePallet.Balance = receivePallet.ReceivedQuantity = rDoc.QuantityLeft = rDoc.Quantity = quantity * rDoc.QtyPerPack;
                    rDoc.Save();
                    receivePallet.Save();
                }
            }
            else if (rDoc.Quantity != quantity * rDoc.QtyPerPack)
            {
                XtraMessageBox.Show("The Quantity was not edited because there was an issue transaction on it.");
            }

            rDoc.RefNo = txtGrvNo.EditValue.ToString();
            //rDoc.SupplierID = Convert.ToInt32(lkSupplier.EditValue);
            if (lkManufacturer.EditValue != null)
                rDoc.ManufacturerId = Convert.ToInt32(lkManufacturer.EditValue);
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            rDoc.Save();
            change.SaveChangeLog(rDoc, CurrentContext.UserId);
            this.LogActivity("Save-Receipt-Change", rDoc.ID);
            this.Close();
        }