Пример #1
0
        public Int32 SaveDrug(Entities.Drug drug)
        {
            var drugId = 0;

            var db = DBConnect.getDBConnection();

            using (DbConnection conn = db.CreateConnection())
            {
                conn.Open();

                using (DbTransaction transaction = conn.BeginTransaction())
                {
                    try
                    {
                        var drugRouteLinkId = 0;

                        if (drug != null)
                        {
                            if (drug.DrugId == null || drug.DrugId == 0)
                            {
                                drugId = AddDrug(drug, transaction);
                            }
                            else
                            {
                                if (drug.IsDeleted == true)
                                {
                                    var result = DeleteDrug(drug, transaction);

                                    drugId = Convert.ToInt32(drug.DrugId);
                                }
                                else
                                {
                                    if (drug.ModifiedBy > 0 || drug.ModifiedBy != null)
                                    {
                                        drugId = UpdateDrug(drug, transaction);

                                        // If records failed to save
                                        if (drugId < 0)
                                        {
                                            drugId = -1;
                                        }
                                    }
                                }
                            }

                            if (drugId > 0)
                            {
                                if (drug.IsDeleted == true)
                                {
                                    DrugsLinkWithDrugRoute dal = new DrugsLinkWithDrugRoute();

                                    var result = dal.DeleteDrugRoutesLinkByDrugId(drugId, (int)drug.DeletedBy, drug.DeletedByIP, transaction);

                                    if (result == true)
                                    {
                                        drugId = 1;
                                    }
                                }

                                // Save Drugs Link with Drug Route
                                if (drug.DrugLinkWithDrugRoutes != null)
                                {
                                    if (drug.DrugLinkWithDrugRoutes.Count > 0)
                                    {
                                        foreach (Entities.DrugLinkWithDrugRoutes drugLinkRoute in drug.DrugLinkWithDrugRoutes)
                                        {
                                            drugLinkRoute.DrugId = drugId;

                                            DrugsLinkWithDrugRoute dal = new DrugsLinkWithDrugRoute();

                                            drugRouteLinkId = dal.SaveDrugLinkWithDrugRoute(drugLinkRoute, transaction);

                                            // If records failed to save
                                            if (drugRouteLinkId < 0)
                                            {
                                                drugId = -1;
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        if (drugId > 0)
                        {
                            transaction.Commit();
                        }
                        else
                        {
                            transaction.Rollback();
                        }
                    }
                    catch (Exception ex)
                    {
                        drugId = -1;
                        transaction.Rollback();
                        throw ex;
                    }
                    finally
                    {
                        db = null;
                    }
                }
            }

            return(drugId);
        }
Пример #2
0
        public Int32 SaveXRayIssueDetails(Entities.XRayIssue xrayIssue)
        {
            var XRayIssueId = 0;

            var db = DBConnect.getDBConnection();

            using (DbConnection conn = db.CreateConnection())
            {
                conn.Open();

                using (DbTransaction dbTransaction = conn.BeginTransaction())
                {
                    try
                    {
                        var xrayFilmUsedId = 0;

                        if (xrayIssue != null)
                        {
                            if (xrayIssue.XRayIssueId == null || xrayIssue.XRayIssueId == 0)
                            {
                                XRayIssueId = AddXRayIssueDetails(xrayIssue, dbTransaction);
                            }
                            else if (xrayIssue.ModifiedBy != null || xrayIssue.ModifiedBy > 0)
                            {
                                XRayIssueId = UpdateXRayIssueDetails(xrayIssue, dbTransaction);
                            }
                            else if (xrayIssue.IsDeleted == true)
                            {
                                var result = DeleteXRayIssueDetails(xrayIssue, dbTransaction);

                                if (result)
                                {
                                    XRayIssueId = (int)xrayIssue.XRayIssueId;
                                }
                                else
                                {
                                    XRayIssueId = -1;
                                }
                            }

                            if (XRayIssueId > 0)
                            {
                                if (xrayIssue.IsDeleted == true)
                                {
                                    XRayFilmUsed xRayFilmUsed = new XRayFilmUsed();

                                    var result = xRayFilmUsed.DeleteXRayFilmUsedDetailsByXRayIssueId((int)xrayIssue.XRayIssueId, (int)xrayIssue.DeletedBy, xrayIssue.DeletedByIP, dbTransaction);

                                    if (result)
                                    {
                                        XRayIssueId = (int)xrayIssue.XRayIssueId;
                                    }
                                }

                                if (xrayIssue.XRayFilmsUsed != null)
                                {
                                    if (xrayIssue.XRayFilmsUsed.Count > 0)
                                    {
                                        foreach (Entities.XRayFilmUsed xrayFilmUsed in xrayIssue.XRayFilmsUsed)
                                        {
                                            XRayFilmUsed xRayFilmUsedDB = new XRayFilmUsed();

                                            xrayFilmUsed.XRayIssueId = XRayIssueId;

                                            xrayFilmUsedId = xRayFilmUsedDB.SaveXRayFilmUsed(xrayFilmUsed, dbTransaction);

                                            if (xrayFilmUsedId < 0)
                                            {
                                                XRayIssueId = -1;
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        if (XRayIssueId > 0)
                        {
                            dbTransaction.Commit();
                        }
                        else
                        {
                            dbTransaction.Rollback();
                        }
                    }
                    catch (Exception ex)
                    {
                        XRayIssueId = -1;
                        dbTransaction.Rollback();
                        throw ex;
                    }
                }

                return(XRayIssueId);
            }
        }
Пример #3
0
 public Drug()
 {
     database = DBConnect.getDBConnection();
 }
Пример #4
0
 public Company()
 {
     database = DBConnect.getDBConnection();
 }
 public DataSearchField()
 {
     database = DBConnect.getDBConnection();
 }
Пример #6
0
 public AddressType()
 {
     database = DBConnect.getDBConnection();
 }
Пример #7
0
 public Role()
 {
     database = DBConnect.getDBConnection();
 }
Пример #8
0
 public Employer()
 {
     database = DBConnect.getDBConnection();
 }
Пример #9
0
 public WorkingPeriod()
 {
     database = DBConnect.getDBConnection();
 }
Пример #10
0
        public Int32 SaveDrugDispenseDetails(Entities.DrugDispense drugDispense)
        {
            var drugDispenseId = 0;

            var db = DBConnect.getDBConnection();

            using (DbConnection conn = db.CreateConnection())
            {
                conn.Open();

                using (DbTransaction dbTransaction = conn.BeginTransaction())
                {
                    try
                    {
                        var drugDispenseDrugUtilisationId = 0;

                        if (drugDispense != null)
                        {
                            if (drugDispense.DrugDispenseId == null || drugDispense.DrugDispenseId == 0)
                            {
                                drugDispenseId = AddDrugDispenseDetails(drugDispense, dbTransaction);
                            }
                            else if (drugDispense.ModifiedBy != null || drugDispense.ModifiedBy > 0)
                            {
                                drugDispenseId = UpdateDrugDispenseDetails(drugDispense, dbTransaction);
                            }
                            else if (drugDispense.IsDeleted == true)
                            {
                                var result = DeleteDrugDispenseDetails(drugDispense, dbTransaction);

                                if (result)
                                {
                                    drugDispenseId = (int)drugDispense.DrugDispenseId;
                                }
                                else
                                {
                                    drugDispenseId = -1;
                                }
                            }

                            if (drugDispenseId > 0)
                            {
                                if (drugDispense.IsDeleted == true)
                                {
                                    DrugDispenseDrugUtilisation drugUtilisationDB = new DrugDispenseDrugUtilisation();

                                    var result = drugUtilisationDB.DeleteDrugDispenseDrugUtilisationDetailsByDrugDispenseId((int)drugDispense.DrugDispenseId, (int)drugDispense.DeletedBy, drugDispense.DeletedByIP, dbTransaction);

                                    if (result)
                                    {
                                        drugDispenseDrugUtilisationId = (int)drugDispense.DrugDispenseId;
                                    }
                                }

                                if (drugDispense.DrugDispenseDrugUtilisations != null)
                                {
                                    if (drugDispense.DrugDispenseDrugUtilisations.Count > 0)
                                    {
                                        foreach (Entities.DrugDispenseDrugUtilisation drugUtilisation in drugDispense.DrugDispenseDrugUtilisations)
                                        {
                                            DrugDispenseDrugUtilisation drugUtilisationDB = new DrugDispenseDrugUtilisation();

                                            drugUtilisation.DrugDispenseId = drugDispenseId;

                                            drugDispenseDrugUtilisationId = drugUtilisationDB.SaveDrugDispenseDrugUtilisation(drugUtilisation, dbTransaction);

                                            if (drugDispenseDrugUtilisationId < 0)
                                            {
                                                drugDispenseId = -1;
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        if (drugDispenseId > 0)
                        {
                            dbTransaction.Commit();
                        }
                        else
                        {
                            dbTransaction.Rollback();
                        }
                    }
                    catch (Exception ex)
                    {
                        drugDispenseId = -1;
                        dbTransaction.Rollback();
                        throw ex;
                    }
                }

                return(drugDispenseId);
            }
        }
 public ClientAddressContact()
 {
     database = DBConnect.getDBConnection();
 }
Пример #12
0
 public DrugDispense()
 {
     database = DBConnect.getDBConnection();
 }
Пример #13
0
 public Precautions()
 {
     database = DBConnect.getDBConnection();
 }
Пример #14
0
 public AccountHead()
 {
     database = DBConnect.getDBConnection();
 }
Пример #15
0
 public ModeOfPayment()
 {
     database = DBConnect.getDBConnection();
 }
Пример #16
0
 public PurchaseBillReturnItem()
 {
     database = DBConnect.getDBConnection();
 }
Пример #17
0
 public Menu()
 {
     database = DBConnect.getDBConnection();
 }
Пример #18
0
 public Client()
 {
     database = DBConnect.getDBConnection();
 }
 public RolePermission()
 {
     database = DBConnect.getDBConnection();
 }
Пример #20
0
        public Int32 SaveClient(List <Entities.Client> client)
        {
            var clientId = 0;

            var db = DBConnect.getDBConnection();

            using (DbConnection conn = db.CreateConnection())
            {
                conn.Open();

                using (DbTransaction transaction = conn.BeginTransaction())
                {
                    try
                    {
                        var clientAddressId = 0;

                        if (client.Count > 0)
                        {
                            foreach (Entities.Client c in client)
                            {
                                if (c.ClientId == null || c.ClientId == 0)
                                {
                                    var result = IsClientNameExists(c.ClientName);

                                    if (result == false)
                                    {
                                        clientId = AddClient(c, transaction);
                                    }
                                    else
                                    {
                                        clientId = -2;
                                    }
                                }
                                else if (c.ModifiedBy == null || c.ModifiedBy == 0)
                                {
                                    clientId = UpdateClient(c, transaction);
                                }
                                else if (c.IsDeleted == true)
                                {
                                    var result = DeleteClient(c, transaction);

                                    if (result)
                                    {
                                        clientId = (int)c.ClientId;
                                    }
                                }

                                if (clientId > 0)
                                {
                                    foreach (Entities.ClientAddress ca in c.ClientAddressess)
                                    {
                                        ca.ClientId = clientId;

                                        ClientAddress clientAddress = new ClientAddress();

                                        clientAddressId = clientAddress.SaveClientAddress(ca, transaction);
                                    }
                                }
                            }
                        }

                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }
                    finally
                    {
                        db = null;
                    }
                }
            }

            return(clientId);
        }
Пример #21
0
 public BloodGroup()
 {
     database = DBConnect.getDBConnection();
 }
Пример #22
0
 public XRayIssue()
 {
     database = DBConnect.getDBConnection();
 }
Пример #23
0
 public Brand()
 {
     database = DBConnect.getDBConnection();
 }
Пример #24
0
 public State()
 {
     database = DBConnect.getDBConnection();
 }