Ejemplo n.º 1
0
        public String repeat_project(Int64 projid, String projname)
        {
            try
            {
                using (var db = new dbsmsEntities())
                {
                    project           p_lama          = db.projects.Find(projid);
                    hrfq              hrfq_lama       = p_lama.hrfqs.First();
                    List <drfq>       drfq_lama       = hrfq_lama.drfqs.ToList();
                    List <findprice>  findprice_lama  = p_lama.findprices.ToList();
                    hpenawaran        hpenawaran_lama = p_lama.hpenawarans.First();
                    List <dpenawaran> dpenawaran_lama = hpenawaran_lama.dpenawarans.ToList();

                    status  s      = new status();
                    project p_baru = new project();
                    p_baru.status1     = s;
                    p_baru.name        = projname;
                    p_baru.status      = 0;
                    p_baru.customer    = p_lama.customer;
                    p_baru.description = "";
                    db.projects.Add(p_baru);

                    hrfq hrfq_baru = new hrfq();
                    hrfq_baru.customer    = hrfq_lama.customer;
                    hrfq_baru.date        = DateTime.Now;
                    hrfq_baru.description = "";
                    hrfq_baru.to          = hrfq_lama.to;
                    hrfq_baru.description = hrfq_lama.description;
                    hrfq_baru.project     = p_baru;
                    db.hrfqs.Add(hrfq_baru);

                    drfq_lama.ForEach(x =>
                    {
                        drfq drfq_baru            = new drfq();
                        drfq_baru.hrfq            = hrfq_baru;
                        drfq_baru.itemcategoryid  = x.itemcategoryid;
                        drfq_baru.itemdescription = x.itemdescription;
                        drfq_baru.qty             = x.qty;
                        drfq_baru.subtotal        = x.subtotal;
                        drfq_baru.unitprice       = x.unitprice;
                        db.drfqs.Add(drfq_baru);
                    });

                    findprice_lama.ForEach(x =>
                    {
                        findprice findprice_baru       = new findprice();
                        findprice_baru.address         = x.address;
                        findprice_baru.description     = x.description;
                        findprice_baru.itemdescription = x.itemdescription;
                        findprice_baru.project         = p_baru;
                        findprice_baru.qty             = x.qty;
                        findprice_baru.status          = x.status;
                        findprice_baru.supplier        = x.supplier;
                        findprice_baru.timeneeded      = x.timeneeded;
                        findprice_baru.unitprice       = x.unitprice;
                        db.findprices.Add(findprice_baru);
                    });

                    hpenawaran hpenawaran_baru = new hpenawaran();
                    hpenawaran_baru.customer    = hpenawaran_lama.customer;
                    hpenawaran_baru.date        = DateTime.Now;
                    hpenawaran_baru.description = "";
                    hpenawaran_baru.to          = hpenawaran_lama.to;
                    hpenawaran_baru.description = hpenawaran_lama.description;
                    hpenawaran_baru.project     = p_baru;
                    hpenawaran_baru.disc        = hpenawaran_lama.disc;
                    hpenawaran_baru.grandtotal  = hpenawaran_lama.grandtotal;
                    hpenawaran_baru.number      = GlobalFunction.generate_code("PNW");
                    hpenawaran_baru.to          = hpenawaran_lama.to;
                    hpenawaran_baru.total       = hpenawaran_lama.total;
                    db.hpenawarans.Add(hpenawaran_baru);

                    dpenawaran_lama.ForEach(x =>
                    {
                        dpenawaran dpenawaran_baru      = new dpenawaran();
                        dpenawaran_baru.hpenawaran      = hpenawaran_baru;
                        dpenawaran_baru.itemcategoryid  = x.itemcategoryid;
                        dpenawaran_baru.itemdescription = x.itemdescription;
                        dpenawaran_baru.qty             = x.qty;
                        dpenawaran_baru.subtotal        = x.subtotal;
                        dpenawaran_baru.unitprice       = x.unitprice;
                        dpenawaran_baru.supplier        = x.supplier;
                        db.dpenawarans.Add(dpenawaran_baru);
                    });

                    p_baru.status1.rfq        = 1;
                    p_baru.status1.findprices = 1;
                    p_baru.status1.penawaran  = 1;

                    db.SaveChanges();
                }
                Int64 id = GlobalFunction.get_max_id("project");
                Session["project"] = id;
                return("success");
            }
            catch
            {
                return("fail");
            }
        }
Ejemplo n.º 2
0
 public String save_all(String quotedate, String quoteto, Int64 projectid, String desc, Int64 total, Int64 disc, Int64 grandtotal, String detail, Boolean edit = false)
 {
     try
     {
         DateTime datenow = Convert.ToDateTime(quotedate);
         using (var db = new dbsmsEntities())
         {
             hpenawaran newdata = new hpenawaran();
             if (edit)
             {
                 newdata = db.projects.Find(projectid).hpenawarans.First();
             }
             newdata.date      = datenow;
             newdata.projectid = projectid;
             if (!edit)
             {
                 newdata.number = GlobalFunction.generate_code("PNW");
             }
             newdata.customerid  = db.projects.Find(projectid).customer.id;
             newdata.to          = quoteto;
             newdata.description = desc;
             newdata.disc        = disc;
             newdata.total       = total;
             newdata.grandtotal  = grandtotal;
             if (!edit)
             {
                 db.hpenawarans.Add(newdata);
             }
             if (edit)
             {
                 List <dpenawaran> dpn = newdata.dpenawarans.ToList();
                 db.dpenawarans.RemoveRange(dpn);
             }
             String[] res = detail.Split('ѥ');
             for (int i = 0; i < res.Length - 1; i++)
             {
                 String[]   result = res[i].Split('Ё');
                 dpenawaran data   = new dpenawaran();
                 //itemcatid+"Ё"+itemdescription+"Ё"+suppid+"Ё"+qty+"Ё"+unitprice+"Ё"+subtotal
                 data.itemcategoryid  = Convert.ToInt64(result[0]);
                 data.itemdescription = result[1];
                 data.supplierid      = Convert.ToInt32(result[2]);
                 data.qty             = Convert.ToInt32(result[3]);
                 data.unitprice       = Convert.ToInt32(result[4]);
                 data.subtotal        = data.qty * data.unitprice;
                 data.hpenawaran      = newdata;
                 //data.penawaranid = GlobalFunction.get_max_id("hpenawaran");
                 db.dpenawarans.Add(data);
             }
             db.SaveChanges();
             using (var db1 = new dbsmsEntities())
             {
                 if (!edit)
                 {
                     db1.hpenawarans.Find(GlobalFunction.get_max_id("hpenawaran")).project.status1.penawaran = 1;
                 }
                 db1.SaveChanges();
                 return("success");
             }
         }
     }
     catch (Exception e)
     {
         return("fail");
     }
 }