public IEnumerable <Detail> Del_now(ShowProduct data) { List <Detail> results = new List <Detail>(); try { Detail value = new Detail(); using (HR_SALEDataContext db = new HR_SALEDataContext()) { //---------------------- HR_DelProduct ---------------// var Del = (from xx in db.HR_SALE_PIs where xx.STCODE == data.de_USER && xx.ABBNO == data.de_ABBNO && xx.MPCODE == data.de_MPCODE select xx).FirstOrDefault(); db.HR_SALE_PIs.DeleteOnSubmit(Del); db.SubmitChanges(); //---------------------------------------------------- var ss = db.HR_SALE_GetBal(data.de_USER).FirstOrDefault(); if (ss == null) { var ss2 = (from sale in db.HR_SALE_USERs where sale.STCODE == data.de_USER select sale).FirstOrDefault(); //---------------------- HR_ChBal ---------------// var USER = (from xx in db.HR_SALE_USERs where xx.STCODE == data.de_USER select xx).FirstOrDefault(); USER.BAL = ss.Total - 0; db.SubmitChanges(); //---------------------------------------------------- } else { //---------------------- HR_ChBal ---------------// var USER = (from xx in db.HR_SALE_USERs where xx.STCODE == data.de_USER select xx).FirstOrDefault(); USER.BAL = ss.Total - ss.NET; db.SubmitChanges(); //---------------------------------------------------- } } results.Add(value); } catch (Exception ex) { Detail res = new Detail(); res.status = "F"; res.message = ex.Message; results.Add(res); } return(results.ToArray()); }
public IEnumerable <Detail> SetProduct(Product data) { List <Detail> results = new List <Detail>(); try { Detail value = new Detail(); if (data.QTY <= 0) { value.Error = "QTY"; //return RedirectToAction("BuyProduct", "Employee"); } else { using (HR_SALEDataContext db = new HR_SALEDataContext()) { var q = (from xx in db.HR_SALE_PIs where xx.STCODE == data.Get_USER select xx).OrderByDescending(xx => xx.ABBNO).FirstOrDefault(); value.q = q; if (q == null) { int Set_QTY = data.QTY; var Set_USER = data.Get_USER; int Set_PRICE = Convert.ToInt32(Convert.ToDouble(data.Get_PRICE)); var Set_MPCODE = data.Get_MPCODE; var ABB = "00001"; int NET = Set_QTY * Set_PRICE; DateTime Get_date = DateTime.Now; DateTime Get_today = DateTime.Today; using (HR_SALEDataContext db2 = new HR_SALEDataContext()) { //var ss = db2.HR_GetBal(Set_USER).FirstOrDefault(); var ss = (from sale in db2.HR_SALE_USERs where sale.STCODE == data.Get_USER select sale).FirstOrDefault(); if (NET > ss.TOTAL) { value.Error = "limit"; //return RedirectToAction("Main", "Employee"); } else { //---------------------- HR_GetProduct ---------------// var ux = new HR_SALE_PI(); ux.STCODE = Set_USER; ux.ABBNO = ABB; ux.MPCODE = Set_MPCODE; ux.QTY = Set_QTY; ux.PRICE = Set_PRICE; ux.NET = NET; ux.PTDATE = Get_date; ux.WORKDATE = Get_today; ux.FLAG = 0; db2.HR_SALE_PIs.InsertOnSubmit(ux); //---------------------------------------------------- //---------------------- HR_ChBal ---------------// var USER = (from xx in db2.HR_SALE_USERs where xx.STCODE == Set_USER select xx).FirstOrDefault(); USER.BAL = ss.TOTAL - NET; db2.SubmitChanges(); //---------------------------------------------------- } } } else { var c = (from xx in db.HR_SALE_PIs where xx.STCODE == data.Get_USER && xx.MPCODE == data.Get_MPCODE && xx.FLAG == 0 select xx); if (c.Count() > 0) { value.Error = "check"; //return RedirectToAction("Main", "Employee"); } else { value.q_FLAG = q.FLAG; if (q.FLAG == 0) { int Set_QTY = data.QTY; var Set_USER = data.Get_USER; int Set_PRICE = Convert.ToInt32(Convert.ToDouble(data.Get_PRICE)); var Set_MPCODE = data.Get_MPCODE; var ABB = q.ABBNO; int NET = Set_QTY * Set_PRICE; DateTime Get_date = DateTime.Now; DateTime Get_today = DateTime.Today; using (HR_SALEDataContext db2 = new HR_SALEDataContext()) { var ss = db2.HR_SALE_GetBal(Set_USER).FirstOrDefault(); if (ss.NET + NET > ss.Total) { value.Error = "limit"; //return RedirectToAction("Main", "Employee"); } else { //---------------------- HR_GetProduct ---------------// var ux = new HR_SALE_PI(); ux.STCODE = Set_USER; ux.ABBNO = ABB; ux.MPCODE = Set_MPCODE; ux.QTY = Set_QTY; ux.PRICE = Set_PRICE; ux.NET = NET; ux.PTDATE = Get_date; ux.WORKDATE = Get_today; ux.FLAG = 0; db2.HR_SALE_PIs.InsertOnSubmit(ux); db2.SubmitChanges(); //---------------------------------------------------- var ss2 = db2.HR_SALE_GetBal(Set_USER).FirstOrDefault(); //---------------------- HR_ChBal ---------------// var USER = (from xx in db2.HR_SALE_USERs where xx.STCODE == Set_USER select xx).FirstOrDefault(); USER.BAL = ss.Total - ss2.NET; db2.SubmitChanges(); //---------------------------------------------------- } } } else if (q.FLAG == 1 || q.FLAG == 2) { //var a = "00001"; //var b = intval(); int intTostr = Convert.ToInt32(Convert.ToDouble(q.ABBNO)); int Plus = intTostr + 1; var New_ABBNO = Plus.ToString(); for (int i = New_ABBNO.Length; i < 5; i++) { New_ABBNO = "0" + New_ABBNO; } int Set_QTY = data.QTY; var Set_USER = data.Get_USER; int Set_PRICE = Convert.ToInt32(Convert.ToDouble(data.Get_PRICE)); var Set_MPCODE = data.Get_MPCODE; var ABB = New_ABBNO; int NET = Set_QTY * Set_PRICE; DateTime Get_date = DateTime.Now; DateTime Get_today = DateTime.Today; using (HR_SALEDataContext db2 = new HR_SALEDataContext()) { var ss2 = (from sale in db.HR_SALE_USERs where sale.STCODE == Set_USER select sale).FirstOrDefault(); //---------------------- HR_GetProduct ---------------// var ux = new HR_SALE_PI(); ux.STCODE = Set_USER; ux.ABBNO = ABB; ux.MPCODE = Set_MPCODE; ux.QTY = Set_QTY; ux.PRICE = Set_PRICE; ux.NET = NET; ux.PTDATE = Get_date; ux.WORKDATE = Get_today; ux.FLAG = 0; db2.HR_SALE_PIs.InsertOnSubmit(ux); //---------------------------------------------------- //---------------------- HR_ChBal ---------------// var USER = (from xx in db2.HR_SALE_USERs where xx.STCODE == Set_USER select xx).FirstOrDefault(); USER.BAL = ss2.TOTAL - NET; db2.SubmitChanges(); //---------------------------------------------------- } } } } } results.Add(value); } } catch (Exception ex) { //Detail res = new Detail(); //res.status = "F"; //res.message = ex.Message; //results.Add(res); } return(results.ToArray()); }
public IEnumerable <Detail> Change_now(ShowProduct data) { List <Detail> results = new List <Detail>(); try { Detail value = new Detail(); if (data.ch_QTY <= 0) { value.Error = "QTY"; //TempData["QTY"] = "false"; //return RedirectToAction("Main", "Employee"); } else { int price = Convert.ToInt32(Convert.ToDouble(data.ch_PRICE)); int ch_price = data.ch_QTY * price; using (HR_SALEDataContext db = new HR_SALEDataContext()) { var ss = db.HR_SALE_GetBal(data.ch_USER).FirstOrDefault(); try { if (ss.NET + ch_price > ss.Total) { value.Error = "limit"; //TempData["limit"] = "false"; //return RedirectToAction("Main", "Employee"); } else { //---------------------- HR_ChProduct ---------------// var ch = (from xx in db.HR_SALE_PIs where xx.STCODE == data.ch_USER && xx.MPCODE == data.ch_MPCODE && xx.ABBNO == data.ch_ABBNO select xx).FirstOrDefault(); ch.QTY = data.ch_QTY; ch.NET = ch_price; db.SubmitChanges(); //---------------------------------------------------- var ss2 = db.HR_SALE_GetBal(data.ch_USER).FirstOrDefault(); //---------------------- HR_ChBal ---------------// var USER = (from xx in db.HR_SALE_USERs where xx.STCODE == data.ch_USER select xx).FirstOrDefault(); USER.BAL = ss2.Total - ss2.NET; db.SubmitChanges(); //---------------------------------------------------- } } catch { } } } results.Add(value); } catch (Exception ex) { Detail res = new Detail(); res.status = "F"; res.message = ex.Message; results.Add(res); } return(results.ToArray()); }