Beispiel #1
0
 public FPrint(rt_product product)
 {
     InitializeComponent();
     image = (Image)(pictureBox1.Image).Clone();
     this.product = product;
 }
Beispiel #2
0
 /// <summary>
 /// 产品属性复制给打印对象 包含 part_No name model img_id img remark capacity 共7项
 /// </summary>
 /// <param name="printObj"></param>
 /// <param name="productObj"></param>
 private void CopyProductToPrintLog(rt_print_log printObj, rt_product productObj)
 {
     printObj.capacity = productObj.capacity;
     printObj.part_No = productObj.part_No;
     printObj.name = productObj.name;
     printObj.model = productObj.model;
     printObj.img_id = productObj.img_id;
     printObj.img = productObj.img;
     printObj.remark = productObj.remark;
 }
Beispiel #3
0
 private void DrawPictureBox(rt_product product, Graphics g,DateTime dt)
 {
     rt_print_log printObj = new rt_print_log();
     this.CopyProductToPrintLog(printObj, this.product);
     printObj.production_date = dt;
     printObj.container_No = 1;
     this.DrawSingle(printObj, g, 0);
 }
Beispiel #4
0
        private bool isOK(rt_product p)
        {
            if (p.part_No.Length == 0) return false;
            if (p.part_No.Length > 20) return false;
            if (p.name.Length > 30) return false;
            if (p.model.Length > 10) return false;
            if (p.capacity < 0) return false;
            if (p.capacity > 999) return false;

            Regex r = new Regex(@"^[\sa-zA-Z0-9-]{1,20}$");
            if (r.IsMatch(p.part_No) == false)
                return false;

            Regex r2 = new Regex(@"^[.\sa-zA-Z0-9-]{1,10}$");
            if (r2.IsMatch(p.model) == false)
                return false;
            return true;
        }
Beispiel #5
0
        private void ImportExcel(string excelPath)
        {
            rt_product pForErrorInfo = new rt_product();
            int error=0;
            bool isError = false;
            try
            {
                IWorkbook wb = WorkbookFactory.Create(excelPath);

                ISheet ist = wb.GetSheetAt(0);
                int rowofPage = ist.LastRowNum + 1;
                using (var db = PublicDB.getDB())
                {
                    for (int j = 1; j < rowofPage; j++)
                    {
                        error = j;
                        IRow irow = ist.GetRow(j);

                        if (irow == null) continue;

                        string partNo = irow.GetCell(0).StringCellValue;
                        if (partNo.Length < 4) continue;

                        var result = (from a in db.rt_product
                                      where a.part_No.Equals(partNo) && a.deleted == 0
                                      select a).FirstOrDefault();
                        if (result == null)
                        {
                            rt_product p = new rt_product();
                            p.id = Guid.NewGuid();
                            p.part_No = ((string)irow.GetCell(0).StringCellValue).ToUpper();
                            p.name = irow.GetCell(1).StringCellValue;
                            p.model = irow.GetCell(2).StringCellValue.ToUpper();
                            try {
                                p.capacity = (int)(PublicTools.GetCellNumic(irow, 4));
                            }
                            catch
                            {
                                p.capacity = 0;

                            }
                            p.deleted = 0;
                            p.remark = "";
                            p.modify_time = DateTime.Now;
                            pForErrorInfo = p;
                            if (isOK(p) == false)
                            {
                                isError = true;
                                break;

                            }
                            db.rt_product.Add(p);
                            db.SaveChanges();

                        }
                        else
                        {
                            result.part_No = partNo.ToUpper();
                            result.name = irow.GetCell(1).StringCellValue;
                            result.model = irow.GetCell(2).StringCellValue.ToUpper();
                            result.capacity = (int)(PublicTools.GetCellNumic(irow, 4));
                            result.deleted = 0;
                            result.remark = "";
                            result.modify_time = DateTime.Now;
                            pForErrorInfo = result;
                            if (isOK(result) == false)
                            {
                                isError = true;
                                break;
                            }
                            db.Entry(result).State = System.Data.Entity.EntityState.Modified;

                            db.SaveChanges();

                        }

                    }
                }
            }
            catch
            {
                isError = true;

            }
            if (isError )
            {
                string errorInfo = "";
                if (error > 0)
                {
                    errorInfo = string.Format("导入失败,第{0}行,编号为{1}", error, pForErrorInfo.part_No);
                }
                else
                {
                    errorInfo = "导入文件打开错误,是否已被打开占用?";
                }
                MessageBox.Show(errorInfo);
            }
        }
