Ejemplo n.º 1
0
    public void CreateRoom()
    {
        roomID        = GenerateID.NumberOnly(5);
        connectAction = ConnectAction.CREATE;

        Connect();
    }
Ejemplo n.º 2
0
    protected void GridViewExpense_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        logger.Info(HttpContext.Current.Request.Cookies["User_ID"].Value + " " + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString() + " " + System.Reflection.MethodBase.GetCurrentMethod().Name);

        if (e.CommandName == "AddNew")
        {
            string        User_ID    = HttpContext.Current.Request.Cookies["User_ID"].Value;
            dbo_UserClass user_class = dbo_UserDataClass.Select_Record(User_ID);

            try
            {
                dbo_RevenueExpenseClass rev = new dbo_RevenueExpenseClass();
                rev.Post_No   = txtPost_No.Text;// GenerateID.Post_No(user_class.CV_CODE);
                rev.CV_Code   = user_class.CV_CODE;
                rev.Post_Date = DateTime.Now;

                TextBox txtFooterRevenue_Amount = (TextBox)GridViewExpense.FooterRow.FindControl("txtFooter_Amount");
                rev.Amount = txtFooterRevenue_Amount.Text == "" ? 0 : decimal.Parse(txtFooterRevenue_Amount.Text);
                DropDownList _ddlFooterDetail = (DropDownList)GridViewExpense.FooterRow.FindControl("ddlFooterDetail");
                rev.Account_Code = _ddlFooterDetail.SelectedValue;
                rev.Account_No   = GenerateID.EP(user_class.CV_CODE);
                TextBox txtFooterRemark = (TextBox)GridViewExpense.FooterRow.FindControl("txtFooterRemark");
                rev.Remark = txtFooterRemark.Text;

                bool succes = false;
                succes = dbo_RevenueExpenseDataClass.Add(rev);

                if (succes)
                {
                    System.Threading.Thread.Sleep(500);
                    ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true);
                    Show("บันทึกสำเร็จ!");
                }

                GridViewExpense.ShowFooter = false;

                InitialExpense();

                System.Threading.Thread.Sleep(500);
                ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true);
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }
        }
        else if (e.CommandName == "_Delete")
        {
            LinkButton lnkView    = (LinkButton)e.CommandSource;
            string     Account_No = lnkView.CommandArgument;

            dbo_RevenueExpenseDataClass.Delete(Account_No);

            System.Threading.Thread.Sleep(500);
            ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true);
            Show("ลบข้อมูลสำเร็จ");

            InitialExpense();
        }
    }
Ejemplo n.º 3
0
    protected void ButtonCreateNew_Click(object sender, EventArgs e)
    {
        //
        GridViewRole.EditIndex = -1;
        //DataTable dt = dbo_RoleDataClass.SelectAll();
        //GridViewRole.DataSource = dt.DefaultView;
        //GridViewRole.DataBind();
        GridViewRole.ShowFooter = true;
        SearchSubmit();

        try
        {
            TextBox _Row_ID = (TextBox)GridViewRole.FooterRow.FindControl("txtNewRole_ID");
            _Row_ID.Enabled = false;
            _Row_ID.Text    = GenerateID.Role_ID();

            TextBox      _Row_Name = (TextBox)GridViewRole.FooterRow.FindControl("txtNewRole_Name");
            DropDownList _Row_Type = (DropDownList)GridViewRole.FooterRow.FindControl("ddlNewRole_Type");

            _Row_Name.Focus();
        }
        catch (Exception)
        {
        }

        //  ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAM", "  window.scrollTo(0, document.body.clientHeight);", true);
        //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(),
        //   "selectNode", @"var node = document.getElementById('ContentPlaceHolder1_TreeView2t22');node.scrollIntoView(true);elem.scrollLeft=0;", true);

        System.Threading.Thread.Sleep(500);
        ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true);
    }
Ejemplo n.º 4
0
        public bool InsertCompanyNoteInfo(NoteInfo noteInfo, List <NoteInfoDetail> noteInfoDetails)
        {
            using (DbContextTransaction transaction = Context.Database.BeginTransaction())
            {
                try
                {
                    long seq = NoteInfoDAO.GetMaxSEQ(BSServerConst.NoteInfoSymbol) + 1;
                    noteInfo.NoteID = GenerateID.NewID(BSServerConst.NoteInfoSymbol, seq, false, false);

                    NoteInfoDAO.InsertNoteInfo(noteInfo);

                    // Thêm chi tiết
                    foreach (var data in noteInfoDetails)
                    {
                        data.NoteID = noteInfo.NoteID;
                        NoteInfoDetailDAO.InsertNoteInfoDetail(data);
                    }

                    transaction.Commit();

                    return(true);
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    BSLog.Logger.Error(ex.Message);
                    return(false);
                }
            }
        }
Ejemplo n.º 5
0
    private void InsertRecord()
    {
        logger.Info(HttpContext.Current.Request.Cookies["User_ID"].Value + " " + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString() + " " + System.Reflection.MethodBase.GetCurrentMethod().Name);
        dbo_ProductClass clsdbo_Product = new dbo_ProductClass();

        SetData(clsdbo_Product);


        bool   success = false;
        string User_ID = HttpContext.Current.Request.Cookies["User_ID"].Value;

        success = dbo_ProductDataClass.Add(clsdbo_Product, User_ID);

        dbo_ProductListClass clsdbo_ProductList = new dbo_ProductListClass();


        List <dbo_PriceGroupClass> price_group    = dbo_PriceGroupDataClass.Search(string.Empty, "0");
        dbo_PriceGroupClass        price_group_id = price_group.FirstOrDefault(f => f.StandardPrice == true);

        clsdbo_ProductList.Price_Group_ID  = price_group_id.Price_Group_ID;
        clsdbo_ProductList.Product_List_ID = GenerateID.Product_List_ID();
        var date = new DateTime(9456, 12, 31);

        clsdbo_ProductList.Agent_Price            = clsdbo_Product.Agent_Price;
        clsdbo_ProductList.Product_Effective_Date = DateTime.Now;
        clsdbo_ProductList.Start_Effective_Date   = DateTime.Now;
        clsdbo_ProductList.End_Effective_Date     = date;
        clsdbo_ProductList.Product_ID             = clsdbo_Product.Product_ID;
        clsdbo_ProductList.Product_Name           = clsdbo_Product.Product_Name;
        clsdbo_ProductList.Point = clsdbo_Product.Point;
        clsdbo_ProductList.Vat   = clsdbo_Product.Vat;
        //clsdbo_ProductList.CP_Meiji_Price = clsdbo_Product.CP_Meiji_Price;

        dbo_ProductListDataClass.Add(clsdbo_ProductList, User_ID);

        price_group    = dbo_PriceGroupDataClass.Search(string.Empty, "1");
        price_group_id = price_group.FirstOrDefault(f => f.StandardPrice == true);


        if (price_group_id != null)
        {
            clsdbo_ProductList.Price_Group_ID  = price_group_id.Price_Group_ID;
            clsdbo_ProductList.SP_Price        = clsdbo_Product.SP_Price;
            clsdbo_ProductList.CP_Meiji_Price  = clsdbo_Product.CP_Meiji_Price;
            clsdbo_ProductList.Agent_Price     = null;
            clsdbo_ProductList.Product_List_ID = GenerateID.Product_List_ID();

            dbo_ProductListDataClass.Add(clsdbo_ProductList, User_ID);
        }

        if (success)
        {
            Show("บันทึกสำเร็จ");
        }
        else
        {
            Show("error");
        }
    }
