Ejemplo n.º 1
0
 public void UpdateDosareAfterCompensare()
 {
     foreach (Edge e in this.Edges)
     {
         if (e.Weight == 0)
         {
             foreach (int id_dosar in e.IduriDosare)
             {
                 //update compensare si status dosar = "compensat"
                 Dosar      d          = new Dosar(authenticatedUserId, connectionString, id_dosar);
                 Compensare compensare = new Compensare(authenticatedUserId, connectionString);
                 compensare.ID_DOSAR = id_dosar;
                 compensare.DATA     = DateTime.Now.Date;
                 compensare.SUMA     = d.VALOARE_REGRES;
                 compensare.REST     = 0;
                 response r = compensare.Insert();
                 if (r.Status)
                 {
                     d.ChangeStatus("COMPENSAT");
                 }
             }
         }
         else
         {
             double sum = 0;
             foreach (int id_dosar in e.IduriDosare)
             {
                 Dosar d = new Dosar(authenticatedUserId, connectionString, id_dosar);
                 sum += Convert.ToDouble(d.VALOARE_REGRES);
                 Compensare compensare = new Compensare(authenticatedUserId, connectionString);
                 compensare.ID_DOSAR = id_dosar;
                 compensare.DATA     = DateTime.Now.Date;
                 string _status = "";
                 if (e.InitialWeight - sum > e.Weight)
                 {
                     //update compensare si status dosar = "compensat"
                     compensare.SUMA = d.VALOARE_REGRES;
                     compensare.REST = 0;
                     _status         = "COMPENSAT";
                 }
                 else
                 {
                     //update compensare cu rest si status dosar = "compensat partial" - TO DO
                     compensare.SUMA = e.InitialWeight - (sum - d.VALOARE_REGRES);
                     compensare.REST = d.VALOARE_REGRES - compensare.SUMA;
                     _status         = "COMPENSAT_PARTIAL";
                 }
                 response r = compensare.Insert();
                 if (r.Status)
                 {
                     d.ChangeStatus(_status);
                 }
             }
         }
     }
 }