コード例 #1
0
        public bool DeleteABSAMember(BSAMemberViewModel item)
        {
            //Connect to the Umbraco DB
            var db = new PetaPoco.Database(sConnectString);

            BSAMember oModel = new BSAMember();

            oModel.BSAMemberId      = item.BSAMemberId;
            oModel.BSAMemberType    = item.BSAMemberType;
            oModel.FirstName        = item.FirstName;
            oModel.LastName         = item.LastName;
            oModel.StreetAddress    = item.StreetAddress;
            oModel.City             = item.City;
            oModel.State            = item.State;
            oModel.ZipCode          = item.ZipCode;
            oModel.District         = item.District;
            oModel.Council          = item.Council;
            oModel.Troop            = item.Troop;
            oModel.Crew             = item.Crew;
            oModel.Telephone        = item.Telephone;
            oModel.BirthDate        = item.BirthDate;
            oModel.EmailAddress     = item.EmailAddress;
            oModel.ScoutMasterId    = item.ScoutMasterId;
            oModel.BackGroundCheck  = item.BackGroundCheck;
            oModel.DeleteRecordFlag = true;

            db.Update(oModel);

            //Return the view with our model and comments
            return(true);
        }
コード例 #2
0
 public static void UpdateCampaign(Campaign campaign)
 {
     using (IDatabase db = new PetaPoco.Database(Settings.ConnectionString, providerName: "SqlServer"))
     {
         db.Update(campaign);
     }
 }
コード例 #3
0
ファイル: IndexDao.cs プロジェクト: RodH257/RetrEave
        /// <summary>
        /// Craetes/updates an index
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public RetreaveIndex SaveOrUpdate(RetreaveIndex entity)
        {
            if (_database.IsNew(entity))
            {
                _database.Insert(entity);
            }
            else
            {
                _database.Update(entity);
            }

            //update the associated users
            _database.Execute("Delete from Users_Indexes where indexId=@0", entity.IndexId);

            foreach (RegisteredUser user in entity.AssociatedUsers)
            {
                if (_database.IsNew(user))
                {
                    throw new Exception("You must save the User entity first");
                }

                _database.Execute("Insert into Users_indexes (UserId, IndexId) values (@0, @1)", user.UserId,
                                  entity.IndexId);
            }
            return(entity);
        }
コード例 #4
0
ファイル: RegisteredUserDao.cs プロジェクト: RodH257/RetrEave
        /// <summary>
        /// UpSerts the user
        /// </summary>
        public RegisteredUser SaveOrUpdate(RegisteredUser entity)
        {
            if (_database.IsNew(entity))
            {
                _database.Insert(entity);
                //save the authentication details
                _database.Insert(entity.AuthDetails);
            }
            else
            {
                _database.Update(entity);
            }

            _database.Update <RegisteredUser>("SET AuthenticationDetails = @0 where UserId=@1",
                                              entity.AuthDetails.AuthenticationDetailsId, entity.UserId);
            return(entity);
        }
コード例 #5
0
 public static void Save(Database db, Purchase purchase)
 {
     var existing = db.SingleOrDefault<Purchase>("SELECT * FROM purchases WHERE UniqueId=@0 ", purchase.UniqueId);
     if (existing != null)
         db.Update("purchases", "PurchaseId", existing);
     else
         db.Insert("purchases", "PurchaseId", purchase);
 }
コード例 #6
0
        public static void Xoa(string id, sanpham sp)
        {
            var db = new PetaPoco.Database("DienThoaiShopConnection");

            //db.Delete<sanpham>("where MaSanPham=@0", id);
            sp       = ChiTietSanPham(id);
            sp.BiXoa = 1;
            db.Update("sanpham", "MaSanPham", sp);
            //var a = new sanpham();
            //var db = new PetaPoco.Database("DienThoaiShopConnection");
            //db.Delete("sanpham", "MaSanPham", null, a);
        }
コード例 #7
0
 public static BoolMessage PpUpdate(object o)
 {
     _checkVal.Data = null;
     try
     {
         if (string.IsNullOrEmpty(_cstring))
         {
             throw new Exception("No connection string provided");
         }
         int rows = _pp.Update(o);
         _checkVal.Success = true;
         _checkVal.Message = string.Format("Successfully updated {0} rows", rows);
     }
     catch (Exception ex)
     {
         _checkVal.Success = false;
         _checkVal.Message = ex.Message;
     }
     return(_checkVal);
 }
コード例 #8
0
        private int SaveABSAMemberRecord(BSAMemberViewModel item)
        {
            //Connect to the Umbraco DB
            var db = new PetaPoco.Database(sConnectString);

            BSAMember oModel = new BSAMember();

            oModel.BSAMemberId      = item.BSAMemberId;
            oModel.UserName         = item.UserName;
            oModel.Password         = item.Password;
            oModel.BSAMemberType    = item.BSAMemberType;
            oModel.FirstName        = item.FirstName;
            oModel.LastName         = item.LastName;
            oModel.StreetAddress    = item.StreetAddress;
            oModel.City             = item.City;
            oModel.State            = item.State;
            oModel.ZipCode          = item.ZipCode;
            oModel.District         = item.District;
            oModel.Council          = item.Council;
            oModel.Troop            = item.Troop;
            oModel.Crew             = item.Crew;
            oModel.ScoutMasterId    = item.ScoutMasterId;
            oModel.Telephone        = item.Telephone;
            oModel.BirthDate        = item.BirthDate;
            oModel.EmailAddress     = item.EmailAddress;
            oModel.BackGroundCheck  = item.BackGroundCheck;
            oModel.DeleteRecordFlag = false;

            if (item.BSAMemberId > 0)
            {
                db.Update(oModel);
            }
            else
            {
                db.Insert(oModel);
            }

            //Return the view with our model and comments
            return(oModel.BSAMemberId);
        }