Ejemplo n.º 6
0
 public override void OnJoinRandomFailed(short returnCode, string message)
 {
     Debug.Log("Falhou ao se conectar a uma sala... Criando Sala");
     roomID = GenerateID.NumberOnly(5);
     PhotonNetwork.CreateRoom(roomID, new RoomOptions {
         MaxPlayers = maxPlayers
     });
 }
Ejemplo n.º 7
0
        public bool InsertCompany(Company data)
        {
            long seq = this.CompanyDAO.GetCompanySEQ() + 1;

            data.CompanyID = GenerateID.CompanyID(seq);

            return(this.CompanyDAO.InsertCompany(data));
        }
 public bool SaveDMQLConnectQL(List <QuanLy> quanLies, DMQuanLy dMQuanLies)
 {
     using (DbContextTransaction transaction = Context.Database.BeginTransaction())
     {
         try
         {
             long seq = DMQLConnectQLDAO.GetDMQLConnectQLSEQ();
             foreach (QuanLy data in quanLies)
             {
                 #region chuẩn bị dữ liệu cho DMQLConnectQL
                 //Khi insert Quan Lý thì Quản Lý sẽ thuộc một Danh mục quản lý được chọn trước đó.
                 //Đảm bảo rằng khi thay đổi năm quyết toán của QuanLy thì dữ liệu quyết toán năm cũ không thay đổi.
                 DMQLConnectQL dMQLConnectQL = new DMQLConnectQL();
                 dMQLConnectQL.DMQuanLyID     = dMQuanLies.DMQuanLyID;
                 dMQLConnectQL.QLID           = data.QLID;
                 dMQLConnectQL.QLMa           = data.QLMa;
                 dMQLConnectQL.QLTen          = data.QLTen;
                 dMQLConnectQL.QLNamQT        = data.QLNamQT;
                 dMQLConnectQL.QLNgayHopDong  = data.QLNgayHopDong;
                 dMQLConnectQL.QLSoHopDong    = data.QLSoHopDong;
                 dMQLConnectQL.QLSoLuongHD    = data.QLSoLuongHD;
                 dMQLConnectQL.QLDoanhThu     = data.QLDoanhThu;
                 dMQLConnectQL.QLVAT          = data.QLVAT;
                 dMQLConnectQL.QLNgayKhoiCong = data.QLNgayKhoiCong;
                 dMQLConnectQL.QLNgayKetThuc  = data.QLNgayKetThuc;
                 dMQLConnectQL.QLHopDong      = data.QLHopDong;
                 dMQLConnectQL.QLDuToan       = data.QLDuToan;
                 dMQLConnectQL.QLQuyetToan    = data.QLQuyetToan;
                 dMQLConnectQL.QLKLHoanThanh  = data.QLKLHoanThanh;
                 dMQLConnectQL.QLBBNghiemThu  = data.QLBBNghiemThu;
                 dMQLConnectQL.QLBBThanhLy    = data.QLBBThanhLy;
                 dMQLConnectQL.QLHSChuan      = data.QLHSChuan;
                 dMQLConnectQL.QLNhatKy       = data.QLNhatKy;
                 dMQLConnectQL.QLYCBoSung     = data.QLYCBoSung;
                 dMQLConnectQL.QLNo           = data.QLNo;
                 dMQLConnectQL.QLStatus       = data.QLStatus;
                 dMQLConnectQL.UserCreate     = UserInfo.UserID;
                 dMQLConnectQL.CompanyID      = CommonInfo.CompanyInfo.CompanyID;
                 #endregion chuẩn bị dữ liệu cho DMQLConnectQL
                 seq++;
                 dMQLConnectQL.DMQLConnectQLID = GenerateID.DMQLConnectQLID(seq);
                 this.DMQLConnectQLDAO.InsertDMQLConnectQL(dMQLConnectQL);
             }
             transaction.Commit();
             return(true);
         }
         catch (Exception e)
         {
             transaction.Rollback();
             Console.WriteLine("Update data fail.\r\n" + e.Message);
             return(false);
         }
     }
 }
        public bool SaveWareHouseDetail(List <WareHouseDetail> saveData, string voucherID)
        {
            using (DbContextTransaction transaction = Context.Database.BeginTransaction())
            {
                try
                {
                    long seq = WareHouseDetailDAO.GetWareHouseDetailSEQ();
                    foreach (WareHouseDetail data in saveData)
                    {
                        switch (data.Status)
                        {
                        // Add new
                        case ModifyMode.Insert:
                            seq++;
                            data.WareHouseDetailID = GenerateID.WareHouseDetailID(seq);
                            this.WareHouseDetailDAO.InsertWareHouseDetail(data);
                            break;

                        // Update
                        case ModifyMode.Update:
                            this.WareHouseDetailDAO.UpdateWareHouseDetail(data);
                            break;

                        // Delete
                        case ModifyMode.Delete:
                            this.WareHouseDetailDAO.DeleteWareHouseDetail(data.WareHouseDetailID, data.CompanyID);
                            DUTOANCONGTRINHmodel itemDTCTModel = new DUTOANCONGTRINHmodel
                            {
                                DonGiaXuat        = 0,
                                SoLuongXuat       = 0,
                                ThanhTienXuat     = 0,
                                WareHouseDetailID = data.WareHouseDetailID,
                                VouchersID        = voucherID,
                                ItemID            = data.ItemID,
                                ItemUnitID        = data.ItemUnitID
                            };
                            this.DUTOANCONGTRINHDAO.EditDUTOANCONGTRINH(itemDTCTModel);
                            //update Dự Toán Công Trình
                            break;
                        }
                    }
                    transaction.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    BSLog.Logger.Error(ex.Message);
                    return(false);
                }
            }
        }
