Ejemplo n.º 1
0
 ///<summary>Returns true if Update(JobQuote,JobQuote) would make changes to the database.
 ///Does not make any changes to the database and can be called before remoting role is checked.</summary>
 public static bool UpdateComparison(JobQuote jobQuote, JobQuote oldJobQuote)
 {
     if (jobQuote.JobNum != oldJobQuote.JobNum)
     {
         return(true);
     }
     if (jobQuote.PatNum != oldJobQuote.PatNum)
     {
         return(true);
     }
     if (jobQuote.Amount != oldJobQuote.Amount)
     {
         return(true);
     }
     if (jobQuote.Note != oldJobQuote.Note)
     {
         return(true);
     }
     if (jobQuote.Hours != oldJobQuote.Hours)
     {
         return(true);
     }
     if (jobQuote.ApprovedAmount != oldJobQuote.ApprovedAmount)
     {
         return(true);
     }
     if (jobQuote.IsCustomerApproved != oldJobQuote.IsCustomerApproved)
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 2
0
 ///<summary>Inserts one JobQuote into the database.  Returns the new priKey.</summary>
 public static long Insert(JobQuote jobQuote)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         jobQuote.JobQuoteNum = DbHelper.GetNextOracleKey("jobquote", "JobQuoteNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(jobQuote, true));
             }
             catch (Oracle.ManagedDataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     jobQuote.JobQuoteNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(jobQuote, false));
     }
 }
Ejemplo n.º 3
0
 private void butDelete_Click(object sender, EventArgs e)
 {
     if (!MsgBox.Show(this, MsgBoxButtons.YesNo, "Delete the current job quote?"))
     {
         return;
     }
     _jobQuote    = null;
     DialogResult = DialogResult.OK;
 }
Ejemplo n.º 4
0
 ///<summary>Inserts one JobQuote into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(JobQuote jobQuote)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(jobQuote, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             jobQuote.JobQuoteNum = DbHelper.GetNextOracleKey("jobquote", "JobQuoteNum");                  //Cacheless method
         }
         return(InsertNoCache(jobQuote, true));
     }
 }
Ejemplo n.º 5
0
        ///<summary>Inserts one JobQuote into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(JobQuote jobQuote, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO jobquote (";

            if (!useExistingPK && isRandomKeys)
            {
                jobQuote.JobQuoteNum = ReplicationServers.GetKeyNoCache("jobquote", "JobQuoteNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "JobQuoteNum,";
            }
            command += "JobNum,PatNum,Amount,Note,Hours,ApprovedAmount,IsCustomerApproved) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(jobQuote.JobQuoteNum) + ",";
            }
            command +=
                POut.Long(jobQuote.JobNum) + ","
                + POut.Long(jobQuote.PatNum) + ","
                + "'" + POut.String(jobQuote.Amount) + "',"
                + DbHelper.ParamChar + "paramNote,"
                + "'" + POut.String(jobQuote.Hours) + "',"
                + "'" + POut.String(jobQuote.ApprovedAmount) + "',"
                + POut.Bool(jobQuote.IsCustomerApproved) + ")";
            if (jobQuote.Note == null)
            {
                jobQuote.Note = "";
            }
            OdSqlParameter paramNote = new OdSqlParameter("paramNote", OdDbType.Text, POut.StringParam(jobQuote.Note));

            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command, paramNote);
            }
            else
            {
                jobQuote.JobQuoteNum = Db.NonQ(command, true, "JobQuoteNum", "jobQuote", paramNote);
            }
            return(jobQuote.JobQuoteNum);
        }
