public MainForm()
        {
            //Check DB
            if (String.IsNullOrEmpty(MainUtils.readDataConnect()))
            {
                loadAttachDBFirst();
            }

            InitializeComponent();

            MainUtils.checkFolder();

            dropboxNemiro = new DropboxNemiro(this, null);
            DBHelper      = new DatabaseHelper();
            mainUtils     = new MainUtils();

            //CheckBox network
            mainUtils.runCheckConnection();

            SyncWithDropbox();

            updateDataGridView();

            loadProductDetail(IDItemCurrent);

            autoComplete();
        }
        private void updateDataGridView()
        {
            List <Product> products = DBHelper.getAllProduct();

            if (products != null)
            {
                //Load database
                dgvProducts.DataSource = DBHelper.getDBConnection().Dt;

                //Update data
                dgvProducts.DataSource = MainUtils.convertListToDataTable(products);

                //Update current cell selected.
                if (iIndex > 0)
                {
                    dgvProducts.CurrentCell = dgvProducts[0, iIndex];
                }

                updateIDItemCurrent();
            }
            else
            {
                MessageBox.Show("Không có sản phẩm nào trong dữ liệu!");
            }
        }
        public void printOrder(List <Product> productsCart)
        {
            var    file        = Path.GetTempFileName();
            string filepath    = Path.GetTempPath();
            string strFilename = MainUtils.getCurrentTime("h_mm_ss") + ".pdf";

            using (MemoryStream ms = new MemoryStream())
            {
                iTextSharp.text.Document document = new iTextSharp.text.Document(getPageSize(), 20, 20, 15, 15);

                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(Path.Combine(filepath, strFilename), FileMode.Create));
                document.AddTitle("Document Title");
                document.Open();

                iTextSharp.text.pdf.BaseFont Vn_Helvetica      = iTextSharp.text.pdf.BaseFont.CreateFont(@"C:\Windows\Fonts\arial.ttf", "Identity-H", iTextSharp.text.pdf.BaseFont.EMBEDDED);
                iTextSharp.text.Font         titleFont         = new iTextSharp.text.Font(Vn_Helvetica, 18, iTextSharp.text.Font.BOLD);
                iTextSharp.text.Font         subTitleFont      = new iTextSharp.text.Font(Vn_Helvetica, 14, iTextSharp.text.Font.NORMAL);
                iTextSharp.text.Font         boldTableFont     = new iTextSharp.text.Font(Vn_Helvetica, 12, iTextSharp.text.Font.BOLD);
                iTextSharp.text.Font         endingMessageFont = new iTextSharp.text.Font(Vn_Helvetica, 10, iTextSharp.text.Font.NORMAL);
                iTextSharp.text.Font         bodyFont          = new iTextSharp.text.Font(Vn_Helvetica, 12, iTextSharp.text.Font.NORMAL);

                document.Add(new iTextSharp.text.Paragraph(Properties.Settings.Default.ShopName, titleFont));

                var orderInfoTable = new PdfPTable(2);
                orderInfoTable.HorizontalAlignment = 0;
                orderInfoTable.SpacingBefore       = 10;
                orderInfoTable.SpacingAfter        = 10;
                orderInfoTable.DefaultCell.Border  = 0;
                orderInfoTable.SetWidths(new int[] { 70, 150 });

                //Id of Order
                orderInfoTable.AddCell(new iTextSharp.text.Phrase("Mã đơn hàng: ", boldTableFont));
                orderInfoTable.AddCell("");
                double totalPrice = 0;

                //Products
                for (int i = 0; i < productsCart.Count; i++)
                {
                    int c = i + 1;
                    orderInfoTable.AddCell(new iTextSharp.text.Phrase("Sản phẩm " + c + ": ", boldTableFont));
                    orderInfoTable.AddCell(new iTextSharp.text.Phrase(productsCart[i].getName(), bodyFont));
                    orderInfoTable.AddCell(new iTextSharp.text.Phrase("Mã sản phẩm " + c + ": ", boldTableFont));
                    orderInfoTable.AddCell(productsCart[i].getpID());
                    orderInfoTable.AddCell(new iTextSharp.text.Phrase("Số lượng " + c + ": ", boldTableFont));
                    orderInfoTable.AddCell(productsCart[i].getQuantity().ToString());
                    totalPrice += double.Parse(productsCart[i].getPrice());
                }

                //Total price
                orderInfoTable.AddCell(new iTextSharp.text.Phrase("Tổng giá:", boldTableFont));
                orderInfoTable.AddCell(Convert.ToDecimal(totalPrice).ToString("###,###,###.00") + " dong");

                document.Add(orderInfoTable);

                document.Close();
            }
            System.Diagnostics.Process.Start(filepath + strFilename);
        }
Example #4
0
        public SelectProductsFrom(List <BuyProduct> buyPros)
        {
            mainUtils = new MainUtils();

            InitializeComponent();
            this.CenterToScreen();
            this.buyPros = buyPros;
            newBuyPros   = new List <BuyProduct>();

            loadCheckListBox();
        }
