예제 #1
0
        //public DataTable LoadData(string strlenh)
        //{
        //    var dt = new DataTable();
        //    cmd.CommandText = strlenh;
        //    cmd.CommandType = CommandType.Text;
        //    cmd.Connection = con.Connection;
        //    try
        //    {
        //        con.OpenConn();

        //        var sda = new SqlDataAdapter(cmd);
        //        sda.Fill(dt);

        //    }
        //    catch (Exception )
        //    {
        //        cmd.Dispose();
        //        con.CloseConn();
        //    }

        //    return dt;
        //}


        public bool AddData(DonSanXuat_AveryObj donSanXuatAveryObj)
        {
            cmd.CommandText =
                "INSERT INTO tbDonSanXuat_Avery(No,OrderDate,RequestDate,SO,RBO,CustomerPO,CustomerItem,Item,Qty,Material,Length,MaterialQty,SKU,Cut,Fold,GopDon,NhanVien,DanhSach) VALUES('" +
                donSanXuatAveryObj.No + "', CONVERT(DATE, '" + donSanXuatAveryObj.Orderdate + "', 103), CONVERT(DATE, '" + donSanXuatAveryObj.Requestdate + "', 103),'" + donSanXuatAveryObj.So + "','" + donSanXuatAveryObj.Rbo + "','" + donSanXuatAveryObj.Customerpo +
                "','" + donSanXuatAveryObj.Customeritem + "','" + donSanXuatAveryObj.Item + "','" +
                donSanXuatAveryObj.Qty + "','" + donSanXuatAveryObj.Material + "','" + donSanXuatAveryObj.Length +
                "','" + donSanXuatAveryObj.Materialqty + "','" + donSanXuatAveryObj.Sku + "' ,N'" +
                donSanXuatAveryObj.Cut + "' ,N'" + donSanXuatAveryObj.Fold + "','" + donSanXuatAveryObj.Gopdon + "',N'" + donSanXuatAveryObj.NhanVien + "','" + donSanXuatAveryObj.Danhsach + "') ";
            cmd.CommandType = CommandType.Text;
            cmd.Connection  = con.Connection;
            try
            {
                con.OpenConn();
                cmd.ExecuteNonQuery();
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Không thêm được");
                var mex = ex.Message;
                cmd.Dispose();
                con.CloseConn();
            }

            return(false);
        }
예제 #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            var dsxObj = new DonSanXuat_AveryObj();

            if (XtraMessageBox.Show("Bạn có muốn lưu dữ liệu không", "Cảnh báo", MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Question) == DialogResult.Yes)
            {
                for (var index = 0; index <= gridView1.RowCount - 1; index++)
                {
                    var dr = gridView1.GetDataRow(index);
                    // Nếu dữ liệu trên grid view có thêm mới dữ liệu
                    if (dr.RowState == DataRowState.Added)
                    {
                        dsxObj.No           = (int)dr["No"];
                        dsxObj.Orderdate    = DateTime.Parse(dr["OrderDate"].ToString());
                        dsxObj.Requestdate  = DateTime.Parse(dr["RequestDate"].ToString());
                        dsxObj.So           = dr["SO"].ToString();
                        dsxObj.Rbo          = dr["RBO"].ToString();
                        dsxObj.Customerpo   = dr["CustomerPO"].ToString();
                        dsxObj.Customeritem = dr["CustomerItem"].ToString();
                        dsxObj.Item         = dr["Item"].ToString();
                        dsxObj.Qty          = (int)dr["Qty"];
                        dsxObj.Material     = dr["Material"].ToString();
                        dsxObj.Length       = (float)Convert.ToDouble(dr["Length"]);
                        dsxObj.Materialqty  = (float)Convert.ToDouble(dr["MaterialQty"]);
                        dsxObj.Sku          = (int)dr["SKU"];
                        dsxObj.Cut          = dr["Cut"].ToString();
                        dsxObj.Fold         = dr["Fold"].ToString();
                        dsxObj.Gopdon       = (int)dr["GopDon"];
                        dsxObj.NhanVien     = nvObj.Tennhanvien;
                        dsxObj.Danhsach     = (int)txtDanhSach.Value;
                        if (donSanXuatAveryCtr.Kiemtra(dsxObj.So) == 0)
                        {
                            donSanXuatAveryCtr.AddData(dsxObj);
                        }
                    }
                }
            }
            //MessageBox.Show("Thêm dữ liệu thành công");
        }
예제 #3
0
        //public DataTable GetData(string strlenh)
        //{
        //    return dsxAveryMod.LoadData(strlenh);
        //}

        public bool AddData(DonSanXuat_AveryObj donSanXuatAveryObj)
        {
            return(dsxAveryMod.AddData(donSanXuatAveryObj));
        }