Ejemplo n.º 10
0
    protected void ButtonAddNew_Click(object sender, EventArgs e)
    {
        logger.Info(HttpContext.Current.Request.Cookies["User_ID"].Value + " " + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString() + " " + System.Reflection.MethodBase.GetCurrentMethod().Name);


        try
        {
            string        User_ID    = HttpContext.Current.Request.Cookies["User_ID"].Value;
            dbo_UserClass user_class = dbo_UserDataClass.Select_Record(User_ID);

            string Post_No = GenerateID.Post_No(user_class.CV_CODE);

            List <dbo_RevenueExpenseClass> item_rev = dbo_RevenueExpenseDataClass.Search(Post_No, null, null, user_class.CV_CODE);

            if (item_rev.Count == 0)
            {
                pnlForm.Visible = true;
                pnlGrid.Visible = false;

                Textbox1.Text     = "0";
                Textbox2.Text     = "0";
                txtPost_Date.Text = DateTime.Now.ToShortDateString();
                txtPost_No.Text   = GenerateID.Post_No(user_class.CV_CODE);

                List <dbo_RevenueExpenseClass> item = dbo_RevenueExpenseDataClass.Search(txtPost_No.Text, null, null, user_class.CV_CODE);

                List <dbo_RevenueExpenseClass> item_rv = item.Where(f => f.Account_No.Substring(6, 2) == "RV").ToList(); //รายรับ
                List <dbo_RevenueExpenseClass> item_ep = item.Where(f => f.Account_No.Substring(6, 2) == "EP").ToList(); //รายจ่าย

                GridViewRevenue.DataSource = item_rv;
                GridViewRevenue.DataBind();

                GridViewExpense.DataSource = item_ep;
                GridViewExpense.DataBind();

                System.Threading.Thread.Sleep(500);
                ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true);
            }
            else
            {
                System.Threading.Thread.Sleep(500);
                ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true);
                Show("คุณได้ทำการบันทึกรายรับรายจ่ายของวันนี้แล้ว กรุณากลับไปแก้ไขรายการเดิม");
            }
        }
        catch (Exception ex)
        {
            logger.Error(ex.Message);
        }
    }
Ejemplo n.º 11
0
        public bool SaveItems(List <Items> saveData, out string itemID)
        {
            itemID = string.Empty;
            using (DbContextTransaction transaction = Context.Database.BeginTransaction())
            {
                try
                {
                    long seq = this.ItemsDAO.GetItemSEQ();
                    foreach (Items data in saveData)
                    {
                        switch (data.Status)
                        {
                        // Add new
                        case ModifyMode.Insert:
                            seq++;
                            data.ItemID = GenerateID.ItemID(seq);
                            itemID      = data.ItemID;

                            this.ItemsDAO.InsertItems(data);

                            break;

                        // Update
                        case ModifyMode.Update:
                            this.ItemsDAO.UpdateItems(data);
                            itemID = data.ItemID;

                            break;

                        // Delete
                        case ModifyMode.Delete:
                            this.ItemsDAO.DeleteItems(data);

                            break;
                        }
                    }

                    transaction.Commit();

                    return(true);
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    BSLog.Logger.Error(ex.Message);
                    return(false);
                }
            }
        }
Ejemplo n.º 12
0
        public bool SaveCustommers(List <Customer> customers, out string customerID)
        {
            customerID = string.Empty;
            using (DbContextTransaction transaction = Context.Database.BeginTransaction())
            {
                try
                {
                    long seq = this.CustomerDAO.GetCustomerSEQ();
                    foreach (Customer customer in customers)
                    {
                        switch (customer.Status)
                        {
                        // Add new
                        case ModifyMode.Insert:
                            seq++;
                            customerID          = GenerateID.CustomerID(seq);
                            customer.CustomerID = GenerateID.CustomerID(seq);

                            this.CustomerDAO.InsertCustomer(customer);

                            break;

                        // Update
                        case ModifyMode.Update:
                            customerID = customer.CustomerID;
                            this.CustomerDAO.UpdateCustomer(customer);

                            break;

                        // Delete
                        case ModifyMode.Delete:
                            this.CustomerDAO.DeleteCustomer(customer);

                            break;
                        }
                    }

                    transaction.Commit();

                    return(true);
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    BSLog.Logger.Error(ex.Message);
                    return(false);
                }
            }
        }
Ejemplo n.º 13
0
        public bool SaveItemType(List <ItemType> saveData)
        {
            using (DbContextTransaction transaction = Context.Database.BeginTransaction())
            {
                try
                {
                    long seq = this.ItemsDAO.GetItemTypeSEQ();
                    foreach (ItemType data in saveData)
                    {
                        switch (data.Status)
                        {
                        // Add new
                        case ModifyMode.Insert:
                            seq++;
                            data.ItemTypeID = GenerateID.ItemTypeID(seq);
                            data.CompanyID  = CommonInfo.CompanyInfo.CompanyID;

                            this.ItemTypeDAO.InsertItemType(data);
                            break;

                        // Update
                        case ModifyMode.Update:
                            data.CompanyID = CommonInfo.CompanyInfo.CompanyID;
                            this.ItemTypeDAO.UpdateItemType(data);
                            break;

                        // Delete
                        case ModifyMode.Delete:
                            this.ItemTypeDAO.DeleteItemType(data);
                            break;
                        }
                    }

                    transaction.Commit();

                    return(true);
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    BSLog.Logger.Error(ex.Message);
                    return(false);
                }
            }
        }