Example #5
0
 private void CreateNewImage(String pathImage, String fileName)
 {
     if (!string.IsNullOrEmpty(pathImage))
     {
         String newImagePath = ConstantPath.imagePath + fileName;
         Image  image        = Image.FromFile(pathImage);
         if (image != null)
         {
             Image newImage = MainUtils.ScaleImage(image, ConstantPath.imageW, ConstantPath.imageH);
             newImage.Save(newImagePath, ImageFormat.Jpeg);
         }
     }
 }
Example #6
0
        public void AddNew()
        {
            tbName.Text        = "";
            tbQuality.Text     = "";
            tvPrice.Text       = "";
            txtPhone.Text      = "";
            txtDate.Text       = MainUtils.getCurrentDate();
            txtProducts.Text   = "";
            txtTotalPrice.Text = "";
            txtDiscount.Text   = "0";
            tbNote.Text        = "";

            addNew = true;
            tbName.Focus();
        }
        private void updateDataGridViewFirst()
        {
            //Load database
            dgvProducts.DataSource = DBHelper.getDBConnection().Dt;

            //Update data
            dgvProducts.DataSource = MainUtils.convertListToDataTable(DBHelper.getAllProduct());

            //Update current cell selected.
            if (!addNew)
            {
                dgvProducts.CurrentCell = dgvProducts[0, MainForm.ItemSelected];
                updateIDItemCurrent();
            }
        }
        public void prepareJsonFile()
        {
            //info file
            VersionUpload versionUpload = new VersionUpload(TimeUtils.getCurrentTimeInMilisecond(), System.Environment.MachineName);
            String        jsonVersion   = JsonHelper.ParseVersionUploadToJson(versionUpload);

            MainUtils.writeFileJson(jsonVersion, ConstantPath.jsonPath + ConstantPath.verJson);

            String json = JsonHelper.ParseProductsToJson(DBhelper.getAllProduct());

            MainUtils.writeFileJson(json, ConstantPath.jsonPath + ConstantPath.productJson);
            //json = JsonHelper.ParseOrdersToJson(DBhelper.getAllOrder());
            //MainUtils.writeFileJson(json, ConstantPath.jsonPath + ConstantPath.orderJson);

            //save version in local
            Properties.Settings.Default.FinalVersionUpload = Convert.ToString(versionUpload.time);
        }
        private void updateSearchDescDataGridView(String value)
        {
            List <Product> products = DBHelper.getProductsLike(ProductsTable.COLUMN_DESC, value);

            if (products.Count > 0)
            {
                //Load database
                dgvProducts.DataSource = DBHelper.getDBConnection().Dt;

                //Update data
                dgvProducts.DataSource = MainUtils.convertListToDataTable(products);

                //Update current cell selected.
                //dgvProducts.CurrentCell = dgvProducts[0, iIndex];

                updateIDItemCurrent();
            }
        }
Example #10
0
        public OrdersForm(MainForm mainForm, String value)
        {
            this.mainForm     = mainForm;
            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.OrderForm_Closing);

            mainUtils = new MainUtils();
            DBhelper  = new DatabaseHelper();

            if (value == null)
            {   // Nothings
            }
            else if (value.Equals("ADDNEW"))
            {
                addNew = true;
            }

            InitializeComponent();
            this.CenterToScreen();

            updateDataGridViewFirst();

            if (addNew)
            {
                eventAdd_Click();
            }
            else
            {
                loadOrderDetail(IDItemCurrent);
            }

            //AutoComple
            List <string> arrays = new List <string>();

            arrays.Add(ProductsTable.COLUMN_NAME);
            arrays.Add(ProductsTable.COLUMN_ID);
            listNameProAutoComplete = mainUtils.getListInfosOfAllProduct(arrays);
            var autoCollection = new AutoCompleteStringCollection();

            autoCollection.AddRange(listNameProAutoComplete.ToArray());
            this.txtAddProduct.AutoCompleteCustomSource = autoCollection;
            this.txtAddProduct.AutoCompleteMode         = AutoCompleteMode.Suggest;
            this.txtAddProduct.AutoCompleteSource       = AutoCompleteSource.CustomSource;
        }
        private void updateDataForCart()
        {
            //Load database
            dgvCart.DataSource = DBHelper.getDBConnection().Dt;

            //Update data
            dgvCart.DataSource = MainUtils.convertListToDataTableCart(productsCart);

            mainUtils.addButtonToGridView(dgvCart);

            //show / hidden cart gridview
            if (productsCart.Count == 0)
            {
                dgvCart.Visible = false;
            }
            else
            {
                dgvCart.Visible = true;
            }
        }
Example #12
0
 public void Connect()
 {
     if (!Connstatus)
     {
         String strCon = MainUtils.readDataConnect();
         //String strCon = ("server="+ Properties.Settings.Default.Server +";" +
         //                         "Trusted_Connection=yes;" +
         //                         "database="+ Properties.Settings.Default.Database +"; " +
         //                         "connection timeout=30");
         try
         {
             Cnn = new SqlConnection(strCon);
             Cnn.Open();
             //                    MessageBox.Show("Well done!");
             Connstatus = true;
         }
         catch (Exception ex)
         {
             MessageBox.Show("You failed!" + ex.Message);
         }
     }
 }