public String save_all(string detail) { try { using (var db = new dbsmsEntities()) { Int64 projid = Convert.ToInt64(Session["project"]); List <findprice> deleted = db.projects.Find(projid).findprices.ToList(); if (deleted.Count > 0) { db.findprices.RemoveRange(deleted); } db.SaveChanges(); String[] res = detail.Split('ѥ'); for (int i = 0; i < res.Length - 1; i++) { String[] result = res[i].Split('Ё'); findprice data = new findprice(); data.supplierid = Convert.ToInt64(result[0]); data.address = ""; data.itemcategoryid = Convert.ToInt64(result[1]); data.itemdescription = result[2]; data.qty = Convert.ToInt64(result[3]); data.unitprice = Convert.ToInt64(result[4]); data.timeneeded = Convert.ToInt64(result[5]); data.description = result[6]; data.status = 1; data.projectid = Convert.ToInt64(Session["project"]); db.findprices.Add(data); } db.SaveChanges(); using (var db1 = new dbsmsEntities()) { db1.findprices.Find(GlobalFunction.get_max_id("findprices")).project.status1.findprices = 1; db1.SaveChanges(); return("success"); } } } catch (Exception e) { return("fail"); } }
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"); } }