コード例 #9
0
ファイル: NewView.cs プロジェクト: MasterGao/DevWinFormFrame
 private void btnOK_Click(object sender, EventArgs e)
 {
     if (!dxValidationProvider1.Validate()) return;
     if (EditMode == Ultra.Web.Core.Enums.EnViewEditMode.New)
     {
         using (var db = new Database())
         {
             var et = db.FirstOrDefault<t_role>("where Name=@0", txtname.Text.Trim());
             if (null != et)
             {
                 MsgBox.ShowMessage(null, "名称已存在,不可重复添加!");
                 return;
             }
             db.Save(new t_role
             {
                 Guid = Guid.NewGuid(),
                 IsUsing = chk.Checked,
                 Name = txtname.Text.Trim(),
                 Creator = this.CurUser,
                 Desc=txtdesc.Text.Trim(),
                 CreateDate=TimeSync.Default.CurrentSyncTime,
                 Remark=string.Empty
             });
         }
     } else if (EditMode == Ultra.Web.Core.Enums.EnViewEditMode.Edit)
     {
         using (var db = new Database())
         {
             var et = db.FirstOrDefault<t_role>(" where guid=@0", GuidKey);
             if (et != null)
             {
                 db.Update<t_role>(" set isusing=@0,[desc]=@1 where guid=@2", chk.Checked, txtdesc.Text.Trim(), et.Guid);
             }
         }
     }
     DialogResult = System.Windows.Forms.DialogResult.OK;
     Close();
 }
コード例 #10
0
ファイル: MainView.cs プロジェクト: ZixiangBoy/YongERP
 private void UpdatePrintCnt(List<t_trade> trds)
 {
     var whr = trds.Select(k => k.Guid.ToString()).Aggregate((s1, s2) => s1 + "','" + s2);
     using (var db = new Database()) {
         db.Update<t_trade>(string.Format(" set printcnt=isnull(printcnt,0)+1 where guid in ('{0}')", whr));
     }
 }
コード例 #11
0
ファイル: Program.cs プロジェクト: openpermit/OpenPermit.NET
        static void Main(string[] args)
        {
            try
            {
                SendEMail("Started MDC OpenPermit Sync");
                Console.WriteLine("Sync Job Started on: " + DateTime.Now.ToString());              
                Console.WriteLine("Bringing data from Socrata");
                var permits = getPermitsToSync();

                Database db = new Database("openpermit");

                Console.WriteLine("Inserting Data into DB");
                foreach (Permit permit in permits.Item1)
                {
                    try
                    {
                        processMDCInpsections(permit, db);
                        db.Insert("Permit", "PermitNum", false, permit);
                    }
                    catch (Exception ex)
                    {
                        string errorMsg = String.Format("Error found Inserting Permit {0}: Error: '{1}' with Stack Trace: {2}",
                            permit.PermitNum, ex.Message, ex.StackTrace);
                        Console.WriteLine(errorMsg);
                        SendEMail(errorMsg);
                    }
                }

                SendEMail(String.Format("Inserted {0} new permit records.", permits.Item1.Count));

                foreach (Permit permit in permits.Item2)
                {
                    try
                    {

                        if (!checkIfExpired(permit))
                        {
                            processMDCInpsections(permit, db);
                        }
                        db.Update("Permit", "PermitNum", permit);
                    }
                    catch (Exception ex)
                    {
                        string errorMsg = String.Format("Error found Processing Permit {0}: Error: '{1}' with Stack Trace: {2}",
                            permit.PermitNum, ex.Message, ex.StackTrace);
                        Console.WriteLine(errorMsg);
                        SendEMail(errorMsg);
                    }
                    
                }

                SendEMail(String.Format("Processed {0} existing permit records.", permits.Item2.Count));

                Console.WriteLine("Populating Geography Field");
                db.Execute("UPDATE Permit SET Location=geography::Point(Latitude, Longitude, 4326) WHERE Location is NULL");
                Console.WriteLine("Sync Job Done on: " + DateTime.Now.ToString());  
                SendEMail("MDC OpenPermit Sync is done");
            }
            catch (Exception ex)
            {
                string errorMsg = String.Format("Error found running MDC OpenPermit Sync. Error: '{0}' with Stack Trace: {1}",
                    ex.Message, ex.StackTrace);
                Console.WriteLine(errorMsg);
                SendEMail(errorMsg);
            }

        }
コード例 #12
0
ファイル: Core.cs プロジェクト: JonathanValle/mixerp
        public void Put(int id, MixERP.Net.Entities.Core.TaxMaster item)
        {
            if (item == null || id <= 0)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            ApiAccessPolicy policy = new ApiAccessPolicy(typeof(MixERP.Net.Entities.Core.TaxMaster), "PUT");
            policy.Authorize();

            if (!policy.IsAuthorized)
            {
                throw new HttpResponseException(HttpStatusCode.Forbidden);
            }

            try
            {
                using (Database db = new Database(Factory.GetConnectionString(), "Npgsql"))
                {
                    db.Update("core.tax_master", "tax_master_id", item);
                }
            }
            catch
            {
                throw new HttpResponseException(HttpStatusCode.InternalServerError);
            }
        }