Beispiel #6
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            using (var db = PublicDB.getDB())
            {
                db.Configuration.EnsureTransactionsForFunctionsAndCommands = true;
                rt_product s = new rt_product();
                s.part_No = txbPartNoForSearch.Text;
                s.name = txbNameForSearch.Text;
                s.model = txbModelForSearch.Text;
                try
                {
                    var query = from q in db.rt_product
                                where q.deleted == 0 && (q.part_No.StartsWith(s.part_No) && q.name.StartsWith(s.name) && q.model.StartsWith(s.model))
                                orderby q.modify_time descending
                                select q;
                    if (query != null && query.Count() > 0)
                    {
                        bdsProduct.DataSource = query.ToArray();
                        PublicTools.RecountRowsNum(dataGridView1);
                    }
                    else
                    {
                        bdsProduct.DataSource = new List<rt_product>();

                        MessageBox.Show("没有查到相关记录");
                    }
                }
                catch (Exception ee)
                {
                    MessageBox.Show("数据库连接失败,请检查网络或配置. "+ee.Message);
                }
            }
        }
Beispiel #7
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txbPart_No.Text.Trim().Length == 0)
            {
                MessageBox.Show("零件编号字段不可为空");
                txbPart_No.Focus();
                txbPart_No.SelectAll();
                return;
            }
            if (txbName.Text.Trim().Length == 0)
            {
                MessageBox.Show("产品名称字段不可为空");
                txbName.Focus();
                txbName.SelectAll();
                return;
            }

            if (txbModel.Text.Trim().Length == 0)
            {
                MessageBox.Show("车型字段不可为空");
                txbModel.Focus();
                txbModel.SelectAll();
                return;
            }
            if (txbCapacity.Text.Trim().Length ==0)
            {
                MessageBox.Show("收容数范围为1-999,请检查");

                txbCapacity.SelectAll();
                txbCapacity.Focus();
                return;
            }

            using (var db = PublicDB.getDB())
            {

                rt_product p = new rt_product();
                p.part_No = txbPart_No.Text;
                p.model = txbModel.Text;
                p.name = txbName.Text;
                p.capacity = int.Parse(txbCapacity.Text);
                p.modify_time = DateTime.Now;
                p.deleted = 0;

                if (isOK(p) == false)
                {
                    MessageBox.Show("输入数值不和规范,请重新检查输入");
                    return;
                }

                if (pictureBox1.Image != null)
                {

                    p.img = PublicTools.imageToByteArray(pictureBox1.Image);

                }

                var q = (from a in db.rt_product
                         where a.part_No == p.part_No && a.deleted == 0
                         select a).FirstOrDefault();
                if (q == null)
                {
                    p.id = System.Guid.NewGuid();
                    p.remark = "量产";
                    db.rt_product.Add(p);
                }
                else
                {

                    q.part_No = txbPart_No.Text;
                    q.model = p.model;
                    q.name = p.name;
                    q.capacity = p.capacity;
                    q.modify_time = DateTime.Now;
                    q.deleted = 0;
                    q.remark = p.remark;
                    q.img = p.img;
                    db.Entry(q).State = System.Data.Entity.EntityState.Modified;
                }

                db.SaveChanges();
            }
            txbPartNoForSearch.Text = txbPart_No.Text;
            txbNameForSearch.Text = "";
            txbModelForSearch.Text = "";

            btnClear_Click(null, null);

            btnSearch_Click(null, null);
        }
Beispiel #8
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            List<rt_product> q = new List<rt_product>();
            using (var db = PublicDB.getDB())
            {

                rt_product s = new rt_product();
                s.part_No = txbPartNoForSearch.Text;
                s.name = txbNameForSearch.Text;
                s.model = txbModelForSearch.Text;
                var query = from item in db.rt_product
                            where item.deleted == 0 && (item.part_No.Contains(s.part_No) && item.name.Contains(s.name) && item.model.Contains(s.model))
                            select item;
                if (query != null)
                {
                    q= query.ToList();
                }

            }

            string excelPath = Application.StartupPath + @"\\导出模板.xls";
            string copedExcelPath = string.Format("{0}\\{1}{2}", Application.StartupPath, DateTime.Now.ToString("MMddHHmmss"), ".xls");
            if (File.Exists(excelPath))
            {
                File.Copy(excelPath, copedExcelPath, true);
            }
            if (File.Exists(copedExcelPath) == false)
            {
                return;
            }

            IWorkbook wb = WorkbookFactory.Create(copedExcelPath);

            //第1页
            ISheet ist = wb.GetSheetAt(0);

            for (int i = 0; i < q.Count; i++)
            {
                IRow irow = ist.CreateRow(i + 1);
                ICell icell0 = irow.CreateCell(0);
                icell0.SetCellValue(q[i].part_No);
                ICell icell1 = irow.CreateCell(1);
                icell1.SetCellValue(q[i].name);
                ICell icell2 = irow.CreateCell(2);
                icell2.SetCellValue(q[i].model);
                ICell icell3 = irow.CreateCell(3);
                icell3.SetCellType(CellType.Numeric);
                icell3.SetCellValue(q[i].capacity);

            }
            foreach (var item in q)
            {

                using (FileStream fs = new FileStream(copedExcelPath, FileMode.Open))
                {

                    wb.Write(fs);
                }
            }

            System.Diagnostics.Process.Start(copedExcelPath);
        }