Ejemplo n.º 14
0
        public void AddItem(Item item)
        {
            PurchaseDetails purchaseDetails = null;

            try
            {
                purchaseDetails = Purchases.Find(x => x.Item.Id == item.Id);
            }
            catch (Exception ex)
            {
                Console.WriteLine("error looking for the same item\n");
                Logging.log.Error(ex);
            }

            if (purchaseDetails != null)
            {
                purchaseDetails.PurchaseItem.Quantity += 1;
                purchaseDetails.PurchaseItem.SubTotal  = purchaseDetails.PurchaseItem.Quantity * item.Price;

                if (PurchaseItemManager.Update(purchaseDetails.PurchaseItem))
                {
                    Console.WriteLine("Item Successfully added.");
                }
                else
                {
                    Console.WriteLine("Item not added! Please try again.");
                }
            }
            else
            {
                PurchaseItem purchaseItem = new PurchaseItem(GenerateID.GetGeneratedID(), PurchaseId, item.Id, 1, item.Price);

                if (PurchaseItemManager.Add(purchaseItem))
                {
                    Purchases.Add(new PurchaseDetails(purchaseItem, item));
                    Console.WriteLine("Item successfully added.");
                }
                else
                {
                    Console.WriteLine("Item not added! Please try again.");
                }
            }
        }
        public bool SaveVoucherCoverDetail(List <VoucherCoverDetail> saveData)
        {
            using (DbContextTransaction transaction = Context.Database.BeginTransaction())
            {
                try
                {
                    long seq = this.VoucherCoverDetailDAO.GetVoucherCoverDetailSEQ();
                    foreach (VoucherCoverDetail data in saveData)
                    {
                        switch (data.Status)
                        {
                        // Add new
                        case ModifyMode.Insert:
                            seq++;
                            data.VoucherCoverDetailID = GenerateID.VoucherCoverDetailID(seq);

                            this.VoucherCoverDetailDAO.InsertVoucherCoverDetail(data);
                            break;

                        // Update
                        case ModifyMode.Update:
                            this.VoucherCoverDetailDAO.UpdateVoucherCoverDetail(data);
                            break;

                        // Delete
                        case ModifyMode.Delete:
                            this.VoucherCoverDetailDAO.DeleteVoucherCoverDetail(data);
                            break;
                        }
                    }

                    transaction.Commit();

                    return(true);
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    BSLog.Logger.Error(ex.Message);
                    return(false);
                }
            }
        }
        //Dùng để thao tác đơn lẻ với S35
        public bool SaveS35MenuSanXuat(List <S35MenuSanXuat> saveData)
        {
            using (DbContextTransaction transaction = Context.Database.BeginTransaction())
            {
                try
                {
                    long seq = S35MenuSanXuatDAO.GetS35MenuSanXuatSEQ();
                    foreach (S35MenuSanXuat data in saveData)
                    {
                        switch (data.Status)
                        {
                        // Add new
                        case ModifyMode.Insert:
                            seq++;
                            data.S35MenuSXID = GenerateID.S35MenuSXID(seq);
                            this.S35MenuSanXuatDAO.InsertS35MenuSanXuat(data);
                            break;

                        // Update
                        case ModifyMode.Update:
                            // this.S35MenuSanXuatDAO.UpdateS35MenuVoucher(data);
                            // this.S35MenuDAO.UpdateS35Menu(data);
                            break;

                        // Delete
                        case ModifyMode.Delete:
                            this.S35MenuSanXuatDAO.DeleteS35MenuSanXuat(data);
                            //Khi delete S35Menu thì DB sẽ tự delete S35MenuDetail
                            break;
                        }
                    }
                    transaction.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    BSLog.Logger.Error(ex.Message);
                    return(false);
                }
            }
        }
Ejemplo n.º 17
0
        public bool SaveAccountGroup(List <AccountGroup> saveData)
        {
            using (DbContextTransaction transaction = Context.Database.BeginTransaction())
            {
                try
                {
                    long seq = this.AccountsDAO.GetAccountGroupSEQ();
                    foreach (AccountGroup data in saveData)
                    {
                        switch (data.Status)
                        {
                        // Add new
                        case ModifyMode.Insert:
                            seq += 1;
                            data.AccountGroupID = GenerateID.AccountGroupID(seq);
                            this.AccountsDAO.InsertAccountGroup(data);
                            break;

                        // Update
                        case ModifyMode.Update:
                            this.AccountsDAO.UpdateAccountGroup(data);
                            break;

                        // Delete
                        case ModifyMode.Delete:
                            this.AccountsDAO.DeleteAccountGroup(data);
                            break;
                        }
                    }

                    transaction.Commit();

                    return(true);
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    BSLog.Logger.Error(ex.Message);
                    return(false);
                }
            }
        }
        public bool SaveWareHouseList(List <WarehouseList> saveData)
        {
            using (DbContextTransaction transaction = Context.Database.BeginTransaction())
            {
                try
                {
                    long seq = WareHouseListDAO.GetWareHouseListSEQ();
                    foreach (WarehouseList data in saveData)
                    {
                        switch (data.Status)
                        {
                        // Add new
                        case ModifyMode.Insert:
                            seq++;
                            data.WarehouseListID = GenerateID.WareHouseListID(seq);
                            this.WareHouseListDAO.InsertWareHouseList(data);
                            break;

                        // Update
                        case ModifyMode.Update:
                            this.WareHouseListDAO.UpdateWareHouseList(data);
                            break;

                        // Delete
                        case ModifyMode.Delete:
                            this.WareHouseListDAO.DeleteWareHouseList(data.WarehouseListID, data.CompanyID);
                            break;
                        }
                    }

                    transaction.Commit();

                    return(true);
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    BSLog.Logger.Error(ex.Message);
                    return(false);
                }
            }
        }
Ejemplo n.º 19
0
        //Dùng để thao tác đơn lẻ với S35
        public bool SaveInvoiceS35(List <InvoiceS35> saveData)
        {
            using (DbContextTransaction transaction = Context.Database.BeginTransaction())
            {
                try
                {
                    long seq = InvoiceS35DAO.GetInvoiceS35SEQ();
                    foreach (InvoiceS35 data in saveData)
                    {
                        switch (data.Status)
                        {
                        // Add new
                        case ModifyMode.Insert:
                            seq++;
                            data.InvoiceS35ID = GenerateID.InvoiceS35ID(seq);
                            this.InvoiceS35DAO.InsertInvoiceS35(data);
                            break;

                        // Update
                        case ModifyMode.Update:
                            this.InvoiceS35DAO.UpdateInvoiceS35(data);
                            break;

                        // Delete
                        case ModifyMode.Delete:
                            this.InvoiceS35DAO.DeleteInvoiceS35(data);
                            //Khi delete InvoiceS35 thì DB sẽ tự delete InvoiceS35Detail
                            break;
                        }
                    }
                    transaction.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    BSLog.Logger.Error(ex.Message);
                    return(false);
                }
            }
        }
        public bool SaveProductMenu(List<ProductMenu> saveData, List<ProductMenu> saveDataBase)
        {
            using (DbContextTransaction transaction = Context.Database.BeginTransaction())
            {
                try
                {
                    long seq = ProductMenuDAO.GetProductMenuSEQ();
                    foreach (ProductMenu data in saveData)
                    {
                        switch (data.Status)
                        {
                            // Add new
                            case ModifyMode.Insert:
                                seq++;
                                data.ProductMenuID = GenerateID.ProductMenuID(seq);
                                this.ProductMenuDAO.InsertProductMenu(data);
                                break;
                            // Update
                            case ModifyMode.Update:
                                this.ProductMenuDAO.UpdateProductMenu(data);
                                break;
                            // Delete
                            case ModifyMode.Delete:
                                this.ProductMenuDAO.DeleteProductMenu(data);
                                break;
                        }
                    }

                    transaction.Commit();

                    return true;
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    BSLog.Logger.Error(ex.Message);
                    return false;
                }
            }
        }