コード例 #13
0
ファイル: Core.cs プロジェクト: JonathanValle/mixerp
        public void Put(string id, MixERP.Net.Entities.Core.TaxBaseAmountType item)
        {
            if (item == null || string.IsNullOrWhiteSpace(id))
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            ApiAccessPolicy policy = new ApiAccessPolicy(typeof(MixERP.Net.Entities.Core.TaxBaseAmountType), "PUT");
            policy.Authorize();

            if (!policy.IsAuthorized)
            {
                throw new HttpResponseException(HttpStatusCode.Forbidden);
            }

            try
            {
                using (Database db = new Database(Factory.GetConnectionString(), "Npgsql"))
                {
                    db.Update("core.tax_base_amount_types", "tax_base_amount_type_code", item);
                }
            }
            catch
            {
                throw new HttpResponseException(HttpStatusCode.InternalServerError);
            }
        }
コード例 #14
0
        protected override void UpdateEntities(List<Entity> entities)
        {
            using (var database = new Database("SQLiteTest"))
            {
                using (var transaction = database.GetTransaction())
                {
                    entities.ForEach(entity => database.Update(entity));

                    transaction.Complete();
                }
            }
        }
コード例 #15
0
        public void Update(Contato contato)
        {
            Database db = new PetaPoco.Database("PRWDEV");

            db.Update("contatosbandre", "ID", contato);
        }
コード例 #16
0
ファイル: MainView.cs プロジェクト: ZixiangBoy/YongERP
 void btnUsing_ItemClick(object sender, ItemClickEventArgs e)
 {
     var et = gridControlEx1.GetFocusedDataSource<t_member>();
     if (null == et) return;
     using (var db = new Database()) {
         db.Update<t_member>(" set isusing=1 where guid=@0", et.Guid);
     }
     et.IsUsing = true;
     gridControlEx1.RefreshDataSource();
 }
コード例 #17
0
ファイル: ride.cs プロジェクト: catflinger/bikes
        public static void setNotes(int rideId, String notes)
        {
            Ride ride = getRide(rideId);
            ride.notes = notes;

            using (Database db = new PetaPoco.Database(ModelConfig.connectionStringName("bikes")))
            {
                db.Update(ride);
            }
        }
コード例 #18
0
ファイル: MainView.cs プロジェクト: ZixiangBoy/YongERP
        /// <summary>
        /// 审核
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void btnReView_ItemClick(object sender, ItemClickEventArgs e)
        {
            var et = gcUnSub.GetFocusedDataSource<t_trade>();
            if (null == et)
                return;

            if (MsgBox.ShowYesNoMessage("", "确定要审核此出货单?") == DialogResult.Yes) {
                using (var db = new Database()) {
                    try {
                        var result = new SqlParameter() {
                            Direction = ParameterDirection.Output,
                            SqlDbType = SqlDbType.Bit,
                            ParameterName = "@result"
                        };
                        db.BeginTransaction();
                        db.Update<t_trade>(" set IsAudit=1 where guid=@0", et.Guid);
                        db.Execute("exec p_tradeupdateinvt @0,@1 output", et.Guid, result);

                        if (!(bool)result.Value) {
                            MsgBox.ShowMessage("", "库存不足!");
                            db.AbortTransaction();
                        } else {
                            db.CompleteTransaction();
                            gcUnSub.RemoveSelected();
                        }
                    } catch (Exception) {
                        db.AbortTransaction();
                        throw;
                    }
                }
            }
        }
コード例 #19
0
ファイル: MainView.cs プロジェクト: ZixiangBoy/YongERP
 void btnInvalid_ItemClick(object sender, ItemClickEventArgs e)
 {
     var et = gcUnSub.GetFocusedDataSource<t_trade>();
     if (null == et)
         return;
     using (var db = new Database()) {
         db.Update<t_trade>(" set IsInvalid=1 where guid=@0", et.Guid);
     }
     gcUnSub.RemoveSelected();
 }
コード例 #20
0
ファイル: EdtPrice.cs プロジェクト: ZixiangBoy/FAS
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (!dxValidationProvider1.Validate()) return;

            var pro = lookUpEdit1.EditValue as T_ERP_Procedure;

            if(ExistsRng!=null && ExistsRng.Where(j => j.ProcedureGuid == pro.Guid && j.Guid != Ent.Guid).Count() > 0){
                MsgBox.ShowMessage("已存在该工序的工价");
                return;
            }

            if (EditMode == Business.Core.Define.EnViewEditMode.New)
            {
                var oj = new UltraDbEntity.T_ERP_ProducePrice
                {
                    Creator = CurUser,
                    Updator = CurUser,
                    Guid = Guid.NewGuid(),
                    Remark = string.Empty,
                    Reserved1 = 0,
                    Reserved2 = string.Empty,
                    Reserved3 = false,

                    CostPrice = labelSpinEdit1.Value,
                    OuterIid = Item.OuterIid,
                    OuterSkuId = Item.OuterSkuId,
                    ItemGuid = Item.Guid,
                    NumIid = Item.NumIid,
                    ProcedureGuid = pro.Guid,
                    ProcedureName = pro.ProcedureName
                };

                using (var db = new Database(this.ConnString))
                {
                    db.Insert(oj);
                }
                DialogResult = System.Windows.Forms.DialogResult.OK;
                Close();
            }
            else if (EditMode == Business.Core.Define.EnViewEditMode.Edit)
            {
                Ent.CostPrice = labelSpinEdit1.Value;
                Ent.ProcedureGuid = pro.Guid;
                Ent.ProcedureName = pro.ProcedureName;
                using (var db = new Database(this.ConnString))
                {
                    db.Update(Ent);
                }
                DialogResult = System.Windows.Forms.DialogResult.OK;
                Close();
            }
        }