예제 #4
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                var dsxObj = new DonSanXuat_AveryObj();
                if (XtraMessageBox.Show("Bạn có muốn lưu dữ liệu không", "Cảnh báo", MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Question) != DialogResult.Yes)
                {
                    return;
                }
                var db = new MyDBContextDataContext();
                if (flagluu == 1)
                {
                    for (var i = 0; i < gridView1.RowCount - 1; i++)
                    {
                        var dr = gridView1.GetDataRow(i);
                        // Nếu dữ liệu trên grid view có thêm mới dữ liệu
                        if (dr.RowState == DataRowState.Added)
                        {
                            dsxObj.No           = (int)dr["No"];
                            dsxObj.Orderdate    = DateTime.Parse(dr["OrderDate"].ToString());
                            dsxObj.Requestdate  = DateTime.Parse(dr["RequestDate"].ToString());
                            dsxObj.So           = dr["SO"].ToString();
                            dsxObj.Rbo          = dr["RBO"].ToString();
                            dsxObj.Customerpo   = dr["CustomerPO"].ToString();
                            dsxObj.Customeritem = dr["CustomerItem"].ToString();
                            dsxObj.Item         = dr["Item"].ToString();
                            dsxObj.Qty          = (int)dr["Qty"];
                            dsxObj.Material     = dr["Material"].ToString();
                            dsxObj.Length       = (float)Convert.ToDouble(dr["Length"]);
                            dsxObj.Materialqty  = (float)Convert.ToDouble(dr["MaterialQty"]);
                            dsxObj.Sku          = (int)dr["SKU"];
                            dsxObj.Cut          = dr["Cut"].ToString();
                            dsxObj.Fold         = dr["Fold"].ToString();
                            dsxObj.Gopdon       = (int)dr["GopDon"];
                            //dsxObj.dj
                            dsxObj.NhanVien = nvObj.Tennhanvien;
                            dsxObj.Danhsach = (int)txtDanhSach.Value;
                            if (donSanXuatAveryCtr.Kiemtra(dsxObj.So) == 0)
                            {
                                donSanXuatAveryCtr.AddData(dsxObj);
                            }
                        }
                    }
                }
                else if (flagluu == 2)
                {
                    for (var i = 0; i < gridView1.RowCount - 1; i++)
                    {
                        var dr = gridView1.GetDataRow(i);
                        if (dr.RowState == DataRowState.Modified)
                        {
                            var dsx = (from s in db.tbDonSanXuat_Averies where s.SO == dr["SO"].ToString() select s).Single();
                            dsx.PO = dr["PO"].ToString();
                        }

                        //var so = gridView1.GetRowCellValue(i, colSO).ToString();
                        //var lst = (from s in db.tbDonSanXuat_Averies where s.SO == so select s).ToList();
                        //if (lst.Count != 1) continue;
                        ////lst.ForEach(x => { x.PO = gridView1.GetRowCellValue(i, colPO).ToString();});
                        //foreach (var item in lst)
                        //{
                        //    item.PO = gridView1.GetRowCellValue(i, colPO).ToString();
                        //    break;
                        //}
                    }
                }
                else if (flagluu == 3)
                {
                    for (var i = 0; i < gridView1.RowCount - 1; i++)
                    {
                        var dr = gridView1.GetDataRow(i);
                        if (dr.RowState == DataRowState.Modified)
                        {
                            var dsx = (from s in db.tbDonSanXuat_Averies where s.SO == dr["SO"].ToString() select s).Single();
                            dsx.Note = dr["Note"].ToString();
                        }
                        //var so = gridView1.GetRowCellValue(i, colSO).ToString();
                        //var lst = (from s in db.tbDonSanXuat_Averies where s.SO == so select s).ToList();
                        //if (lst.Count != 1) continue;
                        //foreach (var item in lst)
                        //{
                        //    item.Note = gridView1.GetRowCellValue(i, colNote).ToString();
                        //    break;
                        //}
                    }
                }

                db.SubmitChanges();
            }
            catch (Exception exception)
            {
                MessageBox.Show("lỗi " + exception);
                //Console.WriteLine(exception);
                //throw;
            }
            //try
            //{
            //    if (XtraMessageBox.Show("Bạn có muốn lưu dữ liệu không", "Cảnh báo", MessageBoxButtons.YesNo,
            //            MessageBoxIcon.Question) != DialogResult.Yes) return;
            //    var db = new MyDBContextDataContext();
            //    var dem = 0;
            //    if (flagluu == 1)
            //    {
            //        for (var i = 0; i < gridView1.RowCount - 1; i++)
            //        {
            //            var so = gridView1.GetRowCellValue(i, colSO).ToString();
            //            var lst = (from s in db.tbDonSanXuat_Averies where s.SO == so select s).ToList();
            //            if (lst.Count == 0)
            //            {
            //                var dsxAvery = new tbDonSanXuat_Avery();
            //                dsxAvery.SO = gridView1.GetRowCellValue(i, colSO).ToString();
            //                dsxAvery.OrderDate =
            //                    Convert.ToDateTime(gridView1.GetRowCellValue(i, colOrderDate).ToString());
            //                dsxAvery.RequestDate =
            //                    Convert.ToDateTime(gridView1.GetRowCellValue(i, colRequestDate).ToString());
            //                dsxAvery.No = Convert.ToInt32(gridView1.GetRowCellValue(i, colNo).ToString());
            //                dsxAvery.RBO = gridView1.GetRowCellValue(i, colRBO).ToString();
            //                dsxAvery.CustomerPO = gridView1.GetRowCellValue(i, colCustomerPO).ToString();
            //                dsxAvery.CustomerItem = gridView1.GetRowCellValue(i, colCustomerItem).ToString();
            //                dsxAvery.Item = gridView1.GetRowCellValue(i, colItem).ToString();
            //                dsxAvery.Qty = Convert.ToInt32(gridView1.GetRowCellValue(i, colQty).ToString());
            //                dsxAvery.Material = gridView1.GetRowCellValue(i, colMaterial).ToString();
            //                dsxAvery.Length = Convert.ToDouble(gridView1.GetRowCellValue(i, colLength).ToString());
            //                dsxAvery.MaterialQty =
            //                    Convert.ToDouble(gridView1.GetRowCellValue(i, colMaterialQty).ToString());
            //                dsxAvery.SKU = Convert.ToInt32(gridView1.GetRowCellValue(i, colSKU).ToString());
            //                dsxAvery.Cut = gridView1.GetRowCellValue(i, colCut).ToString();
            //                dsxAvery.Fold = gridView1.GetRowCellValue(i, colFold).ToString();
            //                dsxAvery.GopDon = Convert.ToInt32(gridView1.GetRowCellValue(i, colGopDon).ToString());
            //                dsxAvery.NhanVien = gridView1.GetRowCellValue(i, colNhanVien).ToString();
            //                dsxAvery.DanhSach =
            //                    Convert.ToInt32(gridView1.GetRowCellValue(i, colDanhSach).ToString());
            //                db.tbDonSanXuat_Averies.InsertOnSubmit(dsxAvery);
            //            }
            //            else
            //            {
            //                MessageBox.Show("SO: {0} đã tồn tại , vui lòng xem lại", so);
            //                dem = dem + 1;
            //            }

            //            if (dem == 3)
            //            {
            //                MessageBox.Show("Đã có 3 SO trùng nên hệ thống sẽ dừng lại");
            //                break;
            //            }
            //        }
            //    }
            //    else if (flagluu == 2)
            //    {
            //        for (var i = 0; i < gridView1.RowCount - 1; i++)
            //        {
            //            var so = gridView1.GetRowCellValue(i, colSO).ToString();
            //            var lst = (from s in db.tbDonSanXuat_Averies where s.SO == so select s).ToList();
            //            if (lst.Count != 1) continue;
            //            //lst.ForEach(x => { x.PO = gridView1.GetRowCellValue(i, colPO).ToString();});
            //            foreach (var item in lst)
            //            {
            //                item.PO = gridView1.GetRowCellValue(i, colPO).ToString();
            //                break;
            //            }

            //            //var dsxAvery = db.tbDonSanXuat_Averies.ToList().Exists(s => s.SO == so);
            //            //if(dsxAvery == false)
            //            //    foreach (var VARIABLE in dsxAvery)
            //            //    {

            //            //    }

            //        }
            //    }
            //    else if (flagluu == 3)
            //    {
            //        //DataSet ds = new DataSet();
            //        //DataTable dt = ds.Tables["tbDonSanXuat_Avery"];
            //        for (var i = 0; i < gridView1.RowCount - 1; i++)
            //        {
            //            var so = gridView1.GetRowCellValue(i, colSO).ToString();
            //            var lst = (from s in db.tbDonSanXuat_Averies where s.SO == so select s).ToList();
            //            if (lst.Count != 1) continue;
            //            foreach (var item in lst)
            //            {
            //                item.Note = gridView1.GetRowCellValue(i, colNote).ToString();
            //                break;
            //            }
            //        }
            //    }

            //    db.SubmitChanges();
            //}
            //catch (Exception exception)
            //{
            //    MessageBox.Show("lỗi " + exception);
            //    //Console.WriteLine(exception);
            //    //throw;
            //}
        }