Ejemplo n.º 6
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <JobQuote> TableToList(DataTable table)
        {
            List <JobQuote> retVal = new List <JobQuote>();
            JobQuote        jobQuote;

            foreach (DataRow row in table.Rows)
            {
                jobQuote                    = new JobQuote();
                jobQuote.JobQuoteNum        = PIn.Long(row["JobQuoteNum"].ToString());
                jobQuote.JobNum             = PIn.Long(row["JobNum"].ToString());
                jobQuote.PatNum             = PIn.Long(row["PatNum"].ToString());
                jobQuote.Amount             = PIn.String(row["Amount"].ToString());
                jobQuote.Note               = PIn.String(row["Note"].ToString());
                jobQuote.Hours              = PIn.String(row["Hours"].ToString());
                jobQuote.ApprovedAmount     = PIn.String(row["ApprovedAmount"].ToString());
                jobQuote.IsCustomerApproved = PIn.Bool(row["IsCustomerApproved"].ToString());
                retVal.Add(jobQuote);
            }
            return(retVal);
        }
Ejemplo n.º 7
0
        ///<summary>Updates one JobQuote in the database.</summary>
        public static void Update(JobQuote jobQuote)
        {
            string command = "UPDATE jobquote SET "
                             + "JobNum            =  " + POut.Long(jobQuote.JobNum) + ", "
                             + "PatNum            =  " + POut.Long(jobQuote.PatNum) + ", "
                             + "Amount            = '" + POut.String(jobQuote.Amount) + "', "
                             + "Note              =  " + DbHelper.ParamChar + "paramNote, "
                             + "Hours             = '" + POut.String(jobQuote.Hours) + "', "
                             + "ApprovedAmount    = '" + POut.String(jobQuote.ApprovedAmount) + "', "
                             + "IsCustomerApproved=  " + POut.Bool(jobQuote.IsCustomerApproved) + " "
                             + "WHERE JobQuoteNum = " + POut.Long(jobQuote.JobQuoteNum);

            if (jobQuote.Note == null)
            {
                jobQuote.Note = "";
            }
            OdSqlParameter paramNote = new OdSqlParameter("paramNote", OdDbType.Text, POut.StringParam(jobQuote.Note));

            Db.NonQ(command, paramNote);
        }
Ejemplo n.º 8
0
        private void gridQuotes_CellDoubleClick(object sender, ODGridClickEventArgs e)
        {
            if (!(gridQuotes.Rows[e.Row].Tag is JobQuote))
            {
                return;                //should never happen
            }
            JobQuote         jq      = (JobQuote)gridQuotes.Rows[e.Row].Tag;
            FormJobQuoteEdit FormJQE = new FormJobQuoteEdit(jq);

            FormJQE.ShowDialog();
            if (FormJQE.DialogResult != DialogResult.OK)
            {
                return;
            }
            _listJobQuotes.RemoveAll(x => x.JobQuoteNum == jq.JobQuoteNum); //should remove only one
            if (FormJQE.JobQuoteCur != null)                                //re-add altered version, iff the jobquote was modified.
            {
                _listJobQuotes.Add(FormJQE.JobQuoteCur);
            }
            FillGridQuotes();
        }
Ejemplo n.º 9
0
 ///<summary>Used for existing Reviews. Pass in the jobNum and the jobReviewNum.</summary>
 public FormJobQuoteEdit(JobQuote jobQuote)
 {
     _jobQuote = jobQuote.Copy();
     InitializeComponent();
     Lan.F(this);
 }