コード例 #21
0
ファイル: ScrudFactory.cs プロジェクト: smartleos/mixerp
        /// <summary>
        /// Inserts or updates multiple instances of ScrudFactory class on the database table "config.scrud_factory";
        /// </summary>
        /// <param name="scrudFactories">List of "ScrudFactory" class to import.</param>
        /// <returns></returns>
        public List<object> BulkImport(List<MixERP.Net.Entities.Config.ScrudFactory> scrudFactories)
        {
            if (!this.SkipValidation)
            {
                if (!this.Validated)
                {
                    this.Validate(AccessTypeEnum.ImportData, this.LoginId, false);
                }

                if (!this.HasAccess)
                {
                    Log.Information("Access to import entity \"ScrudFactory\" was denied to the user with Login ID {LoginId}. {scrudFactories}", this.LoginId, scrudFactories);
                    throw new UnauthorizedException("Access is denied.");
                }
            }

            var result = new List<object>();
            int line = 0;
            try
            {
                using (Database db = new Database(Factory.GetConnectionString(this.Catalog), Factory.ProviderName))
                {
                    using (Transaction transaction = db.GetTransaction())
                    {
                        foreach (var scrudFactory in scrudFactories)
                        {
                            line++;

                            scrudFactory.AuditUserId = this.UserId;
                            scrudFactory.AuditTs = System.DateTime.UtcNow;

                            if (!string.IsNullOrWhiteSpace(scrudFactory.Key))
                            {
                                result.Add(scrudFactory.Key);
                                db.Update(scrudFactory, scrudFactory.Key);
                            }
                            else
                            {
                                result.Add(db.Insert(scrudFactory));
                            }
                        }

                        transaction.Complete();
                    }

                    return result;
                }
            }
            catch (NpgsqlException ex)
            {
                string errorMessage = $"Error on line {line} ";

                if (ex.Code.StartsWith("P"))
                {
                    errorMessage += Factory.GetDBErrorResource(ex);

                    throw new MixERPException(errorMessage, ex);
                }

                errorMessage += ex.Message;
                throw new MixERPException(errorMessage, ex);
            }
            catch (System.Exception ex)
            {
                string errorMessage = $"Error on line {line} ";
                throw new MixERPException(errorMessage, ex);
            }
        }
コード例 #22
0
ファイル: MainView.cs プロジェクト: ZixiangBoy/YongERP
 private void UpdatePrintData(List<t_trade> trds)
 {
     var whr = trds.Select(k => k.Guid.ToString()).Aggregate((s1, s2) => s1 + "','" + s2);
     using (var db = new Database()) {
         try {
             db.Update<t_trade>(string.Format(" set isprint=1,printcnt=isnull(printcnt,0)+1 where guid in ('{0}')", whr));
         } catch (Exception) {
             throw;
         }
     }
 }
コード例 #23
0
ファイル: Currency.cs プロジェクト: pplatek/mixerp
        /// <summary>
        /// Inserts or updates multiple instances of Currency class on the database table "core.currencies";
        /// </summary>
        /// <param name="currencies">List of "Currency" class to import.</param>
        /// <returns></returns>
        public List<object> BulkImport(List<ExpandoObject> currencies)
        {
            if (!this.SkipValidation)
            {
                if (!this.Validated)
                {
                    this.Validate(AccessTypeEnum.ImportData, this._LoginId, this._Catalog, false);
                }

                if (!this.HasAccess)
                {
                    Log.Information("Access to import entity \"Currency\" was denied to the user with Login ID {LoginId}. {currencies}", this._LoginId, currencies);
                    throw new UnauthorizedException("Access is denied.");
                }
            }

            var result = new List<object>();
            int line = 0;
            try
            {
                using (Database db = new Database(Factory.GetConnectionString(this._Catalog), Factory.ProviderName))
                {
                    using (Transaction transaction = db.GetTransaction())
                    {
                        foreach (dynamic currency in currencies)
                        {
                            line++;

                            currency.audit_user_id = this._UserId;
                            currency.audit_ts = System.DateTime.UtcNow;

                            object primaryKeyValue = currency.currency_code;

                            if (!string.IsNullOrWhiteSpace(currency.currency_code))
                            {
                                result.Add(currency.currency_code);
                                db.Update("core.currencies", "currency_code", currency, currency.currency_code);
                            }
                            else
                            {
                                result.Add(db.Insert("core.currencies", "currency_code", currency));
                            }
                        }

                        transaction.Complete();
                    }

                    return result;
                }
            }
            catch (NpgsqlException ex)
            {
                string errorMessage = $"Error on line {line} ";

                if (ex.Code.StartsWith("P"))
                {
                    errorMessage += Factory.GetDBErrorResource(ex);

                    throw new MixERPException(errorMessage, ex);
                }

                errorMessage += ex.Message;
                throw new MixERPException(errorMessage, ex);
            }
            catch (System.Exception ex)
            {
                string errorMessage = $"Error on line {line} ";
                throw new MixERPException(errorMessage, ex);
            }
        }
