예제 #1
0
        public bool UpdateOffer(OfferDetailModel[] list, string OffID, string empApprove)
        {
            string sql_offer  = @"sp_offer_UPDATE";
            string sql_offDta = @"sp_offerDetail_UPDATE";

            object[] obj1 = { "@OffID", OffID, "@EmpApprove", empApprove };

            using (TransactionScope ts = new TransactionScope())
            {
                try { Db.Update(sql_offer, obj1); }
                catch { return(false); }
                foreach (var ls in list)
                {
                    object[] obj2 = { "@OffID", OffID, "@OfdNo", ls.OfdNo, "@PrdID", ls.PrdID, "@AmountApprove", ls.AmountApprove };
                    try { Db.Update(sql_offDta, obj2); }
                    catch { return(false); }
                }
                ts.Complete();
                return(true);
            }
        }
        public bool InsertSellProduct(SELLPRODUCT sellpd)
        {
            string sql         = @"sp_sellproduct_INSERT";
            string sql_dta     = @"sp_sellproductDTA_INSERT";
            string sql_reserve = @"sp_checkout_reserve";
            string retID       = "";

            using (TransactionScope ts = new TransactionScope())
            {
                object[] obj = { "@MemID",     sellpd.MemID,        "@SlpDate",   sellpd.SlpDate,   "@FnameRec", sellpd.FnameRec,
                                 "@LnameRec",  sellpd.LnameRec,     "@AdressRec", sellpd.AdressRec,
                                 "@SlpStatus", "ยังไม่ได้ชำระเงิน", "@SlpSum",    sellpd.SlpSum };
                retID = Db.InsertReturnID(sql, obj);
                if (retID != null)
                {
                    int Num = 0;
                    foreach (var ls in sellpd.SELLPRODUCT_DTA)
                    {
                        object[] obj_dta = { "@SlpID",     retID,        "@SlpNo",    Num++,       "@PrdID",    ls.PrdID,
                                             "@SpdAmount", ls.SpdAmount, "@SpdPrice", ls.SpdPrice, "@Discount", ls.Discount };
                        object[] obj_reserve = { "@PrdID", ls.PrdID, "@Amount", ls.SpdAmount };
                        try
                        {
                            Db.Insert(sql_dta, obj_dta);
                            Db.Update(sql_reserve, obj_reserve);
                        }
                        catch
                        {
                            return(false);
                        }
                    }
                    ts.Complete();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
        public bool DeletePayment(string id, List <SELLPRODUCT_DTA> ls)
        {
            string sql             = "sp_payment_DELETE";
            string sql_del_reserve = "sp_checkout_del_reserve";

            object[] obj = { "@SlpID", id };
            using (TransactionScope ts = new TransactionScope())
            {
                try
                {
                    Db.Delete(sql, obj);
                    foreach (var l in ls)
                    {
                        object[] obj_reverse = { "@PrdID", l.PrdID, "@Amount", l.SpdAmount };
                        Db.Update(sql_del_reserve, obj_reverse);
                    }
                    ts.Complete();
                    return(true);
                }
                catch { return(false); }
            }
        }
        public bool UpdateStock(string id, string status, List <SELLPRODUCT_DTA> ls)
        {
            string sql         = "sp_payment_UPDATE";
            string sql_serial  = "sp_sellproductDTAserial_INSERT";
            string sql_nserial = "sp_sellproductDTANOserial_INSERT";

            object[] obj = { "@SlpID", id, "@SlpStatus", status };

            using (TransactionScope ts = new TransactionScope())
            {
                try
                {
                    foreach (var item in ls)
                    {
                        List <String> tempSrlID   = new List <String>();
                        List <String> tempLot     = new List <String>();
                        int           OrderAmount = item.SpdAmount;
                        if (item.PRODUCT.SerialStatus.Equals("1"))
                        {
                            var result = item.PRODUCT.PRODUCTLOT
                                         .Where(x => x.Amount > 0)
                                         .Select(g => new
                            {
                                sss = g.SERIAL.Where(x => x.SrlStatus == "0").ToList(),
                            })
                                         .ToList();
                            foreach (var dd in result)
                            {
                                if (OrderAmount > 0)
                                {
                                    for (int i = 0; i < dd.sss.Count && OrderAmount > 0; i++)
                                    {
                                        if (tempSrlID.Contains(dd.sss[i].SrlID))
                                        {
                                            continue;
                                        }
                                        tempSrlID.Add(dd.sss[i].SrlID);
                                        OrderAmount--;
                                        object[] obj_serial = { "@SlpID", item.SlpID, "@SlpNo", item.SlpNo, "@SrlID", dd.sss[i].SrlID, "@PrdID", item.PrdID, "@LotNo", dd.sss[i].LotNo };
                                        Db.Insert(sql_serial, obj_serial);
                                    }
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            while (OrderAmount > 0)
                            {
                                var c = item.PRODUCT.PRODUCTLOT.Where(x => x.Amount > 0 && !tempLot.Contains(x.LotNo)).FirstOrDefault();
                                //สำหรับล๊อตที่มี จำนวนน้อยกว่าที่สั่งไว้ ต้องไปดึงมาจากล๊อตต่อไป
                                if (c.Amount <= OrderAmount)
                                {
                                    object[] obj_Nserial = { "@SlpID", item.SlpID, "@SlpNo", item.SlpNo, "@PrdID", item.PrdID, "@LotNo", c.LotNo, "@Amount", c.Amount };
                                    Db.Insert(sql_nserial, obj_Nserial);
                                    OrderAmount = OrderAmount - c.Amount;
                                    tempLot.Add(c.LotNo);
                                }
                                else
                                {
                                    object[] obj_Nserial = { "@SlpID", item.SlpID, "@SlpNo", item.SlpNo, "@PrdID", item.PrdID, "@LotNo", c.LotNo, "@Amount", OrderAmount };
                                    Db.Insert(sql_nserial, obj_Nserial);
                                    OrderAmount = 0;
                                }
                            }
                        }
                    }
                    Db.Update(sql, obj);
                    ts.Complete();
                    return(true);
                }
                catch (Exception ex) { Console.WriteLine(ex.Message); return(false); }
            }
        }
예제 #5
0
        public bool InsertEmpAndPhone(EmployeeEntity employee, ICollection <EMPLOYEE_PHONE> list, string UPDATEDATA)
        {
            string sql       = @"sp_employee_INSERT";
            string sql_phone = @"sp_empAndPhone_INSERT";
            string retID     = "";

            if (UPDATEDATA.Equals("INSERT"))
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    retID = Db.InsertReturnID(sql, Take(employee));
                    if (retID != null)
                    {
                        if (list.Count() == 0)
                        {
                            object[] obj = { "@PhoneNumber", "XXXXXXXXXX" };
                            Db.Insert(sql_phone, obj);
                        }
                        else
                        {
                            foreach (var ls in list)
                            {
                                object[] obj = { "@EmpID", retID, "@PhoneNumber", ls.Phone };
                                try
                                {
                                    Db.Insert(sql_phone, obj);
                                }
                                catch
                                {
                                    return(false);
                                }
                            }
                        }
                        ts.Complete();
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            else if (UPDATEDATA.Equals("UPDATE"))
            {
                string sql_emp = @"sp_employee_UPDATE";
                string sql_upd = @"sp_empAndPhone_UPDATE";
                string sql_del = @"sp_empAndPhone_DELETE";


                using (TransactionScope ts = new TransactionScope())
                {// UPDATE พนักงาน
                    Db.Update(sql_emp, Take2(employee));
                    // ลบ และ สร้าง เบอร์ใหม่ เพื่อ อัพเดท
                    object[] del = { "@EmpID", employee.EmpID };
                    Db.Delete(sql_del, del);
                    {
                        foreach (var ls in list)
                        {
                            object[] obj = { "@EmpID", employee.EmpID, "@Phone", ls.Phone };
                            try { Db.Insert(sql_upd, obj); }
                            catch { return(false); }
                        }
                        ts.Complete();
                        return(true);
                    }
                }
            }
            return(false);
        }