Ejemplo n.º 10
0
        public static ServiceResponseResult AddJobQuote(QuoteModel model, Login login, HttpFileCollectionBase files = null)
        {
            using (var db = new KeysEntities())
            {
                var _currentJobId        = model.JobRequestId;
                var _currentJobMaxBudget = db.TenantJobRequest.SingleOrDefault(j => j.Id == _currentJobId).MaxBudget;
                if (_currentJobMaxBudget != null && _currentJobMaxBudget < model.Amount)
                {
                    return(new ServiceResponseResult
                    {
                        IsSuccess = false,
                        ErrorMessage = "Sorry, you quote is larger than Max Budget of this Job."
                    });
                }
                if (model.Id == -1)
                {
                    var jobQuote = new JobQuote();
                    var mf       = MediaService.SaveMediaFiles(files, 5);
                    if (mf.IsSuccess)
                    {
                        var mediaFiles = mf.NewObject as List <MediaModel>;
                        if (mediaFiles != null)
                        {
                            mediaFiles.ForEach(x => jobQuote.JobQuoteMedia.Add(new JobQuoteMedia
                            {
                                FileName = x.NewFileName,
                                IsActive = true
                            }));
                        }
                    }
                    // Bug Fix #2031
                    jobQuote.JobRequestId = model.JobRequestId;
                    jobQuote.ProviderId   = login.Id;
                    jobQuote.Status       = "opening".ToLower();
                    jobQuote.Amount       = model.Amount;
                    jobQuote.CreatedBy    = login.Email;
                    jobQuote.UpdatedBy    = login.Email;
                    jobQuote.CreatedOn    = DateTime.UtcNow;
                    jobQuote.UpdatedOn    = DateTime.UtcNow;
                    jobQuote.Note         = model.Note;
                    jobQuote.IsViewed     = false;
                    db.JobQuote.Add(jobQuote);
                }
                else
                {
                    var jobQuote  = db.JobQuote.Find(model.Id);
                    var marketJob = db.TenantJobRequest.Find(model.JobRequestId);

                    if (jobQuote != null && marketJob != null)
                    {
                        jobQuote.Amount    = model.Amount;
                        jobQuote.UpdatedBy = login.Email;
                        jobQuote.UpdatedOn = DateTime.UtcNow;
                    }
                }
                try
                {
                    db.SaveChanges();
                    return(new ServiceResponseResult {
                        IsSuccess = true
                    });
                }
                catch (Exception)
                {
                    return(new ServiceResponseResult {
                        IsSuccess = false, ErrorMessage = _error
                    });
                }
            }
        }
Ejemplo n.º 11
0
        ///<summary>Updates one JobQuote in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.  Returns true if an update occurred.</summary>
        public static bool Update(JobQuote jobQuote, JobQuote oldJobQuote)
        {
            string command = "";

            if (jobQuote.JobNum != oldJobQuote.JobNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "JobNum = " + POut.Long(jobQuote.JobNum) + "";
            }
            if (jobQuote.PatNum != oldJobQuote.PatNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "PatNum = " + POut.Long(jobQuote.PatNum) + "";
            }
            if (jobQuote.Amount != oldJobQuote.Amount)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Amount = '" + POut.String(jobQuote.Amount) + "'";
            }
            if (jobQuote.Note != oldJobQuote.Note)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Note = " + DbHelper.ParamChar + "paramNote";
            }
            if (jobQuote.Hours != oldJobQuote.Hours)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Hours = '" + POut.String(jobQuote.Hours) + "'";
            }
            if (jobQuote.ApprovedAmount != oldJobQuote.ApprovedAmount)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ApprovedAmount = '" + POut.String(jobQuote.ApprovedAmount) + "'";
            }
            if (jobQuote.IsCustomerApproved != oldJobQuote.IsCustomerApproved)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "IsCustomerApproved = " + POut.Bool(jobQuote.IsCustomerApproved) + "";
            }
            if (command == "")
            {
                return(false);
            }
            if (jobQuote.Note == null)
            {
                jobQuote.Note = "";
            }
            OdSqlParameter paramNote = new OdSqlParameter("paramNote", OdDbType.Text, POut.StringParam(jobQuote.Note));

            command = "UPDATE jobquote SET " + command
                      + " WHERE JobQuoteNum = " + POut.Long(jobQuote.JobQuoteNum);
            Db.NonQ(command, paramNote);
            return(true);
        }
Ejemplo n.º 12
0
 ///<summary>Inserts one JobQuote into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(JobQuote jobQuote)
 {
     return(InsertNoCache(jobQuote, false));
 }