コード例 #24
0
ファイル: ExchangeRate.cs プロジェクト: netusers2014/mixerp
        /// <summary>
        /// Inserts or updates multiple instances of ExchangeRate class on the database table "core.exchange_rates";
        /// </summary>
        /// <param name="exchangeRates">List of "ExchangeRate" class to import.</param>
        /// <returns></returns>
        public List<object> BulkImport(List<ExpandoObject> exchangeRates)
        {
            if (!this.SkipValidation)
            {
                if (!this.Validated)
                {
                    this.Validate(AccessTypeEnum.ImportData, this._LoginId, this._Catalog, false);
                }

                if (!this.HasAccess)
                {
                    Log.Information("Access to import entity \"ExchangeRate\" was denied to the user with Login ID {LoginId}. {exchangeRates}", this._LoginId, exchangeRates);
                    throw new UnauthorizedException("Access is denied.");
                }
            }

            var result = new List<object>();
            int line = 0;
            try
            {
                using (Database db = new Database(Factory.GetConnectionString(this._Catalog), Factory.ProviderName))
                {
                    using (Transaction transaction = db.GetTransaction())
                    {
                        foreach (dynamic exchangeRate in exchangeRates)
                        {
                            line++;

                            object primaryKeyValue = exchangeRate.exchange_rate_id;

                            if (Cast.To<long>(primaryKeyValue) > 0)
                            {
                                result.Add(exchangeRate.exchange_rate_id);
                                db.Update("core.exchange_rates", "exchange_rate_id", exchangeRate, exchangeRate.exchange_rate_id);
                            }
                            else
                            {
                                result.Add(db.Insert("core.exchange_rates", "exchange_rate_id", exchangeRate));
                            }
                        }

                        transaction.Complete();
                    }

                    return result;
                }
            }
            catch (NpgsqlException ex)
            {
                string errorMessage = $"Error on line {line} ";

                if (ex.Code.StartsWith("P"))
                {
                    errorMessage += Factory.GetDBErrorResource(ex);

                    throw new MixERPException(errorMessage, ex);
                }

                errorMessage += ex.Message;
                throw new MixERPException(errorMessage, ex);
            }
            catch (System.Exception ex)
            {
                string errorMessage = $"Error on line {line} ";
                throw new MixERPException(errorMessage, ex);
            }
        }
コード例 #25
0
ファイル: AttachmentLookup.cs プロジェクト: smartleos/mixerp
        /// <summary>
        /// Inserts or updates multiple instances of AttachmentLookup class on the database table "core.attachment_lookup";
        /// </summary>
        /// <param name="attachmentLookups">List of "AttachmentLookup" class to import.</param>
        /// <returns></returns>
        public List<object> BulkImport(List<MixERP.Net.Entities.Core.AttachmentLookup> attachmentLookups)
        {
            if (!this.SkipValidation)
            {
                if (!this.Validated)
                {
                    this.Validate(AccessTypeEnum.ImportData, this.LoginId, false);
                }

                if (!this.HasAccess)
                {
                    Log.Information("Access to import entity \"AttachmentLookup\" was denied to the user with Login ID {LoginId}. {attachmentLookups}", this.LoginId, attachmentLookups);
                    throw new UnauthorizedException("Access is denied.");
                }
            }

            var result = new List<object>();
            int line = 0;
            try
            {
                using (Database db = new Database(Factory.GetConnectionString(this.Catalog), Factory.ProviderName))
                {
                    using (Transaction transaction = db.GetTransaction())
                    {
                        foreach (var attachmentLookup in attachmentLookups)
                        {
                            line++;

                            if (attachmentLookup.AttachmentLookupId > 0)
                            {
                                result.Add(attachmentLookup.AttachmentLookupId);
                                db.Update(attachmentLookup, attachmentLookup.AttachmentLookupId);
                            }
                            else
                            {
                                result.Add(db.Insert(attachmentLookup));
                            }
                        }

                        transaction.Complete();
                    }

                    return result;
                }
            }
            catch (NpgsqlException ex)
            {
                string errorMessage = $"Error on line {line} ";

                if (ex.Code.StartsWith("P"))
                {
                    errorMessage += Factory.GetDBErrorResource(ex);

                    throw new MixERPException(errorMessage, ex);
                }

                errorMessage += ex.Message;
                throw new MixERPException(errorMessage, ex);
            }
            catch (System.Exception ex)
            {
                string errorMessage = $"Error on line {line} ";
                throw new MixERPException(errorMessage, ex);
            }
        }
