示例#1
0
 /// <summary> 点击导入销售订单事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ImporSaleOrder_Click(object sender, EventArgs e)
 {
     try
     {
         //导入销售订单时,先判断列表中是否存在采购计划单的信息,存在时不允许导入
         foreach (DataGridViewRow dr in gvPurchaseList.Rows)
         {
             if (dr.Cells["parts_code"].Value == null)
             {
                 continue;
             }
             string ImportType = dr.Cells["ImportType"].Value == null ? "" : dr.Cells["ImportType"].Value.ToString();
             if (ImportType == "采购计划单")
             {
                 MessageBoxEx.Show("订单中已经存在采购计划单的信息,不允许再次导入销售订单的信息!");
                 return;
             }
         }
         UCChooseSaleOrder frm = new UCChooseSaleOrder(string.Empty, "宇通采购订单");
         DialogResult result = frm.ShowDialog();
         if (result == DialogResult.OK)
         {
             List<PartsInfoClassBySaleOrder> List_PartInfo = frm.List_PartInfo;
             DataTable dt_SaleOrder = frm.dt_SaleOrder;
             if (List_PartInfo.Count > 0)
             {
                 for (int i = 0; i < List_PartInfo.Count; i++)
                 {
                     bool IsExist = false;//判断要导入的信息是否已经在列表中存在,默认是不存在
                     string sale_order_id = List_PartInfo[i].sale_order_id;
                     string ordercode = string.Empty;
                     string partscode = List_PartInfo[i].parts_code;
                     #region 获取引用单号
                     if (dt_SaleOrder != null && dt_SaleOrder.Rows.Count > 0)
                     {
                         for (int a = 0; a < dt_SaleOrder.Rows.Count; a++)
                         {
                             if (dt_SaleOrder.Rows[a]["sale_order_id"].ToString() == sale_order_id)
                             {
                                 ordercode = dt_SaleOrder.Rows[a]["order_num"].ToString();
                                 ordercode = string.IsNullOrEmpty(ordercode) ? sale_order_id : ordercode;
                                 break;
                             }
                         }
                     }
                     #endregion
                     #region 判断配件信息是否已经存在于列表
                     foreach (DataGridViewRow dr in gvPurchaseList.Rows)
                     {
                         if (dr.Cells["parts_code"].Value == null)
                         {
                             continue;
                         }
                         string relation_order = dr.Cells["relation_order"].Value == null ? "" : dr.Cells["relation_order"].Value.ToString();
                         if (dr.Cells["parts_code"].Value.ToString() == partscode && relation_order == ordercode)
                         {
                             IsExist = true;
                             break;
                         }
                     }
                     #endregion
                     #region 当不存在时,添加到配件列表中
                     if (!IsExist)
                     {
                         string wherestr = " sale_order_id='" + sale_order_id + "' and parts_code='" + partscode + "' and is_suspend=1 and isnull(finish_count,0)<isnull(business_count,0) and len(car_factory_code)>0 ";
                         DataTable dt = DBHelper.GetTable("查询销售订单配件表信息", "tb_parts_sale_order_p", "*", wherestr, "", "");
                         if (dt == null || dt.Rows.Count == 0)
                         {
                             break;
                         }
                         foreach (DataRow dr in dt.Rows)
                         {
                             //int RowsIndex = gvPurchaseList.Rows.Add();
                             int RowsIndex = gvPurchaseList.Rows.Count - 1;
                             DataGridViewRow dgvr = gvPurchaseList.Rows[RowsIndex];
                             GetGridViewRowByDrImport(dgvr, dr, ordercode, RowsIndex, "销售订单");
                         }
                         gvPurchaseList.Rows.Add(1);
                     }
                     #endregion
                     #region 当添加成功时,将销售订单状态设置成占用,使前置单据不可以编辑、删除
                     DataTable dt_is_occupy = DBHelper.GetTable("", "tb_parts_sale_order", "is_occupy", " order_num='" + ordercode + "'", "", "");
                     if (dt_is_occupy != null && dt_is_occupy.Rows.Count > 0)
                     {
                         string is_occupy = dt_is_occupy.Rows[0]["is_occupy"].ToString();
                         if (is_occupy == "0")
                         {
                             Dictionary<string, string> dicValue = new Dictionary<string, string>();
                             dicValue.Add("is_occupy", "1");//单据导入状态,0正常,1占用,2锁定(部分导入), 3锁定(全部导入)
                             DBHelper.Submit_AddOrEdit("修改销售订单的导入状态为占用", "tb_parts_sale_order", "order_num", ordercode, dicValue);
                         }
                     }
                     #endregion
                 }
             }
         }
     }
     catch (Exception ex)
     { }
 }
 /// <summary> 导入销售订单配件信息(销售收货)
 /// </summary>
 void ImportSaleOrderInfo()
 {
     try
     {
         UCChooseSaleOrder frm = new UCChooseSaleOrder(cust_id);
         DialogResult result = frm.ShowDialog();
         if (result == DialogResult.OK)
         {
             List<PartsInfoClassBySaleOrder> List_PartInfo = frm.List_PartInfo;
             DataTable dt_SaleOrder = frm.dt_SaleOrder;
             if (List_PartInfo.Count > 0)
             {
                 if (ddlorder_type.SelectedValue.ToString() == "1")
                 {
                     ImportType = "销售订单";
                 }
                 else if (ddlorder_type.SelectedValue.ToString() == "2" || ddlorder_type.SelectedValue.ToString() == "3")
                 {
                     ImportType = "销售开单";
                 }
                 for (int i = 0; i < List_PartInfo.Count; i++)
                 {
                     bool IsExist = false;//判断要导入的信息是否已经在列表中存在,默认是不存在
                     string sale_order_id = List_PartInfo[i].sale_order_id;
                     string ordercode = string.Empty;
                     string partscode = List_PartInfo[i].parts_code;
                     #region 获取引用单号
                     if (dt_SaleOrder != null && dt_SaleOrder.Rows.Count > 0)
                     {
                         for (int a = 0; a < dt_SaleOrder.Rows.Count; a++)
                         {
                             if (dt_SaleOrder.Rows[a]["sale_order_id"].ToString() == sale_order_id)
                             {
                                 ordercode = dt_SaleOrder.Rows[a]["order_num"].ToString();
                                 ordercode = string.IsNullOrEmpty(ordercode) ? sale_order_id : ordercode;
                                 break;
                             }
                         }
                     }
                     #endregion
                     #region 判断配件信息是否已经存在于列表
                     foreach (DataGridViewRow dr in gvPurchaseList.Rows)
                     {
                         string relation_order = dr.Cells["relation_order"].Value == null ? "" : dr.Cells["relation_order"].Value.ToString();
                         if (dr.Cells["parts_code"].Value.ToString() == partscode && relation_order == ordercode)
                         {
                             IsExist = true;
                             break;
                         }
                     }
                     #endregion
                     #region 当不存在时,添加到配件列表中
                     if (!IsExist)
                     {
                         DataTable dt = DBHelper.GetTable("查询销售订单配件表信息", "tb_parts_sale_order_p", "*", " sale_order_id='" + sale_order_id + "' and parts_code='" + partscode + "' and is_suspend=1 and finish_count<business_count ", "", "");
                         if (dt == null || dt.Rows.Count == 0)
                         {
                             break;
                         }
                         foreach (DataRow dr in dt.Rows)
                         {
                             int rowsindex = gvPurchaseList.Rows.Add();
                             DataGridViewRow dgvr = gvPurchaseList.Rows[rowsindex];
                             GetGridViewRowByDrImport(dgvr, dr, ordercode, "销售订单",rowsindex, ImportType);
                         }
                     }
                     #endregion
                     #region 当添加成功时,将销售订单状态设置成占用,使前置单据不可以编辑、删除
                     DataTable dt_is_occupy = DBHelper.GetTable("", "tb_parts_sale_order", "is_occupy", " order_num='" + ordercode + "'", "", "");
                     if (dt_is_occupy != null && dt_is_occupy.Rows.Count > 0)
                     {
                         string is_occupy = dt_is_occupy.Rows[0]["is_occupy"].ToString();
                         if (is_occupy == "0")
                         {
                             Dictionary<string, string> dicValue = new Dictionary<string, string>();
                             dicValue.Add("is_occupy", "1");//单据导入状态,0正常,1占用,2锁定(部分导入),3锁定(全部导入)
                             DBHelper.Submit_AddOrEdit("修改销售订单的导入状态为占用", "tb_parts_sale_order", "order_num", ordercode, dicValue);
                         }
                     }
                     #endregion
                 }
             }
         }
     }
     catch (Exception ex)
     { }
 }