Пример #1
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            item iTem = new item();

            this.ID       = itemController.getIDfromDB();
            iTem.ID       = this.ID;
            iTem.itemcode = this.txtitemcode.Text;
            iTem.itemname = this.txtitemname.Text;
            iTem.form     = this.cbBox.SelectedItem.ToString();
            iTem.NSX      = this.datetimeNSX.Value;
            iTem.HSD      = this.datetimeHSD.Value;
            iTem.NNK      = this.datetimeNNK.Value;
            iTem.price    = this.txtPrice.Text;
            //   iTem.NCC = this.lstNCC.Text.Trim();

            iTem.listNCC = new List <NCC>();
            string displayNCCs = "";

            for (int i = 0; i < this.lstNCC.Items.Count; i++)
            {
                displayNCCs = displayNCCs.ToString() + this.lstNCC.Items[i].ToString() + " ";
                iTem.listNCC.Add(this.lstNCC.Items[i] as NCC);
            }
            iTem.NCC = displayNCCs;

            // datetimeBirthday.Value.ToString("dd/MM/yy");

            //them item vao csdl


            QRCodeGenerator qrGenerator = new QRCodeGenerator();
            //QRCode qrCode = new QRCode(qrGenerator.CreateQrCode(txtDataQRCode.Text, QRCodeGenerator.ECCLevel.Q));
            QRCode qrCode = new QRCode(qrGenerator.CreateQrCode(iTem.All(), QRCodeGenerator.ECCLevel.Q));

            //QRCodeGenerator.ECCLevel.Q là mức chịu lỗi 25%; .L là 7%; .M là 15% và .H là trên 25%
            pictureBox_QRCode.Image = qrCode.GetGraphic(10, Color.Black, Color.White, false);
            //   iTem.ImageToByteArray(pictureBox_QRCode.Image);


            //add item to database
            if (itemController.Updateitem(iTem) == false)
            {
                MessageBox.Show("Loi them item");
                return;
            }



            //Hien thi datagridview
            source                    = new BindingSource();
            source.DataSource         = itemController.getListitem();
            this.dataitems.DataSource = source;
        }
Пример #2
0
        private void btnAdditem_Click(object sender, EventArgs e)
        {
            errorProvider.Clear();
            int x = 1;

            //Kiem tra du lieu nhap vao
            if (this.txtitemcode.Text.Trim().Length <= 0)
            {
                this.errorProvider.SetError(this.txtitemcode, "Hãy nhập mã sản phẩm!");
                x = 0;
            }
            else if (itemController.getitem(this.txtitemcode.Text.Trim()) != null)
            {
                this.errorProvider.SetError(this.txtitemcode, "item da ton tai");
                return;
            }
            if (this.txtitemname.Text.Trim().Length <= 0)
            {
                this.errorProvider.SetError(this.txtitemname, "Hãy nhập ten san pham");
                x = 0;
            }

            if (cbBox.SelectedItem == null)
            {
                this.errorProvider.SetError(this.cbBox, "Hãy chọn form");
                x = 0;
            }

            if (DateTime.Now.Year < datetimeNSX.Value.Year)
            {
                this.errorProvider.SetError(this.datetimeNSX, "NSX > timeNow");
                x = 0;
            }

            if (this.txtPrice.Text.Trim().Length <= 0)
            {
                this.errorProvider.SetError(this.txtPrice, "Hãy nhập Gia san pham");
                x = 0;
            }

/*
 *          if (this.lstNCC.Items.ToString().Length <= 0)
 *          {
 *              this.errorProvider.SetError(this.lstNCC, "Hãy nhập nha cung cap");
 *              x = 0;
 *          }
 */

            if (x == 0)
            {
                return;
            }
            else
            {
                errorProvider.Clear();
            }


            item iTem = new item();

            this.ID       = itemController.getIDfromDB();
            iTem.ID       = this.ID;
            iTem.itemcode = this.txtitemcode.Text.Trim();
            iTem.itemname = this.txtitemname.Text.Trim();
            iTem.form     = this.cbBox.SelectedItem.ToString();
            iTem.NSX      = this.datetimeNSX.Value;
            iTem.HSD      = this.datetimeHSD.Value;
            iTem.NNK      = this.datetimeNNK.Value;
            iTem.price    = this.txtPrice.Text.Trim();
            //   iTem.NCC = this.lstNCC.Text.Trim();

            iTem.listNCC = new List <NCC>();
            string displayNCCs = "";

            for (int i = 0; i < this.lstNCC.Items.Count; i++)
            {
                displayNCCs = displayNCCs.ToString() + this.lstNCC.Items[i].ToString() + " ";
                iTem.listNCC.Add(this.lstNCC.Items[i] as NCC);
            }
            iTem.NCC = displayNCCs;

            // datetimeBirthday.Value.ToString("dd/MM/yy");

            //them item vao csdl

            //tao qr code
            QRCodeGenerator qrGenerator = new QRCodeGenerator();
            //QRCode qrCode = new QRCode(qrGenerator.CreateQrCode(txtDataQRCode.Text, QRCodeGenerator.ECCLevel.Q));
            QRCode qrCode = new QRCode(qrGenerator.CreateQrCode(iTem.All(), QRCodeGenerator.ECCLevel.Q));

            //QRCodeGenerator.ECCLevel.Q là mức chịu lỗi 25%; .L là 7%; .M là 15% và .H là trên 25%
            pictureBox_QRCode.Image = qrCode.GetGraphic(10, Color.Black, Color.White, false);
            //    iTem.ImageToByteArray(pictureBox_QRCode.Image);


            //add item to database
            if (itemController.Additem(iTem) == false)
            {
                MessageBox.Show("Loi them item");
                return;
            }


            //Hien thi datagridview
            source                    = new BindingSource();
            source.DataSource         = itemController.getListitem();
            this.dataitems.DataSource = source;
            //reset boxes
            this.txtitemcode.ResetText();
            this.txtitemname.ResetText();
            this.cbBox.ResetText();
            this.datetimeNSX.ResetText();
            this.datetimeHSD.ResetText();
            this.datetimeNNK.ResetText();
            this.txtPrice.ResetText();
            //   this.txtNCC.ResetText();
            this.lstNCC.Items.Clear();
            this.errorProvider.Clear();
        }