コード例 #26
0
ファイル: EdtView.cs プロジェクト: ZixiangBoy/FAS
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (!dxValidationProvider1.Validate()) return;

            if (spnOrder.EditValue != null) {
                using (var db = new Database(this.ConnString))
                {
                    var count = db.ExecuteScalar<int>(" select count(1) from T_ERP_Procedure where OrderNo = @0 and Guid <> @1 ", Convert.ToInt32(spnOrder.EditValue), Entity==null?Guid.Empty:Entity.Guid);
                    if (count > 0) {
                        MsgBox.ShowMessage("当前序号已经存在");
                        return;
                    }
                }
            }

            if (EditMode == Business.Core.Define.EnViewEditMode.New)
            {
                var r = new UltraDbEntity.T_ERP_Procedure
                {
                    Guid = Guid.NewGuid(),
                    Creator = CurUser,
                    Updator = CurUser,
                    Remark = string.Empty,
                    Reserved1 = 0,
                    Reserved2 = string.Empty,
                    Reserved3 = false,
                    ProcedureName = txtName.Text,
                    LabourCost = 0,
                    OrderNo = Convert.ToInt32(spnOrder.EditValue),
                    BatchNo = Convert.ToInt32(spnBatch.EditValue),
                    IsUsing = chkusing.Checked
                };
                using (var db = new Database(this.ConnString))
                {
                    db.Insert(r);
                    Entity = r;
                    DialogResult = System.Windows.Forms.DialogResult.OK; Close();
                }
            }
            else if (EditMode == Business.Core.Define.EnViewEditMode.Edit)
            {

                Entity.IsUsing = chkusing.Checked;
                Entity.Updator = CurUser;
                Entity.ProcedureName = txtName.Text;
                Entity.LabourCost = 0;
                Entity.OrderNo = Convert.ToInt32(spnOrder.EditValue);
                Entity.BatchNo = Convert.ToInt32(spnBatch.EditValue);

                using (var db = new Database(this.ConnString))
                {
                    db.Update(Entity);
                    DialogResult = System.Windows.Forms.DialogResult.OK; Close();
                }
            }
        }
コード例 #27
0
ファイル: WidgetGroup.cs プロジェクト: netusers2014/mixerp
        /// <summary>
        /// Inserts or updates multiple instances of WidgetGroup class on the database table "core.widget_groups";
        /// </summary>
        /// <param name="widgetGroups">List of "WidgetGroup" class to import.</param>
        /// <returns></returns>
        public List<object> BulkImport(List<ExpandoObject> widgetGroups)
        {
            if (!this.SkipValidation)
            {
                if (!this.Validated)
                {
                    this.Validate(AccessTypeEnum.ImportData, this._LoginId, this._Catalog, false);
                }

                if (!this.HasAccess)
                {
                    Log.Information("Access to import entity \"WidgetGroup\" was denied to the user with Login ID {LoginId}. {widgetGroups}", this._LoginId, widgetGroups);
                    throw new UnauthorizedException("Access is denied.");
                }
            }

            var result = new List<object>();
            int line = 0;
            try
            {
                using (Database db = new Database(Factory.GetConnectionString(this._Catalog), Factory.ProviderName))
                {
                    using (Transaction transaction = db.GetTransaction())
                    {
                        foreach (dynamic widgetGroup in widgetGroups)
                        {
                            line++;

                            object primaryKeyValue = widgetGroup.widget_group_name;

                            if (!string.IsNullOrWhiteSpace(widgetGroup.widget_group_name))
                            {
                                result.Add(widgetGroup.widget_group_name);
                                db.Update("core.widget_groups", "widget_group_name", widgetGroup, widgetGroup.widget_group_name);
                            }
                            else
                            {
                                result.Add(db.Insert("core.widget_groups", "widget_group_name", widgetGroup));
                            }
                        }

                        transaction.Complete();
                    }

                    return result;
                }
            }
            catch (NpgsqlException ex)
            {
                string errorMessage = $"Error on line {line} ";

                if (ex.Code.StartsWith("P"))
                {
                    errorMessage += Factory.GetDBErrorResource(ex);

                    throw new MixERPException(errorMessage, ex);
                }

                errorMessage += ex.Message;
                throw new MixERPException(errorMessage, ex);
            }
            catch (System.Exception ex)
            {
                string errorMessage = $"Error on line {line} ";
                throw new MixERPException(errorMessage, ex);
            }
        }