Ejemplo n.º 21
0
        public bool SaveVoucherDetail(List <VoucherDetail> saveData)
        {
            using (DbContextTransaction transaction = Context.Database.BeginTransaction())
            {
                try
                {
                    long seq = VoucherDetailDAO.GetVoucherDetailSEQ();
                    foreach (VoucherDetail data in saveData)
                    {
                        switch (data.Status)
                        {
                        // Add new
                        case ModifyMode.Insert:
                            seq++;
                            data.VouchersDetailID = GenerateID.VoucherDetailID(seq);
                            this.VoucherDetailDAO.InsertVouchersDetail(data);
                            break;

                        // Update
                        case ModifyMode.Update:
                            this.VoucherDetailDAO.UpdateVoucherDetail(data);
                            break;

                        // Delete
                        case ModifyMode.Delete:
                            this.VoucherDetailDAO.DeleteVoucherDetail(data.VouchersDetailID, data.CompanyID);
                            break;
                        }
                    }
                    transaction.Commit();
                    return(true);
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    Console.WriteLine("Update data fail.\r\n" + e.Message);
                    return(false);
                }
            }
        }
        public bool SaveLockDB(List <LockDBCompany> saveData)
        {
            using (DbContextTransaction transaction = Context.Database.BeginTransaction())
            {
                try
                {
                    long seq = LockDBCompanyDAO.GetLockDBCompanySEQ();
                    foreach (LockDBCompany data in saveData)
                    {
                        switch (data.Status)
                        {
                        // Add new
                        case ModifyMode.Insert:
                            seq++;
                            data.ClockDBID = GenerateID.LockDBID(seq);
                            this.LockDBCompanyDAO.InsertLockDB(data);
                            break;

                        // Update
                        case ModifyMode.Update:
                            this.LockDBCompanyDAO.UpdateLockDB(data);
                            break;

                        // Delete
                        case ModifyMode.Delete:
                            this.LockDBCompanyDAO.DeleteLockDB(data);
                            break;
                        }
                    }
                    transaction.Commit();
                    return(true);
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    Console.WriteLine("Update data fail.\r\n" + e.Message);
                    return(false);
                }
            }
        }
        public bool SaveS35MenuSelected(List <S35MenuSelected> saveData)
        {
            using (DbContextTransaction transaction = Context.Database.BeginTransaction())
            {
                try
                {
                    long seq = S35MenuSelectedDAO.GetS35MenuSelectedSEQ();
                    foreach (S35MenuSelected data in saveData)
                    {
                        switch (data.Status)
                        {
                        // Add new
                        case ModifyMode.Insert:
                            seq++;
                            data.S35MenuSelectedID = GenerateID.S35MenuSelectedID(seq);
                            this.S35MenuSelectedDAO.InsertS35MenuSelected(data);
                            break;

                        // Update
                        case ModifyMode.Update:
                            this.S35MenuSelectedDAO.UpdateS35MenuSelected(data);
                            break;

                        // Delete
                        case ModifyMode.Delete:
                            this.S35MenuSelectedDAO.DeleteS35MenuSelected(data);
                            break;
                        }
                    }
                    transaction.Commit();
                    return(true);
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    Console.WriteLine("Update data fail.\r\n" + e.Message);
                    return(false);
                }
            }
        }
Ejemplo n.º 24
0
        public bool SaveBalance(List <Balance> saveData)
        {
            using (DbContextTransaction transaction = Context.Database.BeginTransaction())
            {
                try
                {
                    long seq = BalanceDAO.GetBalanceSEQ();
                    foreach (Balance data in saveData)
                    {
                        switch (data.Status)
                        {
                        // Add new
                        case ModifyMode.Insert:
                            seq++;
                            data.BalanceID = GenerateID.BalanceID(seq);
                            this.BalanceDAO.InsertBalance(data);
                            break;

                        // Update
                        case ModifyMode.Update:
                            this.BalanceDAO.UpdateBalance(data);
                            break;

                        // Delete
                        case ModifyMode.Delete:
                            this.BalanceDAO.DeleteBalance(data);
                            break;
                        }
                    }
                    transaction.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    BSLog.Logger.Error(ex.Message);
                    return(false);
                }
            }
        }
        //Thêm, xóa, sửa dự toán công trình
        public bool SaveDUTOANCONGTRINH(List <DUTOANCONGTRINHmodel> saveData)
        {
            using (DbContextTransaction transaction = Context.Database.BeginTransaction())
            {
                try
                {
                    long seq = DUTOANCONGTRINHDAO.GetDUTOANCONGTRINHSEQ();
                    foreach (DUTOANCONGTRINHmodel data in saveData)
                    {
                        switch (data.Status)
                        {
                        // Add new
                        case ModifyMode.Insert:
                            seq++;
                            data.DTCTID = GenerateID.DuToanCongTrinhID(seq);
                            this.DUTOANCONGTRINHDAO.InsertDUTOANCONGTRINH(data);
                            break;

                        // Update
                        case ModifyMode.Update:
                            this.DUTOANCONGTRINHDAO.UpdateDUTOANCONGTRINH(data);
                            break;

                        // Delete
                        case ModifyMode.Delete:
                            this.DUTOANCONGTRINHDAO.DeleteDUTOANCONGTRINH(data);
                            break;
                        }
                    }
                    transaction.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    BSLog.Logger.Error(ex.Message);
                    return(false);
                }
            }
        }
        private static int GetID()
        {
            int           id  = GenerateID.GetID(table);
            SqlConnection sql = new SqlConnection(constr);

            sql.Open();
            String        command       = "SELECT *  FROM " + table + " ;";
            SqlCommand    sql1          = new SqlCommand(command, sql);
            SqlDataReader sqlDataReader = sql1.ExecuteReader();

            ;
            int ID = 1;

            while (sqlDataReader.Read())
            {
                ID = (int)sqlDataReader[0] + 1;
            }
            sqlDataReader.Close();
            sql.Close();
            sql1.Dispose();
            return(ID);
        }
