Ejemplo n.º 1
0
        /// <summary>
        /// 从System.Data.DataTable导入数据到数据库
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        private int InsertData(DataTable dt)
        {
            int      i = 0;
            string   cmonth = dateTimePickerMonth.Text;
            string   mat_code = "", mat_name = "";
            decimal  price = 0;
            DateTime begin_date, end_date;
            ConnDB   conn = new ConnDB();
            bool     err  = false;

            foreach (DataRow dr in dt.Rows)
            {
                if (dr["料号"].ToString().Trim() == null || dr["料号"].ToString().Trim() == "")
                {
                    MessageBox.Show("料号格式有错误!");
                    err = true;
                    break;
                }
                else if (dr["价格开始日期"].ToString().Trim() == null || dr["价格开始日期"].ToString().Trim() == "")
                {
                    MessageBox.Show("价格开始日期格式有错误!");
                    err = true;
                    break;
                }
                else if (dr["价格结束日期"].ToString().Trim() == null || dr["价格结束日期"].ToString().Trim() == "")
                {
                    MessageBox.Show("价格结束日期格式有错误!");
                    err = true;
                    break;
                }
            }
            if (!err)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    mat_code   = dr["料号"].ToString().Trim();
                    mat_name   = dr["物料名称"].ToString().Trim();
                    price      = Common.StrToDecimal(dr["单价"].ToString().Trim());
                    begin_date = Convert.ToDateTime(dr["价格开始日期"].ToString().Trim());
                    end_date   = Convert.ToDateTime(dr["价格结束日期"].ToString().Trim());
                    string sql = string.Format("Insert into COST_MATL_PRICE(MATL_NO,MATL_NAME,PRICE,BEGIN_DATE,END_DATE) Values ('{0}','{1}','{2}','{3}',{4})", mat_code, mat_name, price, begin_date, end_date);
                    conn.EditDatabase(sql);
                    i++;
                }
            }

            return(i);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 从System.Data.DataTable导入数据到数据库
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        private int InsertData(DataTable dt)
        {
            int     i              = 0;
            string  cmonth         = dateTimePickerMonth.Text;
            string  mat_code       = "";
            string  customer       = "";
            string  product_model  = "";
            decimal standard_hours = 0;
            ConnDB  conn           = new ConnDB();
            bool    err            = false;

            foreach (DataRow dr in dt.Rows)
            {
                if (dr["新物料编码"].ToString().Trim() == null || dr["新物料编码"].ToString().Trim() == "")
                {
                    MessageBox.Show("新物料编码格式有错误!");
                    err = true;
                    break;
                }
            }
            if (!err)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    mat_code       = dr["新物料编码"].ToString().Trim();
                    customer       = dr["客户"].ToString().Trim();
                    product_model  = dr["产品型号"].ToString().Trim();
                    standard_hours = Common.StrToDecimal(dr["标准单机工时"].ToString().Trim());
                    string sql = string.Format("Insert into COST_HH_STANDARD_HOURS(CMONTH,MAT_CODE,CUSTOMER,PRODUCT_MODEL,STANDARD_HOURS) Values ('{0}','{1}','{2}','{3}',{4})", cmonth, mat_code, customer, product_model, standard_hours);
                    conn.EditDatabase(sql);
                    i++;
                }
            }

            return(i);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 从System.Data.DataTable导入数据到数据库
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        private int InsertData(DataTable dt)
        {
            int      i = 0;
            string   cmonth = dateTimePickerMonth.Text;
            string   mat_code = "", mat_name = "";
            string   sql, sql2, msg;
            decimal  price = 0;
            DateTime begin_date, end_date;
            ConnDB   conn = new ConnDB();
            DataSet  ds;
            bool     err = false;

            foreach (DataRow dr in dt.Rows)
            {
                sql2 = "select price from COST_MATL_PRICE where matl_no ='" + dr["料号"].ToString().Trim() + "' and not (begin_date > '" + dr["价格结束日期"].ToString().Trim() + "' or end_date <'" + dr["价格开始日期"].ToString().Trim() + "')";
                //rows = conn.ReturnRecordCount(sql2);
                ds = conn.ReturnDataSet(sql2);
                if (dr["料号"].ToString().Trim() == null || dr["料号"].ToString().Trim() == "")
                {
                    MessageBox.Show("料号格式有错误!");
                    err = true;
                    break;
                }
                else if (dr["价格开始日期"].ToString().Trim() == null || dr["价格开始日期"].ToString().Trim() == "")
                {
                    MessageBox.Show("价格开始日期格式有错误!");
                    err = true;
                    break;
                }
                else if (dr["价格结束日期"].ToString().Trim() == null || dr["价格结束日期"].ToString().Trim() == "")
                {
                    MessageBox.Show("价格结束日期格式有错误!");
                    err = true;
                    break;
                }
                else if (ds.Tables[0].Rows.Count > 0)
                {
                    msg = dr["料号"].ToString().Trim() + "已存在重叠时间范围的价格信息!";
                    MessageBox.Show(msg);
                    showDetail(ds);
                    err = true;
                    break;
                }
            }
            if (!err)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    mat_code   = dr["料号"].ToString().Trim();
                    mat_name   = dr["物料名称"].ToString().Trim();
                    price      = Common.StrToDecimal(dr["单价"].ToString().Trim());
                    begin_date = Convert.ToDateTime(dr["价格开始日期"].ToString().Trim());
                    end_date   = Convert.ToDateTime(dr["价格结束日期"].ToString().Trim());
                    sql        = string.Format("Insert into COST_MATL_PRICE(MATL_NO,MATL_NAME,PRICE,BEGIN_DATE,END_DATE) Values ('{0}','{1}','{2}','{3}',{4})", mat_code, mat_name, price, begin_date, end_date);
                    conn.EditDatabase(sql);
                    i++;
                }
            }

            return(i);
        }