コード例 #28
0
        protected void SaveNewUpd(bool flgChkAuto)
        {
            bool flgNew   = false;
            bool flgValid = false;

            try
            {
                //Validate first...
                flgValid = validateFields();
                //
                if (!flgValid)
                {
                    return;
                }

                // Create a PetaPoco database object
                var db = new PetaPoco.Database("Shell_AutoArchDBConnectionString");

                // Get a record
                var a = db.SingleOrDefault <planning>("SELECT * FROM shell_Planning WHERE UniqueId=@0", txt_uniqueid.Text);

                //Test if record exists...
                if (null == a)
                {
                    a      = new planning();
                    flgNew = true;
                }
                //if update, check if status is not equal to CVR... or Closed...
                else if (flgChkAuto)
                {
                    if (txt_status.Text.IndexOf("Archival Order Closed") == -1)
                    {
                        if ((a.Status.IndexOf("Rejected") >= 0) || (a.Status.IndexOf("CVR Created") >= 0)) //Rejected
                        {
                            ClrFields(false);
                            return;
                        }
                    }
                }

                // Change it
                //
                if (txt_actaoenddate.Text != a.ActAOEndDate.ToString("yyyy-MM-dd HH:mm:ss.ttt"))
                {
                    a.ActAOEndDate = DateTime.Parse(txt_actaoenddate.Text);
                }
                //
                if (txt_actaoreceivedate.Text != a.ActAOReceiveDate.ToString("yyyy-MM-dd HH:mm:ss.ttt"))
                {
                    a.ActAOReceiveDate = DateTime.Parse(txt_actaoreceivedate.Text);
                }
                //
                if (txt_actaostartdate.Text != a.ActAOStartDate.ToString("yyyy-MM-dd HH:mm:ss.ttt"))
                {
                    a.ActAOStartDate = DateTime.Parse(txt_actaostartdate.Text);
                }
                //
                if (txt_colsitenum.Text != "")
                {
                    if (Convert.ToInt16(txt_colsitenum.Text) != a.ColSiteNum)
                    {
                        a.ColSiteNum = Convert.ToInt16(txt_colsitenum.Text);
                    }
                }
                //
                if (txt_comment.Text != a.Comment)
                {
                    a.Comment = txt_comment.Text;
                }
                //
                if (chk_dataexpctrchk.Checked)
                {
                    a.DataExpCtrChk = 1;
                }
                else
                {
                    a.DataExpCtrChk = 0;
                }
                //
                if (txt_duname.Text != a.DUName)
                {
                    a.DUName = txt_duname.Text;
                }
                //
                //
                if ((txt_actaostartdate.Text != "") && (txt_actaoenddate.Text != ""))
                {
                    DateTime dtf = DateTime.Parse(txt_actaostartdate.Text);
                    DateTime dtt = DateTime.Parse(txt_actaoenddate.Text);
                    a.DurationWorkDays = GetWorkingDays(dtf, dtt);
                }
                else if (Convert.ToInt16(txt_durationworkdays.Text) != a.DurationWorkDays)
                {
                    a.DurationWorkDays = Convert.ToInt16(txt_durationworkdays.Text);
                }
                //
                //
                if (txt_operatorname.Text != a.OperatorName)
                {
                    a.OperatorName = txt_operatorname.Text;
                }
                //
                if (txt_planaoenddate.Text != a.PlanAOEndDate.ToString("yyyy-MM-dd HH:mm:ss.ttt"))
                {
                    a.PlanAOEndDate = DateTime.Parse(txt_planaoenddate.Text);
                }
                //
                if (txt_planaoreceivedate.Text != a.PlanAOReceiveDate.ToString("yyyy-MM-dd HH:mm:ss.ttt"))
                {
                    a.PlanAOReceiveDate = DateTime.Parse(txt_planaoreceivedate.Text);
                }
                //
                if (txt_planaostartdate.Text != a.PlanAOStartDate.ToString("yyyy-MM-dd HH:mm:ss.ttt"))
                {
                    a.PlanAOStartDate = DateTime.Parse(txt_planaostartdate.Text);
                }
                //
                if (txt_status.Text != a.Status)
                {
                    a.Status = txt_status.Text;
                }
                //
                if (txt_instanceid.Text != a.InstanceId)
                {
                    a.InstanceId = txt_instanceid.Text;
                }
                //
                if ((float)Convert.ToDouble(txt_volumegb.Text) != a.VolumeGB)
                {
                    a.VolumeGB = (float)Convert.ToDouble(txt_volumegb.Text);
                }
                //
                if (chk_waiverchk.Checked)
                {
                    a.WaiverChk = 1;
                }
                else
                {
                    a.WaiverChk = 0;
                }
                //

                string msg = "Archiving Order updated! - ";
                if (flgNew)
                {
                    a.UniqueId = txt_uniqueid.Text;
                    msg        = "New Archiving Order inserted! - ";
                    db.Save(a);
                }
                else
                {
                    db.Update(a);
                }

                if (flgChkAuto)
                {
                    divMessage.InnerHtml += "<span id='msg' style='color:#FF3300;font-size:Smaller;font-weight:bold;'>" + msg + txt_uniqueid.Text + "  </span><br>";
                }
                else
                {
                    divMessage.InnerHtml = "<span id='msg' style='color:#FF3300;font-size:Smaller;font-weight:bold;'>" + msg + txt_uniqueid.Text + "  </span>";
                }
            }
            catch (Exception eg)
            {
                if (flgChkAuto)
                {
                    divMessage.InnerHtml += "<span id='msg' style='color:#FF3300;font-size:Smaller;font-weight:bold;'>" + "Error Message: " + eg.Message + "  </span>";
                }
                else
                {
                    divMessage.InnerHtml = "<span id='msg' style='color:#FF3300;font-size:Smaller;font-weight:bold;'>" + "Error Message: " + eg.Message + "  </span>";
                }
            }
        }
