Beispiel #1
0
 public String save_all(String number, String date, long customerid, string to, string description, String projectName, string detail)
 {
     try
     {
         using (var db = new dbsmsEntities())
         {
             status  s = new status();
             project p = new project();
             p.status1     = s;
             p.name        = projectName;
             p.status      = 0;
             p.description = "";
             db.projects.Add(p);
             db.SaveChanges();
             Session["project"] = db.projects.Select(x => x.id).Max();
         }
         DateTime datenow = Convert.ToDateTime(date);
         using (var db = new dbsmsEntities())
         {
             hrfq newdata = new hrfq();
             newdata.number      = number;
             newdata.date        = datenow;
             newdata.customerid  = customerid;
             newdata.to          = to;
             newdata.description = description;
             newdata.projectid   = Convert.ToInt64(Session["project"]);
             db.hrfqs.Add(newdata);
             String[] res = detail.Split('ѥ');
             for (int i = 0; i < res.Length - 1; i++)
             {
                 String[] result = res[i].Split('Ё');
                 drfq     data   = new drfq();
                 data.itemcategoryid  = Convert.ToInt64(result[0]);
                 data.itemdescription = result[1];
                 data.qty             = Convert.ToInt32(result[2]);
                 data.unitprice       = Convert.ToInt32(result[3]);
                 data.subtotal        = data.qty * data.unitprice;
                 db.drfqs.Add(data);
             }
             db.SaveChanges();
             using (var db1 = new dbsmsEntities())
             {
                 db1.hrfqs.Find(GlobalFunction.get_max_id("hrfq")).project.status1.rfq = 1;
                 db1.hrfqs.Find(GlobalFunction.get_max_id("hrfq")).project.customerid  = customerid;
                 db1.SaveChanges();
                 return("success");
             }
         }
     }
     catch (Exception e)
     {
         return("fail");
     }
 }
Beispiel #2
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");
            }
        }