Ejemplo n.º 27
0
    protected void GridViewCycle_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        logger.Info(HttpContext.Current.Request.Cookies["User_ID"].Value + " " + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString() + " " + System.Reflection.MethodBase.GetCurrentMethod().Name);
        if (e.CommandName == "EditCycle")
        {
            int RowIndex = Convert.ToInt32((e.CommandArgument).ToString());

            List <dbo_OrderAndDeliveryCycleClass> item1 = dbo_OrderAndDeliveryCycleDataClass.SelectAll();

            if (item1.Count < GridViewCycle.Rows.Count && RowIndex > int.Parse(ViewState["current_index"].ToString()))
            {
                RowIndex--;
            }

            current_index = RowIndex;

            ViewState["current_index"] = current_index;

            LinkButton currbtn = (LinkButton)GridViewCycle.Rows[RowIndex].FindControl("lnkB_SetOrder_Cycle_Name");

            //Label cycle_id = (Label)GridViewCycle.Rows[RowIndex].FindControl("lblOrder_Cycle_ID");
            string orderCycleID = item1[RowIndex].Order_Cycle_ID;


            if (currbtn.Text == "แก้ไขรอบสั่งรอบส่ง")
            {
                dbo_OrderAndDeliveryCycleClass cycle = new dbo_OrderAndDeliveryCycleClass()
                {
                };

                List <dbo_OrderAndDeliveryCycleClass> item = dbo_OrderAndDeliveryCycleDataClass.SelectAll();

                item.Insert(RowIndex + 1, new dbo_OrderAndDeliveryCycleClass()
                {
                });

                GridViewCycle.DataSource = item;

                GridViewCycle.DataBind();
                currbtn      = (LinkButton)GridViewCycle.Rows[RowIndex].FindControl("lnkB_SetOrder_Cycle_Name");
                currbtn.Text = "ปิด";


                //List<dbo_OrderAndDeliveryCycleValueClass> item_value = dbo_OrderAndDeliveryCycleValueDataClass.Search(cycle_id.Text);
                List <dbo_OrderAndDeliveryCycleValueClass> item_value = dbo_OrderAndDeliveryCycleValueDataClass.Search(orderCycleID);

                GridView   gv         = (GridView)GridViewCycle.Rows[RowIndex + 1].FindControl("grdNewValue");
                Button     newbutton1 = (Button)GridViewCycle.Rows[RowIndex + 1].FindControl("btnNewValue");
                LinkButton Cycle_Name = (LinkButton)GridViewCycle.Rows[RowIndex + 1].FindControl("lnkB_SetOrder_Cycle_Name");

                gv.DataSource = item_value;
                gv.DataBind();
                gv.Visible         = true;
                newbutton1.Visible = true;
                Cycle_Name.Visible = false;

                GridViewCycle.Rows[RowIndex + 1].Cells[2].ColumnSpan = 5;
                GridViewCycle.Rows[RowIndex + 1].Cells[0].Visible    = false;
                GridViewCycle.Rows[RowIndex + 1].Cells[1].Visible    = false;
                GridViewCycle.Rows[RowIndex + 1].Cells[3].Visible    = false;
                GridViewCycle.Rows[RowIndex + 1].Cells[4].Visible    = false;
                GridViewCycle.Rows[RowIndex + 1].Cells[5].Visible    = false;


                Label currlbl = (Label)GridViewCycle.Rows[RowIndex + 1].FindControl("lblOrder");
                currlbl.Visible = false;
                //
                currbtn.Visible = true;

                for (int i = RowIndex + 1; i < GridViewCycle.Rows.Count; i++)
                {
                    Label lbl_Amount = (Label)GridViewCycle.Rows[i].FindControl("lblOrder");
                    lbl_Amount.Text = i.ToString();
                }
            }
            else
            {
                List <dbo_OrderAndDeliveryCycleClass> item = dbo_OrderAndDeliveryCycleDataClass.SelectAll();
                GridViewCycle.DataSource = item.OrderBy(f => f.Order_Cycle_ID);;
                GridViewCycle.DataBind();
            }
        }
        else if (e.CommandName == "AddNew")
        {
            string _Order_Cycle_ID = GenerateID.Order_Cycle_ID();

            TextBox _Order_Cycle_Name = (TextBox)GridViewCycle.FooterRow.FindControl("txtNewOrder_Cycle_Name");
            if (_Order_Cycle_Name.Text.Trim() != string.Empty)
            {
                dbo_OrderAndDeliveryCycleClass cycle = new dbo_OrderAndDeliveryCycleClass()
                {
                    Order_Cycle_ID = _Order_Cycle_ID, Order_Cycle_Name = _Order_Cycle_Name.Text
                };

                bool   success = false;
                string User_ID = HttpContext.Current.Request.Cookies["User_ID"].Value;
                success = dbo_OrderAndDeliveryCycleDataClass.Add(cycle, User_ID);

                if (success)
                {
                    //string script = @"swal(""บันทึกสำเร็จ!"", """", ""success"")";
                    //ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAM", script, true);

                    // Show("บันทึกสำเร็จ");

                    GridViewCycle.ShowFooter = false;


                    List <dbo_OrderAndDeliveryCycleClass> item = dbo_OrderAndDeliveryCycleDataClass.SelectAll();
                    GridViewCycle.DataSource = item.OrderBy(f => f.Order_Cycle_ID);;
                    GridViewCycle.DataBind();
                }

                System.Threading.Thread.Sleep(500);
                ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true);
            }
            else
            {
                System.Threading.Thread.Sleep(500);
                ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true);
                Show("กรุณากรอกข้อมูลที่จำเป็นให้ครบถ้วน");
            }
        }
    }
        //S35MenuFinal
        //S35MenuFinalEx
        //S35MenuFinalWH
        public bool SaveS35MenuFinalFull(List <S35MenuFinalEx> dataList, List <S35MenuFinal> detailListData, List <S35MenuFinalWH> finalWHData)
        {
            using (DbContextTransaction transaction = Context.Database.BeginTransaction())
            {
                try
                {
                    foreach (S35MenuFinalEx data in dataList)
                    {
                        List <S35MenuFinal> detailData = detailListData.Where(o => o.S35MenuFinalExID == data.S35MenuFinalExID).ToList();
                        long seq       = S35MenuFinalExDAO.GetS35MenuFinalExSEQ();
                        long seqdetail = S35MenuFinalDAO.GetS35MenuFinalSEQ();
                        switch (data.Status)
                        {
                        // Thêm warehouse mới thì sẽ thực hiện thêm Detail mới nếu ListDetail có giá trị
                        case ModifyMode.Insert:
                            seq++;
                            data.S35MenuFinalExID = GenerateID.S35MenuFinalExID(seq);
                            this.S35MenuFinalExDAO.InsertS35MenuFinalEx(data);
                            if (detailData.Count > 0)
                            {
                                //thêm S35MenuFinal
                                #region insert S35MenuFinal
                                foreach (S35MenuFinal s35MenuFinal in detailData)
                                {
                                    if (s35MenuFinal.Status == ModifyMode.Insert)
                                    {
                                        seqdetail++;
                                        s35MenuFinal.S35MenuFinalID   = GenerateID.S35MenuFinalID(seqdetail);
                                        s35MenuFinal.S35MenuFinalExID = data.S35MenuFinalExID;
                                        this.S35MenuFinalDAO.InsertS35MenuFinal(s35MenuFinal);
                                    }
                                }
                                #endregion insert S35MenuFinal
                            }
                            break;

                        // Delete
                        case ModifyMode.Delete:
                            this.S35MenuFinalExDAO.DeleteS35MenuFinalEx(data);
                            //Khi delete warehouse thì DB sẽ tự delete warehouse
                            break;
                        }
                    }
                    //Them Final Warehouse
                    foreach (S35MenuFinalWH s35MenuFinalWH in finalWHData)
                    {
                        long seq = S35MenuFinalWHDAO.GetS35MenuFinalWHSEQ();
                        switch (s35MenuFinalWH.Status)
                        {
                        case ModifyMode.Insert:
                            seq++;
                            s35MenuFinalWH.S35MenuFinalWHID = GenerateID.S35MenuFinalWHID(seq);
                            this.S35MenuFinalWHDAO.InsertS35MenuFinalWH(s35MenuFinalWH);
                            break;
                        }
                    }

                    transaction.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    BSLog.Logger.Error(ex.Message);
                    return(false);
                }
            }
        }
        }                                                     //Không có ID riêng

        public bool SaveS35MenuDetailSanXuatFinal(ThanhPhamKey thanhpham, List <S35MenuDetailSanXuatFinal> s35menudetailsx, List <S35MenuSanXuatWH> nguyenlieu, List <ItemDetailS35MenuSX> congthucsd, List <S35MenuSanXuat> s35menusx)
        {
            using (DbContextTransaction transaction = Context.Database.BeginTransaction())
            {
                try
                {
                    long tpseq = ThanhPhamKeyDAO.ThanhPhamSEQ();
                    tpseq++;
                    thanhpham.TPID = GenerateID.ThanhPhamID(tpseq);
                    ThanhPhamKeyDAO.InsertThanhPhamKey(thanhpham);
                    //Insert truy vết MenuSanXuat
                    foreach (S35MenuSanXuat s35MenuSanXuat in s35menusx)
                    {
                        S35MenuSXConnectDT tempData = new S35MenuSXConnectDT
                        {
                            TPID        = thanhpham.TPID,
                            S35MenuSXID = s35MenuSanXuat.S35MenuSXID,
                            CompanyID   = CommonInfo.CompanyInfo.CompanyID,
                            CreateUser  = UserInfo.UserID
                        };
                        S35MenuSXConnectDTDAO.InsertS35MenuSXConnectDT(tempData);
                    }

                    long s35menudetailsxseq = S35MenuDetailSanXuatFinalDAO.S35MenuDetailSanXuatFinalSEQ();
                    long nguyenlieuseq      = S35MenuSanXuatWHDAO.S35MenuSanXuatWHSEQ();
                    long congthucsdseq      = ItemDetailS35MenuSXDAO.ItemDetailMenuSEQ();
                    //insert danh sách thành phẩm
                    foreach (S35MenuDetailSanXuatFinal s35MenuDetailSanXuatFinal in s35menudetailsx)
                    {
                        //Chạy từng món
                        switch (s35MenuDetailSanXuatFinal.Status)
                        {
                        // Thêm S35 mới thì sẽ thực hiện thêm Detail mới nếu ListDetail có giá trị
                        case ModifyMode.Insert:
                            s35menudetailsxseq++;
                            s35MenuDetailSanXuatFinal.S35MenuDetailSXFNID = GenerateID.S35MenuDetailSXFNID(s35menudetailsxseq);
                            s35MenuDetailSanXuatFinal.TPID = thanhpham.TPID;
                            this.S35MenuDetailSanXuatFinalDAO.InsertS35MenuDetailSanXuatFinal(s35MenuDetailSanXuatFinal);
                            s35MenuDetailSanXuatFinal.Status = ModifyMode.None;
                            //Sau khi insert S35MenuDetailSanXuatFinal thành công thì insert danh sách nguyên liệu, lưu lại loại công thức, Lưu vết truy xuất liên quan menu
                            List <ItemDetailS35MenuSX> nguyenlieuListmenu = congthucsd.Where(o => o.ItemID == s35MenuDetailSanXuatFinal.ItemID).ToList();
                            //Insert công thức liên quan của 1 món
                            foreach (ItemDetailS35MenuSX itemDetailS35MenuSX in nguyenlieuListmenu)
                            {
                                congthucsdseq++;
                                itemDetailS35MenuSX.ItemDetailS35MenuSXID = GenerateID.ItemDetailMenuID(congthucsdseq);
                                itemDetailS35MenuSX.S35MenuDetailSXFNID   = s35MenuDetailSanXuatFinal.S35MenuDetailSXFNID;
                                ItemDetailS35MenuSXDAO.InsertItemDetailS35MenuSX(itemDetailS35MenuSX);
                            }
                            break;
                        }
                    }
                    //Insert nguyên liệu
                    foreach (S35MenuSanXuatWH nguyenlieuItem in nguyenlieu)
                    {
                        //Chạy từng món
                        switch (nguyenlieuItem.Status)
                        {
                        // Thêm S35 mới thì sẽ thực hiện thêm Detail mới nếu ListDetail có giá trị
                        case ModifyMode.Insert:
                            nguyenlieuseq++;
                            nguyenlieuItem.S35MenuSanXuatWHID = GenerateID.S35MenuSXWHID(nguyenlieuseq);
                            nguyenlieuItem.TPID = thanhpham.TPID;
                            this.S35MenuSanXuatWHDAO.InsertS35MenuSanXuatWH(nguyenlieuItem);
                            nguyenlieuItem.Status = ModifyMode.None;
                            break;
                        }
                    }

                    transaction.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    BSLog.Logger.Error(ex.Message);
                    return(false);
                }
            }
        }