コード例 #29
0
ファイル: LeaveApplication.cs プロジェクト: gjms2000/mixerp
        /// <summary>
        /// Inserts or updates multiple instances of LeaveApplication class on the database table "hrm.leave_applications";
        /// </summary>
        /// <param name="leaveApplications">List of "LeaveApplication" class to import.</param>
        /// <returns></returns>
        public List<object> BulkImport(List<MixERP.Net.Entities.HRM.LeaveApplication> leaveApplications)
        {
            if (!this.SkipValidation)
            {
                if (!this.Validated)
                {
                    this.Validate(AccessTypeEnum.ImportData, this._LoginId, false);
                }

                if (!this.HasAccess)
                {
                    Log.Information("Access to import entity \"LeaveApplication\" was denied to the user with Login ID {LoginId}. {leaveApplications}", this._LoginId, leaveApplications);
                    throw new UnauthorizedException("Access is denied.");
                }
            }

            var result = new List<object>();
            int line = 0;
            try
            {
                using (Database db = new Database(Factory.GetConnectionString(this._Catalog), Factory.ProviderName))
                {
                    using (Transaction transaction = db.GetTransaction())
                    {
                        foreach (var leaveApplication in leaveApplications)
                        {
                            line++;

                            leaveApplication.AuditUserId = this._UserId;
                            leaveApplication.EnteredBy = this._UserId;
                            leaveApplication.AuditTs = System.DateTime.UtcNow;

                            if (leaveApplication.LeaveApplicationId > 0)
                            {
                                result.Add(leaveApplication.LeaveApplicationId);
                                db.Update(leaveApplication, leaveApplication.LeaveApplicationId);
                            }
                            else
                            {
                                result.Add(db.Insert(leaveApplication));
                            }
                        }

                        transaction.Complete();
                    }

                    return result;
                }
            }
            catch (NpgsqlException ex)
            {
                string errorMessage = $"Error on line {line} ";

                if (ex.Code.StartsWith("P"))
                {
                    errorMessage += Factory.GetDBErrorResource(ex);

                    throw new MixERPException(errorMessage, ex);
                }

                errorMessage += ex.Message;
                throw new MixERPException(errorMessage, ex);
            }
            catch (System.Exception ex)
            {
                string errorMessage = $"Error on line {line} ";
                throw new MixERPException(errorMessage, ex);
            }
        }
コード例 #30
0
ファイル: Program.cs プロジェクト: juarola/PetaPocoTest
        private static void TransactionTest(Database db)
        {
            // Transaktio
            using (var tx = new TransactionScope())
            {
                // Lähderivi
                var source = db.SingleOrDefault<Customer>("SELECT * FROM Customer WITH(NOLOCK) WHERE CustId = 287350");

                // Kohderivi
                var target = db.SingleOrDefault<Customer>("SELECT * FROM Customer WITH(NOLOCK) WHERE CustId = 287348");

                target.CustName = source.CustName;

                // Vars. muutos: "taulu", "avain", data
                db.Update("customer", "custid", target);

                // Luetaan testimielessä likainen rivi
                var dirty = db.SingleOrDefault<Customer>("SELECT * FROM Customer WITH(NOLOCK)  WHERE CustId = 287348");
                Console.WriteLine("dirty: {0} - {1}", dirty.CustId, dirty.CustName);
                Console.WriteLine();
            }

            // Ei committia, eli ei tallentunut
            var rolledback = db.SingleOrDefault<Customer>("SELECT * FROM Customer WITH(NOLOCK)  WHERE CustId = 287348");
            Console.WriteLine("eiku: {0} - {1}", rolledback.CustId, rolledback.CustName);
            Console.WriteLine();
        }
コード例 #31
-1
ファイル: WorkCenter.cs プロジェクト: pplatek/mixerp
        /// <summary>
        /// Inserts or updates multiple instances of WorkCenter class on the database table "office.work_centers";
        /// </summary>
        /// <param name="workCenters">List of "WorkCenter" class to import.</param>
        /// <returns></returns>
        public List<object> BulkImport(List<ExpandoObject> workCenters)
        {
            if (!this.SkipValidation)
            {
                if (!this.Validated)
                {
                    this.Validate(AccessTypeEnum.ImportData, this._LoginId, this._Catalog, false);
                }

                if (!this.HasAccess)
                {
                    Log.Information("Access to import entity \"WorkCenter\" was denied to the user with Login ID {LoginId}. {workCenters}", this._LoginId, workCenters);
                    throw new UnauthorizedException("Access is denied.");
                }
            }

            var result = new List<object>();
            int line = 0;
            try
            {
                using (Database db = new Database(Factory.GetConnectionString(this._Catalog), Factory.ProviderName))
                {
                    using (Transaction transaction = db.GetTransaction())
                    {
                        foreach (dynamic workCenter in workCenters)
                        {
                            line++;

                            workCenter.audit_user_id = this._UserId;
                            workCenter.audit_ts = System.DateTime.UtcNow;

                            object primaryKeyValue = workCenter.work_center_id;

                            if (Cast.To<int>(primaryKeyValue) > 0)
                            {
                                result.Add(workCenter.work_center_id);
                                db.Update("office.work_centers", "work_center_id", workCenter, workCenter.work_center_id);
                            }
                            else
                            {
                                result.Add(db.Insert("office.work_centers", "work_center_id", workCenter));
                            }
                        }

                        transaction.Complete();
                    }

                    return result;
                }
            }
            catch (NpgsqlException ex)
            {
                string errorMessage = $"Error on line {line} ";

                if (ex.Code.StartsWith("P"))
                {
                    errorMessage += Factory.GetDBErrorResource(ex);

                    throw new MixERPException(errorMessage, ex);
                }

                errorMessage += ex.Message;
                throw new MixERPException(errorMessage, ex);
            }
            catch (System.Exception ex)
            {
                string errorMessage = $"Error on line {line} ";
                throw new MixERPException(errorMessage, ex);
            }
        }