コード例 #1
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            string         filePath = "";
            OpenFileDialog ofd      = new OpenFileDialog();

            ofd.Multiselect = false;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                filePath = ofd.FileName;
            }
            else
            {
                return;
            }

            DataTable dt = TextUtils.ExcelToDatatableNoHeader(filePath, "Sheet1");

            dt.Rows.RemoveAt(0);
            dt.Rows.RemoveAt(0);
            int count = 0;

            DataTable dtError = new DataTable();

            dtError.Columns.Add("STT");
            dtError.Columns.Add("PartsCode");
            dtError.Columns.Add("PartsName");
            dtError.Columns.Add("IsPart", typeof(int));
            dtError.Columns.Add("IsPartGereral", typeof(int));

            DataTable dtPartsGeneral = LibQLSX.Select("select PartsCode from [vPartsGeneral]");
            DataTable dtParts        = LibQLSX.Select("select PartsCode from [Parts] where PartsCode is not null and PartsCode <> ''");

            foreach (DataRow row in dt.Rows)
            {
                string partsCode = TextUtils.ToString(row["F2"]);
                if (partsCode == "")
                {
                    continue;
                }
                string  name           = TextUtils.ToString(row["F1"]);
                string  unit           = TextUtils.ToString(row["F4"]);
                string  hang           = TextUtils.ToString(row["F5"]);
                decimal qtyMin         = TextUtils.ToDecimal(row["F6"]);
                decimal price          = TextUtils.ToDecimal(row["F7"]);
                decimal qty            = TextUtils.ToDecimal(row["F9"]);
                decimal total          = TextUtils.ToDecimal(row["F9"]);
                decimal projectPercent = TextUtils.ToDecimal(row["F10"]);
                int     type           = TextUtils.ToInt(row["F11"]);
                int     isProject      = TextUtils.ToInt(row["F12"]);

                PartAccessoriesModel model = new PartAccessoriesModel();
                model.Code           = partsCode;
                model.Name           = name;
                model.Hang           = hang;
                model.IsProject      = isProject;
                model.Price          = price;
                model.ProjectPercent = projectPercent;
                model.Qty            = qty;
                model.QtyDM          = 0;
                model.QtyMin         = qtyMin;
                model.Total          = total;
                model.Type           = type;
                model.Unit           = unit;
                PartAccessoriesBO.Instance.Insert(model);
                count++;
            }

            //foreach (DataRow row in dt.Rows)
            //{
            //    string partsCode = TextUtils.ToString(row["F3"]);
            //    if (partsCode == "") continue;
            //    DataRow[] drsG = dtPartsGeneral.Select("PartsCode = '" + partsCode + "'");
            //    DataRow[] drsP = dtParts.Select("PartsCode = '" + partsCode + "'");
            //    DataRow dr = dtError.NewRow();
            //    dr["STT"] = TextUtils.ToString(row["F1"]);
            //    dr["PartsCode"] = partsCode;
            //    dr["PartsName"] = TextUtils.ToString(row["F2"]);
            //    dr["IsPart"] = drsP.Length > 0 ? 1 : 0;
            //    dr["IsPartGereral"] = drsG.Length > 0 ? 1 : 0;
            //    dtError.Rows.Add(dr);
            //    count++;
            //}
            //TextUtils.DatatableToCSV(dtError, "D:\\1.csv");
            MessageBox.Show(count.ToString());
            LoadInfoSearch();
        }
コード例 #2
0
 protected PartAccessoriesFacade(PartAccessoriesModel model) : base(model)
 {
 }