Ejemplo n.º 30
0
        static void Main(string[] args)
        {
            IView customerList = new CustomerListView();
            IView customerView = null;

            while (customerView == null)
            {
                customerList.Show();
                Console.WriteLine("\nAre you a new customer?\nPress 1 if yes, otherwise press 2.");
                int response = Console.ReadLine().ToInt(-1);
                Console.Clear();

                if (response == 1)
                {
                    Customer customer = new Customer();

                    customer.Id = GenerateID.GetGeneratedID();
                    Console.WriteLine("Enter your first name:");
                    customer.FirstName = Console.ReadLine();
                    Console.WriteLine("Enter your Middle name:");
                    customer.MiddleName = Console.ReadLine();
                    Console.WriteLine("Enter your Last name:");
                    customer.LastName = Console.ReadLine();
                    Console.WriteLine("Enter your gender 'M' - Male, 'F' - Female:");
                    customer.Gender = Console.ReadLine();
                    Console.WriteLine("Enter your contact no.");
                    customer.ContactNo = Console.ReadLine();
                    Console.WriteLine("Enter your email address:");
                    customer.Email = Console.ReadLine();
                    Console.WriteLine("Enter your current address");
                    customer.Address = Console.ReadLine();

                    customerView = new CustomerView(customer);

                    if (((CustomerView)customerView).CustomerManager.Add(customer))
                    {
                        Console.WriteLine("Member succesfully added! See details below.");
                        customerView.Show();
                    }
                    else
                    {
                        Console.WriteLine("Member can't be added.");
                        customerView = null;
                    }
                }
                else if (response == 2)
                {
                    Console.WriteLine("Enter your Id.");
                    Customer customer = ((CustomerListView)customerList).Manager.GetById(Console.ReadLine().ToInt(-1), "Id");
                    if (customer == null)
                    {
                        Console.WriteLine($"Entered Id can't be found!");
                    }
                    else
                    {
                        customerView = new CustomerView(customer);
                    }
                }
                else
                {
                    Console.WriteLine("Response not recognize. Please try again.");
                }
            }

            while (true)
            {
                Console.WriteLine($"\nHello {((CustomerView)customerView).Customer.Info.FirstName}! What would you like to do?");
                Console.WriteLine("Press 1 to show your order history. Press 2 to shop! Press 3 to exit.\n");
                int response = Console.ReadLine().ToInt(-1);

                Console.Clear();

                if (response == 1)
                {
                    customerView.Show();
                }
                else if (response == 2)
                {
                    IView           cartView        = null;
                    bool            doneShopping    = false;
                    PurchaseHistory purchaseHistory = ((CustomerView)customerView).Customer.PurchaseHistory.Find(x => x.Purchase.Status == "Pending");
                    Purchase        purchase;

                    if (purchaseHistory == null)
                    {
                        purchase = new Purchase(GenerateID.GetGeneratedID(), ((CustomerView)customerView).Customer.Info.Id,
                                                "Pending", DateTime.Now.ToString(), 0);

                        if (((CustomerView)customerView).PurchaseManager.Add(purchase))
                        {
                            Console.WriteLine("New purchase. Add items to your cart.");
                            ((CustomerView)customerView).Customer.PurchaseHistory.Add(new PurchaseHistory(purchase));
                            cartView = new CartView(new List <PurchaseDetails>(), purchase.Id);
                        }
                        else
                        {
                            Console.WriteLine("Can't create new purchase. Please try again.");
                            doneShopping = true;
                        }
                    }
                    else
                    {
                        purchase = purchaseHistory.Purchase;
                        Console.WriteLine("You have a pending purchase. Restoring.");
                        cartView = new CartView(purchaseHistory.PurchaseDetails, purchaseHistory.Purchase.Id);
                    }

                    IView groceriesView = new GroceriesView();

                    while (!doneShopping)
                    {
                        Console.WriteLine("Press 1 to add an item, 2 to change the quantity of an item, " +
                                          "3 to show your cart, and 4 to check out, 5 to exit.\n");
                        groceriesView.Show();
                        Console.WriteLine();

                        int input;

                        input = Console.ReadLine().ToInt(0);
                        Actions action = (Actions)input;

                        Console.Clear();

                        switch (action)
                        {
                        case Actions.ADD_ITEM:
                        {
                            Console.WriteLine("Enter the barcode of an item");
                            Item item = ((GroceriesView)groceriesView).Manager.GetById(Console.ReadLine().ToInt(-1), "Id");

                            if (item == null)
                            {
                                Console.WriteLine("Item can't be found.");
                            }
                            else
                            {
                                ((CartView)cartView).AddItem(item);
                            }

                            break;
                        }

                        case Actions.CHANGE_QUANTITY:
                        {
                            Console.WriteLine("Enter the barcode of an item to change quantity.");
                            int id = Console.ReadLine().ToInt(-1);

                            Item item = null;

                            try
                            {
                                item = ((CartView)cartView).Purchases.Find(x => x.PurchaseItem.ItemId == id).Item;
                            }
                            catch (Exception ex)
                            {
                                Logging.log.Error(ex);
                            }

                            if (item != null)
                            {
                                Console.WriteLine("Enter the new quantity of the item");
                                int quantity = Console.ReadLine().ToInt(-1);

                                if (quantity == -1)
                                {
                                    Console.WriteLine("Can't change quantity for that value");
                                }
                                else
                                {
                                    ((CartView)cartView).ChangeQuantity(item, quantity);
                                }
                            }
                            else
                            {
                                Console.WriteLine("Entered item can't be found!");
                            }

                            break;
                        }

                        case Actions.SHOW_CART:
                        {
                            cartView.Show();
                            break;
                        }

                        case Actions.CHECK_OUT:
                        {
                            using (TransactionScope scope = new TransactionScope())
                            {
                                float total = ((CartView)cartView).ComputeTotalPrice();
                                purchase.Status = "Purchased";
                                purchase.Date   = DateTime.Now.ToString();
                                purchase.Total  = total;

                                if (((CustomerView)customerView).PurchaseManager.Update(purchase))
                                {
                                    Console.WriteLine("Thank you. Please come again.");
                                    doneShopping = true;
                                }
                                else
                                {
                                    Console.WriteLine("Can't proceed to check out. Please try again.");
                                    break;
                                }

                                scope.Complete();
                            }

                            break;
                        }

                        case Actions.EXIT:
                        {
                            doneShopping = true;
                            break;
                        }

                        default:
                        {
                            Console.WriteLine("Action not recognize. Try again.");
                            break;
                        }
                        }
                    }
                }
                else if (response == 3)
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Response not recognize. Please try again.");
                }
            }
        }